diff options
author | 2006-02-10 01:50:20 +1000 | |
---|---|---|
committer | 2006-02-10 01:50:20 +1000 | |
commit | d1c9bca2e9f0eaac2fb8e00e5ed07e8e2906bb02 (patch) | |
tree | 9de2b4fd732398afaebd00c732d8fe41762ac322 /halloc.c | |
parent | 49973b85dac4baf843b95ae22ffaed7f41ae43bc (diff) |
Another halloc:ification of fish. Halloc has been extended to allow registering function calls, this has allowed the creation of halloc-handled arraylists, stringbuffers, etc. More job parsing halloc-ification has reduced the error handling code to only a shadow of it's former self
darcs-hash:20060209155020-ac50b-e119c5293ce2368e252cfc01b98ab7c629fdd678.gz
Diffstat (limited to 'halloc.c')
-rw-r--r-- | halloc.c | 36 |
1 files changed, 19 insertions, 17 deletions
@@ -18,7 +18,6 @@ typedef struct halloc { array_list_t children; - array_list_t hchildren; long long data[0]; } halloc_t; @@ -30,49 +29,52 @@ static halloc_t *halloc_from_data( void *data ) void *halloc( void *context, size_t size ) -{ - +{ halloc_t *me, *parent; me = (halloc_t *)calloc( 1, sizeof(halloc_t) + size ); - + if( !me ) return 0; - + al_init( &me->children ); - + if( context ) { parent = halloc_from_data( context ); - al_push( &parent->hchildren, &me->data ); + al_push( &parent->children, &halloc_free ); + al_push( &parent->children, &me->data ); } - + return &me->data; } -void *halloc_register( void *context, void *data ) +void halloc_register_function( void *context, void (*func)(void *), void *data ) { halloc_t *me; if( !context ) - return data; + return; me = halloc_from_data( context ); + al_push( &me->children, func ); al_push( &me->children, data ); - return data; } - void halloc_free( void *context ) { halloc_t *me; + int i; + if( !context ) return; - + me = halloc_from_data( context ); - al_foreach( &me->hchildren, (void (*)(const void *))&halloc_free ); - al_foreach( &me->children, (void (*)(const void *))&free ); + for( i=0; i<al_get_count(&me->children); i+=2 ) + { + void (*func)(void *) = (void (*)(void *))al_get( &me->children, i ); + void * data = (void *)al_get( &me->children, i+1 ); + func( data ); + } al_destroy( &me->children ); - al_destroy( &me->hchildren ); free(me); } - |