[open-ils-commits] r8550 - trunk/Open-ILS/src/c-apps

svn at svn.open-ils.org svn at svn.open-ils.org
Thu Jan 31 14:29:09 EST 2008


Author: miker
Date: 2008-01-31 14:01:25 -0500 (Thu, 31 Jan 2008)
New Revision: 8550

Modified:
   trunk/Open-ILS/src/c-apps/oils_dataloader.c
Log:
1. In main() we allocate a growing_buffer named "json".  I added a
line to free it.

2. In commitTransaction() and rollbackTransaction() I eliminated
a layer of jsonObjectClone(), along with the associated
jsonObjectFree().  Now we extract the string we want directly from
the original object without making an unnecessary copy.

3. I renamed the four macros starting with "E" so as to start
with "E_" instead.

4. All functions (other than main()) are now static, as are the three
variables that had been declared at global scope.



Modified: trunk/Open-ILS/src/c-apps/oils_dataloader.c
===================================================================
--- trunk/Open-ILS/src/c-apps/oils_dataloader.c	2008-01-31 18:56:38 UTC (rev 8549)
+++ trunk/Open-ILS/src/c-apps/oils_dataloader.c	2008-01-31 19:01:25 UTC (rev 8550)
@@ -12,20 +12,20 @@
 #define CSTORE "open-ils.cstore"
 #define APPNAME "oils_dataloader"
 
-#define ESUCCESS 0
-#define ECOMMITERROR -1
-#define ECOMMANDERROR -2
-#define EROLLBACKERROR -3
+#define E_SUCCESS 0
+#define E_COMMITERROR -1
+#define E_COMMANDERROR -2
+#define E_ROLLBACKERROR -3
 
-int sendCommand ( char* );
-int startTransaction ( );
-int commitTransaction ( );
-int rollbackTransaction ( );
+static int sendCommand ( const char* );
+static int startTransaction ( );
+static int commitTransaction ( );
+static int rollbackTransaction ( );
 
 
-osrfHash* mnames = NULL;
-osrfAppSession* session = NULL;
-char* trans_id = NULL;
+static osrfHash* mnames = NULL;
+static osrfAppSession* session = NULL;
+static char* trans_id = NULL;
 
 int main (int argc, char **argv) {
 	if( argc < 4 ) {
@@ -80,12 +80,12 @@
 		}
 		buffer_fadd(_method_name, ".%s", method);
 
-		char* m = buffer_data(_method_name);
+		char* m = buffer_release(_method_name);
 		osrfHashSet( mnames, m, classname );
 
 		osrfLogDebug(OSRF_LOG_MARK, "Constructed %s method named %s for %s", method, m, classname);
 
-		buffer_free(_method_name);
+		free(_fm);
 	}
 
 	free(config);
@@ -124,11 +124,11 @@
 					if (!rollbackTransaction()) {
 						osrfAppSessionFree(session);
 						osrfLogError(OSRF_LOG_MARK, "An error occured while attempting to complete a transaction");
-						return EROLLBACKERROR;
+						return E_ROLLBACKERROR;
 					}
 
 					osrfAppSessionFree(session);
-					return ECOMMANDERROR;
+					return E_COMMANDERROR;
 				}
 
 				counter++;
@@ -143,29 +143,30 @@
 		}
 	}
 
+	buffer_free(json);
+
 	// clean up, commit, go away
 	if (!commitTransaction()) {
 		osrfLogError(OSRF_LOG_MARK, "An error occured while attempting to complete a transaction");
 		osrfAppSessionFree(session);
-		return ECOMMITERROR;
+		return E_COMMITERROR;
 	}
 
 	osrfAppSessionFree(session);
 	free(method);
 
-	return ESUCCESS;
+	return E_SUCCESS;
 }
 
-int commitTransaction () {
+static int commitTransaction () {
 	int ret = 1;
-	jsonObject* data;
+	const jsonObject* data;
 	int req_id = osrfAppSessionMakeRequest( session, NULL, "open-ils.cstore.transaction.commit", 1, NULL );
 	osrf_message* res = osrfAppSessionRequestRecv( session, req_id, 5 );
-	if ( (data = jsonObjectClone(osrfMessageGetResult(res))) ) {
+	if ( (data = osrfMessageGetResult(res)) ) {
 		if(!(trans_id = jsonObjectGetString(data))) {
 			ret = 0;
 		}
-		jsonObjectFree(data);
 	} else {
 		ret = 0;
 	}
@@ -174,16 +175,15 @@
 	return ret;
 }
 
-int rollbackTransaction () {
+static int rollbackTransaction () {
 	int ret = 1;
-	jsonObject* data;
+	const jsonObject* data;
 	int req_id = osrfAppSessionMakeRequest( session, NULL, "open-ils.cstore.transaction.rollback", 1, NULL );
 	osrf_message* res = osrfAppSessionRequestRecv( session, req_id, 5 );
-	if ( (data = jsonObjectClone(osrfMessageGetResult(res))) ) {
+	if ( (data = osrfMessageGetResult(res)) ) {
 		if(!(trans_id = jsonObjectGetString(data))) {
 			ret = 0;
 		}
-		jsonObjectFree(data);
 	} else {
 		ret = 0;
 	}
@@ -192,7 +192,7 @@
 	return ret;
 }
 
-int startTransaction () {
+static int startTransaction () {
 	int ret = 1;
 	jsonObject* data;
 	int req_id = osrfAppSessionMakeRequest( session, NULL, "open-ils.cstore.transaction.begin", 1, NULL );
@@ -209,7 +209,7 @@
 	return ret;
 }
 
-int sendCommand ( char* json ) {
+static int sendCommand ( const char* json ) {
 	int ret = 1;
 	jsonObject* item = jsonParseString(json);
 



More information about the open-ils-commits mailing list