From 0788e1f853cae7be12203116b0d277ab1d653afb Mon Sep 17 00:00:00 2001 From: solar Date: Sun, 5 Feb 2006 21:37:24 +0000 Subject: [PATCH] Fallback to static array as pre-main malloc() created problems. (_start calls atexit once.) --- functions/stdlib/atexit.c | 10 ++++------ functions/stdlib/exit.c | 16 +++++++++------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/functions/stdlib/atexit.c b/functions/stdlib/atexit.c index 1436356..0d61e32 100644 --- a/functions/stdlib/atexit.c +++ b/functions/stdlib/atexit.c @@ -12,20 +12,18 @@ #ifndef REGTEST -extern struct _PDCLIB_exitfunc_t * regstack; +extern void (*_PDCLIB_regstack[])( void ); +extern size_t _PDCLIB_regptr; int atexit( void (*func)( void ) ) { - struct _PDCLIB_exitfunc_t * regfunc = (struct _PDCLIB_exitfunc_t *)malloc( sizeof( struct _PDCLIB_exitfunc_t ) ); - if ( regfunc == NULL ) + if ( _PDCLIB_regptr == 0 ) { return -1; } else { - regfunc->func = func; - regfunc->next = regstack; - regstack = regfunc; + _PDCLIB_regstack[ --_PDCLIB_regptr ] = func; return 0; } } diff --git a/functions/stdlib/exit.c b/functions/stdlib/exit.c index 969b795..0d816a3 100644 --- a/functions/stdlib/exit.c +++ b/functions/stdlib/exit.c @@ -16,17 +16,19 @@ functions that had already been called at the time it was registered. */ -struct _PDCLIB_exitfunc_t * regstack = NULL; +/* TODO: 32 is guaranteed. This should be dynamic but ATM gives problems + with my malloc. +*/ +#define NUMBER_OF_SLOTS 40 + +void (*_PDCLIB_regstack[ NUMBER_OF_SLOTS ])( void ); +size_t _PDCLIB_regptr = NUMBER_OF_SLOTS; void exit( int status ) { - struct _PDCLIB_exitfunc_t * next = regstack; - while ( next != NULL ) + while ( _PDCLIB_regptr < NUMBER_OF_SLOTS ) { - next->func(); - regstack = next->next; - free( next ); - next = regstack; + _PDCLIB_regstack[ _PDCLIB_regptr++ ](); } _Exit( status ); } -- 2.40.0