From 702b8dc815caecba59a5c40697701ca6e7ef7637 Mon Sep 17 00:00:00 2001 From: miker Date: Mon, 7 Jan 2008 01:55:25 +0000 Subject: [PATCH] Two patch sets from Scott McKellar First: 1. I moved the macros OSRF_LIST_DEFAULT_SIZE and OSRF_LIST_INC_SIZE from the header into the implementation file. No other source files reference them, nor should they. 2. I moved the OSRF_LIST_MAX_SIZE macro into the implementation file as well, and then commented it out. It is nowhere referenced, but out of caution I preserved it like a fly in amber. 3. I removed a leading underscore from each of the struct names __osrfListStruct and __osrfListIteratorStruct. 4. I removed some obsolete comment text concerning osrfNewList(). 5. I deleted the declaration for __osrfListSetSize(), which is nowhere defined. 6. I made sure to explicitly initialize all struct members. 7. When allocating pointer arrays, I explicitly initialize all the pointers to NULL. 8. I rewrote osrfNewList() as a thin wrapper for osrfNewListSize(), to eliminate some duplication of code. Second: These patches eliminate the following identifiers, which have all been replaced by their camel-case equivalents: osrf_app_session_make_req osrf_app_session_destroy osrf_app_session_request_recv osrf_app_request osrf_system_get_transport_client osrf_system_bootstrap_client_resc git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@1205 9efc2488-bf62-4759-914b-345cdb29e865 --- include/opensrf/osrf_app_session.h | 10 +--------- include/opensrf/osrf_list.h | 22 +++++----------------- include/opensrf/osrf_system.h | 2 -- src/libopensrf/osrf_app_session.c | 19 +------------------ src/libopensrf/osrf_list.c | 30 ++++++++++++++++++++++-------- src/libopensrf/osrf_system.c | 13 ++----------- 6 files changed, 31 insertions(+), 65 deletions(-) diff --git a/include/opensrf/osrf_app_session.h b/include/opensrf/osrf_app_session.h index d2fb31e..d5d0b19 100644 --- a/include/opensrf/osrf_app_session.h +++ b/include/opensrf/osrf_app_session.h @@ -39,7 +39,6 @@ struct osrf_app_request_struct { timeout and set this variable back to false */ int reset_timeout; }; -typedef struct osrf_app_request_struct osrf_app_request; typedef struct osrf_app_request_struct osrfAppRequest; struct osrf_app_session_struct { @@ -116,10 +115,6 @@ int osrfAppSessionMakeRequest( osrfAppSession* session, const jsonObject* params, const char* method_name, int protocol, string_array* param_strings); -int osrf_app_session_make_req( - osrfAppSession* session, const jsonObject* params, - const char* method_name, int protocol, string_array* param_strings); - /** Sets the given request to complete state */ void osrf_app_session_set_complete( osrfAppSession* session, int request_id ); @@ -129,8 +124,6 @@ int osrf_app_session_request_complete( const osrfAppSession* session, int reques /** Does a recv call on the given request */ osrf_message* osrfAppSessionRequestRecv( osrfAppSession* session, int request_id, int timeout ); -osrf_message* osrf_app_session_request_recv( - osrfAppSession* session, int request_id, int timeout ); /** Removes the request from the request set and frees the reqest */ void osrf_app_session_request_finish( osrfAppSession* session, int request_id ); @@ -167,9 +160,8 @@ int osrf_app_session_queue_wait( osrfAppSession*, int timeout, int* recvd ); /** Disconnects (if client), frees any attached app_reuqests, removes the session from the * global session cache and frees the session. Needless to say, only call this when the - * session is completey done. + * session is completely done. */ -void osrf_app_session_destroy ( osrfAppSession* ); void osrfAppSessionFree( osrfAppSession* ); /* tells the request to reset it's wait timeout */ diff --git a/include/opensrf/osrf_list.h b/include/opensrf/osrf_list.h index f59669a..d740686 100644 --- a/include/opensrf/osrf_list.h +++ b/include/opensrf/osrf_list.h @@ -3,11 +3,6 @@ #include -#define OSRF_LIST_DEFAULT_SIZE 48 /* most opensrf lists are small... */ -#define OSRF_LIST_INC_SIZE 256 -#define OSRF_LIST_MAX_SIZE 10240 - - #define OSRF_LIST_GET_INDEX(l, i) (!l || i >= l->size) ? NULL: l->arrlist[i] /** @@ -16,20 +11,20 @@ then, it will be used on any item that needs to be freed, so don't mix data types in the list if you want magic freeing */ -struct __osrfListStruct { +struct _osrfListStruct { unsigned int size; /* how many items in the list including NULL items between non-NULL items */ void (*freeItem) (void* item); /* callback for freeing stored items */ void** arrlist; int arrsize; /* how big is the currently allocated array */ }; -typedef struct __osrfListStruct osrfList; +typedef struct _osrfListStruct osrfList; -struct __osrfListIteratorStruct { +struct _osrfListIteratorStruct { const osrfList* list; unsigned int current; }; -typedef struct __osrfListIteratorStruct osrfListIterator; +typedef struct _osrfListIteratorStruct osrfListIterator; osrfList* osrfNewListSize( unsigned int size ); @@ -55,9 +50,6 @@ void osrfListIteratorReset( osrfListIterator* itr ); /** Allocates a new list - @param compress If true, the list will compress empty slots on delete. If item positionality - is not important, then using this feature is reccomended to keep the list from growing indefinitely. - if item positionality is not important. @return The allocated list */ osrfList* osrfNewList(); @@ -81,7 +73,7 @@ void* osrfListPop( osrfList* list ); /** Puts the given item into the list at the specified position. If there - is already an item at the given position and the list has it's + is already an item at the given position and the list has its "freeItem" function defined, then it will be used to free said item. If no 'freeItem' callback is defined, then the displaced item will be returned; @@ -124,10 +116,6 @@ void* osrfListRemove( osrfList* list, unsigned int position ); */ int osrfListFind( const osrfList* list, void* addr ); - -void __osrfListSetSize( osrfList* list ); - - /** @return The number of non-null items in the list */ diff --git a/include/opensrf/osrf_system.h b/include/opensrf/osrf_system.h index 540e8d1..12243a4 100644 --- a/include/opensrf/osrf_system.h +++ b/include/opensrf/osrf_system.h @@ -26,7 +26,6 @@ int osrf_system_bootstrap_client( char* config_file, char* contextnode ); @return 1 on successs, 0 on failure. */ int osrfSystemBootstrapClientResc( char* configFile, char* contextNode, char* resource ); -int osrf_system_bootstrap_client_resc( char* config_file, char* contextnode, char* resource ); /** Bootstrap the server. @@ -39,7 +38,6 @@ int osrf_system_bootstrap_client_resc( char* config_file, char* contextnode, cha int osrfSystemBootstrap( char* hostName, char* configfile, char* contextNode ); transport_client* osrfSystemGetTransportClient( void ); -transport_client* osrf_system_get_transport_client( void ); /* disconnects and destroys the current client connection */ int osrf_system_disconnect_client(); diff --git a/src/libopensrf/osrf_app_session.c b/src/libopensrf/osrf_app_session.c index 2662822..58f477d 100644 --- a/src/libopensrf/osrf_app_session.c +++ b/src/libopensrf/osrf_app_session.c @@ -374,14 +374,6 @@ int osrfAppSessionMakeRequest( method_name, protocol, param_strings, NULL ); } -int osrf_app_session_make_req( - osrfAppSession* session, const jsonObject* params, - const char* method_name, int protocol, string_array* param_strings) { - - return osrfAppSessionMakeLocaleRequest(session, params, - method_name, protocol, param_strings, NULL); -} - static int osrfAppSessionMakeLocaleRequest( osrfAppSession* session, const jsonObject* params, const char* method_name, int protocol, string_array* param_strings, char* locale ) { @@ -635,12 +627,7 @@ int osrf_app_session_queue_wait( osrfAppSession* session, int timeout, int* recv /** Disconnects (if client) and removes the given session from the global session cache * ! This free's all attached app_requests ! */ -void osrfAppSessionFree( osrfAppSession* ses ) { - osrf_app_session_destroy( ses ); -} - - -void osrf_app_session_destroy( osrfAppSession* session ){ +void osrfAppSessionFree( osrfAppSession* session ){ if(session == NULL) return; osrfLogDebug(OSRF_LOG_MARK, "AppSession [%s] [%s] destroying self and deleting requests", @@ -658,10 +645,6 @@ void osrf_app_session_destroy( osrfAppSession* session ){ osrf_message* osrfAppSessionRequestRecv( osrfAppSession* session, int req_id, int timeout ) { - return osrf_app_session_request_recv( session, req_id, timeout ); -} -osrf_message* osrf_app_session_request_recv( - osrfAppSession* session, int req_id, int timeout ) { if(req_id < 0 || session == NULL) return NULL; osrfAppRequest* req = OSRF_LIST_GET_INDEX( session->request_queue, req_id ); diff --git a/src/libopensrf/osrf_list.c b/src/libopensrf/osrf_list.c index 2d37b02..a95691b 100644 --- a/src/libopensrf/osrf_list.c +++ b/src/libopensrf/osrf_list.c @@ -1,19 +1,28 @@ #include +#define OSRF_LIST_DEFAULT_SIZE 48 /* most opensrf lists are small... */ +#define OSRF_LIST_INC_SIZE 256 +//#define OSRF_LIST_MAX_SIZE 10240 + osrfList* osrfNewList() { - osrfList* list; - OSRF_MALLOC(list, sizeof(osrfList)); - list->arrsize = OSRF_LIST_DEFAULT_SIZE; - OSRF_MALLOC(list->arrlist, list->arrsize * sizeof(void*)); - return list; + return osrfNewListSize( OSRF_LIST_DEFAULT_SIZE ); } osrfList* osrfNewListSize( unsigned int size ) { osrfList* list; OSRF_MALLOC(list, sizeof(osrfList)); + list->size = 0; + list->freeItem = NULL; if( size <= 0 ) size = 16; list->arrsize = size; OSRF_MALLOC( list->arrlist, list->arrsize * sizeof(void*) ); + + // Nullify all pointers in the array + + int i; + for( i = 0; i < list->arrsize; ++i ) + list->arrlist[ i ] = NULL; + return list; } @@ -36,17 +45,22 @@ int osrfListPushFirst( osrfList* list, void* item ) { void* osrfListSet( osrfList* list, void* item, unsigned int position ) { if(!list || position < 0) return NULL; - int i; int newsize = list->arrsize; - void** newarr; while( position >= newsize ) newsize += OSRF_LIST_INC_SIZE; if( newsize > list->arrsize ) { /* expand the list if necessary */ + void** newarr; OSRF_MALLOC(newarr, newsize * sizeof(void*)); - for( i = 0; i < list->arrsize; i++ ) + + // Copy the old pointers, and nullify the new ones + + int i; + for( i = 0; i < list->arrsize; i++ ) newarr[i] = list->arrlist[i]; + for( ; i < newsize; i++ ) + newarr[i] = NULL; free(list->arrlist); list->arrlist = newarr; list->arrsize = newsize; diff --git a/src/libopensrf/osrf_system.c b/src/libopensrf/osrf_system.c index f3807bf..ca389f3 100644 --- a/src/libopensrf/osrf_system.c +++ b/src/libopensrf/osrf_system.c @@ -34,19 +34,10 @@ void osrfSystemIgnoreTransportClient() { osrfGlobalTransportClient = NULL; } -transport_client* osrf_system_get_transport_client( void ) { - return osrfGlobalTransportClient; -} - int osrf_system_bootstrap_client( char* config_file, char* contextnode ) { - return osrf_system_bootstrap_client_resc(config_file, contextnode, NULL); -} - -int osrfSystemBootstrapClientResc( char* config_file, char* contextnode, char* resource ) { - return osrf_system_bootstrap_client_resc( config_file, contextnode, resource ); + return osrfSystemBootstrapClientResc(config_file, contextnode, NULL); } - static int _osrfSystemInitCache( void ) { jsonObject* cacheServers = osrf_settings_host_value_object("/cache/global/servers/server"); @@ -295,7 +286,7 @@ static ChildNode* seek_child( pid_t pid ) { /*----------- End of routines to manage list of children --*/ -int osrf_system_bootstrap_client_resc( char* config_file, char* contextnode, char* resource ) { +int osrfSystemBootstrapClientResc( char* config_file, char* contextnode, char* resource ) { int failure = 0; -- 2.43.2