# HG changeset patch # User Me@portablequad # Date 1329167506 28800 # Node ID 89d35be7a31e7d57158eb42fec82053c56d52314 # Parent 093cad17d9923e999680681a388c9bbabbc4a922 deprecated default brch diff -r 093cad17d992 -r 89d35be7a31e .brch__default --- a/.brch__default Sat Feb 11 18:00:56 2012 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -The default branch is for use with normal C code. Other branches specialize the library for use with VMS.. they may need VMS header files, and the working directory may be located at various different positions relative to the VMS implementation. \ No newline at end of file diff -r 093cad17d992 -r 89d35be7a31e .hgignore --- a/.hgignore Sat Feb 11 18:00:56 2012 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,3 +0,0 @@ -syntax: glob - -*.o diff -r 093cad17d992 -r 89d35be7a31e PrivateHash.c --- a/PrivateHash.c Sat Feb 11 18:00:56 2012 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,242 +0,0 @@ -/* - * Copyright 2009 OpenSourceStewardshipFoundation.org - * Licensed under GNU General Public License version 2 - * - * - * Author: seanhalle@yahoo.com - */ - -#include "PrivateHash.h" - - - HashTable * -makeHashTable( int numHashSlots, FreeEntryContentFnPtr freeFn ) - { HashTable * retTable; - retTable = malloc( sizeof( HashTable ) ); - - retTable->freeEntryContentFn = freeFn; - - retTable->entries = malloc( numHashSlots * sizeof(HashEntry *) ); - retTable->numEntries = 0; - retTable->tableSz = numHashSlots; - - nullOutTablesArray( retTable ); - - return retTable; - } - - void -doubleTableSize( HashTable *table ) - { int i, oldTableSz, newTableSz; - HashEntry *entry, *nextEntry, **oldEntries, **newEntries; - - oldTableSz = table->tableSz; - oldEntries = table->entries; - - newTableSz = 2 * oldTableSz + 1; - newEntries = malloc( newTableSz * sizeof(HashEntry *) ); - - table->tableSz = newTableSz; - table->entries = newEntries; - table->numEntries = 0; //about to add them all back! - - // move all the entries from old to new - for( i=0; i < oldTableSz; i++ ) - { if( oldEntries[i] != NULL ) - { entry = oldEntries[i]; - while( entry != NULL ) - { nextEntry = entry->next; - entry->next = NULL; - putEntryIntoTable( entry, table ); //does not allocate anything - entry = nextEntry; - } - } - } - } - -void -nullOutTablesArray( HashTable *table ) - { int i, tableSz; - tableSz = table->tableSz; - HashEntry ** entries = table->entries; - for( i = 0; i < tableSz; i++ ) - entries[ i ] = NULL; - } - -unsigned int -hashThisKey( char* s, int hashSz ) - { unsigned int h = 0; - unsigned int i; - hashkey_t* key = (hashkey_t*)s; - - for(i=0 ; ihashable[i] + h*31; - return h % hashSz; - } - -/*Need this to be separated out, for use in both getParam and putParam - */ -HashEntry * -getEntryFromTable( char *key, HashTable * table ) - { unsigned int - hashIndex = hashThisKey( key, table->tableSz ); - HashEntry* - hashEntry = table->entries[ hashIndex ]; - for( ; hashEntry != NULL; hashEntry = hashEntry->next ) - { - if( memcmp( hashEntry->key, key, sizeof(hashkey_t) ) == 0 ) - return hashEntry; - } - return NULL; - } - -void * -getValueFromTable( char *key, HashTable * table ) - { HashEntry *entry; - entry = getEntryFromTable( key, table ); - if( entry == NULL ) return NULL; - - return entry->content; - } - - -/*If key already has a value, clobber the old one and replace it - */ - int -addValueIntoTable( char* key, void *content, HashTable *table ) - { unsigned int hashIdx; - HashEntry* hashEntry; - - hashEntry = getEntryFromTable( key, table ); - if( hashEntry == NULL ) - { hashIdx = hashThisKey( key, table->tableSz ); - hashEntry = (HashEntry*) malloc( sizeof( HashEntry ) ); - if( hashEntry == NULL ) return 0; - hashEntry->key = malloc( sizeof(hashkey_t) ); - if( hashEntry->key == NULL ) return 0; - memcpy( hashEntry->key, key, sizeof(hashkey_t) ); - hashEntry->next = (table->entries)[hashIdx]; - (table->entries)[hashIdx] = hashEntry; - table->numEntries += 1; - if( table->tableSz < table->numEntries ) doubleTableSize( table ); - } - else - { (*(table->freeEntryContentFn))( hashEntry->content ); - } - hashEntry->content = content; - return 1; - } - - int -putEntryIntoTable( HashEntry *entry, HashTable *table ) - { unsigned int hashIdx; - HashEntry* testEntry; - - testEntry = getEntryFromTable( entry->key, table ); - if( testEntry == NULL ) - { hashIdx = hashThisKey( entry->key, table->tableSz ); - entry->next = (table->entries)[hashIdx]; - (table->entries)[hashIdx] = entry; - table->numEntries += 1; - if( table->tableSz < table->numEntries ) doubleTableSize( table ); - } - else - { (*(table->freeEntryContentFn))( testEntry->content ); - //being lazy -- will create bug in code that relies on having ptr to - // elem given to insert into table! - testEntry->content = entry->content; - entry->content = NULL; - freeHashEntryButNotContent( entry ); - } - return 1; - } - -/*Better version - */ - void -untested_putEntryIntoTable( HashEntry *entry, HashTable * table ) - { HashEntry *testEntry, *prevEntry = NULL; - unsigned int - hashIndex = hashThisKey( entry->key, table->tableSz ); - - testEntry = table->entries[ hashIndex ]; - for( ; testEntry != NULL; testEntry = testEntry->next ) - { if( memcmp( testEntry->key, entry->key, sizeof(hashkey_t)) == 0 ) - { if( prevEntry == NULL ) - { table->entries[hashIndex] = entry; - entry->next = testEntry->next; - } - else - { prevEntry->next = entry; - entry->next = testEntry->next; - } - freeHashEntryUsing( testEntry, table ); //frees content too! - return; - } - } - //wasn't found, so insert - entry->next = table->entries[hashIndex]; - table->entries[hashIndex] = entry; - } - - - - bool8 -deleteEntryFromTable( char *key, HashTable *table ) - { HashEntry *hashEntry; - HashEntry **addrOfHashEntryPtr; - unsigned int hashIndex; - - hashIndex = hashThisKey( key, table->tableSz ); - addrOfHashEntryPtr = &( table->entries[ hashIndex ] ); - hashEntry = *addrOfHashEntryPtr; - while( hashEntry != NULL ) - { if( memcmp( hashEntry->key, key, sizeof(hashkey_t) ) == 0 ) - { - *addrOfHashEntryPtr = hashEntry->next; - //TODO: Free the contents of entry? - freeHashEntryButNotContent( hashEntry ); - table->numEntries -= 1; - return TRUE; - } - addrOfHashEntryPtr = &( hashEntry->next ); - hashEntry = *addrOfHashEntryPtr; - } - return FALSE; - } - -void -freeHashTable( HashTable *table ) - { int i; - HashEntry *hashEntry, *temp, **entries; - - entries = table->entries; - for( i=0; i < table->tableSz; i++ ) - { if( entries[i] != NULL ) - { hashEntry = entries[i]; - while( hashEntry != NULL ) - { - temp = hashEntry->next; - freeHashEntryUsing( hashEntry, table ); - hashEntry = temp; - } - } - } - } - -void -freeHashEntryUsing( HashEntry *entry, HashTable *table ) - { - if( entry->content != NULL ) - (*(table->freeEntryContentFn))( entry->content ); - free( entry->key ); //was malloc'd above, so free it - free( entry ); - } - -void -freeHashEntryButNotContent( HashEntry *entry ) - { - free( entry->key ); //was malloc'd above, so free it - free( entry ); - } - diff -r 093cad17d992 -r 89d35be7a31e PrivateHash.h --- a/PrivateHash.h Sat Feb 11 18:00:56 2012 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,74 +0,0 @@ -/* - * Copyright 2009 OpenSourceStewardshipFoundation.org - * Licensed under GNU General Public License version 2 - * - * Author: seanhalle@yahoo.com - */ - -#ifndef _PRIVATE_HASH_H -#define _PRIVATE_HASH_H - - -#include -#include -#include -#include - -#define TRUE 1 -#define FALSE 0 - -union hashkey_t{ - char hashable[8]; - int parts[2]; -}; - -typedef union hashkey_t hashkey_t; - -#define DEFAULT_HASHSIZE 1 << 10 - -typedef struct _HashEntry HashEntry; - -struct _HashEntry - { - char *key; - void *content; - HashEntry *next; - }; - -typedef void (*FreeEntryContentFnPtr) ( void * ); - -typedef struct - { int tableSz; - int numEntries; - HashEntry* *entries; - FreeEntryContentFnPtr freeEntryContentFn; - } -HashTable; - - -//=========================================================================== -// Public functions -HashTable *makeHashTable( int numHashSlots, FreeEntryContentFnPtr freeFn ); - -int putEntryIntoTable( HashEntry *entry, HashTable *table); -int addValueIntoTable( char* key, void *value, HashTable *table); -HashEntry *getEntryFromTable( char *key, HashTable *table ); -void *getValueFromTable( char *key, HashTable *table ); - -bool8 deleteEntryFromTable( char *key, HashTable *table ); -bool8 deleteThisEntryFromTable( HashEntry *entry, HashTable *table ); -bool8 deleteEntrysValueInTable( char *key, HashTable *table ); -bool8 deleteEntryFromTableAndFreeValue( char *key, HashTable *table ); -void freeHashTable( HashTable *table ); -//char *paramBagToString( ParamBag * bag ) - -//=========================================================================== -// Internal functions -void freeHashEntryUsing( HashEntry *entry, HashTable *table ); -unsigned int hashThisKey( char *s, int hashSz ); -void nullOutTablesArray( HashTable *table ); -void doubleTableSize( HashTable *table ); -void freeHashEntryButNotContent( HashEntry *entry ); - -#endif /* _PRIVATE_HASH_H */ - diff -r 093cad17d992 -r 89d35be7a31e __brch__DEPRECATED_README --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/__brch__DEPRECATED_README Mon Feb 13 13:11:46 2012 -0800 @@ -0,0 +1,8 @@ + +There are two versions of the library -- one for pure C use, the other for use inside VMS or within applications written in a VMS-based language (IE, inside a top-level function or a call descendant of a top-level function) -- but only when the VMS is the "MC_shared" version. + +The reason is that VMS that uses shared memory on multicores moves the SlaveVPs around among cores. But, the libC and glibC malloc stores info at the top of the stack (a "clever" hack), for a speed improvement. So, when VMS manipulates the stack pointer, and/or moves Slaves to different cores, the "free" seg faults (that was FUN to figure out ; ) So, this version of VMS implements its own malloc. + +It is anticipated that the MC_split version, where each core has separate data, and messages are sent between cores, can handle malloc and free to use the glibC version. + +For now, update to the version of the library you wish to use..