[Opensrf-commits] r1303 - trunk/src/router

svn at svn.open-ils.org svn at svn.open-ils.org
Fri Apr 11 10:41:03 EDT 2008


Author: miker
Date: 2008-04-11 10:03:27 -0400 (Fri, 11 Apr 2008)
New Revision: 1303

Modified:
   trunk/src/router/osrf_router.c
Log:
Patch from Scott McKellar (with commentary on future plans):

This patch applies the const qualifier to several variables, each of
them a copy of the "current" member of an osrfHashIterator.

**********************

While this patch is pretty inconsequential on its own, it is part of a
larger plan to streamline the use of osrfHashIterators.

The "current" member points to a dynamically allocated string.  Every
time we advance the iterator, we free the string and allocate another
one to replace it.

My plan is to reuse the buffer whenever possible so as to reduce the
churning of memory through malloc() and free().  This approach will
require an additional member to keep track of the current capacity of
the buffer, rather like the "size" member of a growing_buffer.

It will also require that all code using osrfHashIterators treat the
"current" member as read-only.  If somebody frees and replaces the
buffer outside of the proper interface, then buffer management will
get very confused.

I doubt that any code does anything so perfidious, but I'm going
through the files to make sure.  Adding the const qualifier is an
easy way not only to verify that nothing bad is happening, but also
to make it less likely that something bad will happen in the future.



Modified: trunk/src/router/osrf_router.c
===================================================================
--- trunk/src/router/osrf_router.c	2008-04-11 12:13:59 UTC (rev 1302)
+++ trunk/src/router/osrf_router.c	2008-04-11 14:03:27 UTC (rev 1303)
@@ -128,7 +128,7 @@
 
 			while( (class = osrfHashIteratorNext(itr)) ) {
 
-				char* classname = itr->current;
+				const char* classname = itr->current;
 
 				if( classname && (class = osrfRouterFindClass( router, classname )) ) {
 
@@ -574,7 +574,7 @@
 	osrfHashIterator* itr = osrfNewHashIterator(router->classes);
 
 	while( (class = osrfHashIteratorNext(itr)) ) {
-		char* classname = itr->current;
+		const char* classname = itr->current;
 
 		if( classname && (class = osrfRouterFindClass( router, classname )) ) {
 			sockid = class->ROUTER_SOCKFD;
@@ -732,7 +732,7 @@
 		while( (class = osrfHashIteratorNext(class_itr)) ) {
 
 			jsonObject* class_res = jsonNewObjectType(JSON_HASH);
-			char* classname = class_itr->current;
+			const char* classname = class_itr->current;
 
 			osrfHashIterator* node_itr = osrfNewHashIterator(class->nodes);
 			while( (node = osrfHashIteratorNext(node_itr)) ) {
@@ -756,7 +756,7 @@
 		while( (class = osrfHashIteratorNext(class_itr)) ) {
 
 			count = 0;
-			char* classname = class_itr->current;
+			const char* classname = class_itr->current;
 
 			osrfHashIterator* node_itr = osrfNewHashIterator(class->nodes);
 			while( (node = osrfHashIteratorNext(node_itr)) ) {



More information about the opensrf-commits mailing list