Date: Sat, 14 Jul 2007 07:38:19 GMT From: Andrew Turner <andrew@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 123472 for review Message-ID: <200707140738.l6E7cJvJ040127@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=123472 Change 123472 by andrew@andrew_hermies on 2007/07/14 07:38:14 Make the facund_object_get_* functions take in a const object Add facund_object_array_size to get the number of items in an array Don't use NULL for the first argument in the XML string returned in facund_object_xml_string Affected files ... .. //depot/projects/soc2007/andrew-update/lib/facund_object.c#7 edit .. //depot/projects/soc2007/andrew-update/lib/facund_object.h#5 edit Differences ... ==== //depot/projects/soc2007/andrew-update/lib/facund_object.c#7 (text+ko) ==== @@ -82,14 +82,17 @@ } int -facund_object_get_bool(struct facund_object *obj) +facund_object_get_bool(const struct facund_object *obj) { + struct facund_object *real_obj; + /* TODO: Change these to proper checks */ assert(obj != NULL); assert(obj->obj_type == FACUND_BOOL); assert(obj->obj_assigned == 1); - obj->obj_error = FACUND_OBJECT_ERROR_NONE; + real_obj = __DECONST(struct facund_object *, obj); + real_obj->obj_error = FACUND_OBJECT_ERROR_NONE; return obj->obj_int; } @@ -124,14 +127,17 @@ } int32_t -facund_object_get_int(struct facund_object *obj) +facund_object_get_int(const struct facund_object *obj) { + struct facund_object *real_obj; + /* TODO: Change these to proper checks */ assert(obj != NULL); assert(obj->obj_type == FACUND_INT); assert(obj->obj_assigned == 1); - obj->obj_error = FACUND_OBJECT_ERROR_NONE; + real_obj = __DECONST(struct facund_object *, obj); + real_obj->obj_error = FACUND_OBJECT_ERROR_NONE; return obj->obj_int; } @@ -166,14 +172,17 @@ } uint32_t -facund_object_get_uint(struct facund_object *obj) +facund_object_get_uint(const struct facund_object *obj) { + struct facund_object *real_obj; + /* TODO: Change these to proper checks */ assert(obj != NULL); assert(obj->obj_type == FACUND_UINT); assert(obj->obj_assigned == 1); - obj->obj_error = FACUND_OBJECT_ERROR_NONE; + real_obj = __DECONST(struct facund_object *, obj); + real_obj->obj_error = FACUND_OBJECT_ERROR_NONE; return (uint32_t)obj->obj_int; } @@ -220,14 +229,18 @@ } const char * -facund_object_get_string(struct facund_object *obj) +facund_object_get_string(const struct facund_object *obj) { + struct facund_object *real_obj; + /* TODO: Change these to proper checks */ assert(obj != NULL); assert(obj->obj_type == FACUND_STRING); assert(obj->obj_assigned == 1); - obj->obj_error = FACUND_OBJECT_ERROR_NONE; + real_obj = __DECONST(struct facund_object *, obj); + real_obj->obj_error = FACUND_OBJECT_ERROR_NONE; + return obj->obj_string; } @@ -246,7 +259,7 @@ int facund_object_array_append(struct facund_object *obj, - struct facund_object *item __unused) + struct facund_object *item) { struct facund_object **new; @@ -282,8 +295,10 @@ } const struct facund_object * -facund_object_get_array_item(struct facund_object *obj, unsigned int pos) +facund_object_get_array_item(const struct facund_object *obj, unsigned int pos) { + struct facund_object *real_obj; + /* TODO: Change these to proper checks */ assert(obj != NULL); assert(obj->obj_type == FACUND_ARRAY); @@ -291,10 +306,23 @@ if (pos >= obj->obj_array_count) return NULL; - obj->obj_error = FACUND_OBJECT_ERROR_NONE; + real_obj = __DECONST(struct facund_object *, obj); + real_obj->obj_error = FACUND_OBJECT_ERROR_NONE; return obj->obj_array[pos]; } +size_t +facund_object_array_size(const struct facund_object *obj) +{ + if (obj == NULL) + return 0; + + if (obj->obj_type != FACUND_ARRAY) + return 0; + + return obj->obj_array_count; +} + /* * Free an object and it's children */ @@ -384,7 +412,7 @@ } enum facund_object_error -facund_object_get_error(struct facund_object *obj) +facund_object_get_error(const struct facund_object *obj) { if (obj == NULL) { return FACUND_OBJECT_ERROR_NO_OBJECT; @@ -393,7 +421,7 @@ } enum facund_type -facund_object_get_type(struct facund_object *obj) +facund_object_get_type(const struct facund_object *obj) { return obj->obj_type; } @@ -438,7 +466,11 @@ /* Append the new data to the end of the data */ olddata = data; - asprintf(&data, "%s%s", data, tmpdata); + if (data == NULL) { + asprintf(&data, "%s", tmpdata); + } else { + asprintf(&data, "%s%s", data, tmpdata); + } free(olddata); } ==== //depot/projects/soc2007/andrew-update/lib/facund_object.h#5 (text+ko) ==== @@ -50,27 +50,28 @@ struct facund_object *facund_object_new_bool(void); int facund_object_set_bool(struct facund_object *, int); -int facund_object_get_bool(struct facund_object *); +int facund_object_get_bool(const struct facund_object *); struct facund_object *facund_object_new_int(void); int facund_object_set_int(struct facund_object *, int32_t); -int32_t facund_object_get_int(struct facund_object *); +int32_t facund_object_get_int(const struct facund_object *); struct facund_object *facund_object_new_uint(void); int facund_object_set_uint(struct facund_object *, uint32_t); -uint32_t facund_object_get_uint(struct facund_object *); +uint32_t facund_object_get_uint(const struct facund_object *); struct facund_object *facund_object_new_string(void); int facund_object_set_string(struct facund_object *, const char *); -const char *facund_object_get_string(struct facund_object *); +const char *facund_object_get_string(const struct facund_object *); struct facund_object *facund_object_new_array(void); int facund_object_array_append(struct facund_object *, struct facund_object *); -const struct facund_object *facund_object_get_array_item(struct facund_object *, - unsigned int); +const struct facund_object *facund_object_get_array_item( + const struct facund_object *, unsigned int); +size_t facund_object_array_size(const struct facund_object *); void facund_object_free(struct facund_object *); @@ -78,8 +79,8 @@ int facund_object_set_from_str(struct facund_object *, const char *); -enum facund_object_error facund_object_get_error(struct facund_object*); -enum facund_type facund_object_get_type(struct facund_object *); +enum facund_object_error facund_object_get_error(const struct facund_object*); +enum facund_type facund_object_get_type(const struct facund_object *); const char *facund_object_xml_string(struct facund_object *); void facund_object_print(struct facund_object *);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200707140738.l6E7cJvJ040127>