[Opensrf-commits] r1803 - in trunk: include/opensrf src/libopensrf (scottmk)

svn at svn.open-ils.org svn at svn.open-ils.org
Fri Oct 2 15:02:29 EDT 2009


Author: scottmk
Date: 2009-10-02 15:02:25 -0400 (Fri, 02 Oct 2009)
New Revision: 1803

Modified:
   trunk/include/opensrf/osrf_json.h
   trunk/src/libopensrf/osrf_json_object.c
Log:
Change the return type of jsonObjectGetString so that it
is a pointer to const char, instead of to non-const char.

We don't want the calling code to be able to modify the innards
of the jsonObject, at least not by this back door.

I have already examined all uses of this function and modified
them where necessary to avoid compile problems.

M    include/opensrf/osrf_json.h
M    src/libopensrf/osrf_json_object.c


Modified: trunk/include/opensrf/osrf_json.h
===================================================================
--- trunk/include/opensrf/osrf_json.h	2009-10-02 16:34:12 UTC (rev 1802)
+++ trunk/include/opensrf/osrf_json.h	2009-10-02 19:02:25 UTC (rev 1803)
@@ -389,7 +389,7 @@
 
 unsigned long jsonObjectRemoveKey( jsonObject* dest, const char* key);
 
-char* jsonObjectGetString(const jsonObject*);
+const char* jsonObjectGetString(const jsonObject*);
 
 double jsonObjectGetNumber( const jsonObject* obj );
 

Modified: trunk/src/libopensrf/osrf_json_object.c
===================================================================
--- trunk/src/libopensrf/osrf_json_object.c	2009-10-02 16:34:12 UTC (rev 1802)
+++ trunk/src/libopensrf/osrf_json_object.c	2009-10-02 19:02:25 UTC (rev 1803)
@@ -668,8 +668,9 @@
 	detectably corrupted, or if the jsonObject to be traversed is of a type other than
 	JSON_HASH or JSON_ARRAY.
 
-	Once jsonIteratorNext has returned NULL, subsequent calls using the same iterator will
-	continue to return NULL.  There is no available function to start over at the beginning.
+	Once jsonIteratorNext has reached the end of the jsonObject that it is traversing,
+	subsequent calls using the same iterator will continue to return NULL.  There is no available
+	function to start over at the beginning.
 
 	The pointer returned, if not NULL, points to an internal element of the jsonObject being
 	traversed.  The calling code should @em not try to free it, but it may modify its contents.
@@ -819,12 +820,8 @@
 	If @a obj points to a jsonObject of type JSON_STRING or JSON_NUMBER, the returned value
 	points to the string stored internally (a numeric string in the case of a JSON_NUMBER).
 	Otherwise the returned value is NULL.
-
-	The returned pointer should be treated as a pointer to const.  In particular it should
-	@em not be freed.  In a future release, the returned pointer may indeed be a pointer
-	to const.
 */
-char* jsonObjectGetString(const jsonObject* obj) {
+const char* jsonObjectGetString(const jsonObject* obj) {
 	if(obj)
 	{
 		if( obj->type == JSON_STRING )



More information about the opensrf-commits mailing list