1
0
mirror of https://github.com/adtools/clib2.git synced 2025-12-08 14:59:05 +00:00

- 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
This commit is contained in:
Olaf Barthel
2004-09-29 19:57:58 +00:00
parent f49a45f6a8
commit 5d9e4c07a6
19 changed files with 148 additions and 147 deletions

View File

@ -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)

View File

@ -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];
/****************************************************************************/

View File

@ -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];
/****************************************************************************/

View File

@ -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 */

View File

@ -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();
}
/****************************************************************************/

View File

@ -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();
}
/****************************************************************************/

View File

@ -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;
/****************************************************************************/

View File

@ -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.

View File

@ -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();
}

View File

@ -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.

View File

@ -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",

View File

@ -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];

View File

@ -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;
/****************************************************************************/

View File

@ -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;
/****************************************************************************/

View File

@ -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;
/****************************************************************************/

View File

@ -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__ */
/****************************************************************************/

View File

@ -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();
}
/****************************************************************************/

View File

@ -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__ */

View File

@ -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__ */
/****************************************************************************/