From 0105cf98dabb886a72baa5375ea787ac0f2b4537 Mon Sep 17 00:00:00 2001 From: Karl Williamson Date: Tue, 9 Feb 2021 12:48:18 -0700 Subject: [PATCH] Unixish.h, doshish.h: Reorder terminations; simplify The IO and memory terminations need to be after other things. Add a comment so that future maintainers won't make the mistakes I did. Also refactor to that amiga os doesn't have a separate list to get out of sync I suspect that the amiga termination should be moved to earlier in the sequence, but absent any evidence; I'm leaving it unchanged. --- dosish.h | 17 +++++++++++------ unixish.h | 40 +++++++++++++++++++++------------------- 2 files changed, 32 insertions(+), 25 deletions(-) diff --git a/dosish.h b/dosish.h index 74aa1270556e..003cbaa2d1af 100644 --- a/dosish.h +++ b/dosish.h @@ -17,7 +17,7 @@ # define BIT_BUCKET "nul" # define OP_BINARY O_BINARY # define PERL_SYS_INIT_BODY(c,v) \ - MALLOC_CHECK_TAINT2(*c,*v) Perl_DJGPP_init(c,v); PERLIO_INIT + MALLOC_CHECK_TAINT2(*c,*v) Perl_DJGPP_init(c,v); PERLIO_INIT # define init_os_extras Perl_init_os_extras # define HAS_UTIME # define HAS_KILL @@ -30,8 +30,8 @@ # define PERL_FS_VER_FMT "%d_%d_%d" # endif # define PERL_FS_VERSION STRINGIFY(PERL_REVISION) "_" \ - STRINGIFY(PERL_VERSION) "_" \ - STRINGIFY(PERL_SUBVERSION) + STRINGIFY(PERL_VERSION) "_" \ + STRINGIFY(PERL_SUBVERSION) #elif defined(WIN32) # define PERL_SYS_INIT_BODY(c,v) \ MALLOC_CHECK_TAINT2(*c,*v) Perl_win32_init(c,v); PERLIO_INIT @@ -47,12 +47,17 @@ # define BIT_BUCKET "\\dev\\nul" /* "wanna be like, umm, Newlined, or somethin?" */ #endif +/* Generally add things last-in first-terminated. IO and memory terminations + * need to be generally last + * + * BEWARE that using PerlIO in these will be using freed memory, so may appear + * to work, but must NOT be retained in production code. */ #ifndef PERL_SYS_TERM_BODY # define PERL_SYS_TERM_BODY() \ + ENV_TERM; USER_PROP_MUTEX_TERM; LOCALE_TERM; \ HINTS_REFCNT_TERM; KEYWORD_PLUGIN_MUTEX_TERM; \ - OP_CHECK_MUTEX_TERM; OP_REFCNT_TERM; PERLIO_TERM; \ - MALLOC_TERM; LOCALE_TERM; USER_PROP_MUTEX_TERM; \ - ENV_TERM; + OP_CHECK_MUTEX_TERM; OP_REFCNT_TERM; \ + PERLIO_TERM; MALLOC_TERM; #endif #define dXSUB_SYS dNOOP diff --git a/unixish.h b/unixish.h index eafc6f1e8b88..eb4c4a0f1e44 100644 --- a/unixish.h +++ b/unixish.h @@ -136,29 +136,31 @@ int afstat(int fd, struct stat *statb); #define Mkdir(path,mode) mkdir((path),(mode)) #if defined(__amigaos4__) -# define PERL_SYS_INIT_BODY(c,v) \ - MALLOC_CHECK_TAINT2(*c,*v) PERL_FPU_INIT; PERLIO_INIT; MALLOC_INIT; amigaos4_init_fork_array(); amigaos4_init_environ_sema(); -# define PERL_SYS_TERM_BODY() \ - HINTS_REFCNT_TERM; KEYWORD_PLUGIN_MUTEX_TERM; \ - OP_CHECK_MUTEX_TERM; OP_REFCNT_TERM; PERLIO_TERM; \ - MALLOC_TERM; LOCALE_TERM; USER_PROP_MUTEX_TERM; \ - ENV_TERM; \ - amigaos4_dispose_fork_array(); +# define AMIGAOS_SYS_TERM_ amigaos4_dispose_fork_array() +# define AMIGAOS_SYS_INIT_ STMT_START { \ + amigaos4_init_fork_array(); \ + amigaos4_init_environ_sema(); \ + } STMT_END +#else +# define AMIGAOS_SYS_TERM_ NOOP +# define AMIGAOS_SYS_INIT_ NOOP #endif -#ifndef PERL_SYS_INIT_BODY -# define PERL_SYS_INIT_BODY(c,v) \ - MALLOC_CHECK_TAINT2(*c,*v) PERL_FPU_INIT; PERLIO_INIT; MALLOC_INIT -#endif +#define PERL_SYS_INIT_BODY(c,v) \ + MALLOC_CHECK_TAINT2(*c,*v) PERL_FPU_INIT; PERLIO_INIT; \ + MALLOC_INIT; AMIGAOS_SYS_INIT_; -#ifndef PERL_SYS_TERM_BODY -# define PERL_SYS_TERM_BODY() \ +/* Generally add things last-in first-terminated. IO and memory terminations + * need to be generally last + * + * BEWARE that using PerlIO in these will be using freed memory, so may appear + * to work, but must NOT be retained in production code. */ +#define PERL_SYS_TERM_BODY() \ + ENV_TERM; USER_PROP_MUTEX_TERM; LOCALE_TERM; \ HINTS_REFCNT_TERM; KEYWORD_PLUGIN_MUTEX_TERM; \ - OP_CHECK_MUTEX_TERM; OP_REFCNT_TERM; PERLIO_TERM; \ - MALLOC_TERM; LOCALE_TERM; USER_PROP_MUTEX_TERM; \ - ENV_TERM; - -#endif + OP_CHECK_MUTEX_TERM; OP_REFCNT_TERM; \ + PERLIO_TERM; MALLOC_TERM; \ + AMIGAOS_SYS_TERM_; #define BIT_BUCKET "/dev/null"