From 1df294c07e3e593ad05abb8f0bb231362ea7f1d2 Mon Sep 17 00:00:00 2001 From: Olaf Barthel Date: Mon, 28 Feb 2005 10:07:35 +0000 Subject: [PATCH] - The thread-safety code is now subject to conditional compilation. Both the library and the user code need to be rebuilt with the preprocessor symbol __THREAD_SAFE defined to get thread-safe code. git-svn-id: file:///Users/olsen/Code/migration-svn-zu-git/logical-line-staging/clib2/trunk@14843 87f5fb63-7c3d-0410-a384-fd976d0f7a62 --- library/changes | 5 ++ library/dirent_data.c | 30 ++++++--- library/dirent_headers.h | 19 +++++- library/fcntl_read.c | 8 +-- library/fcntl_write.c | 8 +-- library/include/stdio.h | 18 +++++- library/locale_headers.h | 22 ++++++- library/locale_init_exit.c | 38 ++++++++---- library/mount_fstatfs.c | 8 +-- library/stat_chmod.c | 8 +-- library/stat_fstat.c | 8 +-- library/stat_lstat.c | 8 +-- library/stat_mkdir.c | 8 +-- library/stat_rmdir.c | 8 +-- library/stat_stat.c | 8 +-- library/stdio_asprintf.c | 8 +-- library/stdio_fclose.c | 8 +-- library/stdio_flockfile.c | 8 +-- library/stdio_freopen.c | 8 +-- library/stdio_ftrylockfile.c | 8 +-- library/stdio_funlockfile.c | 8 +-- library/stdio_headers.h | 28 ++++++++- library/stdio_init_exit.c | 22 ++++--- library/stdio_lock.c | 10 ++- library/stdio_openiob.c | 22 ++++--- library/stdio_popen.c | 14 ++--- library/stdio_printf.c | 8 +-- library/stdio_protos.h | 10 +-- library/stdio_record_locking.c | 6 +- library/stdio_remove.c | 8 +-- library/stdio_rename.c | 8 +-- library/stdio_scanf.c | 8 +-- library/stdio_snprintf.c | 8 +-- library/stdio_sprintf.c | 8 +-- library/stdio_sscanf.c | 8 +-- library/stdio_vasprintf.c | 8 +-- library/stdio_vprintf.c | 8 +-- library/stdio_vsnprintf.c | 8 +-- library/stdio_vsprintf.c | 8 +-- library/stdlib_free.c | 70 +-------------------- library/stdlib_getenv.c | 8 +-- library/stdlib_headers.h | 31 ++++++++-- library/stdlib_malloc.c | 107 ++++++++++++++++++++++++++++++--- library/stdlib_mktemp.c | 8 +-- library/stdlib_protos.h | 6 +- library/stdlib_putenv.c | 8 +-- library/stdlib_setenv.c | 8 +-- library/stdlib_unsetenv.c | 5 +- library/unistd_access.c | 8 +-- library/unistd_chdir.c | 8 +-- library/unistd_chown.c | 8 +-- library/unistd_getcwd.c | 8 +-- library/unistd_getopt.c | 8 +-- library/unistd_lchown.c | 8 +-- library/unistd_link.c | 8 +-- library/unistd_readlink.c | 8 +-- library/unistd_realpath.c | 8 +-- library/unistd_symlink.c | 8 +-- library/unistd_truncate.c | 8 +-- library/unistd_unlink.c | 8 +-- library/utime_utime.c | 8 +-- 61 files changed, 488 insertions(+), 319 deletions(-) diff --git a/library/changes b/library/changes index bc3a679..834fcfb 100644 --- a/library/changes +++ b/library/changes @@ -67,6 +67,11 @@ not reentrant (this is not ixemul.library) it should be thread-safe now. Thread-safe in the sense of POSIX 1003.1c-1995. +- The thread-safety code is now subject to conditional compilation. + Both the library and the user code need to be rebuilt with the + preprocessor symbol __THREAD_SAFE defined to get thread-safe + code. + c.lib 1.188 (7.2.2005) diff --git a/library/dirent_data.c b/library/dirent_data.c index e4d4659..733f2c3 100644 --- a/library/dirent_data.c +++ b/library/dirent_data.c @@ -1,5 +1,5 @@ /* - * $Id: dirent_data.c,v 1.6 2005-02-27 21:58:21 obarthel Exp $ + * $Id: dirent_data.c,v 1.7 2005-02-28 10:07:30 obarthel Exp $ * * :ts=4 * @@ -42,6 +42,10 @@ struct MinList NOCOMMON __directory_list; /****************************************************************************/ +#if defined(__THREAD_SAFE) + +/****************************************************************************/ + static struct SignalSemaphore * dirent_lock; /****************************************************************************/ @@ -64,6 +68,10 @@ __dirent_unlock(void) /****************************************************************************/ +#endif /* __THREAD_SAFE */ + +/****************************************************************************/ + CLIB_CONSTRUCTOR(__dirent_init) { BOOL success = FALSE; @@ -72,11 +80,15 @@ CLIB_CONSTRUCTOR(__dirent_init) NewList((struct List *)&__directory_list); - dirent_lock = AllocVec(sizeof(*dirent_lock),MEMF_ANY|MEMF_PUBLIC); - if(dirent_lock == NULL) - goto out; + #if defined(__THREAD_SAFE) + { + dirent_lock = AllocVec(sizeof(*dirent_lock),MEMF_ANY|MEMF_PUBLIC); + if(dirent_lock == NULL) + goto out; - InitSemaphore(dirent_lock); + InitSemaphore(dirent_lock); + } + #endif /* __THREAD_SAFE */ success = TRUE; @@ -102,8 +114,12 @@ CLIB_DESTRUCTOR(__dirent_exit) closedir((DIR *)__directory_list.mlh_Head); } - FreeVec(dirent_lock); - dirent_lock = NULL; + #if defined(__THREAD_SAFE) + { + FreeVec(dirent_lock); + dirent_lock = NULL; + } + #endif /* __THREAD_SAFE */ LEAVE(); } diff --git a/library/dirent_headers.h b/library/dirent_headers.h index 71c1e63..508730b 100644 --- a/library/dirent_headers.h +++ b/library/dirent_headers.h @@ -1,5 +1,5 @@ /* - * $Id: dirent_headers.h,v 1.6 2005-02-27 21:58:21 obarthel Exp $ + * $Id: dirent_headers.h,v 1.7 2005-02-28 10:07:30 obarthel Exp $ * * :ts=4 * @@ -73,9 +73,26 @@ extern struct MinList NOCOMMON __directory_list; /****************************************************************************/ +#if defined(__THREAD_SAFE) + +/****************************************************************************/ + extern void __dirent_lock(void); extern void __dirent_unlock(void); /****************************************************************************/ +#else + +/****************************************************************************/ + +#define __dirent_lock() ((void)0) +#define __dirent_unlock() ((void)0) + +/****************************************************************************/ + +#endif /* __THREAD_SAFE */ + +/****************************************************************************/ + #endif /* _DIRENT_HEADERS_H */ diff --git a/library/fcntl_read.c b/library/fcntl_read.c index 8ed1b39..f74935a 100644 --- a/library/fcntl_read.c +++ b/library/fcntl_read.c @@ -1,5 +1,5 @@ /* - * $Id: fcntl_read.c,v 1.6 2005-02-20 15:46:52 obarthel Exp $ + * $Id: fcntl_read.c,v 1.7 2005-02-28 10:07:30 obarthel Exp $ * * :ts=4 * @@ -63,6 +63,9 @@ read(int file_descriptor, void * buffer, size_t num_bytes) assert( buffer != NULL ); assert( (int)num_bytes >= 0); + if(__check_abort_enabled) + __check_abort(); + #if defined(CHECK_FOR_NULL_POINTERS) { if(buffer == NULL) @@ -79,9 +82,6 @@ read(int file_descriptor, void * buffer, size_t num_bytes) assert( __fd[file_descriptor] != NULL ); assert( FLAG_IS_SET(__fd[file_descriptor]->fd_Flags,FDF_IN_USE) ); - if(__check_abort_enabled) - __check_abort(); - fd = __get_file_descriptor(file_descriptor); if(fd == NULL) { diff --git a/library/fcntl_write.c b/library/fcntl_write.c index e1e8bfa..83d6e0e 100644 --- a/library/fcntl_write.c +++ b/library/fcntl_write.c @@ -1,5 +1,5 @@ /* - * $Id: fcntl_write.c,v 1.6 2005-02-20 15:46:52 obarthel Exp $ + * $Id: fcntl_write.c,v 1.7 2005-02-28 10:07:30 obarthel Exp $ * * :ts=4 * @@ -63,6 +63,9 @@ write(int file_descriptor, const void * buffer, size_t num_bytes) assert( buffer != NULL ); assert( (int)num_bytes >= 0 ); + if(__check_abort_enabled) + __check_abort(); + #if defined(CHECK_FOR_NULL_POINTERS) { if(buffer == NULL) @@ -79,9 +82,6 @@ write(int file_descriptor, const void * buffer, size_t num_bytes) assert( __fd[file_descriptor] != NULL ); assert( FLAG_IS_SET(__fd[file_descriptor]->fd_Flags,FDF_IN_USE) ); - if(__check_abort_enabled) - __check_abort(); - fd = __get_file_descriptor(file_descriptor); if(fd == NULL) { diff --git a/library/include/stdio.h b/library/include/stdio.h index 8459371..d0adb7a 100644 --- a/library/include/stdio.h +++ b/library/include/stdio.h @@ -1,5 +1,5 @@ /* - * $Id: stdio.h,v 1.6 2005-02-27 18:09:12 obarthel Exp $ + * $Id: stdio.h,v 1.7 2005-02-28 10:07:35 obarthel Exp $ * * :ts=4 * @@ -292,7 +292,7 @@ extern int __unlockfile(FILE *stream,int c); ((FILE *)(f))->buffer[((FILE *)(f))->position++] : \ fgetc(f)) -#define getc_unlocked(f) +#define getc_unlocked(f) __getc_unlocked(f) /****************************************************************************/ @@ -311,7 +311,7 @@ extern int __unlockfile(FILE *stream,int c); (((FILE *)(f))->buffer[((FILE *)(f))->num_write_bytes-1]))) : \ fputc((c),(f))) -#define putc_unlocked(c,f) __putc((c),(f)) +#define putc_unlocked(c,f) __putc_unlocked((c),(f)) /****************************************************************************/ @@ -320,8 +320,20 @@ extern int __unlockfile(FILE *stream,int c); /****************************************************************************/ +#if defined(__THREAD_SAFE) + #define getc(f) (flockfile(f), __unlockfile((f),__getc_unlocked(f))) #define putc(c,f) (flockfile(f), __unlockfile((f),__putc_unlocked((c),(f)))) + +#else + +#define getc(f) __getc_unlocked(f) +#define putc(c,f) __putc_unlocked((c),(f)) + +#endif /* __THREAD_SAFE */ + +/****************************************************************************/ + #define getchar() getc(stdin) #define putchar(c) putc((c),stdout) diff --git a/library/locale_headers.h b/library/locale_headers.h index 336a321..46d127d 100644 --- a/library/locale_headers.h +++ b/library/locale_headers.h @@ -1,5 +1,5 @@ /* - * $Id: locale_headers.h,v 1.5 2005-02-27 21:58:21 obarthel Exp $ + * $Id: locale_headers.h,v 1.6 2005-02-28 10:07:30 obarthel Exp $ * * :ts=4 * @@ -78,8 +78,28 @@ extern char NOCOMMON __locale_name_table[NUM_LOCALES][MAX_LOCALE_NAME_LEN]; /****************************************************************************/ +#if defined(__THREAD_SAFE) + +/****************************************************************************/ + extern void __locale_lock(void); extern void __locale_unlock(void); + +/****************************************************************************/ + +#else + +/****************************************************************************/ + +#define __locale_lock() ((void)0) +#define __locale_unlock() ((void)0) + +/****************************************************************************/ + +#endif /* __THREAD_SAFE */ + +/****************************************************************************/ + extern void __close_all_locales(void); /****************************************************************************/ diff --git a/library/locale_init_exit.c b/library/locale_init_exit.c index 520de7d..78ce026 100644 --- a/library/locale_init_exit.c +++ b/library/locale_init_exit.c @@ -1,5 +1,5 @@ /* - * $Id: locale_init_exit.c,v 1.6 2005-02-27 21:58:21 obarthel Exp $ + * $Id: locale_init_exit.c,v 1.7 2005-02-28 10:07:30 obarthel Exp $ * * :ts=4 * @@ -41,10 +41,6 @@ /****************************************************************************/ -static struct SignalSemaphore * locale_lock; - -/****************************************************************************/ - struct Library * NOCOMMON __LocaleBase; /****************************************************************************/ @@ -188,6 +184,14 @@ __locale_init(void) /****************************************************************************/ +#if defined(__THREAD_SAFE) + +/****************************************************************************/ + +static struct SignalSemaphore * locale_lock; + +/****************************************************************************/ + void __locale_lock(void) { @@ -206,14 +210,22 @@ __locale_unlock(void) /****************************************************************************/ +#endif /* __THREAD_SAFE */ + +/****************************************************************************/ + CLIB_DESTRUCTOR(__locale_exit_destructor) { ENTER(); __locale_exit(); - FreeVec(locale_lock); - locale_lock = NULL; + #if defined(__THREAD_SAFE) + { + FreeVec(locale_lock); + locale_lock = NULL; + } + #endif /* __THREAD_SAFE */ LEAVE(); } @@ -227,11 +239,15 @@ CLIB_CONSTRUCTOR(__locale_init_constructor) ENTER(); - locale_lock = AllocVec(sizeof(*locale_lock),MEMF_ANY|MEMF_PUBLIC); - if(locale_lock == NULL) - goto out; + #if defined(__THREAD_SAFE) + { + locale_lock = AllocVec(sizeof(*locale_lock),MEMF_ANY|MEMF_PUBLIC); + if(locale_lock == NULL) + goto out; - InitSemaphore(locale_lock); + InitSemaphore(locale_lock); + } + #endif /* __THREAD_SAFE */ for(i = 0 ; i < NUM_LOCALES ; i++) strcpy(__locale_name_table[i],"C"); diff --git a/library/mount_fstatfs.c b/library/mount_fstatfs.c index d731520..5669fbb 100644 --- a/library/mount_fstatfs.c +++ b/library/mount_fstatfs.c @@ -1,5 +1,5 @@ /* - * $Id: mount_fstatfs.c,v 1.6 2005-02-21 10:21:42 obarthel Exp $ + * $Id: mount_fstatfs.c,v 1.7 2005-02-28 10:07:30 obarthel Exp $ * * :ts=4 * @@ -63,6 +63,9 @@ fstatfs(int file_descriptor, struct statfs *buf) assert( buf != NULL ); + if(__check_abort_enabled) + __check_abort(); + #if defined(CHECK_FOR_NULL_POINTERS) { if(buf == NULL) @@ -79,9 +82,6 @@ fstatfs(int file_descriptor, struct statfs *buf) assert( __fd[file_descriptor] != NULL ); assert( FLAG_IS_SET(__fd[file_descriptor]->fd_Flags,FDF_IN_USE) ); - if(__check_abort_enabled) - __check_abort(); - fd = __get_file_descriptor(file_descriptor); if(fd == NULL) { diff --git a/library/stat_chmod.c b/library/stat_chmod.c index a124a03..61f1833 100644 --- a/library/stat_chmod.c +++ b/library/stat_chmod.c @@ -1,5 +1,5 @@ /* - * $Id: stat_chmod.c,v 1.4 2005-02-03 16:56:15 obarthel Exp $ + * $Id: stat_chmod.c,v 1.5 2005-02-28 10:07:30 obarthel Exp $ * * :ts=4 * @@ -64,6 +64,9 @@ chmod(const char * path_name, mode_t mode) assert( path_name != NULL ); + if(__check_abort_enabled) + __check_abort(); + #if defined(CHECK_FOR_NULL_POINTERS) { if(path_name == NULL) @@ -76,9 +79,6 @@ chmod(const char * path_name, mode_t mode) } #endif /* CHECK_FOR_NULL_POINTERS */ - if(__check_abort_enabled) - __check_abort(); - #if defined(UNIX_PATH_SEMANTICS) { if(__unix_path_semantics) diff --git a/library/stat_fstat.c b/library/stat_fstat.c index 36c5153..24c11f6 100644 --- a/library/stat_fstat.c +++ b/library/stat_fstat.c @@ -1,5 +1,5 @@ /* - * $Id: stat_fstat.c,v 1.6 2005-02-20 15:46:52 obarthel Exp $ + * $Id: stat_fstat.c,v 1.7 2005-02-28 10:07:30 obarthel Exp $ * * :ts=4 * @@ -62,6 +62,9 @@ fstat(int file_descriptor, struct stat * buffer) assert( buffer != NULL ); + if(__check_abort_enabled) + __check_abort(); + #if defined(CHECK_FOR_NULL_POINTERS) { if(buffer == NULL) @@ -78,9 +81,6 @@ fstat(int file_descriptor, struct stat * buffer) assert( __fd[file_descriptor] != NULL ); assert( FLAG_IS_SET(__fd[file_descriptor]->fd_Flags,FDF_IN_USE) ); - if(__check_abort_enabled) - __check_abort(); - fd = __get_file_descriptor(file_descriptor); if(fd == NULL) { diff --git a/library/stat_lstat.c b/library/stat_lstat.c index d6f4de9..2ae2fc8 100644 --- a/library/stat_lstat.c +++ b/library/stat_lstat.c @@ -1,5 +1,5 @@ /* - * $Id: stat_lstat.c,v 1.4 2005-02-03 16:56:15 obarthel Exp $ + * $Id: stat_lstat.c,v 1.5 2005-02-28 10:07:30 obarthel Exp $ * * :ts=4 * @@ -59,6 +59,9 @@ lstat(const char * path_name, struct stat * buffer) assert( path_name != NULL && buffer != NULL ); + if(__check_abort_enabled) + __check_abort(); + #if defined(CHECK_FOR_NULL_POINTERS) { if(path_name == NULL || buffer == NULL) @@ -71,9 +74,6 @@ lstat(const char * path_name, struct stat * buffer) } #endif /* CHECK_FOR_NULL_POINTERS */ - if(__check_abort_enabled) - __check_abort(); - result = stat(path_name,buffer); out: diff --git a/library/stat_mkdir.c b/library/stat_mkdir.c index 98ec8c5..216acdf 100644 --- a/library/stat_mkdir.c +++ b/library/stat_mkdir.c @@ -1,5 +1,5 @@ /* - * $Id: stat_mkdir.c,v 1.4 2005-02-03 16:56:15 obarthel Exp $ + * $Id: stat_mkdir.c,v 1.5 2005-02-28 10:07:30 obarthel Exp $ * * :ts=4 * @@ -64,6 +64,9 @@ mkdir(const char * path_name, mode_t mode) assert( path_name != NULL ); + if(__check_abort_enabled) + __check_abort(); + #if defined(CHECK_FOR_NULL_POINTERS) { if(path_name == NULL) @@ -76,9 +79,6 @@ mkdir(const char * path_name, mode_t mode) } #endif /* CHECK_FOR_NULL_POINTERS */ - if(__check_abort_enabled) - __check_abort(); - #if defined(UNIX_PATH_SEMANTICS) { if(__unix_path_semantics) diff --git a/library/stat_rmdir.c b/library/stat_rmdir.c index 676b17e..8ea1319 100644 --- a/library/stat_rmdir.c +++ b/library/stat_rmdir.c @@ -1,5 +1,5 @@ /* - * $Id: stat_rmdir.c,v 1.4 2005-02-03 16:56:15 obarthel Exp $ + * $Id: stat_rmdir.c,v 1.5 2005-02-28 10:07:30 obarthel Exp $ * * :ts=4 * @@ -64,6 +64,9 @@ rmdir(const char * path_name) assert( path_name != NULL ); + if(__check_abort_enabled) + __check_abort(); + #if defined(CHECK_FOR_NULL_POINTERS) { if(path_name == NULL) @@ -76,9 +79,6 @@ rmdir(const char * path_name) } #endif /* CHECK_FOR_NULL_POINTERS */ - if(__check_abort_enabled) - __check_abort(); - #if defined(UNIX_PATH_SEMANTICS) { if(__unix_path_semantics) diff --git a/library/stat_stat.c b/library/stat_stat.c index fedc4de..bb61549 100644 --- a/library/stat_stat.c +++ b/library/stat_stat.c @@ -1,5 +1,5 @@ /* - * $Id: stat_stat.c,v 1.6 2005-02-03 16:56:15 obarthel Exp $ + * $Id: stat_stat.c,v 1.7 2005-02-28 10:07:30 obarthel Exp $ * * :ts=4 * @@ -74,6 +74,9 @@ stat(const char * path_name, struct stat * st) assert( path_name != NULL && st != NULL ); + if(__check_abort_enabled) + __check_abort(); + #if defined(CHECK_FOR_NULL_POINTERS) { if(path_name == NULL || st == NULL) @@ -86,9 +89,6 @@ stat(const char * path_name, struct stat * st) } #endif /* CHECK_FOR_NULL_POINTERS */ - if(__check_abort_enabled) - __check_abort(); - #if defined(UNIX_PATH_SEMANTICS) { if(__unix_path_semantics) diff --git a/library/stdio_asprintf.c b/library/stdio_asprintf.c index dcfca91..d450d1c 100644 --- a/library/stdio_asprintf.c +++ b/library/stdio_asprintf.c @@ -1,5 +1,5 @@ /* - * $Id: stdio_asprintf.c,v 1.4 2005-02-03 16:56:15 obarthel Exp $ + * $Id: stdio_asprintf.c,v 1.5 2005-02-28 10:07:30 obarthel Exp $ * * :ts=4 * @@ -60,6 +60,9 @@ asprintf(char **ret, const char *format, ...) assert( ret != NULL && format != NULL ); + if(__check_abort_enabled) + __check_abort(); + #if defined(CHECK_FOR_NULL_POINTERS) { if(ret == NULL || format == NULL) @@ -70,9 +73,6 @@ asprintf(char **ret, const char *format, ...) } #endif /* CHECK_FOR_NULL_POINTERS */ - if(__check_abort_enabled) - __check_abort(); - va_start(arg,format); result = vasprintf(ret,format,arg); va_end(arg); diff --git a/library/stdio_fclose.c b/library/stdio_fclose.c index e251f0d..f8f546a 100644 --- a/library/stdio_fclose.c +++ b/library/stdio_fclose.c @@ -1,5 +1,5 @@ /* - * $Id: stdio_fclose.c,v 1.6 2005-02-27 18:09:10 obarthel Exp $ + * $Id: stdio_fclose.c,v 1.7 2005-02-28 10:07:30 obarthel Exp $ * * :ts=4 * @@ -64,6 +64,9 @@ fclose(FILE *stream) assert( file->iob_Lock == NULL || file->iob_Lock->ss_Owner == NULL ); + if(__check_abort_enabled) + __check_abort(); + #if defined(CHECK_FOR_NULL_POINTERS) { if(stream == NULL) @@ -78,9 +81,6 @@ fclose(FILE *stream) } #endif /* CHECK_FOR_NULL_POINTERS */ - if(__check_abort_enabled) - __check_abort(); - assert( __is_valid_iob(file) ); assert( FLAG_IS_SET(file->iob_Flags,IOBF_IN_USE) ); assert( file->iob_BufferSize > 0 ); diff --git a/library/stdio_flockfile.c b/library/stdio_flockfile.c index ab94333..286b278 100644 --- a/library/stdio_flockfile.c +++ b/library/stdio_flockfile.c @@ -1,5 +1,5 @@ /* - * $Id: stdio_flockfile.c,v 1.1 2005-02-27 18:09:10 obarthel Exp $ + * $Id: stdio_flockfile.c,v 1.2 2005-02-28 10:07:30 obarthel Exp $ * * :ts=4 * @@ -54,6 +54,9 @@ flockfile(FILE *stream) assert( stream != NULL ); + if(__check_abort_enabled) + __check_abort(); + #if defined(CHECK_FOR_NULL_POINTERS) { if(stream == NULL) @@ -66,9 +69,6 @@ flockfile(FILE *stream) } #endif /* CHECK_FOR_NULL_POINTERS */ - if(__check_abort_enabled) - __check_abort(); - assert( __is_valid_iob(file) ); assert( FLAG_IS_SET(file->iob_Flags,IOBF_IN_USE) ); diff --git a/library/stdio_freopen.c b/library/stdio_freopen.c index ecb0744..32e0bb2 100644 --- a/library/stdio_freopen.c +++ b/library/stdio_freopen.c @@ -1,5 +1,5 @@ /* - * $Id: stdio_freopen.c,v 1.3 2005-02-03 16:56:16 obarthel Exp $ + * $Id: stdio_freopen.c,v 1.4 2005-02-28 10:07:30 obarthel Exp $ * * :ts=4 * @@ -58,6 +58,9 @@ freopen(const char *filename, const char *mode, FILE *stream) assert( filename != NULL && mode != NULL && stream != NULL ); + if(__check_abort_enabled) + __check_abort(); + #if defined(CHECK_FOR_NULL_POINTERS) { if(filename == NULL || mode == NULL || stream == NULL) @@ -70,9 +73,6 @@ freopen(const char *filename, const char *mode, FILE *stream) } #endif /* CHECK_FOR_NULL_POINTERS */ - if(__check_abort_enabled) - __check_abort(); - assert( __is_valid_iob(file) ); assert( FLAG_IS_SET(file->iob_Flags,IOBF_IN_USE) ); assert( file->iob_BufferSize > 0 ); diff --git a/library/stdio_ftrylockfile.c b/library/stdio_ftrylockfile.c index e998c50..db479f6 100644 --- a/library/stdio_ftrylockfile.c +++ b/library/stdio_ftrylockfile.c @@ -1,5 +1,5 @@ /* - * $Id: stdio_ftrylockfile.c,v 1.1 2005-02-27 18:09:10 obarthel Exp $ + * $Id: stdio_ftrylockfile.c,v 1.2 2005-02-28 10:07:30 obarthel Exp $ * * :ts=4 * @@ -55,6 +55,9 @@ ftrylockfile(FILE *stream) assert( stream != NULL ); + if(__check_abort_enabled) + __check_abort(); + #if defined(CHECK_FOR_NULL_POINTERS) { if(stream == NULL) @@ -67,9 +70,6 @@ ftrylockfile(FILE *stream) } #endif /* CHECK_FOR_NULL_POINTERS */ - if(__check_abort_enabled) - __check_abort(); - assert( __is_valid_iob(file) ); assert( FLAG_IS_SET(file->iob_Flags,IOBF_IN_USE) ); diff --git a/library/stdio_funlockfile.c b/library/stdio_funlockfile.c index b8ac728..59dae4e 100644 --- a/library/stdio_funlockfile.c +++ b/library/stdio_funlockfile.c @@ -1,5 +1,5 @@ /* - * $Id: stdio_funlockfile.c,v 1.1 2005-02-27 18:09:10 obarthel Exp $ + * $Id: stdio_funlockfile.c,v 1.2 2005-02-28 10:07:31 obarthel Exp $ * * :ts=4 * @@ -54,6 +54,9 @@ funlockfile(FILE *stream) assert( stream != NULL ); + if(__check_abort_enabled) + __check_abort(); + #if defined(CHECK_FOR_NULL_POINTERS) { if(stream == NULL) @@ -66,9 +69,6 @@ funlockfile(FILE *stream) } #endif /* CHECK_FOR_NULL_POINTERS */ - if(__check_abort_enabled) - __check_abort(); - assert( __is_valid_iob(file) ); assert( FLAG_IS_SET(file->iob_Flags,IOBF_IN_USE) ); diff --git a/library/stdio_headers.h b/library/stdio_headers.h index 38b6a2c..78afa3f 100644 --- a/library/stdio_headers.h +++ b/library/stdio_headers.h @@ -1,5 +1,5 @@ /* - * $Id: stdio_headers.h,v 1.16 2005-02-27 18:09:10 obarthel Exp $ + * $Id: stdio_headers.h,v 1.17 2005-02-28 10:07:31 obarthel Exp $ * * :ts=4 * @@ -428,6 +428,32 @@ extern BOOL NOCOMMON __no_standard_io; /****************************************************************************/ +#if defined(__THREAD_SAFE) + +/****************************************************************************/ + +extern void __stdio_lock(void); +extern void __stdio_unlock(void); +extern void __stdio_lock_exit(void); +extern int __stdio_lock_init(void); + +/****************************************************************************/ + +#else + +/****************************************************************************/ + +#define __stdio_lock() ((void)0) +#define __stdio_unlock() ((void)0) +#define __stdio_lock_exit() ((void)0) +#define __stdio_lock_init() (0) + +/****************************************************************************/ + +#endif /* __THREAD_SAFE */ + +/****************************************************************************/ + #ifndef _STDIO_PROTOS_H #include "stdio_protos.h" #endif /* _STDIO_PROTOS_H */ diff --git a/library/stdio_init_exit.c b/library/stdio_init_exit.c index 85d6427..68838db 100644 --- a/library/stdio_init_exit.c +++ b/library/stdio_init_exit.c @@ -1,5 +1,5 @@ /* - * $Id: stdio_init_exit.c,v 1.19 2005-02-27 21:58:21 obarthel Exp $ + * $Id: stdio_init_exit.c,v 1.20 2005-02-28 10:07:31 obarthel Exp $ * * :ts=4 * @@ -193,13 +193,21 @@ __stdio_init(void) if(buffer == NULL) goto out; - /* Allocate memory for an arbitration mechanism, then - initialize it. */ - lock = AllocVec(sizeof(*lock),MEMF_ANY|MEMF_PUBLIC); - if(lock == NULL) - goto out; + #if defined(__THREAD_SAFE) + { + /* Allocate memory for an arbitration mechanism, then + initialize it. */ + lock = AllocVec(sizeof(*lock),MEMF_ANY|MEMF_PUBLIC); + if(lock == NULL) + goto out; - InitSemaphore(lock); + InitSemaphore(lock); + } + #else + { + lock = NULL; + } + #endif /* __THREAD_SAFE */ /* Check if this stream is attached to a console window. */ if(default_file != ZERO) diff --git a/library/stdio_lock.c b/library/stdio_lock.c index 3b33407..9ca851f 100644 --- a/library/stdio_lock.c +++ b/library/stdio_lock.c @@ -1,5 +1,5 @@ /* - * $Id: stdio_lock.c,v 1.1 2005-02-27 21:58:21 obarthel Exp $ + * $Id: stdio_lock.c,v 1.2 2005-02-28 10:07:31 obarthel Exp $ * * :ts=4 * @@ -37,6 +37,10 @@ /****************************************************************************/ +#if defined(__THREAD_SAFE) + +/****************************************************************************/ + static struct SignalSemaphore * stdio_lock; /****************************************************************************/ @@ -94,3 +98,7 @@ __stdio_lock_init(void) return(result); } + +/****************************************************************************/ + +#endif /* __THREAD_SAFE */ diff --git a/library/stdio_openiob.c b/library/stdio_openiob.c index 20666e7..e98c527 100644 --- a/library/stdio_openiob.c +++ b/library/stdio_openiob.c @@ -1,5 +1,5 @@ /* - * $Id: stdio_openiob.c,v 1.9 2005-02-27 21:58:21 obarthel Exp $ + * $Id: stdio_openiob.c,v 1.10 2005-02-28 10:07:31 obarthel Exp $ * * :ts=4 * @@ -165,13 +165,21 @@ __open_iob(const char *filename, const char *mode, int file_descriptor, int slot CLEAR_FLAG(fd->fd_Flags,FDF_APPEND); } - /* Allocate memory for an arbitration mechanism, then - initialize it. */ - lock = AllocVec(sizeof(*lock),MEMF_ANY|MEMF_PUBLIC); - if(lock == NULL) - goto out; + #if defined(__THREAD_SAFE) + { + /* Allocate memory for an arbitration mechanism, then + initialize it. */ + lock = AllocVec(sizeof(*lock),MEMF_ANY|MEMF_PUBLIC); + if(lock == NULL) + goto out; - InitSemaphore(lock); + InitSemaphore(lock); + } + #else + { + lock = NULL; + } + #endif /* __THREAD_SAFE */ /* Figure out the buffered file access mode by looking at the open mode. */ file_flags = IOBF_IN_USE | IOBF_NO_NUL; diff --git a/library/stdio_popen.c b/library/stdio_popen.c index 513b247..f855dab 100644 --- a/library/stdio_popen.c +++ b/library/stdio_popen.c @@ -1,5 +1,5 @@ /* - * $Id: stdio_popen.c,v 1.5 2005-02-03 16:56:16 obarthel Exp $ + * $Id: stdio_popen.c,v 1.6 2005-02-28 10:07:31 obarthel Exp $ * * :ts=4 * @@ -64,6 +64,9 @@ pclose(FILE *stream) assert(stream != NULL); + if(__check_abort_enabled) + __check_abort(); + #if defined(CHECK_FOR_NULL_POINTERS) { if(stream == NULL) @@ -76,9 +79,6 @@ pclose(FILE *stream) } #endif /* CHECK_FOR_NULL_POINTERS */ - if(__check_abort_enabled) - __check_abort(); - fclose(stream); /* ZZZ we actually could catch the program's termination code @@ -117,6 +117,9 @@ popen(const char *command, const char *type) assert(command != NULL && type != NULL); + if(__check_abort_enabled) + __check_abort(); + #if defined(CHECK_FOR_NULL_POINTERS) { if(command == NULL || type == NULL) @@ -129,9 +132,6 @@ popen(const char *command, const char *type) } #endif /* CHECK_FOR_NULL_POINTERS */ - if(__check_abort_enabled) - __check_abort(); - /* The first character selects the access mode: read or write. We don't support anything else. */ switch(type[0]) diff --git a/library/stdio_printf.c b/library/stdio_printf.c index fda97d0..4eac361 100644 --- a/library/stdio_printf.c +++ b/library/stdio_printf.c @@ -1,5 +1,5 @@ /* - * $Id: stdio_printf.c,v 1.3 2005-02-03 16:56:16 obarthel Exp $ + * $Id: stdio_printf.c,v 1.4 2005-02-28 10:07:31 obarthel Exp $ * * :ts=4 * @@ -55,6 +55,9 @@ printf(const char *format, ...) assert( format != NULL ); + if(__check_abort_enabled) + __check_abort(); + #if defined(CHECK_FOR_NULL_POINTERS) { if(format == NULL) @@ -65,9 +68,6 @@ printf(const char *format, ...) } #endif /* CHECK_FOR_NULL_POINTERS */ - if(__check_abort_enabled) - __check_abort(); - va_start(arg,format); result = vfprintf(stdout,format,arg); va_end(arg); diff --git a/library/stdio_protos.h b/library/stdio_protos.h index 277afd7..c23b32f 100644 --- a/library/stdio_protos.h +++ b/library/stdio_protos.h @@ -1,5 +1,5 @@ /* - * $Id: stdio_protos.h,v 1.9 2005-02-27 21:58:21 obarthel Exp $ + * $Id: stdio_protos.h,v 1.10 2005-02-28 10:07:31 obarthel Exp $ * * :ts=4 * @@ -215,12 +215,4 @@ extern void __remove_fd_alias(struct fd * fd); /****************************************************************************/ -/* stdio_lock.c */ -extern void __stdio_lock(void); -extern void __stdio_unlock(void); -extern void __stdio_lock_exit(void); -extern int __stdio_lock_init(void); - -/****************************************************************************/ - #endif /* _STDIO_PROTOS_H */ diff --git a/library/stdio_record_locking.c b/library/stdio_record_locking.c index 1d312c4..68afe82 100644 --- a/library/stdio_record_locking.c +++ b/library/stdio_record_locking.c @@ -1,5 +1,5 @@ /* - * $Id: stdio_record_locking.c,v 1.3 2005-02-25 10:14:21 obarthel Exp $ + * $Id: stdio_record_locking.c,v 1.4 2005-02-28 10:07:31 obarthel Exp $ * * :ts=4 * @@ -999,7 +999,9 @@ __handle_record_locking(int cmd,struct flock * l,struct fd * fd,int * error_ptr) (*error_ptr) = EINTR; - __check_abort(); + if(__check_abort_enabled) + __check_abort(); + goto out; } diff --git a/library/stdio_remove.c b/library/stdio_remove.c index c1dd069..b459e2e 100644 --- a/library/stdio_remove.c +++ b/library/stdio_remove.c @@ -1,5 +1,5 @@ /* - * $Id: stdio_remove.c,v 1.3 2005-02-03 16:56:16 obarthel Exp $ + * $Id: stdio_remove.c,v 1.4 2005-02-28 10:07:31 obarthel Exp $ * * :ts=4 * @@ -54,6 +54,9 @@ remove(const char *filename) assert( filename != NULL ); + if(__check_abort_enabled) + __check_abort(); + #if defined(CHECK_FOR_NULL_POINTERS) { if(filename == NULL) @@ -66,9 +69,6 @@ remove(const char *filename) } #endif /* CHECK_FOR_NULL_POINTERS */ - if(__check_abort_enabled) - __check_abort(); - #if defined(UNIX_PATH_SEMANTICS) { result = unlink(filename); diff --git a/library/stdio_rename.c b/library/stdio_rename.c index 46a8c07..cf71fc7 100644 --- a/library/stdio_rename.c +++ b/library/stdio_rename.c @@ -1,5 +1,5 @@ /* - * $Id: stdio_rename.c,v 1.3 2005-02-03 16:56:16 obarthel Exp $ + * $Id: stdio_rename.c,v 1.4 2005-02-28 10:07:31 obarthel Exp $ * * :ts=4 * @@ -60,6 +60,9 @@ rename(const char *oldname,const char *newname) assert( oldname != NULL && newname != NULL ); + if(__check_abort_enabled) + __check_abort(); + #if defined(CHECK_FOR_NULL_POINTERS) { if(oldname == NULL || newname == NULL) @@ -72,9 +75,6 @@ rename(const char *oldname,const char *newname) } #endif /* CHECK_FOR_NULL_POINTERS */ - if(__check_abort_enabled) - __check_abort(); - #if defined(UNIX_PATH_SEMANTICS) { if(__unix_path_semantics) diff --git a/library/stdio_scanf.c b/library/stdio_scanf.c index ee3811c..87e28d4 100644 --- a/library/stdio_scanf.c +++ b/library/stdio_scanf.c @@ -1,5 +1,5 @@ /* - * $Id: stdio_scanf.c,v 1.3 2005-02-03 16:56:16 obarthel Exp $ + * $Id: stdio_scanf.c,v 1.4 2005-02-28 10:07:31 obarthel Exp $ * * :ts=4 * @@ -55,6 +55,9 @@ scanf(const char *format, ...) assert(format != NULL); + if(__check_abort_enabled) + __check_abort(); + #if defined(CHECK_FOR_NULL_POINTERS) { if(format == NULL) @@ -67,9 +70,6 @@ scanf(const char *format, ...) } #endif /* CHECK_FOR_NULL_POINTERS */ - if(__check_abort_enabled) - __check_abort(); - va_start(arg,format); result = __vfscanf(stdin,format,arg); va_end(arg); diff --git a/library/stdio_snprintf.c b/library/stdio_snprintf.c index a37d230..9b427ec 100644 --- a/library/stdio_snprintf.c +++ b/library/stdio_snprintf.c @@ -1,5 +1,5 @@ /* - * $Id: stdio_snprintf.c,v 1.3 2005-02-03 16:56:16 obarthel Exp $ + * $Id: stdio_snprintf.c,v 1.4 2005-02-28 10:07:31 obarthel Exp $ * * :ts=4 * @@ -60,6 +60,9 @@ snprintf(char *s, size_t size, const char *format, ...) assert( size == 0 || s != NULL ); assert( (int)size >= 0); + if(__check_abort_enabled) + __check_abort(); + #if defined(CHECK_FOR_NULL_POINTERS) { if((size > 0 && s == NULL) || format == NULL) @@ -70,9 +73,6 @@ snprintf(char *s, size_t size, const char *format, ...) } #endif /* CHECK_FOR_NULL_POINTERS */ - if(__check_abort_enabled) - __check_abort(); - va_start(arg,format); result = vsnprintf(s,size,format,arg); va_end(arg); diff --git a/library/stdio_sprintf.c b/library/stdio_sprintf.c index 9d761d7..147a6dc 100644 --- a/library/stdio_sprintf.c +++ b/library/stdio_sprintf.c @@ -1,5 +1,5 @@ /* - * $Id: stdio_sprintf.c,v 1.3 2005-02-03 16:56:16 obarthel Exp $ + * $Id: stdio_sprintf.c,v 1.4 2005-02-28 10:07:31 obarthel Exp $ * * :ts=4 * @@ -56,6 +56,9 @@ sprintf(char *s, const char *format, ...) assert( s != NULL && format != NULL ); + if(__check_abort_enabled) + __check_abort(); + #if defined(CHECK_FOR_NULL_POINTERS) { if(s == NULL || format == NULL) @@ -66,9 +69,6 @@ sprintf(char *s, const char *format, ...) } #endif /* CHECK_FOR_NULL_POINTERS */ - if(__check_abort_enabled) - __check_abort(); - va_start(arg,format); result = vsprintf(s,format,arg); va_end(arg); diff --git a/library/stdio_sscanf.c b/library/stdio_sscanf.c index aeb12bd..1aed7f0 100644 --- a/library/stdio_sscanf.c +++ b/library/stdio_sscanf.c @@ -1,5 +1,5 @@ /* - * $Id: stdio_sscanf.c,v 1.5 2005-02-27 18:09:11 obarthel Exp $ + * $Id: stdio_sscanf.c,v 1.6 2005-02-28 10:07:31 obarthel Exp $ * * :ts=4 * @@ -58,6 +58,9 @@ sscanf(const char *s,const char *format, ...) assert( s != NULL && format != NULL ); + if(__check_abort_enabled) + __check_abort(); + #if defined(CHECK_FOR_NULL_POINTERS) { if(s == NULL || format == NULL) @@ -70,9 +73,6 @@ sscanf(const char *s,const char *format, ...) } #endif /* CHECK_FOR_NULL_POINTERS */ - if(__check_abort_enabled) - __check_abort(); - __initialize_iob(&string_iob,__sscanf_hook_entry, NULL, local_buffer,sizeof(local_buffer), diff --git a/library/stdio_vasprintf.c b/library/stdio_vasprintf.c index cf7c507..35e7d4e 100644 --- a/library/stdio_vasprintf.c +++ b/library/stdio_vasprintf.c @@ -1,5 +1,5 @@ /* - * $Id: stdio_vasprintf.c,v 1.8 2005-02-27 18:09:11 obarthel Exp $ + * $Id: stdio_vasprintf.c,v 1.9 2005-02-28 10:07:31 obarthel Exp $ * * :ts=4 * @@ -71,6 +71,9 @@ __vasprintf(const char *file,int line,char **ret,const char *format,va_list arg) assert( ret != NULL && format != NULL && arg != NULL ); + if(__check_abort_enabled) + __check_abort(); + #if defined(CHECK_FOR_NULL_POINTERS) { if(ret == NULL || format == NULL || format == arg) @@ -83,9 +86,6 @@ __vasprintf(const char *file,int line,char **ret,const char *format,va_list arg) } #endif /* CHECK_FOR_NULL_POINTERS */ - if(__check_abort_enabled) - __check_abort(); - (*ret) = NULL; __initialize_iob(&string_iob,__vasprintf_hook_entry, diff --git a/library/stdio_vprintf.c b/library/stdio_vprintf.c index 78ae0db..6323e4c 100644 --- a/library/stdio_vprintf.c +++ b/library/stdio_vprintf.c @@ -1,5 +1,5 @@ /* - * $Id: stdio_vprintf.c,v 1.3 2005-02-03 16:56:16 obarthel Exp $ + * $Id: stdio_vprintf.c,v 1.4 2005-02-28 10:07:31 obarthel Exp $ * * :ts=4 * @@ -55,6 +55,9 @@ vprintf(const char *format,va_list arg) assert( format != NULL && arg != NULL ); + if(__check_abort_enabled) + __check_abort(); + #if defined(CHECK_FOR_NULL_POINTERS) { if(format == NULL || arg == NULL) @@ -65,9 +68,6 @@ vprintf(const char *format,va_list arg) } #endif /* CHECK_FOR_NULL_POINTERS */ - if(__check_abort_enabled) - __check_abort(); - result = vfprintf(stdout,format,arg); out: diff --git a/library/stdio_vsnprintf.c b/library/stdio_vsnprintf.c index 9d1fc93..af20a41 100644 --- a/library/stdio_vsnprintf.c +++ b/library/stdio_vsnprintf.c @@ -1,5 +1,5 @@ /* - * $Id: stdio_vsnprintf.c,v 1.6 2005-02-27 18:09:11 obarthel Exp $ + * $Id: stdio_vsnprintf.c,v 1.7 2005-02-28 10:07:31 obarthel Exp $ * * :ts=4 * @@ -63,6 +63,9 @@ vsnprintf(char *buffer,size_t size,const char *format,va_list arg) assert( format != NULL && arg != NULL && (int)size >= 0 ); + if(__check_abort_enabled) + __check_abort(); + #if defined(CHECK_FOR_NULL_POINTERS) { if(format == NULL || (buffer == NULL && size > 0)) @@ -75,9 +78,6 @@ vsnprintf(char *buffer,size_t size,const char *format,va_list arg) } #endif /* CHECK_FOR_NULL_POINTERS */ - if(__check_abort_enabled) - __check_abort(); - __initialize_iob(&string_iob,__vsnprintf_hook_entry, NULL, local_buffer,sizeof(local_buffer), diff --git a/library/stdio_vsprintf.c b/library/stdio_vsprintf.c index dc7714c..8c9258f 100644 --- a/library/stdio_vsprintf.c +++ b/library/stdio_vsprintf.c @@ -1,5 +1,5 @@ /* - * $Id: stdio_vsprintf.c,v 1.5 2005-02-27 18:09:11 obarthel Exp $ + * $Id: stdio_vsprintf.c,v 1.6 2005-02-28 10:07:31 obarthel Exp $ * * :ts=4 * @@ -52,6 +52,9 @@ vsprintf(char *s,const char *format,va_list arg) assert( s != NULL && format != NULL ); + if(__check_abort_enabled) + __check_abort(); + #if defined(CHECK_FOR_NULL_POINTERS) { if(s == NULL || format == NULL) @@ -62,9 +65,6 @@ vsprintf(char *s,const char *format,va_list arg) } #endif /* CHECK_FOR_NULL_POINTERS */ - if(__check_abort_enabled) - __check_abort(); - __initialize_iob(&string_iob,__vsprintf_hook_entry, NULL, buffer,sizeof(buffer), diff --git a/library/stdlib_free.c b/library/stdlib_free.c index 54216b2..aa0002b 100644 --- a/library/stdlib_free.c +++ b/library/stdlib_free.c @@ -1,5 +1,5 @@ /* - * $Id: stdlib_free.c,v 1.7 2005-02-27 21:58:21 obarthel Exp $ + * $Id: stdlib_free.c,v 1.8 2005-02-28 10:07:31 obarthel Exp $ * * :ts=4 * @@ -522,71 +522,3 @@ free(void * ptr) { __free(ptr,NULL,0); } - -/****************************************************************************/ - -void -__memory_exit(void) -{ - ENTER(); - - #ifdef __MEM_DEBUG - { - kprintf("[%s] %ld bytes still allocated upon exit, maximum of %ld bytes allocated at a time.\n", - __program_name,__current_memory_allocated,__maximum_memory_allocated); - - kprintf("[%s] %ld chunks of memory still allocated upon exit, maximum of %ld chunks allocated at a time.\n", - __program_name,__current_num_memory_chunks_allocated,__maximum_num_memory_chunks_allocated); - - __check_memory_allocations(__FILE__,__LINE__); - - __never_free = FALSE; - - if(__memory_list.mlh_Head != NULL) - { - while(NOT IsListEmpty((struct List *)&__memory_list)) - { - ((struct MemoryNode *)__memory_list.mlh_Head)->mn_AlreadyFree = FALSE; - - __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(__memory_pool != NULL) - { - NewList((struct List *)&__memory_list); - - DeletePool(__memory_pool); - __memory_pool = NULL; - } - else - { - if(__memory_list.mlh_Head != NULL) - { - #ifdef __MEM_DEBUG - { - while(NOT IsListEmpty((struct List *)&__memory_list)) - __free_memory_node((struct MemoryNode *)__memory_list.mlh_Head,__FILE__,__LINE__); - } - #else - { - while(NOT IsListEmpty((struct List *)&__memory_list)) - __free_memory_node((struct MemoryNode *)__memory_list.mlh_Head,NULL,0); - } - #endif /* __MEM_DEBUG */ - } - } - - FreeVec(__memory_semaphore); - __memory_semaphore = NULL; - - LEAVE(); -} diff --git a/library/stdlib_getenv.c b/library/stdlib_getenv.c index 707577b..e4b5809 100644 --- a/library/stdlib_getenv.c +++ b/library/stdlib_getenv.c @@ -1,5 +1,5 @@ /* - * $Id: stdlib_getenv.c,v 1.3 2005-02-03 16:56:16 obarthel Exp $ + * $Id: stdlib_getenv.c,v 1.4 2005-02-28 10:07:31 obarthel Exp $ * * :ts=4 * @@ -55,6 +55,9 @@ getenv(const char * name) assert( name != NULL ); + if(__check_abort_enabled) + __check_abort(); + #if defined(CHECK_FOR_NULL_POINTERS) { if(name == NULL) @@ -67,9 +70,6 @@ getenv(const char * name) } #endif /* CHECK_FOR_NULL_POINTERS */ - if(__check_abort_enabled) - __check_abort(); - if(GetVar((STRPTR)name,env_var_buffer,sizeof(env_var_buffer),0) < 0) { SHOWMSG("couldn't get the variable"); diff --git a/library/stdlib_headers.h b/library/stdlib_headers.h index a4ba3bd..3ca7860 100644 --- a/library/stdlib_headers.h +++ b/library/stdlib_headers.h @@ -1,5 +1,5 @@ /* - * $Id: stdlib_headers.h,v 1.10 2005-02-27 21:58:21 obarthel Exp $ + * $Id: stdlib_headers.h,v 1.11 2005-02-28 10:07:32 obarthel Exp $ * * :ts=4 * @@ -198,10 +198,9 @@ extern unsigned int NOCOMMON __random_seed; /****************************************************************************/ -extern struct SignalSemaphore * NOCOMMON __memory_semaphore; -extern struct MemoryTree NOCOMMON __memory_tree; -extern struct MinList NOCOMMON __memory_list; -extern APTR NOCOMMON __memory_pool; +extern struct MemoryTree NOCOMMON __memory_tree; +extern struct MinList NOCOMMON __memory_list; +extern APTR NOCOMMON __memory_pool; /****************************************************************************/ @@ -263,6 +262,28 @@ extern int NOCOMMON __default_puddle_size; /****************************************************************************/ +#if defined(__THREAD_SAFE) + +/****************************************************************************/ + +extern void __memory_lock(void); +extern void __memory_unlock(void); + +/****************************************************************************/ + +#else + +/****************************************************************************/ + +#define __memory_lock() ((void)0) +#define __memory_unlock() ((void)0) + +/****************************************************************************/ + +#endif /* __THREAD_SAFE */ + +/****************************************************************************/ + #ifndef _STDLIB_PROTOS_H #include "stdlib_protos.h" #endif /* _STDLIB_PROTOS_H */ diff --git a/library/stdlib_malloc.c b/library/stdlib_malloc.c index 1687dac..43e6e69 100644 --- a/library/stdlib_malloc.c +++ b/library/stdlib_malloc.c @@ -1,5 +1,5 @@ /* - * $Id: stdlib_malloc.c,v 1.8 2005-02-27 21:58:21 obarthel Exp $ + * $Id: stdlib_malloc.c,v 1.9 2005-02-28 10:07:32 obarthel Exp $ * * :ts=4 * @@ -63,7 +63,6 @@ struct MemoryTree __memory_tree; /****************************************************************************/ -struct SignalSemaphore * NOCOMMON __memory_semaphore; APTR NOCOMMON __memory_pool; struct MinList NOCOMMON __memory_list; @@ -267,11 +266,19 @@ malloc(size_t size) /****************************************************************************/ +#if defined(__THREAD_SAFE) + +/****************************************************************************/ + +static struct SignalSemaphore * memory_semaphore; + +/****************************************************************************/ + void __memory_lock(void) { - if(__memory_semaphore != NULL) - ObtainSemaphore(__memory_semaphore); + if(memory_semaphore != NULL) + ObtainSemaphore(memory_semaphore); } /****************************************************************************/ @@ -279,8 +286,84 @@ __memory_lock(void) void __memory_unlock(void) { - if(__memory_semaphore != NULL) - ReleaseSemaphore(__memory_semaphore); + if(memory_semaphore != NULL) + ReleaseSemaphore(memory_semaphore); +} + +/****************************************************************************/ + +#endif /* __THREAD_SAFE */ + +/****************************************************************************/ + +void +__memory_exit(void) +{ + ENTER(); + + #ifdef __MEM_DEBUG + { + kprintf("[%s] %ld bytes still allocated upon exit, maximum of %ld bytes allocated at a time.\n", + __program_name,__current_memory_allocated,__maximum_memory_allocated); + + kprintf("[%s] %ld chunks of memory still allocated upon exit, maximum of %ld chunks allocated at a time.\n", + __program_name,__current_num_memory_chunks_allocated,__maximum_num_memory_chunks_allocated); + + __check_memory_allocations(__FILE__,__LINE__); + + __never_free = FALSE; + + if(__memory_list.mlh_Head != NULL) + { + while(NOT IsListEmpty((struct List *)&__memory_list)) + { + ((struct MemoryNode *)__memory_list.mlh_Head)->mn_AlreadyFree = FALSE; + + __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(__memory_pool != NULL) + { + NewList((struct List *)&__memory_list); + + DeletePool(__memory_pool); + __memory_pool = NULL; + } + else + { + if(__memory_list.mlh_Head != NULL) + { + #ifdef __MEM_DEBUG + { + while(NOT IsListEmpty((struct List *)&__memory_list)) + __free_memory_node((struct MemoryNode *)__memory_list.mlh_Head,__FILE__,__LINE__); + } + #else + { + while(NOT IsListEmpty((struct List *)&__memory_list)) + __free_memory_node((struct MemoryNode *)__memory_list.mlh_Head,NULL,0); + } + #endif /* __MEM_DEBUG */ + } + } + + #if defined(__THREAD_SAFE) + { + FreeVec(memory_semaphore); + memory_semaphore = NULL; + } + #endif /* __THREAD_SAFE */ + + LEAVE(); } /****************************************************************************/ @@ -292,11 +375,15 @@ __memory_init(void) ENTER(); - __memory_semaphore = AllocVec(sizeof(*__memory_semaphore),MEMF_ANY|MEMF_PUBLIC); - if(__memory_semaphore == NULL) - goto out; + #if defined(__THREAD_SAFE) + { + memory_semaphore = AllocVec(sizeof(*memory_semaphore),MEMF_ANY|MEMF_PUBLIC); + if(memory_semaphore == NULL) + goto out; - InitSemaphore(__memory_semaphore); + InitSemaphore(memory_semaphore); + } + #endif /* __THREAD_SAFE */ #if defined(__USE_MEM_TREES) && defined(__MEM_DEBUG) { diff --git a/library/stdlib_mktemp.c b/library/stdlib_mktemp.c index 4d559e4..7717c35 100644 --- a/library/stdlib_mktemp.c +++ b/library/stdlib_mktemp.c @@ -1,5 +1,5 @@ /* - * $Id: stdlib_mktemp.c,v 1.6 2005-02-03 16:56:16 obarthel Exp $ + * $Id: stdlib_mktemp.c,v 1.7 2005-02-28 10:07:32 obarthel Exp $ * * :ts=4 * @@ -77,7 +77,8 @@ mktemp(char * name_template) assert(name_template != NULL); - this_process = (struct Process *)FindTask(NULL); + if(__check_abort_enabled) + __check_abort(); #if defined(CHECK_FOR_NULL_POINTERS) { @@ -91,8 +92,7 @@ mktemp(char * name_template) } #endif /* CHECK_FOR_NULL_POINTERS */ - if(__check_abort_enabled) - __check_abort(); + this_process = (struct Process *)FindTask(NULL); SHOWSTRING(name_template); diff --git a/library/stdlib_protos.h b/library/stdlib_protos.h index 2647bb4..68d5130 100644 --- a/library/stdlib_protos.h +++ b/library/stdlib_protos.h @@ -1,5 +1,5 @@ /* - * $Id: stdlib_protos.h,v 1.8 2005-02-27 21:58:21 obarthel Exp $ + * $Id: stdlib_protos.h,v 1.9 2005-02-28 10:07:32 obarthel Exp $ * * :ts=4 * @@ -139,13 +139,11 @@ extern int __startup_init(void); /* stdlib_malloc.c */ extern int __memory_init(void); +extern void __memory_exit(void); extern size_t __get_allocation_size(size_t size); extern void * __allocate_memory(size_t size,BOOL never_free,const char * file,int line); -extern void __memory_lock(void); -extern void __memory_unlock(void); /* stdlib_free.c */ -extern void __memory_exit(void); extern struct MemoryNode * __find_memory_node(void * address); extern void __force_free(void * ptr,const char * file,int line); extern void __check_memory_allocations(const char * file,int line); diff --git a/library/stdlib_putenv.c b/library/stdlib_putenv.c index 4e0dc8d..861526d 100644 --- a/library/stdlib_putenv.c +++ b/library/stdlib_putenv.c @@ -1,5 +1,5 @@ /* - * $Id: stdlib_putenv.c,v 1.4 2005-02-03 16:56:16 obarthel Exp $ + * $Id: stdlib_putenv.c,v 1.5 2005-02-28 10:07:32 obarthel Exp $ * * :ts=4 * @@ -58,6 +58,9 @@ putenv(const char *string) assert( string != NULL ); + if(__check_abort_enabled) + __check_abort(); + #if defined(CHECK_FOR_NULL_POINTERS) { if(string == NULL) @@ -70,9 +73,6 @@ putenv(const char *string) } #endif /* CHECK_FOR_NULL_POINTERS */ - if(__check_abort_enabled) - __check_abort(); - result = setenv(string,"",1); out: diff --git a/library/stdlib_setenv.c b/library/stdlib_setenv.c index dc3bc61..b3c4940 100644 --- a/library/stdlib_setenv.c +++ b/library/stdlib_setenv.c @@ -1,5 +1,5 @@ /* - * $Id: stdlib_setenv.c,v 1.6 2005-02-03 16:56:17 obarthel Exp $ + * $Id: stdlib_setenv.c,v 1.7 2005-02-28 10:07:32 obarthel Exp $ * * :ts=4 * @@ -106,6 +106,9 @@ setenv(const char *original_name, const char *original_value, int overwrite) assert(original_name != NULL || original_value != NULL); + if(__check_abort_enabled) + __check_abort(); + #if defined(CHECK_FOR_NULL_POINTERS) { if(original_name == NULL && original_value == NULL) @@ -118,9 +121,6 @@ setenv(const char *original_name, const char *original_value, int overwrite) } #endif /* CHECK_FOR_NULL_POINTERS */ - if(__check_abort_enabled) - __check_abort(); - if(name != NULL) { for(i = 0 ; i < strlen(name) ; i++) diff --git a/library/stdlib_unsetenv.c b/library/stdlib_unsetenv.c index 05801ff..4e4c1dc 100644 --- a/library/stdlib_unsetenv.c +++ b/library/stdlib_unsetenv.c @@ -1,5 +1,5 @@ /* - * $Id: stdlib_unsetenv.c,v 1.4 2005-02-03 16:56:17 obarthel Exp $ + * $Id: stdlib_unsetenv.c,v 1.5 2005-02-28 10:07:32 obarthel Exp $ * * :ts=4 * @@ -60,7 +60,8 @@ unsetenv(const char *original_name) char * name_copy = NULL; unsigned i; - __check_abort(); + if(__check_abort_enabled) + __check_abort(); assert( name != NULL ); diff --git a/library/unistd_access.c b/library/unistd_access.c index 1f101a9..d80d9d9 100644 --- a/library/unistd_access.c +++ b/library/unistd_access.c @@ -1,5 +1,5 @@ /* - * $Id: unistd_access.c,v 1.4 2005-02-03 16:56:17 obarthel Exp $ + * $Id: unistd_access.c,v 1.5 2005-02-28 10:07:32 obarthel Exp $ * * :ts=4 * @@ -63,6 +63,9 @@ access(const char * path_name, int mode) assert( path_name != NULL ); + if(__check_abort_enabled) + __check_abort(); + #if defined(CHECK_FOR_NULL_POINTERS) { if(path_name == NULL) @@ -75,9 +78,6 @@ access(const char * path_name, int mode) } #endif /* CHECK_FOR_NULL_POINTERS */ - if(__check_abort_enabled) - __check_abort(); - if(mode < 0 || mode > (R_OK|W_OK|X_OK|F_OK)) { SHOWMSG("invalid mode"); diff --git a/library/unistd_chdir.c b/library/unistd_chdir.c index 3260da3..dd2af56 100644 --- a/library/unistd_chdir.c +++ b/library/unistd_chdir.c @@ -1,5 +1,5 @@ /* - * $Id: unistd_chdir.c,v 1.4 2005-02-03 16:56:17 obarthel Exp $ + * $Id: unistd_chdir.c,v 1.5 2005-02-28 10:07:32 obarthel Exp $ * * :ts=4 * @@ -64,6 +64,9 @@ chdir(const char * path_name) assert( path_name != NULL ); + if(__check_abort_enabled) + __check_abort(); + #if defined(CHECK_FOR_NULL_POINTERS) { if(path_name == NULL) @@ -76,9 +79,6 @@ chdir(const char * path_name) } #endif /* CHECK_FOR_NULL_POINTERS */ - if(__check_abort_enabled) - __check_abort(); - #if defined(UNIX_PATH_SEMANTICS) { if(__unix_path_semantics) diff --git a/library/unistd_chown.c b/library/unistd_chown.c index 96aa276..692ae41 100644 --- a/library/unistd_chown.c +++ b/library/unistd_chown.c @@ -1,5 +1,5 @@ /* - * $Id: unistd_chown.c,v 1.5 2005-02-03 16:56:17 obarthel Exp $ + * $Id: unistd_chown.c,v 1.6 2005-02-28 10:07:32 obarthel Exp $ * * :ts=4 * @@ -65,6 +65,9 @@ chown(const char * path_name, uid_t owner, gid_t group) assert( path_name != NULL ); + if(__check_abort_enabled) + __check_abort(); + #if defined(CHECK_FOR_NULL_POINTERS) { if(path_name == NULL) @@ -77,9 +80,6 @@ chown(const char * path_name, uid_t owner, gid_t group) } #endif /* CHECK_FOR_NULL_POINTERS */ - if(__check_abort_enabled) - __check_abort(); - if(owner > 65535 || group > 65535) { SHOWMSG("invalid owner or group"); diff --git a/library/unistd_getcwd.c b/library/unistd_getcwd.c index 3a4cd0a..d979b83 100644 --- a/library/unistd_getcwd.c +++ b/library/unistd_getcwd.c @@ -1,5 +1,5 @@ /* - * $Id: unistd_getcwd.c,v 1.6 2005-02-03 16:56:17 obarthel Exp $ + * $Id: unistd_getcwd.c,v 1.7 2005-02-28 10:07:32 obarthel Exp $ * * :ts=4 * @@ -81,6 +81,9 @@ __getcwd(char * buffer,size_t buffer_size,const char *file,int line) assert( buffer != NULL ); assert( (int)buffer_size >= 0 ); + if(__check_abort_enabled) + __check_abort(); + #if defined(CHECK_FOR_NULL_POINTERS) { if(buffer == NULL || buffer_size == 0) @@ -93,9 +96,6 @@ __getcwd(char * buffer,size_t buffer_size,const char *file,int line) } #endif /* CHECK_FOR_NULL_POINTERS */ - if(__check_abort_enabled) - __check_abort(); - PROFILE_OFF(); dir_lock = Lock("",SHARED_LOCK); PROFILE_ON(); diff --git a/library/unistd_getopt.c b/library/unistd_getopt.c index 5cc64e4..8a57926 100644 --- a/library/unistd_getopt.c +++ b/library/unistd_getopt.c @@ -1,5 +1,5 @@ /* - * $Id: unistd_getopt.c,v 1.4 2005-02-03 16:56:17 obarthel Exp $ + * $Id: unistd_getopt.c,v 1.5 2005-02-28 10:07:32 obarthel Exp $ * * :ts=4 * @@ -70,6 +70,9 @@ getopt(int argc, char * argv[], char *opts) assert( argc > 0 && argv != NULL && opts != NULL ); + if(__check_abort_enabled) + __check_abort(); + #if defined(CHECK_FOR_NULL_POINTERS) { if(argv == NULL || opts == NULL) @@ -82,9 +85,6 @@ getopt(int argc, char * argv[], char *opts) } #endif /* CHECK_FOR_NULL_POINTERS */ - if(__check_abort_enabled) - __check_abort(); - SHOWVALUE(optind); if(sp == 1) diff --git a/library/unistd_lchown.c b/library/unistd_lchown.c index f0a22c6..4b79a98 100644 --- a/library/unistd_lchown.c +++ b/library/unistd_lchown.c @@ -1,5 +1,5 @@ /* - * $Id: unistd_lchown.c,v 1.4 2005-02-03 16:56:17 obarthel Exp $ + * $Id: unistd_lchown.c,v 1.5 2005-02-28 10:07:32 obarthel Exp $ * * :ts=4 * @@ -60,6 +60,9 @@ lchown(const char * path_name, uid_t owner, gid_t group) assert( path_name != NULL ); + if(__check_abort_enabled) + __check_abort(); + #if defined(CHECK_FOR_NULL_POINTERS) { if(path_name == NULL) @@ -72,9 +75,6 @@ lchown(const char * path_name, uid_t owner, gid_t group) } #endif /* CHECK_FOR_NULL_POINTERS */ - if(__check_abort_enabled) - __check_abort(); - result = chown(path_name,owner,group); out: diff --git a/library/unistd_link.c b/library/unistd_link.c index 7f35d23..1f4cad6 100644 --- a/library/unistd_link.c +++ b/library/unistd_link.c @@ -1,5 +1,5 @@ /* - * $Id: unistd_link.c,v 1.4 2005-02-03 16:56:17 obarthel Exp $ + * $Id: unistd_link.c,v 1.5 2005-02-28 10:07:32 obarthel Exp $ * * :ts=4 * @@ -65,6 +65,9 @@ link(const char * existing_path,const char * new_path) assert( existing_path != NULL && new_path != NULL ); + if(__check_abort_enabled) + __check_abort(); + #if defined(CHECK_FOR_NULL_POINTERS) { if(existing_path == NULL || new_path == NULL) @@ -77,9 +80,6 @@ link(const char * existing_path,const char * new_path) } #endif /* CHECK_FOR_NULL_POINTERS */ - if(__check_abort_enabled) - __check_abort(); - #if defined(UNIX_PATH_SEMANTICS) { if(__unix_path_semantics) diff --git a/library/unistd_readlink.c b/library/unistd_readlink.c index b785a09..f177b62 100644 --- a/library/unistd_readlink.c +++ b/library/unistd_readlink.c @@ -1,5 +1,5 @@ /* - * $Id: unistd_readlink.c,v 1.4 2005-02-03 16:56:17 obarthel Exp $ + * $Id: unistd_readlink.c,v 1.5 2005-02-28 10:07:32 obarthel Exp $ * * :ts=4 * @@ -66,6 +66,9 @@ readlink(const char * path_name, char * buffer, int buffer_size) assert( path_name != NULL && buffer != NULL ); + if(__check_abort_enabled) + __check_abort(); + #if defined(CHECK_FOR_NULL_POINTERS) { if(path_name == NULL || buffer == NULL) @@ -78,9 +81,6 @@ readlink(const char * path_name, char * buffer, int buffer_size) } #endif /* CHECK_FOR_NULL_POINTERS */ - if(__check_abort_enabled) - __check_abort(); - #if defined(UNIX_PATH_SEMANTICS) { if(__unix_path_semantics && __translate_unix_to_amiga_path_name(&path_name,&path_name_nti) != 0) diff --git a/library/unistd_realpath.c b/library/unistd_realpath.c index befd871..bb2a3c1 100644 --- a/library/unistd_realpath.c +++ b/library/unistd_realpath.c @@ -1,5 +1,5 @@ /* - * $Id: unistd_realpath.c,v 1.4 2005-02-03 16:56:17 obarthel Exp $ + * $Id: unistd_realpath.c,v 1.5 2005-02-28 10:07:32 obarthel Exp $ * * :ts=4 * @@ -65,6 +65,9 @@ realpath(const char * path_name, char * buffer) assert( path_name != NULL && buffer != NULL ); + if(__check_abort_enabled) + __check_abort(); + #if defined(CHECK_FOR_NULL_POINTERS) { if(path_name == NULL || buffer == NULL) @@ -77,9 +80,6 @@ realpath(const char * path_name, char * buffer) } #endif /* CHECK_FOR_NULL_POINTERS */ - if(__check_abort_enabled) - __check_abort(); - #if defined(UNIX_PATH_SEMANTICS) { if(__unix_path_semantics && __translate_unix_to_amiga_path_name(&path_name,&path_name_nti) != 0) diff --git a/library/unistd_symlink.c b/library/unistd_symlink.c index 387868e..0fb5400 100644 --- a/library/unistd_symlink.c +++ b/library/unistd_symlink.c @@ -1,5 +1,5 @@ /* - * $Id: unistd_symlink.c,v 1.4 2005-02-03 16:56:17 obarthel Exp $ + * $Id: unistd_symlink.c,v 1.5 2005-02-28 10:07:32 obarthel Exp $ * * :ts=4 * @@ -63,6 +63,9 @@ symlink(const char * actual_path, const char * symbolic_path) assert( actual_path != NULL && symbolic_path != NULL ); + if(__check_abort_enabled) + __check_abort(); + #if defined(CHECK_FOR_NULL_POINTERS) { if(actual_path == NULL || symbolic_path == NULL) @@ -75,9 +78,6 @@ symlink(const char * actual_path, const char * symbolic_path) } #endif /* CHECK_FOR_NULL_POINTERS */ - if(__check_abort_enabled) - __check_abort(); - SHOWMSG("trying to make that link"); PROFILE_OFF(); diff --git a/library/unistd_truncate.c b/library/unistd_truncate.c index c81bd82..ad9b464 100644 --- a/library/unistd_truncate.c +++ b/library/unistd_truncate.c @@ -1,5 +1,5 @@ /* - * $Id: unistd_truncate.c,v 1.4 2005-02-03 16:56:17 obarthel Exp $ + * $Id: unistd_truncate.c,v 1.5 2005-02-28 10:07:32 obarthel Exp $ * * :ts=4 * @@ -60,6 +60,9 @@ truncate(const char * path_name, off_t length) assert( path_name != NULL ); + if(__check_abort_enabled) + __check_abort(); + #if defined(CHECK_FOR_NULL_POINTERS) { if(path_name == NULL) @@ -72,9 +75,6 @@ truncate(const char * path_name, off_t length) } #endif /* CHECK_FOR_NULL_POINTERS */ - if(__check_abort_enabled) - __check_abort(); - if(length < 0) { SHOWMSG("invalid length"); diff --git a/library/unistd_unlink.c b/library/unistd_unlink.c index 2752eb3..93cd9f0 100644 --- a/library/unistd_unlink.c +++ b/library/unistd_unlink.c @@ -1,5 +1,5 @@ /* - * $Id: unistd_unlink.c,v 1.4 2005-02-03 16:56:17 obarthel Exp $ + * $Id: unistd_unlink.c,v 1.5 2005-02-28 10:07:32 obarthel Exp $ * * :ts=4 * @@ -70,6 +70,9 @@ unlink(const char * path_name) assert( path_name != NULL ); + if(__check_abort_enabled) + __check_abort(); + #if defined(CHECK_FOR_NULL_POINTERS) { if(path_name == NULL) @@ -82,9 +85,6 @@ unlink(const char * path_name) } #endif /* CHECK_FOR_NULL_POINTERS */ - if(__check_abort_enabled) - __check_abort(); - #if defined(UNIX_PATH_SEMANTICS) { if(__unix_path_semantics) diff --git a/library/utime_utime.c b/library/utime_utime.c index d488dec..5e82538 100644 --- a/library/utime_utime.c +++ b/library/utime_utime.c @@ -1,5 +1,5 @@ /* - * $Id: utime_utime.c,v 1.6 2005-02-03 16:56:17 obarthel Exp $ + * $Id: utime_utime.c,v 1.7 2005-02-28 10:07:32 obarthel Exp $ * * :ts=4 * @@ -67,6 +67,9 @@ utime(const char * path_name,const struct utimbuf * times) assert( path_name != NULL ); + if(__check_abort_enabled) + __check_abort(); + #if defined(CHECK_FOR_NULL_POINTERS) { if(path_name == NULL) @@ -77,9 +80,6 @@ utime(const char * path_name,const struct utimbuf * times) } #endif /* CHECK_FOR_NULL_POINTERS */ - if(__check_abort_enabled) - __check_abort(); - /* If a modification time is provided, convert it into the local DateStamp format, as used by the SetFileDate() function. */ if(times != NULL)