Patch from Scott McKellar (with commentary on future plans):
authormiker <miker@9efc2488-bf62-4759-914b-345cdb29e865>
Fri, 11 Apr 2008 14:03:27 +0000 (14:03 +0000)
committermiker <miker@9efc2488-bf62-4759-914b-345cdb29e865>
Fri, 11 Apr 2008 14:03:27 +0000 (14:03 +0000)
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.

git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@1303 9efc2488-bf62-4759-914b-345cdb29e865

src/router/osrf_router.c

index 5a50041..dbeea1f 100644 (file)
@@ -128,7 +128,7 @@ void osrfRouterRun( osrfRouter* router ) {
 
                        while( (class = osrfHashIteratorNext(itr)) ) {
 
 
                        while( (class = osrfHashIteratorNext(itr)) ) {
 
-                               char* classname = itr->current;
+                               const char* classname = itr->current;
 
                                if( classname && (class = osrfRouterFindClass( router, classname )) ) {
 
 
                                if( classname && (class = osrfRouterFindClass( router, classname )) ) {
 
@@ -574,7 +574,7 @@ static int _osrfRouterFillFDSet( osrfRouter* router, fd_set* set ) {
        osrfHashIterator* itr = osrfNewHashIterator(router->classes);
 
        while( (class = osrfHashIteratorNext(itr)) ) {
        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;
 
                if( classname && (class = osrfRouterFindClass( router, classname )) ) {
                        sockid = class->ROUTER_SOCKFD;
@@ -732,7 +732,7 @@ static int osrfRouterProcessAppRequest( osrfRouter* router, transport_message* m
                while( (class = osrfHashIteratorNext(class_itr)) ) {
 
                        jsonObject* class_res = jsonNewObjectType(JSON_HASH);
                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)) ) {
 
                        osrfHashIterator* node_itr = osrfNewHashIterator(class->nodes);
                        while( (node = osrfHashIteratorNext(node_itr)) ) {
@@ -756,7 +756,7 @@ static int osrfRouterProcessAppRequest( osrfRouter* router, transport_message* m
                while( (class = osrfHashIteratorNext(class_itr)) ) {
 
                        count = 0;
                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)) ) {
 
                        osrfHashIterator* node_itr = osrfNewHashIterator(class->nodes);
                        while( (node = osrfHashIteratorNext(node_itr)) ) {