From: miker Date: Sun, 30 Sep 2007 17:54:25 +0000 (+0000) Subject: Continued const-correctness improvement from Scott McKellar: X-Git-Tag: osrf_rel_2_0_1~871 X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=1d6d0446b3a3b5bee4077e7a22e9e176216ba5c3;p=OpenSRF.git Continued const-correctness improvement from Scott McKellar: 1. I changed the signature of jsonObjectDecodeClass so that it accepts a non-const pointer parameter. Since it doesn't change the contents of the jsonObject, there's no need to confine it to non-const jsonObjects. 2. I replaced jsonObjectGetKey() with jsonObjectGetKeyConst(). 3. In one spot I captured the return value of jsonObjectGetIndex() with a const pointer instead of a non-const pointer. git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@1095 9efc2488-bf62-4759-914b-345cdb29e865 --- diff --git a/include/opensrf/osrf_json.h b/include/opensrf/osrf_json.h index 9acb6e5..5243f03 100644 --- a/include/opensrf/osrf_json.h +++ b/include/opensrf/osrf_json.h @@ -355,7 +355,7 @@ jsonObject* jsonParseFile( char* filename ); * classname set * Caller must free the returned object */ -jsonObject* jsonObjectDecodeClass( jsonObject* obj ); +jsonObject* jsonObjectDecodeClass( const jsonObject* obj ); /** Converts an object with a classname into a diff --git a/src/libopensrf/osrf_json_tools.c b/src/libopensrf/osrf_json_tools.c index b37bd97..aaf65a5 100644 --- a/src/libopensrf/osrf_json_tools.c +++ b/src/libopensrf/osrf_json_tools.c @@ -75,21 +75,21 @@ char* jsonFormatString( const char* string ) { -jsonObject* jsonObjectDecodeClass( jsonObject* obj ) { +jsonObject* jsonObjectDecodeClass( const jsonObject* obj ) { if(!obj) return jsonNewObject(NULL); - jsonObject* newObj = NULL; - jsonObject* classObj = NULL; - jsonObject* payloadObj = NULL; + jsonObject* newObj = NULL; + const jsonObject* classObj = NULL; + const jsonObject* payloadObj = NULL; int i; if( obj->type == JSON_HASH ) { /* are we a special class object? */ - if( (classObj = jsonObjectGetKey( obj, JSON_CLASS_KEY )) ) { + if( (classObj = jsonObjectGetKeyConst( obj, JSON_CLASS_KEY )) ) { /* do we have a payload */ - if( (payloadObj = jsonObjectGetKey( obj, JSON_DATA_KEY )) ) { + if( (payloadObj = jsonObjectGetKeyConst( obj, JSON_DATA_KEY )) ) { newObj = jsonObjectDecodeClass( payloadObj ); jsonObjectSetClass( newObj, jsonObjectGetString(classObj) ); @@ -239,7 +239,7 @@ jsonObject* _jsonObjectFindPathRecurse(const jsonObject* obj, char* root, char* /* gather all of the sub-objects that match the full path */ for( i = 0; i < arr->size; i++ ) { - jsonObject* a = jsonObjectGetIndex(arr, i); + const jsonObject* a = jsonObjectGetIndex(arr, i); jsonObject* thing = jsonObjectFindPath(a , path + strlen(root) + 1); if(thing) { //jsonObjectPush(newarr, thing);