diff --git a/library/GNUmakefile.68k b/library/GNUmakefile.68k index 99b8807..c8e078b 100644 --- a/library/GNUmakefile.68k +++ b/library/GNUmakefile.68k @@ -1,5 +1,5 @@ # -# $Id: GNUmakefile.68k,v 1.18 2004-12-24 18:31:37 obarthel Exp $ +# $Id: GNUmakefile.68k,v 1.19 2004-12-26 10:28:56 obarthel Exp $ # # :ts=8 # @@ -237,9 +237,7 @@ C_LIB = \ stdio_translateioerror.o \ stdio_ungetc.o \ stdio_vasprintf.o \ - stdio_vasprintf_debug.o \ stdio_vasprintf_hook_entry.o \ - stdio_vasprintf_hook_entry_debug.o \ stdio_vfprintf.o \ stdio_vfscanf.o \ stdio_vprintf.o \ @@ -250,14 +248,12 @@ C_LIB = \ stdlib_abort.o \ stdlib_abs.o \ stdlib_alloca.o \ - stdlib_alloca_debug.o \ stdlib_assertion_failure.o \ stdlib_atexit.o \ stdlib_atoi.o \ stdlib_atol.o \ stdlib_bsearch.o \ stdlib_calloc.o \ - stdlib_calloc_debug.o \ stdlib_checkdetach.o \ stdlib_constructor.o \ stdlib_constructor_begin.o \ @@ -274,7 +270,6 @@ C_LIB = \ stdlib_dosbase.o \ stdlib_exit.o \ stdlib_free.o \ - stdlib_free_debug.o \ stdlib_getdefstacksize.o \ stdlib_getenv.o \ stdlib_getsp.o \ @@ -284,7 +279,6 @@ C_LIB = \ stdlib_ldiv.o \ stdlib_machine_test.o \ stdlib_malloc.o \ - stdlib_malloc_debug.o \ stdlib_math.o \ stdlib_mkdtemp.o \ stdlib_mkstemp.o \ @@ -303,6 +297,7 @@ C_LIB = \ stdlib_red_black.o \ stdlib_setenv.o \ stdlib_setjmp.o \ + stdlib_set_process_window.o \ stdlib_shell_escape.o \ stdlib_showerror.o \ stdlib_socket.o \ @@ -348,7 +343,6 @@ C_LIB = \ string_strcpy.o \ string_strcspn.o \ string_strdup.o \ - string_strdup_debug.o \ string_strerror.o \ string_strlcat.o \ string_strlcpy.o \ @@ -391,7 +385,6 @@ C_LIB = \ unistd_fileno.o \ unistd_ftruncate.o \ unistd_getcwd.o \ - unistd_getcwd_debug.o \ unistd_getopt.o \ unistd_getpid.o \ unistd_init_exit.o \ @@ -446,7 +439,6 @@ UNIX_LIB = \ unistd_chdir_exit.o \ unistd_chown.o \ unistd_getcwd.o \ - unistd_getcwd_debug.o \ unistd_lchown.o \ unistd_link.o \ unistd_readlink.o \ @@ -504,7 +496,6 @@ MATH_LIB = \ stdio_sprintf.o \ stdio_sscanf.o \ stdio_vasprintf.o \ - stdio_vasprintf_debug.o \ stdio_vfprintf.o \ stdio_vfscanf.o \ stdio_vprintf.o \ @@ -702,6 +693,17 @@ AMIGA_LIB = \ amiga_timedelay.o \ amiga_waitbeam.o +MEMDEBUG_LIB = \ + stdio_vasprintf_debug.o \ + stdio_vasprintf_debug.o \ + stdio_vasprintf_hook_entry_debug.o \ + stdlib_alloca_debug.o \ + stdlib_calloc_debug.o \ + stdlib_free_debug.o \ + stdlib_malloc_debug.o \ + string_strdup_debug.o \ + unistd_getcwd_debug.o + ############################################################################## LIBS_68K := $(LIBC_OBJS)/libc.a $(LIBSTACK_OBJS)/libstack.a $(LIBUNIX_OBJS)/libunix.a \ diff --git a/library/GNUmakefile.os4 b/library/GNUmakefile.os4 index 568a78f..0115d83 100644 --- a/library/GNUmakefile.os4 +++ b/library/GNUmakefile.os4 @@ -1,5 +1,5 @@ # -# $Id: GNUmakefile.os4,v 1.18 2004-12-24 18:31:37 obarthel Exp $ +# $Id: GNUmakefile.os4,v 1.19 2004-12-26 10:28:56 obarthel Exp $ # # :ts=8 # @@ -241,9 +241,7 @@ C_LIB = \ stdio_translateioerror.o \ stdio_ungetc.o \ stdio_vasprintf.o \ - stdio_vasprintf_debug.o \ stdio_vasprintf_hook_entry.o \ - stdio_vasprintf_hook_entry_debug.o \ stdio_vfprintf.o \ stdio_vfscanf.o \ stdio_vprintf.o \ @@ -254,14 +252,12 @@ C_LIB = \ stdlib_abort.o \ stdlib_abs.o \ stdlib_alloca.o \ - stdlib_alloca_debug.o \ stdlib_assertion_failure.o \ stdlib_atexit.o \ stdlib_atoi.o \ stdlib_atol.o \ stdlib_bsearch.o \ stdlib_calloc.o \ - stdlib_calloc_debug.o \ stdlib_checkdetach.o \ stdlib_constructor.o \ stdlib_constructor_begin.o \ @@ -278,7 +274,6 @@ C_LIB = \ stdlib_dosbase.o \ stdlib_exit.o \ stdlib_free.o \ - stdlib_free_debug.o \ stdlib_getdefstacksize.o \ stdlib_getenv.o \ stdlib_getsp.o \ @@ -288,7 +283,6 @@ C_LIB = \ stdlib_ldiv.o \ stdlib_machine_test.o \ stdlib_malloc.o \ - stdlib_malloc_debug.o \ stdlib_math.o \ stdlib_mkdtemp.o \ stdlib_mkstemp.o \ @@ -307,6 +301,7 @@ C_LIB = \ stdlib_red_black.o \ stdlib_setenv.o \ stdlib_setjmp.o \ + stdlib_set_process_window.o \ stdlib_shell_escape.o \ stdlib_showerror.o \ stdlib_socket.o \ @@ -352,7 +347,6 @@ C_LIB = \ string_strcpy.o \ string_strcspn.o \ string_strdup.o \ - string_strdup_debug.o \ string_strerror.o \ string_strlcat.o \ string_strlcpy.o \ @@ -395,7 +389,6 @@ C_LIB = \ unistd_fileno.o \ unistd_ftruncate.o \ unistd_getcwd.o \ - unistd_getcwd_debug.o \ unistd_getopt.o \ unistd_getpid.o \ unistd_init_exit.o \ @@ -451,7 +444,6 @@ UNIX_LIB = \ unistd_chdir_exit.o \ unistd_chown.o \ unistd_getcwd.o \ - unistd_getcwd_debug.o \ unistd_lchown.o \ unistd_link.o \ unistd_readlink.o \ @@ -516,7 +508,6 @@ MATH_LIB = \ stdio_sprintf.o \ stdio_sscanf.o \ stdio_vasprintf.o \ - stdio_vasprintf_debug.o \ stdio_vfprintf.o \ stdio_vfscanf.o \ stdio_vprintf.o \ @@ -669,6 +660,16 @@ AMIGA_LIB = \ amiga_timedelay.o \ amiga_waitbeam.o +MEMDEBUG_LIB = \ + stdio_vasprintf_debug.o \ + stdio_vasprintf_hook_entry_debug.o \ + stdlib_alloca_debug.o \ + stdlib_calloc_debug.o \ + stdlib_free_debug.o \ + stdlib_malloc_debug.o \ + string_strdup_debug.o \ + unistd_getcwd_debug.o + ############################################################################## # The libraries to be built, prefixed by the respective path names diff --git a/library/changes b/library/changes index c8d285b..a2ee545 100644 --- a/library/changes +++ b/library/changes @@ -16,6 +16,17 @@ normal versions. Let's see how well this works out in the GCC version. SAS/C does not seem to like it... +- Changed the definition of alloca() for GCC, which now defaults + to the built-in function. + +- Updated the stdio.h, stdlib.h, string.h and unistd.h header files + to declare function prototypes for the __MEM_DEBUG versions of the + library functions only if that preprocessor symbol is defined. + +- If a SIGINT signal is caught and processed by the default signal + handler, the localized "*** BREAK" string will be printed rather + than the built-in one. + c.lib 1.184 (28.11.2004) diff --git a/library/include/stdio.h b/library/include/stdio.h index f7de983..ae39600 100644 --- a/library/include/stdio.h +++ b/library/include/stdio.h @@ -1,5 +1,5 @@ /* - * $Id: stdio.h,v 1.3 2004-08-25 15:27:28 obarthel Exp $ + * $Id: stdio.h,v 1.4 2004-12-26 10:28:57 obarthel Exp $ * * :ts=4 * @@ -328,11 +328,9 @@ extern FILE * popen(const char *command, const char *type); extern int vasprintf(char **ret,const char *format,va_list arg); -/* This is the version for use with memory debugging; do not call - it directly! */ +#ifdef __MEM_DEBUG extern int __vasprintf(const char *file,int line,char **ret,const char *format,va_list arg); -#ifdef __MEM_DEBUG #define vasprintf(ret,format,arg) __vasprintf(__FILE__,__LINE__,(ret),(format),(arg)) #endif /* __MEM_DEBUG */ diff --git a/library/include/stdlib.h b/library/include/stdlib.h index b66f78e..f07842b 100644 --- a/library/include/stdlib.h +++ b/library/include/stdlib.h @@ -1,5 +1,5 @@ /* - * $Id: stdlib.h,v 1.3 2004-09-20 17:16:07 obarthel Exp $ + * $Id: stdlib.h,v 1.4 2004-12-26 10:28:57 obarthel Exp $ * * :ts=4 * @@ -83,14 +83,12 @@ extern void *calloc(size_t num_elements,size_t element_size); extern void free(void *ptr); extern void *realloc(void *ptr,size_t size); -/* This are the versions for use with memory debugging; do not call - them directly! */ +#ifdef __MEM_DEBUG extern void *__malloc(size_t size,const char *file,int line); extern void *__calloc(size_t num_elements,size_t element_size,const char *file,int line); extern void __free(void *ptr,const char *file,int line); extern void *__realloc(void *ptr,size_t size,const char *file,int line); -#ifdef __MEM_DEBUG #define malloc(size) __malloc((size),__FILE__,__LINE__) #define calloc(num_elements,element_size) __calloc((num_elements),(element_size),__FILE__,__LINE__) #define free(ptr) __free((ptr),__FILE__,__LINE__) @@ -157,15 +155,14 @@ extern unsigned long long strtoull(const char *str, char **ptr, int base); /****************************************************************************/ #if defined(__GNUC__) - #if defined(alloca) - #undef alloca - #define alloca(size) __builtin_alloca(size) - #endif /* alloca */ + #undef alloca + #define alloca(size) __builtin_alloca(size) #else extern void * alloca(size_t size); - extern void * __alloca(size_t size,const char *file,int line); #ifdef __MEM_DEBUG + extern void * __alloca(size_t size,const char *file,int line); + #define alloca(size) __alloca((size),__FILE__,__LINE__) #endif /* __MEM_DEBUG */ #endif /* __GNUC__ */ diff --git a/library/include/string.h b/library/include/string.h index 2ccecbc..64ff167 100644 --- a/library/include/string.h +++ b/library/include/string.h @@ -1,5 +1,5 @@ /* - * $Id: string.h,v 1.5 2004-11-17 19:07:26 obarthel Exp $ + * $Id: string.h,v 1.6 2004-12-26 10:28:57 obarthel Exp $ * * :ts=4 * @@ -106,11 +106,9 @@ extern char * rindex(const char *s, int c); extern char * strdup(const char *s); -/* This is the version for use with memory debugging; do not call - it directly! */ +#ifdef __MEM_DEBUG extern char * __strdup(const char *s,const char *file,int line); -#ifdef __MEM_DEBUG #define strdup(s) __strdup((s),__FILE__,__LINE__) #endif /* __MEM_DEBUG */ diff --git a/library/include/unistd.h b/library/include/unistd.h index 0febd8d..20a32fc 100644 --- a/library/include/unistd.h +++ b/library/include/unistd.h @@ -1,5 +1,5 @@ /* - * $Id: unistd.h,v 1.6 2004-09-29 14:17:46 obarthel Exp $ + * $Id: unistd.h,v 1.7 2004-12-26 10:28:57 obarthel Exp $ * * :ts=4 * @@ -103,11 +103,9 @@ extern char *realpath(const char *file_name, char *resolved_name); extern char * getcwd(char * buffer, size_t buffer_size); -/* This is the version for use with memory debugging; do not call - it directly! */ +#ifdef __MEM_DEBUG extern char * __getcwd(char * buffer,size_t buffer_size,const char *file,int line); -#ifdef __MEM_DEBUG #define getcwd(buffer,buffer_size) __getcwd((buffer),(buffer_size),__FILE__,__LINE__) #endif /* __MEM_DEBUG */ diff --git a/library/signal_data.c b/library/signal_data.c index 606a730..ff82167 100644 --- a/library/signal_data.c +++ b/library/signal_data.c @@ -1,5 +1,5 @@ /* - * $Id: signal_data.c,v 1.1.1.1 2004-07-26 16:31:04 obarthel Exp $ + * $Id: signal_data.c,v 1.2 2004-12-26 10:28:56 obarthel Exp $ * * :ts=4 * @@ -57,5 +57,4 @@ BOOL __check_abort_enabled = TRUE; /****************************************************************************/ -BOOL __termination_message_printed; BOOL __termination_message_disabled; diff --git a/library/signal_headers.h b/library/signal_headers.h index 81db57f..9282379 100644 --- a/library/signal_headers.h +++ b/library/signal_headers.h @@ -1,5 +1,5 @@ /* - * $Id: signal_headers.h,v 1.3 2004-12-24 18:31:38 obarthel Exp $ + * $Id: signal_headers.h,v 1.4 2004-12-26 10:28:56 obarthel Exp $ * * :ts=4 * @@ -76,15 +76,10 @@ extern int NOCOMMON __signals_blocked; /****************************************************************************/ -extern BOOL NOCOMMON __termination_message_printed; extern BOOL NOCOMMON __termination_message_disabled; /****************************************************************************/ -extern const char NOCOMMON __abnormal_program_termination[]; - -/****************************************************************************/ - #ifndef _STDLIB_HEADERS_H #include "stdlib_headers.h" #endif /* _STDLIB_HEADERS_H */ diff --git a/library/signal_raise.c b/library/signal_raise.c index b485dd4..be337a4 100644 --- a/library/signal_raise.c +++ b/library/signal_raise.c @@ -1,5 +1,5 @@ /* - * $Id: signal_raise.c,v 1.1.1.1 2004-07-26 16:31:05 obarthel Exp $ + * $Id: signal_raise.c,v 1.2 2004-12-26 10:28:56 obarthel Exp $ * * :ts=4 * @@ -68,12 +68,16 @@ raise(int sig) if(handler == SIG_DFL) { + char break_string[80]; + SHOWMSG("this is the default handler"); /* Don't trigger a recursion. */ __check_abort_enabled = FALSE; - __print_termination_message((sig == SIGINT) ? "*** BREAK\n" : __abnormal_program_termination); + Fault(ERROR_BREAK,NULL,break_string,(LONG)sizeof(break_string)); + + __print_termination_message((sig == SIGINT) ? break_string : NULL); SHOWMSG("bye, bye..."); diff --git a/library/smakefile b/library/smakefile index fe1b599..73dd883 100644 --- a/library/smakefile +++ b/library/smakefile @@ -1,5 +1,5 @@ # -# $Id: smakefile,v 1.14 2004-12-24 18:31:38 obarthel Exp $ +# $Id: smakefile,v 1.15 2004-12-26 10:28:56 obarthel Exp $ # # :ts=8 # @@ -345,9 +345,7 @@ STDIO_OBJ = \ stdio_translateioerror.o \ stdio_ungetc.o \ stdio_vasprintf.o \ - stdio_vasprintf_debug.o \ stdio_vasprintf_hook_entry.o \ - stdio_vasprintf_hook_debug.o \ stdio_vfprintf.o \ stdio_vfscanf.o \ stdio_vprintf.o \ @@ -360,10 +358,6 @@ STDLIB_OBJ = \ stdlib_abort.o \ stdlib_abs.o \ stdlib_alloca.o \ - stdlib_alloca_debug.o \ - stdlib_calloc_debug.o \ - stdlib_free_debug.o \ - stdlib_malloc_debug.o \ stdlib_assertion_failure.o \ stdlib_atexit.o \ stdlib_atof.o \ @@ -413,6 +407,7 @@ STDLIB_OBJ = \ stdlib_red_black.o \ stdlib_setenv.o \ stdlib_setjmp.o \ + stdlib_set_process_window.o \ stdlib_shell_escape.o \ stdlib_showerror.o \ stdlib_srand.o \ @@ -452,7 +447,6 @@ STRING_OBJ = \ string_strcpy.o \ string_strcspn.o \ string_strdup.o \ - string_strdup_debug.o \ string_strerror.o \ string_strlcat.o \ string_strlcpy.o \ @@ -504,7 +498,6 @@ UNISTD_OBJ = \ unistd_fileno.o \ unistd_ftruncate.o \ unistd_getcwd.o \ - unistd_getcwd_debug.o \ unistd_getopt.o \ unistd_getpid.o \ unistd_init_exit.o \ @@ -564,6 +557,16 @@ USERGROUP_OBJ = \ UTIME_OBJ = \ utime_utime.o +MEMDEBUG_OBJ = \ + stdio_vasprintf_debug.o \ + stdio_vasprintf_hook_debug.o \ + stdlib_alloca_debug.o \ + stdlib_calloc_debug.o \ + stdlib_free_debug.o \ + stdlib_malloc_debug.o \ + string_strdup_debug.o \ + unistd_getcwd_debug.o + ############################################################################## all: setup c.lib startup.o cleanup diff --git a/library/socket_init_exit.c b/library/socket_init_exit.c index 2a389a4..f9bc175 100644 --- a/library/socket_init_exit.c +++ b/library/socket_init_exit.c @@ -1,5 +1,5 @@ /* - * $Id: socket_init_exit.c,v 1.5 2004-11-14 11:06:27 obarthel Exp $ + * $Id: socket_init_exit.c,v 1.6 2004-12-26 10:28:56 obarthel Exp $ * * :ts=4 * @@ -127,7 +127,6 @@ CLIB_DESTRUCTOR(__socket_exit) int __socket_init(void) { - struct Process * this_process; struct TagItem tags[5]; int result = ERROR; LONG status; @@ -201,15 +200,25 @@ __socket_init(void) /* Check if this program was launched as a server by the Internet * superserver. */ - this_process = (struct Process *)FindTask(NULL); - if(this_process->pr_CLI != ZERO && NOT __detach) + if(Cli() != NULL && NOT __detach) { struct DaemonMessage * dm; /* The socket the superserver may have launched this program * with is attached to the exit data entry of the process. */ - dm = (struct DaemonMessage *)this_process->pr_ExitData; + #if defined(__amigaos4__) + { + dm = (struct DaemonMessage *)GetExitData(); + } + #else + { + struct Process * this_process = (struct Process *)FindTask(NULL); + + dm = (struct DaemonMessage *)this_process->pr_ExitData; + } + #endif /* __amigaos4__ */ + if(TypeOfMem(dm) != 0 && TypeOfMem(((char *)dm) + sizeof(*dm)-1) != 0) { int daemon_socket; diff --git a/library/stdio_init_exit.c b/library/stdio_init_exit.c index a725877..75b5b13 100644 --- a/library/stdio_init_exit.c +++ b/library/stdio_init_exit.c @@ -1,5 +1,5 @@ /* - * $Id: stdio_init_exit.c,v 1.2 2004-09-29 14:17:44 obarthel Exp $ + * $Id: stdio_init_exit.c,v 1.3 2004-12-26 10:28:56 obarthel Exp $ * * :ts=4 * @@ -194,9 +194,8 @@ __stdio_init(void) } /* If the program was launched from Workbench, we continue by - * duplicating the default output stream for use as the - * standard error stream. - */ + duplicating the default output stream for use as the + standard error stream. */ if(__WBenchMsg != NULL) { PROFILE_OFF(); @@ -207,14 +206,26 @@ __stdio_init(void) } else { - struct Process * this_process = (struct Process *)FindTask(NULL); + BPTR ces; + + /* Figure out what the default error output stream is. */ + #if defined(__amigaos4__) + { + ces = ErrorOutput(); + } + #else + { + struct Process * this_process = (struct Process *)FindTask(NULL); + + ces = this_process->pr_CES; + } + #endif /* __amigaos4__ */ /* Is the standard error stream configured? If so, use it. - * Otherwise, try to duplicate the standard output stream. - */ - if(this_process->pr_CES != ZERO) + Otherwise, try to duplicate the standard output stream. */ + if(ces != ZERO) { - __fd[STDERR_FILENO]->fd_DefaultFile = this_process->pr_CES; + __fd[STDERR_FILENO]->fd_DefaultFile = ces; SET_FLAG(__fd[STDERR_FILENO]->fd_Flags,FDF_NO_CLOSE); } @@ -231,8 +242,7 @@ __stdio_init(void) PROFILE_OFF(); /* Check if the standard error output refers to a console or must - * be considered unusable for console output. - */ + be considered unusable for console output. */ if(__fd[STDERR_FILENO]->fd_DefaultFile == ZERO || ((struct FileHandle *)BADDR(__fd[STDERR_FILENO]->fd_DefaultFile))->fh_Type == NULL || NOT IsInteractive(__fd[STDERR_FILENO]->fd_DefaultFile)) diff --git a/library/stdio_tmpnam.c b/library/stdio_tmpnam.c index 8acf5b6..a29f49a 100644 --- a/library/stdio_tmpnam.c +++ b/library/stdio_tmpnam.c @@ -1,5 +1,5 @@ /* - * $Id: stdio_tmpnam.c,v 1.1.1.1 2004-07-26 16:31:42 obarthel Exp $ + * $Id: stdio_tmpnam.c,v 1.2 2004-12-26 10:28:56 obarthel Exp $ * * :ts=4 * @@ -35,6 +35,10 @@ #include "stdio_headers.h" #endif /* _STDIO_HEADERS_H */ +#ifndef _STDLIB_HEADERS_H +#include "stdlib_headers.h" +#endif /* _STDLIB_HEADERS_H */ + /****************************************************************************/ char * @@ -42,7 +46,6 @@ tmpnam(char *buf) { static char local_buffer[L_tmpnam]; static unsigned short counter; - struct Process * this_process; APTR old_window_pointer; unsigned short c; char * result = NULL; /* ZZZ compiler claims that this assignment is unnecessary. */ @@ -58,10 +61,6 @@ tmpnam(char *buf) if(buf == NULL) buf = local_buffer; - this_process = (struct Process *)FindTask(NULL); - - old_window_pointer = this_process->pr_WindowPtr; - while(TRUE) { if(__check_abort_enabled) @@ -85,7 +84,7 @@ tmpnam(char *buf) D(("checking if '%s' exists",buf)); /* Turn off DOS error requesters. */ - this_process->pr_WindowPtr = (APTR)-1; + old_window_pointer = __set_process_window((APTR)-1); /* Does this object exist already? */ PROFILE_OFF(); @@ -93,7 +92,7 @@ tmpnam(char *buf) PROFILE_ON(); /* Restore DOS requesters. */ - this_process->pr_WindowPtr = old_window_pointer; + __set_process_window(old_window_pointer); if(lock == ZERO) { diff --git a/library/stdio_vasprintf.c b/library/stdio_vasprintf.c index 335ecdc..2248730 100644 --- a/library/stdio_vasprintf.c +++ b/library/stdio_vasprintf.c @@ -1,5 +1,5 @@ /* - * $Id: stdio_vasprintf.c,v 1.3 2004-12-24 18:31:38 obarthel Exp $ + * $Id: stdio_vasprintf.c,v 1.4 2004-12-26 10:28:56 obarthel Exp $ * * :ts=4 * @@ -123,10 +123,6 @@ __vasprintf(const char *file,int line,char **ret,const char *format,va_list arg) /****************************************************************************/ -#if NOT defined(__MEM_DEBUG) - -/****************************************************************************/ - int vasprintf(char **ret,const char *format,va_list arg) { @@ -136,7 +132,3 @@ vasprintf(char **ret,const char *format,va_list arg) return(result); } - -/****************************************************************************/ - -#endif /* __MEM_DEBUG */ diff --git a/library/stdlib_abort.c b/library/stdlib_abort.c index 5194e2c..8cf62e8 100644 --- a/library/stdlib_abort.c +++ b/library/stdlib_abort.c @@ -1,5 +1,5 @@ /* - * $Id: stdlib_abort.c,v 1.1.1.1 2004-07-26 16:31:50 obarthel Exp $ + * $Id: stdlib_abort.c,v 1.2 2004-12-26 10:28:56 obarthel Exp $ * * :ts=4 * @@ -52,7 +52,7 @@ abort(void) __check_abort_enabled = FALSE; - __print_termination_message(__abnormal_program_termination); + __print_termination_message(NULL); /* Note that we drop into the exit() function which * does not trigger the exit trap. diff --git a/library/stdlib_alloca.c b/library/stdlib_alloca.c index 336a350..7bb7e31 100644 --- a/library/stdlib_alloca.c +++ b/library/stdlib_alloca.c @@ -1,5 +1,5 @@ /* - * $Id: stdlib_alloca.c,v 1.3 2004-12-24 18:31:38 obarthel Exp $ + * $Id: stdlib_alloca.c,v 1.4 2004-12-26 10:28:56 obarthel Exp $ * * :ts=4 * @@ -90,7 +90,7 @@ __alloca_cleanup(const char * file,int line) /* The assumption is that the stack grows downwards. If this function is called, we must get rid off all the allocations associated with stack - pointers whose addresses are less than the current stack pointer. + pointers whose addresses are smaller than the current stack pointer. Which so happen to be stored near the end of the list. The further we move up from the end to the top of the list, the closer we get to the allocations made in the context of a stack frame near to @@ -104,7 +104,7 @@ __alloca_cleanup(const char * file,int line) Remove((struct Node *)mcn); __force_free(mcn->mcn_Memory,file,line); - __force_free(mcn,file,line); + __free(mcn,file,line); } } } @@ -151,7 +151,7 @@ __alloca(size_t size,const char * file,int line) { SHOWMSG("not enough memory"); - __force_free(mcn,file,line); + __free(mcn,file,line); goto out; } @@ -170,10 +170,6 @@ __alloca(size_t size,const char * file,int line) /****************************************************************************/ -#if NOT defined(__MEM_DEBUG) - -/****************************************************************************/ - void * alloca(size_t size) { @@ -183,7 +179,3 @@ alloca(size_t size) return(result); } - -/****************************************************************************/ - -#endif /* __MEM_DEBUG */ diff --git a/library/stdlib_assertion_failure.c b/library/stdlib_assertion_failure.c index 4fbf94f..7e90172 100644 --- a/library/stdlib_assertion_failure.c +++ b/library/stdlib_assertion_failure.c @@ -1,5 +1,5 @@ /* - * $Id: stdlib_assertion_failure.c,v 1.1.1.1 2004-07-26 16:31:50 obarthel Exp $ + * $Id: stdlib_assertion_failure.c,v 1.2 2004-12-26 10:28:56 obarthel Exp $ * * :ts=4 * @@ -64,8 +64,7 @@ __assertion_failure( BOOL use_stderr = FALSE; /* Figure out if the assertion failure message can be printed - * on the stderr stream. - */ + on the stderr stream. */ if(__iob != NULL && NOT __no_standard_io) { struct iob * iob; @@ -121,7 +120,7 @@ __assertion_failure( { if(IntuitionBase != NULL) { - IIntuition = (struct IntuitionIFace *)GetInterface((struct Library *)IntuitionBase, "main", 1, 0); + IIntuition = (struct IntuitionIFace *)GetInterface(IntuitionBase, "main", 1, 0); if(IIntuition == NULL) { CloseLibrary(IntuitionBase); @@ -134,7 +133,6 @@ __assertion_failure( if(IntuitionBase != NULL) { struct EasyStruct es; - ULONG args[3]; memset(&es,0,sizeof(es)); @@ -143,11 +141,7 @@ __assertion_failure( es.es_TextFormat = (STRPTR)"Assertion of expression\n'%s'\nfailed in file '%s', line %ld"; es.es_GadgetFormat = (STRPTR)"Sorry"; - args[0] = (ULONG)expression; - args[1] = (ULONG)file_name; - args[2] = (ULONG)line_number; - - EasyRequestArgs(NULL,&es,NULL,args); + EasyRequest(NULL,&es,NULL,expression,file_name,line_number); #if defined(__amigaos4__) { diff --git a/library/stdlib_calloc.c b/library/stdlib_calloc.c index 53d71d9..0e2eecf 100644 --- a/library/stdlib_calloc.c +++ b/library/stdlib_calloc.c @@ -1,5 +1,5 @@ /* - * $Id: stdlib_calloc.c,v 1.2 2004-12-24 18:31:38 obarthel Exp $ + * $Id: stdlib_calloc.c,v 1.3 2004-12-26 10:28:56 obarthel Exp $ * * :ts=4 * @@ -82,10 +82,6 @@ __calloc(size_t num_elements,size_t element_size,const char * file,int line) /****************************************************************************/ -#if NOT defined(__MEM_DEBUG) - -/****************************************************************************/ - void * calloc(size_t num_elements,size_t element_size) { @@ -95,7 +91,3 @@ calloc(size_t num_elements,size_t element_size) return(result); } - -/****************************************************************************/ - -#endif /* __MEM_DEBUG */ diff --git a/library/stdlib_free.c b/library/stdlib_free.c index 682b1fe..5b2a085 100644 --- a/library/stdlib_free.c +++ b/library/stdlib_free.c @@ -1,5 +1,5 @@ /* - * $Id: stdlib_free.c,v 1.3 2004-12-24 18:31:38 obarthel Exp $ + * $Id: stdlib_free.c,v 1.4 2004-12-26 10:28:56 obarthel Exp $ * * :ts=4 * @@ -505,10 +505,6 @@ __free(void * ptr,const char * file,int line) /****************************************************************************/ -#if NOT defined(__MEM_DEBUG) - -/****************************************************************************/ - void free(void * ptr) { @@ -517,10 +513,6 @@ free(void * ptr) /****************************************************************************/ -#endif /* __MEM_DEBUG */ - -/****************************************************************************/ - void __memory_exit(void) { @@ -535,11 +527,7 @@ __memory_exit(void) __program_name,__current_num_memory_chunks_allocated,__maximum_num_memory_chunks_allocated); __check_memory_allocations(__FILE__,__LINE__); - } - #endif /* __MEM_DEBUG */ - #if defined(__MEM_DEBUG) - { __never_free = FALSE; if(__memory_list.mlh_Head != NULL) @@ -551,15 +539,15 @@ __memory_exit(void) __free_memory_node((struct MemoryNode *)__memory_list.mlh_Head,__FILE__,__LINE__); } } + + #if defined(__USE_MEM_TREES) + { + __initialize_red_black_tree(&__memory_tree); + } + #endif /* __USE_MEM_TREES */ } #endif /* __MEM_DEBUG */ - #if defined(__USE_MEM_TREES) && defined(__MEM_DEBUG) - { - __initialize_red_black_tree(&__memory_tree); - } - #endif /* __USE_MEM_TREES && __MEM_DEBUG */ - if(__memory_pool != NULL) { NewList((struct List *)&__memory_list); diff --git a/library/stdlib_main.c b/library/stdlib_main.c index 754e1cb..9a09b30 100644 --- a/library/stdlib_main.c +++ b/library/stdlib_main.c @@ -1,5 +1,5 @@ /* - * $Id: stdlib_main.c,v 1.7 2004-11-14 11:43:30 obarthel Exp $ + * $Id: stdlib_main.c,v 1.8 2004-12-26 10:28:56 obarthel Exp $ * * :ts=4 * @@ -285,8 +285,9 @@ detach_cleanup(REG(d0, LONG UNUSED unused_return_code),REG(d1, BPTR segment_list /****************************************************************************/ static ULONG -get_stack_size(struct Task * tc) +get_stack_size(void) { + struct Task * tc = FindTask(NULL); ULONG upper,lower; ULONG result; @@ -307,9 +308,9 @@ _main(void) struct Process * child_process = NULL; struct WBStartup * startup_message; struct Process * this_process; + APTR old_window_pointer = NULL; int return_code = RETURN_FAIL; ULONG current_stack_size; - APTR old_window_pointer; int os_version; SysBase = *(struct Library **)4; @@ -337,11 +338,6 @@ _main(void) startup_message = NULL; } - old_window_pointer = this_process->pr_WindowPtr; - - if(__disable_dos_requesters) - this_process->pr_WindowPtr = (APTR)-1; - __WBenchMsg = startup_message; /* Check which minimum operating system version we actually require. */ @@ -381,6 +377,19 @@ _main(void) } #endif /* __amigaos4__ */ + if(__disable_dos_requesters) + { + /* Don't display any requesters. */ + old_window_pointer = __set_process_window((APTR)-1); + } + else + { + /* Just remember the original pointer. */ + old_window_pointer = __set_process_window(NULL); + + __set_process_window(old_window_pointer); + } + /* 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. */ @@ -394,7 +403,7 @@ _main(void) } /* How much stack size was provided? */ - current_stack_size = get_stack_size(&this_process->pr_Task); + current_stack_size = get_stack_size(); /* If this is a resident program, don't allow for the detach code to run. Same goes for launching the program from @@ -550,7 +559,8 @@ _main(void) out: - this_process->pr_WindowPtr = old_window_pointer; + if(DOSBase != NULL) + __set_process_window(old_window_pointer); if(child_process == NULL) { diff --git a/library/stdlib_malloc.c b/library/stdlib_malloc.c index a822b74..786f470 100644 --- a/library/stdlib_malloc.c +++ b/library/stdlib_malloc.c @@ -1,5 +1,5 @@ /* - * $Id: stdlib_malloc.c,v 1.3 2004-12-24 18:31:38 obarthel Exp $ + * $Id: stdlib_malloc.c,v 1.4 2004-12-26 10:28:56 obarthel Exp $ * * :ts=4 * @@ -250,10 +250,6 @@ __malloc(size_t size,const char * file,int line) /****************************************************************************/ -#if NOT defined(__MEM_DEBUG) - -/****************************************************************************/ - void * malloc(size_t size) { @@ -264,11 +260,6 @@ malloc(size_t size) return(result); } - -/****************************************************************************/ - -#endif /* __MEM_DEBUG */ - /****************************************************************************/ void diff --git a/library/stdlib_mktemp.c b/library/stdlib_mktemp.c index 721af37..eb4cda4 100644 --- a/library/stdlib_mktemp.c +++ b/library/stdlib_mktemp.c @@ -1,5 +1,5 @@ /* - * $Id: stdlib_mktemp.c,v 1.3 2004-11-10 17:45:40 obarthel Exp $ + * $Id: stdlib_mktemp.c,v 1.4 2004-12-26 10:28:56 obarthel Exp $ * * :ts=4 * @@ -162,8 +162,6 @@ mktemp(char * name_template) SHOWSTRING(name_template); - old_window_pointer = this_process->pr_WindowPtr; - /* Now check if the name we picked is unique. If not, make another name. */ while(TRUE) { @@ -193,7 +191,7 @@ mktemp(char * name_template) #endif /* UNIX_PATH_SEMANTICS */ /* Turn off DOS error requesters. */ - this_process->pr_WindowPtr = (APTR)-1; + old_window_pointer = __set_process_window((APTR)-1); /* Does this object exist already? */ PROFILE_OFF(); @@ -201,7 +199,7 @@ mktemp(char * name_template) PROFILE_ON(); /* Restore DOS requesters. */ - this_process->pr_WindowPtr = old_window_pointer; + __set_process_window(old_window_pointer); if(lock == ZERO) { diff --git a/library/stdlib_protos.h b/library/stdlib_protos.h index f517539..1467ba0 100644 --- a/library/stdlib_protos.h +++ b/library/stdlib_protos.h @@ -1,5 +1,5 @@ /* - * $Id: stdlib_protos.h,v 1.4 2004-12-24 18:31:38 obarthel Exp $ + * $Id: stdlib_protos.h,v 1.5 2004-12-26 10:28:56 obarthel Exp $ * * :ts=4 * @@ -185,6 +185,9 @@ extern void __stkovf(void); /* stdlib_termination_message.c */ extern void __print_termination_message(const char * termination_message); +/* stdlib_set_process_window.c */ +APTR __set_process_window(APTR new_window_pointer); + /****************************************************************************/ #endif /* _STDLIB_PROTOS_H */ diff --git a/library/stdlib_realloc.c b/library/stdlib_realloc.c index 5919357..e81484d 100644 --- a/library/stdlib_realloc.c +++ b/library/stdlib_realloc.c @@ -1,5 +1,5 @@ /* - * $Id: stdlib_realloc.c,v 1.2 2004-12-24 18:31:38 obarthel Exp $ + * $Id: stdlib_realloc.c,v 1.3 2004-12-26 10:28:56 obarthel Exp $ * * :ts=4 * @@ -199,10 +199,6 @@ __realloc(void *ptr,size_t size,const char * file,int line) /****************************************************************************/ -#if NOT defined(__MEM_DEBUG) - -/****************************************************************************/ - void * realloc(void *ptr,size_t size) { @@ -212,7 +208,3 @@ realloc(void *ptr,size_t size) return(result); } - -/****************************************************************************/ - -#endif /* __MEM_DEBUG */ diff --git a/library/stdlib_set_process_window.c b/library/stdlib_set_process_window.c new file mode 100644 index 0000000..6138197 --- /dev/null +++ b/library/stdlib_set_process_window.c @@ -0,0 +1,60 @@ +/* + * $Id: stdlib_set_process_window.c,v 1.1 2004-12-26 10:28:56 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_HEADERS_H +#include "stdlib_headers.h" +#endif /* _STDLIB_HEADERS_H */ + +/****************************************************************************/ + +APTR +__set_process_window(APTR new_window_pointer) +{ + APTR result; + + #if defined(__amigaos4__) + { + result = SetProcWindow(new_window_pointer); + } + #else + { + struct Process * this_process = (struct Process *)FindTask(NULL); + + result = this_process->pr_WindowPtr; + + this_process->pr_WindowPtr = new_window_pointer; + } + #endif /* __amigaos4__ */ + + return(result); +} diff --git a/library/stdlib_showerror.c b/library/stdlib_showerror.c index 88f5648..aa147fe 100644 --- a/library/stdlib_showerror.c +++ b/library/stdlib_showerror.c @@ -1,5 +1,5 @@ /* - * $Id: stdlib_showerror.c,v 1.3 2004-12-24 10:52:02 obarthel Exp $ + * $Id: stdlib_showerror.c,v 1.4 2004-12-26 10:28:56 obarthel Exp $ * * :ts=4 * @@ -89,11 +89,11 @@ __show_error(const char * message) #if defined(__amigaos4__) { - IDOS = (struct DOSIFace *)GetInterface((struct Library *)DOSBase, "main", 1, 0); + IDOS = (struct DOSIFace *)GetInterface(DOSBase, "main", 1, 0); if (IDOS == NULL) goto out; - IIntuition = (struct IntuitionIFace *)GetInterface((struct Library *)IntuitionBase, "main", 1, 0); + IIntuition = (struct IntuitionIFace *)GetInterface(IntuitionBase, "main", 1, 0); if (IIntuition == NULL) goto out; } diff --git a/library/stdlib_termination_message.c b/library/stdlib_termination_message.c index c74292b..2860fc5 100644 --- a/library/stdlib_termination_message.c +++ b/library/stdlib_termination_message.c @@ -1,5 +1,5 @@ /* - * $Id: stdlib_termination_message.c,v 1.1.1.1 2004-07-26 16:32:12 obarthel Exp $ + * $Id: stdlib_termination_message.c,v 1.2 2004-12-26 10:28:56 obarthel Exp $ * * :ts=4 * @@ -45,18 +45,20 @@ /****************************************************************************/ -const char __abnormal_program_termination[] = "Abnormal program termination\n"; - -/****************************************************************************/ - void __print_termination_message(const char * termination_message) { - if(NOT __termination_message_printed) + static BOOL termination_message_printed = FALSE; + + if(NOT termination_message_printed) { - __termination_message_printed = TRUE; + termination_message_printed = TRUE; if(NOT __termination_message_disabled && NOT __no_standard_io) - fputs(termination_message,stderr); + { + fputs((termination_message != NULL) ? termination_message : "Abnormal program termination",stderr); + + fputc('\n',stderr); + } } } diff --git a/library/string_strdup.c b/library/string_strdup.c index 712edab..33448d0 100644 --- a/library/string_strdup.c +++ b/library/string_strdup.c @@ -1,5 +1,5 @@ /* - * $Id: string_strdup.c,v 1.3 2004-12-24 18:31:38 obarthel Exp $ + * $Id: string_strdup.c,v 1.4 2004-12-26 10:28:56 obarthel Exp $ * * :ts=4 * @@ -90,10 +90,6 @@ __strdup(const char *s,const char * file,int line) /****************************************************************************/ -#if NOT defined(__MEM_DEBUG) - -/****************************************************************************/ - char * strdup(const char *s) { @@ -103,7 +99,3 @@ strdup(const char *s) return(result); } - -/****************************************************************************/ - -#endif /* __MEM_DEBUG */ diff --git a/library/time_asctime_r.c b/library/time_asctime_r.c index 7b13bdd..2055add 100644 --- a/library/time_asctime_r.c +++ b/library/time_asctime_r.c @@ -1,5 +1,5 @@ /* - * $Id: time_asctime_r.c,v 1.1 2004-11-18 09:40:37 obarthel Exp $ + * $Id: time_asctime_r.c,v 1.2 2004-12-26 10:28:56 obarthel Exp $ * * :ts=4 * @@ -44,10 +44,9 @@ /****************************************************************************/ static void -add_to_string(char * to,int to_size,const char * string,int * offset_ptr) +add_to_string(char * to,size_t to_size,const char * string,size_t * offset_ptr) { - int offset; - int len; + size_t offset, len; assert( to != NULL && to_size > 0 && string != NULL && offset_ptr != NULL ); @@ -81,7 +80,7 @@ __asctime_r(const struct tm *tm,char * buffer,size_t buffer_size) char number[16]; char * result = NULL; const char * b; - int offset = 0; + size_t offset = 0; ENTER(); diff --git a/library/unistd_getcwd.c b/library/unistd_getcwd.c index aecc8ff..76838f1 100644 --- a/library/unistd_getcwd.c +++ b/library/unistd_getcwd.c @@ -1,5 +1,5 @@ /* - * $Id: unistd_getcwd.c,v 1.3 2004-12-24 18:31:38 obarthel Exp $ + * $Id: unistd_getcwd.c,v 1.4 2004-12-26 10:28:56 obarthel Exp $ * * :ts=4 * @@ -215,10 +215,6 @@ __getcwd(char * buffer,size_t buffer_size,const char *file,int line) /****************************************************************************/ -#if NOT defined(__MEM_DEBUG) - -/****************************************************************************/ - char * getcwd(char * buffer, size_t buffer_size) { @@ -228,7 +224,3 @@ getcwd(char * buffer, size_t buffer_size) return(result); } - -/****************************************************************************/ - -#endif /* __MEM_DEBUG */