From 5d9e4c07a6a7c747c0c943503af676e792909411 Mon Sep 17 00:00:00 2001 From: Olaf Barthel Date: Wed, 29 Sep 2004 19:57:58 +0000 Subject: [PATCH] - The start time used by clock() is now initialized by a constructor function. - NOTE THAT ALL THE CHANGES WITH REGARD TO USE OF DESTRUCTOR AND CONSTRUCTOR FUNCTIONS REQUIRE A COMPLETE REBUILD OF THE LIBRARY! IF YOU DO NOT DO THIS, THE CONSTRUCTOR/DESTRUCTOR FUNCTIONS MAY NOT GET CALLED. git-svn-id: file:///Users/olsen/Code/migration-svn-zu-git/logical-line-staging/clib2/trunk@14744 87f5fb63-7c3d-0410-a384-fd976d0f7a62 --- library/changes | 8 +++ library/locale_headers.h | 8 +-- library/locale_init_exit.c | 12 ++-- library/macros.h | 4 +- library/math_init_exit.c | 6 +- library/stdlib_constructor_begin.c | 101 ++++++++--------------------- library/stdlib_locale_utility.h | 16 +++-- library/stdlib_main.c | 29 +++++++-- library/stdlib_startup.c | 6 +- library/time_clock.c | 22 ++++++- library/time_data.c | 6 +- library/time_headers.h | 6 +- library/unistd_chdir_exit.c | 8 +-- library/unistd_headers.h | 23 ++++--- library/unistd_init_exit.c | 4 +- library/unistd_timer.c | 12 ++-- library/unistd_wildcard_expand.c | 8 ++- library/usergroup_headers.h | 6 +- library/usergroup_init_exit.c | 10 +-- 19 files changed, 148 insertions(+), 147 deletions(-) diff --git a/library/changes b/library/changes index 92ca471..6794599 100644 --- a/library/changes +++ b/library/changes @@ -31,6 +31,14 @@ c.lib 1.177 (29.9.2004) - The socket exit code now calls the common stdio function which flushes and shuts down all buffered and unbuffered files. +- The start time used by clock() is now initialized by a constructor + function. + +- NOTE THAT ALL THE CHANGES WITH REGARD TO USE OF DESTRUCTOR AND + CONSTRUCTOR FUNCTIONS REQUIRE A COMPLETE REBUILD OF THE LIBRARY! IF + YOU DO NOT DO THIS, THE CONSTRUCTOR/DESTRUCTOR FUNCTIONS MAY NOT + GET CALLED. + c.lib 1.175 (10.9.2004) diff --git a/library/locale_headers.h b/library/locale_headers.h index 6023fd4..336d78c 100644 --- a/library/locale_headers.h +++ b/library/locale_headers.h @@ -1,5 +1,5 @@ /* - * $Id: locale_headers.h,v 1.1.1.1 2004-07-26 16:30:35 obarthel Exp $ + * $Id: locale_headers.h,v 1.2 2004-09-29 19:57:57 obarthel Exp $ * * :ts=4 * @@ -69,12 +69,12 @@ /****************************************************************************/ -extern struct Locale * __default_locale; -extern struct Locale * __locale_table[NUM_LOCALES]; +extern struct Locale * NOCOMMON __default_locale; +extern struct Locale * NOCOMMON __locale_table[NUM_LOCALES]; /****************************************************************************/ -extern char __locale_name_table[NUM_LOCALES][MAX_LOCALE_NAME_LEN]; +extern char NOCOMMON __locale_name_table[NUM_LOCALES][MAX_LOCALE_NAME_LEN]; /****************************************************************************/ diff --git a/library/locale_init_exit.c b/library/locale_init_exit.c index 48eab7e..c3557a1 100644 --- a/library/locale_init_exit.c +++ b/library/locale_init_exit.c @@ -1,5 +1,5 @@ /* - * $Id: locale_init_exit.c,v 1.2 2004-09-29 14:17:44 obarthel Exp $ + * $Id: locale_init_exit.c,v 1.3 2004-09-29 19:57:57 obarthel Exp $ * * :ts=4 * @@ -41,22 +41,22 @@ /****************************************************************************/ -struct Library * __LocaleBase; +struct Library * NOCOMMON __LocaleBase; /****************************************************************************/ #if defined(__amigaos4__) -struct LocaleIFace * __ILocale; +struct LocaleIFace * NOCOMMON __ILocale; #endif /* __amigaos4__ */ /****************************************************************************/ -struct Locale * __default_locale; -struct Locale * __locale_table[NUM_LOCALES]; +struct Locale * NOCOMMON __default_locale; +struct Locale * NOCOMMON __locale_table[NUM_LOCALES]; /****************************************************************************/ -char __locale_name_table[NUM_LOCALES][MAX_LOCALE_NAME_LEN]; +char NOCOMMON __locale_name_table[NUM_LOCALES][MAX_LOCALE_NAME_LEN]; /****************************************************************************/ diff --git a/library/macros.h b/library/macros.h index 1411f82..15c1fac 100644 --- a/library/macros.h +++ b/library/macros.h @@ -1,5 +1,5 @@ /* - * $Id: macros.h,v 1.1.1.1 2004-07-26 16:30:36 obarthel Exp $ + * $Id: macros.h,v 1.2 2004-09-29 19:57:57 obarthel Exp $ * * :ts=4 * @@ -148,8 +148,10 @@ #ifndef UNUSED #ifdef __GNUC__ #define UNUSED __attribute__((unused)) +#define NOCOMMON __attribute__((nocommon)) #else #define UNUSED /* UNUSED */ +#define NOCOMMON /* NOCOMMON */ #endif #endif /* UNUSED */ diff --git a/library/math_init_exit.c b/library/math_init_exit.c index ec2ced7..803315b 100644 --- a/library/math_init_exit.c +++ b/library/math_init_exit.c @@ -1,5 +1,5 @@ /* - * $Id: math_init_exit.c,v 1.4 2004-09-29 14:17:44 obarthel Exp $ + * $Id: math_init_exit.c,v 1.5 2004-09-29 19:57:57 obarthel Exp $ * * :ts=4 * @@ -55,6 +55,8 @@ CLIB_DESTRUCTOR(__math_exit) { + ENTER(); + #if defined(IEEE_FLOATING_POINT_SUPPORT) { if(MathIeeeSingBasBase != NULL) @@ -76,6 +78,8 @@ CLIB_DESTRUCTOR(__math_exit) } } #endif /* IEEE_FLOATING_POINT_SUPPORT */ + + LEAVE(); } /****************************************************************************/ diff --git a/library/stdlib_constructor_begin.c b/library/stdlib_constructor_begin.c index 1069a28..ea2f839 100644 --- a/library/stdlib_constructor_begin.c +++ b/library/stdlib_constructor_begin.c @@ -1,5 +1,5 @@ /* - * $Id: stdlib_constructor_begin.c,v 1.1.1.1 2004-07-26 16:31:52 obarthel Exp $ + * $Id: stdlib_constructor_begin.c,v 1.2 2004-09-29 19:57:57 obarthel Exp $ * * :ts=4 * @@ -42,80 +42,7 @@ /****************************************************************************/ -#if defined(__amigaos4__) - -/****************************************************************************/ - -/* - * Dummy constructor and destructor array. The linker script will put these at the - * very beginning of section ".ctors" and ".dtors". crtend.o contains a similar entry - * with a NULL pointer entry and is put at the end of the sections. This way, the init - * code can find the global constructor/destructor pointers - */ -static void (*__CTOR_LIST__[1]) (void) __attribute__((section(".ctors"))) = { (void *)-1 }; -static void (*__DTOR_LIST__[1]) (void) __attribute__((section(".dtors"))) = { (void *)-1 }; - -/****************************************************************************/ - -static void -_do_ctors(void) -{ - void (**pFuncPtr)(void); - - /* Skip the first entry in the list (it's -1 anyway) */ - pFuncPtr = __CTOR_LIST__ + 1; - - /* Call all constructors in forward order */ - while (*pFuncPtr != NULL) - (**pFuncPtr++)(); -} - -/****************************************************************************/ - -static void -_do_dtors(void) -{ - static ULONG i = ~0UL; - void (**pFuncPtr)(void); - - if(i == ~0UL) - { - ULONG j = (ULONG)__DTOR_LIST__[0]; - - if(j == ~0UL) - { - /* Find the end of the destructors list. */ - j = 1; - - while(__DTOR_LIST__[j] != NULL) - j++; - - /* We're at the NULL entry now. Go back by one. */ - j--; - } - - i = j; - } - - /* If one of the destructors drops into - * exit(), processing will continue with - * the next following destructor. - */ - (void)setjmp(__exit_jmp_buf); - - /* Call all destructors in reverse order. */ - pFuncPtr = &__DTOR_LIST__[i]; - while(i > 0) - { - i--; - - (**pFuncPtr--)(); - } -} - -/****************************************************************************/ - -#elif defined(__SASC) +#if defined(__SASC) /****************************************************************************/ @@ -201,9 +128,21 @@ _do_ctors(void) ULONG nptrs = (ULONG)__CTOR_LIST__[0]; ULONG i; + ENTER(); + + D(("there are %ld constructors to be called",nptrs)); + /* Call all constructors in forward order */ for(i = 0 ; i < nptrs ; i++) + { + D(("calling constructor #%ld, 0x%08lx",i,__CTOR_LIST__[1+i])); + __CTOR_LIST__[1+i](); + } + + SHOWMSG("all done."); + + LEAVE(); } /****************************************************************************/ @@ -216,6 +155,10 @@ _do_dtors(void) ULONG nptrs = (ULONG)__DTOR_LIST__[0]; static ULONG i; + ENTER(); + + D(("there are %ld destructors to be called",nptrs)); + /* If one of the destructors drops into * exit(), processing will continue with * the next following destructor. @@ -224,7 +167,15 @@ _do_dtors(void) /* Call all destructors in reverse order */ while(i++ < nptrs) + { + D(("calling destructor #%ld, 0x%08lx",i,__DTOR_LIST__[1+nptrs - i])); + __DTOR_LIST__[1+nptrs - i](); + } + + SHOWMSG("all done."); + + LEAVE(); } /****************************************************************************/ diff --git a/library/stdlib_locale_utility.h b/library/stdlib_locale_utility.h index 7c4092a..7508bd1 100644 --- a/library/stdlib_locale_utility.h +++ b/library/stdlib_locale_utility.h @@ -1,5 +1,5 @@ /* - * $Id: stdlib_locale_utility.h,v 1.1.1.1 2004-07-26 16:31:57 obarthel Exp $ + * $Id: stdlib_locale_utility.h,v 1.2 2004-09-29 19:57:58 obarthel Exp $ * * :ts=4 * @@ -49,8 +49,14 @@ /****************************************************************************/ -extern struct Library * __UtilityBase; -extern struct Library * __LocaleBase; +#ifndef _MACROS_H +#include "macros.h" +#endif /* _MACROS_H */ + +/****************************************************************************/ + +extern struct Library * NOCOMMON __UtilityBase; +extern struct Library * NOCOMMON __LocaleBase; /****************************************************************************/ @@ -58,8 +64,8 @@ extern struct Library * __LocaleBase; /****************************************************************************/ -extern struct UtilityIFace * __IUtility; -extern struct LocaleIFace * __ILocale; +extern struct UtilityIFace NOCOMMON * __IUtility; +extern struct LocaleIFace NOCOMMON * __ILocale; /****************************************************************************/ diff --git a/library/stdlib_main.c b/library/stdlib_main.c index 03578d7..2c7b206 100644 --- a/library/stdlib_main.c +++ b/library/stdlib_main.c @@ -1,5 +1,5 @@ /* - * $Id: stdlib_main.c,v 1.3 2004-09-29 14:17:44 obarthel Exp $ + * $Id: stdlib_main.c,v 1.4 2004-09-29 19:57:58 obarthel Exp $ * * :ts=4 * @@ -142,19 +142,32 @@ call_main(void) static size_t i; + ENTER(); + /* This plants the return buffer for _exit(). */ if(setjmp(__exit_jmp_buf) != 0) goto out; + SHOWMSG("calling init functions"); + for(i = 0 ; init_functions[i] != NULL ; i++) { + D(("calling init function #%ld",i)); + if((*init_functions[i])() != OK) + { + SHOWMSG("that didn't work"); goto out; + } } + SHOWMSG("now invoking the constructors"); + /* Go through the constructor list */ _init(); + SHOWMSG("done."); + /* If the SAS/C profiling code is set up for printing function call chains, switch it on now. */ #if defined(__USE_SAS_PROFILING_FOR_MONITORING) @@ -183,6 +196,8 @@ call_main(void) */ if(__stack_overflow) { + SHOWMSG("we have a stack overflow"); + /* Dump whatever is waiting to be written to the * standard I/O streams, and make sure that no * break signal is about to make things any more @@ -205,9 +220,15 @@ call_main(void) /* If necessary, print stack size usage information. */ __stack_usage_exit(); + SHOWMSG("invoking the destructors"); + /* Go through the destructor list */ _fini(); + SHOWMSG("done."); + + SHOWMSG("calling the exit functions"); + /* Any of the following cleanup routines may call * _exit() by way of abort() or through a hook * function. Which is why we redirect the exit @@ -215,10 +236,13 @@ call_main(void) */ for(i = 0 ; exit_functions[i] != NULL ; i++) { + D(("calling exit function #%ld",i)); + if(setjmp(__exit_jmp_buf) == 0) (*exit_functions[i])(); } + RETURN(__exit_value); return(__exit_value); } @@ -349,9 +373,6 @@ _main(void) } #endif /* __amigaos4__ */ - /* Remember when this program was started. */ - DateStamp(&__start_time); - /* If a callback was provided which can fill us in on which * minimum stack size should be used, invoke it now and * store its result in the global __stack_size variable. diff --git a/library/stdlib_startup.c b/library/stdlib_startup.c index 0d2ab6b..77c1c53 100644 --- a/library/stdlib_startup.c +++ b/library/stdlib_startup.c @@ -1,5 +1,5 @@ /* - * $Id: stdlib_startup.c,v 1.2 2004-09-29 14:17:44 obarthel Exp $ + * $Id: stdlib_startup.c,v 1.3 2004-09-29 19:57:58 obarthel Exp $ * * :ts=4 * @@ -423,6 +423,8 @@ __startup_init(void) CLIB_DESTRUCTOR(__startup_exit) { + ENTER(); + PROFILE_OFF(); /* Now clean up after the streams set up for the Workbench @@ -460,4 +462,6 @@ CLIB_DESTRUCTOR(__startup_exit) } PROFILE_ON(); + + LEAVE(); } diff --git a/library/time_clock.c b/library/time_clock.c index 464b4e9..97524c2 100644 --- a/library/time_clock.c +++ b/library/time_clock.c @@ -1,5 +1,5 @@ /* - * $Id: time_clock.c,v 1.1.1.1 2004-07-26 16:32:21 obarthel Exp $ + * $Id: time_clock.c,v 1.2 2004-09-29 19:57:58 obarthel Exp $ * * :ts=4 * @@ -37,6 +37,22 @@ /****************************************************************************/ +static struct DateStamp start_time; + +/****************************************************************************/ + +CLIB_CONSTRUCTOR(init_start_time) +{ + /* Remember when this program was started. */ + DateStamp(&start_time); + + RETURN(OK); + + CONSTRUCTOR_SUCCEED(); +} + +/****************************************************************************/ + clock_t clock(void) { @@ -57,8 +73,8 @@ clock(void) minutes_now = now.ds_Days * 24 * 60 + now.ds_Minute; ticks_now = now.ds_Tick; - minutes_start = __start_time.ds_Days * 24 * 60 + __start_time.ds_Minute; - ticks_start = __start_time.ds_Tick; + minutes_start = start_time.ds_Days * 24 * 60 + start_time.ds_Minute; + ticks_start = start_time.ds_Tick; /* Subtract the start time from the current time. We start * with the ticks. diff --git a/library/time_data.c b/library/time_data.c index 40dc126..8bda54f 100644 --- a/library/time_data.c +++ b/library/time_data.c @@ -1,5 +1,5 @@ /* - * $Id: time_data.c,v 1.1.1.1 2004-07-26 16:32:22 obarthel Exp $ + * $Id: time_data.c,v 1.2 2004-09-29 19:57:58 obarthel Exp $ * * :ts=4 * @@ -37,10 +37,6 @@ /****************************************************************************/ -struct DateStamp __start_time; - -/****************************************************************************/ - const char * const __abbreviated_week_day_names[7] = { "Sun", diff --git a/library/time_headers.h b/library/time_headers.h index fa1b9ca..78b0c67 100644 --- a/library/time_headers.h +++ b/library/time_headers.h @@ -1,5 +1,5 @@ /* - * $Id: time_headers.h,v 1.1.1.1 2004-07-26 16:32:23 obarthel Exp $ + * $Id: time_headers.h,v 1.2 2004-09-29 19:57:58 obarthel Exp $ * * :ts=4 * @@ -84,10 +84,6 @@ /****************************************************************************/ -extern struct DateStamp __start_time; - -/****************************************************************************/ - extern const char * const __abbreviated_week_day_names[7]; extern const char * const __week_day_names[7]; extern const char * const __abbreviated_month_names[12]; diff --git a/library/unistd_chdir_exit.c b/library/unistd_chdir_exit.c index 668e146..7d565a0 100644 --- a/library/unistd_chdir_exit.c +++ b/library/unistd_chdir_exit.c @@ -1,5 +1,5 @@ /* - * $Id: unistd_chdir_exit.c,v 1.1 2004-09-29 14:17:44 obarthel Exp $ + * $Id: unistd_chdir_exit.c,v 1.2 2004-09-29 19:57:58 obarthel Exp $ * * :ts=4 * @@ -43,9 +43,9 @@ /* If the program's current directory was changed, here is where we find out about it. */ -BPTR __original_current_directory; -BOOL __current_directory_changed; -BOOL __unlock_current_directory; +BPTR NOCOMMON __original_current_directory; +BOOL NOCOMMON __current_directory_changed; +BOOL NOCOMMON __unlock_current_directory; /****************************************************************************/ diff --git a/library/unistd_headers.h b/library/unistd_headers.h index c4e671c..0926530 100644 --- a/library/unistd_headers.h +++ b/library/unistd_headers.h @@ -1,5 +1,5 @@ /* - * $Id: unistd_headers.h,v 1.2 2004-09-29 12:10:29 obarthel Exp $ + * $Id: unistd_headers.h,v 1.3 2004-09-29 19:57:58 obarthel Exp $ * * :ts=4 * @@ -47,30 +47,29 @@ extern char __current_path_name[MAXPATHLEN]; /****************************************************************************/ /* Names of files and directories to delete when shutting down. */ -extern struct MinList __unlink_list; +extern struct MinList NOCOMMON __unlink_list; /****************************************************************************/ /* Local timer I/O. */ -extern struct MsgPort * __timer_port; -extern struct timerequest * __timer_request; -extern BOOL __timer_busy; -extern struct Library * __TimerBase; +extern struct MsgPort * NOCOMMON __timer_port; +extern struct timerequest * NOCOMMON __timer_request; +extern BOOL NOCOMMON __timer_busy; +extern struct Library * NOCOMMON __TimerBase; /****************************************************************************/ #if defined(__amigaos4__) -extern struct TimerIFace * __ITimer; +extern struct TimerIFace * NOCOMMON __ITimer; #endif /* __amigaos4__ */ /****************************************************************************/ /* If the program's current directory was changed, here is where - * we find out about it. - */ -extern BPTR __original_current_directory; -extern BOOL __current_directory_changed; -extern BOOL __unlock_current_directory; + we find out about it. */ +extern BPTR NOCOMMON __original_current_directory; +extern BOOL NOCOMMON __current_directory_changed; +extern BOOL NOCOMMON __unlock_current_directory; /****************************************************************************/ diff --git a/library/unistd_init_exit.c b/library/unistd_init_exit.c index 13ca7d3..6592e74 100644 --- a/library/unistd_init_exit.c +++ b/library/unistd_init_exit.c @@ -1,5 +1,5 @@ /* - * $Id: unistd_init_exit.c,v 1.5 2004-09-29 14:17:44 obarthel Exp $ + * $Id: unistd_init_exit.c,v 1.6 2004-09-29 19:57:58 obarthel Exp $ * * :ts=4 * @@ -42,7 +42,7 @@ /****************************************************************************/ /* Names of files and directories to delete when shutting down. */ -struct MinList __unlink_list; +struct MinList NOCOMMON __unlink_list; /****************************************************************************/ diff --git a/library/unistd_timer.c b/library/unistd_timer.c index c50aaa3..d73b4f9 100644 --- a/library/unistd_timer.c +++ b/library/unistd_timer.c @@ -1,5 +1,5 @@ /* - * $Id: unistd_timer.c,v 1.1 2004-09-29 14:21:34 obarthel Exp $ + * $Id: unistd_timer.c,v 1.2 2004-09-29 19:57:58 obarthel Exp $ * * :ts=4 * @@ -46,15 +46,15 @@ /****************************************************************************/ /* Local timer I/O. */ -struct MsgPort * __timer_port; -struct timerequest * __timer_request; -BOOL __timer_busy; -struct Library * __TimerBase; +struct MsgPort * NOCOMMON __timer_port; +struct timerequest * NOCOMMON __timer_request; +BOOL NOCOMMON __timer_busy; +struct Library * NOCOMMON __TimerBase; /****************************************************************************/ #if defined(__amigaos4__) -struct TimerIFace * __ITimer; +struct TimerIFace * NOCOMMON __ITimer; #endif /* __amigaos4__ */ /****************************************************************************/ diff --git a/library/unistd_wildcard_expand.c b/library/unistd_wildcard_expand.c index dc48d57..8994d0c 100644 --- a/library/unistd_wildcard_expand.c +++ b/library/unistd_wildcard_expand.c @@ -1,5 +1,5 @@ /* - * $Id: unistd_wildcard_expand.c,v 1.2 2004-09-29 14:17:44 obarthel Exp $ + * $Id: unistd_wildcard_expand.c,v 1.3 2004-09-29 19:57:58 obarthel Exp $ * * :ts=4 * @@ -76,13 +76,15 @@ static struct AnchorPath * anchor; CLIB_DESTRUCTOR(__wildcard_expand_exit) { + ENTER(); + if(anchor != NULL) { MatchEnd(anchor); - - free(anchor); anchor = NULL; } + + LEAVE(); } /****************************************************************************/ diff --git a/library/usergroup_headers.h b/library/usergroup_headers.h index f54bc38..62b4d89 100644 --- a/library/usergroup_headers.h +++ b/library/usergroup_headers.h @@ -1,5 +1,5 @@ /* - * $Id: usergroup_headers.h,v 1.2 2004-09-16 08:45:03 obarthel Exp $ + * $Id: usergroup_headers.h,v 1.3 2004-09-29 19:57:58 obarthel Exp $ * * :ts=4 * @@ -42,13 +42,13 @@ /****************************************************************************/ -extern struct Library * __UserGroupBase; +extern struct Library * NOCOMMON __UserGroupBase; /****************************************************************************/ #if defined(__amigaos4__) -extern struct UserGroupIFace *__IUserGroup; +extern struct UserGroupIFace * NOCOMMON __IUserGroup; #endif /* __amigaos4__ */ diff --git a/library/usergroup_init_exit.c b/library/usergroup_init_exit.c index cad4d62..536d642 100644 --- a/library/usergroup_init_exit.c +++ b/library/usergroup_init_exit.c @@ -1,5 +1,5 @@ /* - * $Id: usergroup_init_exit.c,v 1.2 2004-09-29 14:17:44 obarthel Exp $ + * $Id: usergroup_init_exit.c,v 1.3 2004-09-29 19:57:58 obarthel Exp $ * * :ts=4 * @@ -54,16 +54,12 @@ extern char * __program_name; /****************************************************************************/ -extern void __show_error(const char * message); - -/****************************************************************************/ - -struct Library * __UserGroupBase; +struct Library * NOCOMMON __UserGroupBase; /****************************************************************************/ #if defined(__amigaos4__) -struct UserGroupIFace * __IUserGroup; +struct UserGroupIFace * NOCOMMON __IUserGroup; #endif /* __amigaos4__ */ /****************************************************************************/