From owner-p4-projects@FreeBSD.ORG Sat Jul 14 07:38:20 2007 Return-Path: X-Original-To: p4-projects@freebsd.org Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id DBE3816A403; Sat, 14 Jul 2007 07:38:19 +0000 (UTC) X-Original-To: perforce@freebsd.org Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id B42AE16A400 for ; Sat, 14 Jul 2007 07:38:19 +0000 (UTC) (envelope-from andrew@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [69.147.83.41]) by mx1.freebsd.org (Postfix) with ESMTP id A53FB13C4A6 for ; Sat, 14 Jul 2007 07:38:19 +0000 (UTC) (envelope-from andrew@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.1/8.14.1) with ESMTP id l6E7cJ7m040130 for ; Sat, 14 Jul 2007 07:38:19 GMT (envelope-from andrew@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.1/8.14.1/Submit) id l6E7cJvJ040127 for perforce@freebsd.org; Sat, 14 Jul 2007 07:38:19 GMT (envelope-from andrew@freebsd.org) Date: Sat, 14 Jul 2007 07:38:19 GMT Message-Id: <200707140738.l6E7cJvJ040127@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to andrew@freebsd.org using -f From: Andrew Turner To: Perforce Change Reviews Cc: Subject: PERFORCE change 123472 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 14 Jul 2007 07:38:20 -0000 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 *);