From d267701a918634b5811685d7363454f87a32bc25 Mon Sep 17 00:00:00 2001 From: Chet Ramey Date: Wed, 29 Mar 2023 15:43:46 -0400 Subject: [PATCH] more ANSI/ISO C changes; start on converting the unwind-protect framework to ANSI C --- CWRU/CWRU.chlog | 32 +++++++++++++++++ aclocal.m4 | 20 ----------- builtins/common.c | 23 ++----------- builtins/mkbuiltins.c | 22 +++++------- builtins/printf.def | 10 ++---- config-bot.h | 11 ------ configure | 37 +------------------- configure.ac | 5 ++- error.c | 29 +++++++--------- execute_cmd.c | 15 ++++---- general.h | 4 --- include/memalloc.h | 4 --- include/stdc.h | 8 +---- jobs.h | 4 +-- lib/malloc/alloca.c | 4 --- lib/malloc/imalloc.h | 14 +------- lib/malloc/malloc.c | 6 ++-- lib/malloc/shmalloc.h | 7 ---- lib/malloc/xmalloc.c | 6 ---- lib/readline/bind.c | 22 ------------ lib/readline/complete.c | 4 --- lib/readline/display.c | 59 +------------------------------- lib/readline/examples/rl.c | 6 +--- lib/readline/funmap.c | 4 --- lib/readline/histlib.h | 3 -- lib/readline/parens.c | 4 --- lib/readline/readline.h | 6 +--- lib/readline/rldefs.h | 12 +------ lib/readline/rlprivate.h | 8 +---- lib/readline/rlstdc.h | 14 +------- lib/readline/util.c | 64 ---------------------------------- lib/sh/dprintf.c | 11 ++---- lib/sh/fdprintf.c | 70 -------------------------------------- lib/sh/snprintf.c | 11 ++---- lib/sh/vprint.c | 6 +--- lib/termcap/termcap.h | 26 +------------- m4/iconv.m4 | 4 --- pcomplete.c | 8 ++--- print_cmd.c | 25 ++------------ unwind_prot.c | 59 ++++++++++++-------------------- unwind_prot.h | 11 +++++- 41 files changed, 128 insertions(+), 570 deletions(-) delete mode 100644 lib/sh/fdprintf.c diff --git a/CWRU/CWRU.chlog b/CWRU/CWRU.chlog index 44d61616..403f645f 100644 --- a/CWRU/CWRU.chlog +++ b/CWRU/CWRU.chlog @@ -5884,4 +5884,36 @@ builtins/common.c,examples/loadables/getconf.c execute_cmd.c,pcomplete.c,subst.c lib/sh/stringlist.c,lib/sh/stringvec.c - changes and casts now that the generic list functions are prototyped + From Paul Eggert + + 3/29 + ---- +aclocal.m4,configure.ac +builtins/common.c,builtins/mkbuiltins.c,builtins/printf.def +include/memalloc.h,include/stdc.h +general.h,jobs.h +pcomplete.c,print_cmd.c +m4/iconv.m4 +lib/readline/bind.c,lib/readline/complete.c,lib/readline/display.c +lib/readline/funmap.c,lib/readline/util.c,lib/readline/parens.c +lib/readline/histlib.h +lib/readline/readline.h,lib/readline/rldefs.h,lib/readline/rlstdc.h,lib/readline/rlprivate.h +lib/sh/dprintf.c,lib/sh/snprintf.c,lib/sh/vprintf.c +lib/malloc/shmalloc.h,lib/malloc/imalloc.h,lib/malloc/xmalloc.c +lib/termcap/termcap.h + - stdarg: since we now assume C89 for prototypes at least, always + prefer stdarg to old-style varargs + - SH_VA_START: now use plain old va_start + - don't bother with extern declarations for standard C89 functions + From Paul Eggert + +config-bot.h + - PREFER_STDARG: remove + +builtins/mkbuiltins.c +execute_cmd.c,unwind_prot.c +unwind_prot.h + - start on ANSI/ISO C changes for the unwind-protect framework + - introduce new unwind-protect function pointer type to replace + Function From Paul Eggert diff --git a/aclocal.m4 b/aclocal.m4 index 9387a117..2a86c70c 100644 --- a/aclocal.m4 +++ b/aclocal.m4 @@ -69,11 +69,7 @@ AC_DEFUN(BASH_DECL_PRINTF, AC_CACHE_VAL(bash_cv_printf_declared, [AC_RUN_IFELSE([AC_LANG_SOURCE([[ #include -#ifdef __STDC__ typedef int (*_bashfunc)(const char *, ...); -#else -typedef int (*_bashfunc)(); -#endif #include int main() @@ -594,7 +590,6 @@ fi # We should check for putenv before calling this AC_DEFUN(BASH_FUNC_STD_PUTENV, [ -AC_REQUIRE([AC_C_PROTOTYPES]) AC_CACHE_CHECK([for standard-conformant putenv declaration], bash_cv_std_putenv, [AC_LINK_IFELSE([AC_LANG_PROGRAM([[ #if HAVE_STDLIB_H @@ -615,7 +610,6 @@ fi # We should check for unsetenv before calling this AC_DEFUN(BASH_FUNC_STD_UNSETENV, [ -AC_REQUIRE([AC_C_PROTOTYPES]) AC_CACHE_CHECK([for standard-conformant unsetenv declaration], bash_cv_std_unsetenv, [AC_LINK_IFELSE([AC_LANG_PROGRAM([[ #if HAVE_STDLIB_H @@ -2065,31 +2059,17 @@ AC_DEFUN([BASH_FUNC_VSNPRINTF], if test X$ac_cv_func_vsnprintf = Xyes; then AC_CACHE_CHECK([for standard-conformant vsnprintf], [bash_cv_func_vsnprintf], [AC_RUN_IFELSE([AC_LANG_SOURCE([[ -#if HAVE_STDARG_H #include -#else -#include -#endif #include #include static int -#if HAVE_STDARG_H foo(const char *fmt, ...) -#else -foo(format, va_alist) - const char *format; - va_dcl -#endif { va_list args; int n; -#if HAVE_STDARG_H va_start(args, fmt); -#else - va_start(args); -#endif n = vsnprintf(0, 0, fmt, args); va_end (args); return n; diff --git a/builtins/common.c b/builtins/common.c index 52a1f68a..e5402961 100644 --- a/builtins/common.c +++ b/builtins/common.c @@ -34,12 +34,7 @@ #include #include - -#if defined (PREFER_STDARG) -# include -#else -# include -#endif +#include #include "../bashansi.h" #include "../bashintl.h" @@ -100,19 +95,13 @@ builtin_error_prolog (void) } void -#if defined (PREFER_STDARG) builtin_error (const char *format, ...) -#else -builtin_error (format, va_alist) - const char *format; - va_dcl -#endif { va_list args; builtin_error_prolog (); - SH_VA_START (args, format); + va_start (args, format); vfprintf (stderr, format, args); va_end (args); @@ -120,20 +109,14 @@ builtin_error (format, va_alist) } void -#if defined (PREFER_STDARG) builtin_warning (const char *format, ...) -#else -builtin_warning (format, va_alist) - const char *format; - va_dcl -#endif { va_list args; builtin_error_prolog (); fprintf (stderr, _("warning: ")); - SH_VA_START (args, format); + va_start (args, format); vfprintf (stderr, format, args); va_end (args); diff --git a/builtins/mkbuiltins.c b/builtins/mkbuiltins.c index 7b7f68ce..d0d5559f 100644 --- a/builtins/mkbuiltins.c +++ b/builtins/mkbuiltins.c @@ -1,7 +1,7 @@ /* mkbuiltins.c - Create builtins.c, builtext.h, and builtdoc.c from a single source file called builtins.def. */ -/* Copyright (C) 1987-2022 Free Software Foundation, Inc. +/* Copyright (C) 1987-2023 Free Software Foundation, Inc. This file is part of GNU Bash, the Bourne Again SHell. @@ -59,11 +59,8 @@ extern int errno; #endif -static char *xmalloc (size_t), *xrealloc (void *, size_t); - -#if !defined (__STDC__) && !defined (strcpy) -extern char *strcpy (); -#endif /* !__STDC__ && !strcpy */ +static void *xmalloc (size_t); +static void *xrealloc (void *, size_t); #define savestring(x) strcpy (xmalloc (1 + strlen (x)), (x)) #define whitespace(c) (((c) == ' ') || ((c) == '\t')) @@ -456,7 +453,6 @@ array_free (ARRAY *array) /* **************************************************************** */ /* The definition of a function. */ -typedef int Function (); typedef int mk_handler_func_t (char *, DEF_FILE *, char *); /* Structure handles processor directives. */ @@ -995,25 +991,25 @@ file_error (char *filename) static void memory_error_and_abort (void); -static char * +static void * xmalloc (size_t bytes) { - char *temp = (char *)malloc (bytes); + void *temp = malloc (bytes); if (!temp) memory_error_and_abort (); return (temp); } -static char * +static void * xrealloc (void *pointer, size_t bytes) { - char *temp; + void *temp; if (!pointer) - temp = (char *)malloc (bytes); + temp = malloc (bytes); else - temp = (char *)realloc (pointer, bytes); + temp = realloc (pointer, bytes); if (!temp) memory_error_and_abort (); diff --git a/builtins/printf.def b/builtins/printf.def index 4f8cb3b5..c0610a34 100644 --- a/builtins/printf.def +++ b/builtins/printf.def @@ -68,11 +68,7 @@ $END # define INT_MIN (-2147483647-1) #endif -#if defined (PREFER_STDARG) -# include -#else -# include -#endif +#include #include #include @@ -1229,7 +1225,7 @@ vbprintf (const char *format, ...) size_t nlen; int blen; - SH_VA_START (args, format); + va_start (args, format); blen = vsnprintf (vbuf + vblen, vbsize - vblen, format, args); va_end (args); @@ -1238,7 +1234,7 @@ vbprintf (const char *format, ...) { vbsize = ((nlen + 63) >> 6) << 6; vbuf = (char *)xrealloc (vbuf, vbsize); - SH_VA_START (args, format); + va_start (args, format); blen = vsnprintf (vbuf + vblen, vbsize - vblen, format, args); va_end (args); } diff --git a/config-bot.h b/config-bot.h index a687e402..07e910f1 100644 --- a/config-bot.h +++ b/config-bot.h @@ -36,17 +36,6 @@ # define HAVE_BSD_PGRP #endif -/* Try this without testing __STDC__ for the time being. */ -#if defined (HAVE_STDARG_H) -# define PREFER_STDARG -# define USE_VARARGS -#else -# if defined (HAVE_VARARGS_H) -# define PREFER_VARARGS -# define USE_VARARGS -# endif -#endif - #if defined (HAVE_SYS_SOCKET_H) && defined (HAVE_GETPEERNAME) && defined (HAVE_NETINET_IN_H) # define HAVE_NETWORK #endif diff --git a/configure b/configure index 6193d304..74dc82e8 100755 --- a/configure +++ b/configure @@ -1,5 +1,5 @@ #! /bin/sh -# From configure.ac for Bash 5.2, version 5.048. +# From configure.ac for Bash 5.2, version 5.049. # Guess values for system-dependent variables and create Makefiles. # Generated by GNU Autoconf 2.71 for bash 5.2-maint. # @@ -7402,15 +7402,6 @@ printf "%s\n" "#define HAVE_LONG_DOUBLE 1" >>confdefs.h fi -if test "$ac_prog_cc_stdc" != no; then - -printf "%s\n" "#define PROTOTYPES 1" >>confdefs.h - - -printf "%s\n" "#define __PROTOTYPES 1" >>confdefs.h - -fi - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether char is unsigned" >&5 printf %s "checking whether char is unsigned... " >&6; } if test ${ac_cv_c_char_unsigned+y} @@ -11324,11 +11315,7 @@ extern #ifdef __cplusplus "C" #endif -#if defined(__STDC__) || defined(_MSC_VER) || defined(__cplusplus) size_t iconv (iconv_t cd, char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft); -#else -size_t iconv(); -#endif int main (void) @@ -14228,12 +14215,6 @@ if test "x$ac_cv_header_stdlib_h" = xyes then : printf "%s\n" "#define HAVE_STDLIB_H 1" >>confdefs.h -fi -ac_fn_c_check_header_compile "$LINENO" "stdarg.h" "ac_cv_header_stdarg_h" "$ac_includes_default" -if test "x$ac_cv_header_stdarg_h" = xyes -then : - printf "%s\n" "#define HAVE_STDARG_H 1" >>confdefs.h - fi ac_fn_c_check_header_compile "$LINENO" "varargs.h" "ac_cv_header_varargs_h" "$ac_includes_default" if test "x$ac_cv_header_varargs_h" = xyes @@ -20375,31 +20356,17 @@ else $as_nop cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ -#if HAVE_STDARG_H #include -#else -#include -#endif #include #include static int -#if HAVE_STDARG_H foo(const char *fmt, ...) -#else -foo(format, va_alist) - const char *format; - va_dcl -#endif { va_list args; int n; -#if HAVE_STDARG_H va_start(args, fmt); -#else - va_start(args); -#endif n = vsnprintf(0, 0, fmt, args); va_end (args); return n; @@ -20498,7 +20465,6 @@ fi if test "$ac_cv_func_putenv" = "yes"; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for standard-conformant putenv declaration" >&5 printf %s "checking for standard-conformant putenv declaration... " >&6; } if test ${bash_cv_std_putenv+y} @@ -20547,7 +20513,6 @@ printf "%s\n" "#define HAVE_STD_PUTENV 1" >>confdefs.h fi if test "$ac_cv_func_unsetenv" = "yes"; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for standard-conformant unsetenv declaration" >&5 printf %s "checking for standard-conformant unsetenv declaration... " >&6; } if test ${bash_cv_std_unsetenv+y} diff --git a/configure.ac b/configure.ac index a933af90..68c38c09 100644 --- a/configure.ac +++ b/configure.ac @@ -21,7 +21,7 @@ dnl Process this file with autoconf to produce a configure script. # You should have received a copy of the GNU General Public License # along with this program. If not, see . -AC_REVISION([for Bash 5.2, version 5.048])dnl +AC_REVISION([for Bash 5.2, version 5.049])dnl define(bashvers, 5.2) define(relstatus, maint) @@ -759,7 +759,6 @@ AC_C_INLINE AC_C_BIGENDIAN AC_C_STRINGIZE AC_TYPE_LONG_DOUBLE -AC_C_PROTOTYPES AC_C_CHAR_UNSIGNED AC_C_VOLATILE AC_C_RESTRICT @@ -773,7 +772,7 @@ AC_HEADER_MAJOR BASH_HEADER_INTTYPES -AC_CHECK_HEADERS(unistd.h stdlib.h stdarg.h varargs.h limits.h string.h \ +AC_CHECK_HEADERS(unistd.h stdlib.h varargs.h limits.h string.h \ memory.h locale.h termcap.h termio.h termios.h dlfcn.h \ stdbool.h stddef.h stdint.h netdb.h pwd.h grp.h strings.h \ regex.h syslog.h ulimit.h) diff --git a/error.c b/error.c index 76d20529..366d012f 100644 --- a/error.c +++ b/error.c @@ -27,12 +27,7 @@ # include #endif -#if defined (PREFER_STDARG) -# include -#else -# include -#endif - +#include #include #include @@ -143,7 +138,7 @@ programming_error (const char *format, ...) give_terminal_to (shell_pgrp, 0); #endif /* JOB_CONTROL */ - SH_VA_START (args, format); + va_start (args, format); vfprintf (stderr, format, args); fprintf (stderr, "\n"); @@ -178,7 +173,7 @@ report_error (const char *format, ...) error_prolog (1); - SH_VA_START (args, format); + va_start (args, format); vfprintf (stderr, format, args); fprintf (stderr, "\n"); @@ -199,7 +194,7 @@ fatal_error (const char *format, ...) error_prolog (0); - SH_VA_START (args, format); + va_start (args, format); vfprintf (stderr, format, args); fprintf (stderr, "\n"); @@ -215,7 +210,7 @@ internal_error (const char *format, ...) error_prolog (1); - SH_VA_START (args, format); + va_start (args, format); vfprintf (stderr, format, args); fprintf (stderr, "\n"); @@ -231,7 +226,7 @@ internal_warning (const char *format, ...) error_prolog (1); fprintf (stderr, _("warning: ")); - SH_VA_START (args, format); + va_start (args, format); vfprintf (stderr, format, args); fprintf (stderr, "\n"); @@ -248,7 +243,7 @@ internal_inform (const char *format, ...) /* TRANSLATORS: this is a prefix for informational messages. */ fprintf (stderr, _("INFORM: ")); - SH_VA_START (args, format); + va_start (args, format); vfprintf (stderr, format, args); fprintf (stderr, "\n"); @@ -265,7 +260,7 @@ internal_debug (const char *format, ...) error_prolog (1); fprintf (stderr, _("DEBUG warning: ")); - SH_VA_START (args, format); + va_start (args, format); vfprintf (stderr, format, args); fprintf (stderr, "\n"); @@ -285,7 +280,7 @@ sys_error (const char *format, ...) e = errno; error_prolog (0); - SH_VA_START (args, format); + va_start (args, format); vfprintf (stderr, format, args); fprintf (stderr, ": %s\n", strerror (e)); @@ -319,7 +314,7 @@ parser_error (int lineno, const char *format, ...) else fprintf (stderr, "%s: %s:%s%d: ", ename, iname, gnu_error_format ? "" : _(" line "), lineno); - SH_VA_START (args, format); + va_start (args, format); vfprintf (stderr, format, args); fprintf (stderr, "\n"); @@ -367,7 +362,7 @@ itrace (const char *format, ...) fprintf(stderr, "TRACE: pid %ld: ", (long)getpid()); - SH_VA_START (args, format); + va_start (args, format); vfprintf (stderr, format, args); fprintf (stderr, "\n"); @@ -395,7 +390,7 @@ trace (const char *format, ...) fprintf(tracefp, "TRACE: pid %ld: ", (long)getpid()); - SH_VA_START (args, format); + va_start (args, format); vfprintf (tracefp, format, args); fprintf (tracefp, "\n"); diff --git a/execute_cmd.c b/execute_cmd.c index e135d360..88f195a5 100644 --- a/execute_cmd.c +++ b/execute_cmd.c @@ -123,7 +123,7 @@ static int shell_control_structure (enum command_type); static void cleanup_redirects (REDIRECT *); #if defined (JOB_CONTROL) -static int restore_signal_mask (sigset_t *); +static void restore_signal_mask (void *); #endif static int builtin_status (int); @@ -505,10 +505,10 @@ dispose_partial_redirects (void) #if defined (JOB_CONTROL) /* A function to restore the signal mask to its proper value when the shell is interrupted or errors occur while creating a pipeline. */ -static int -restore_signal_mask (sigset_t *set) +static void +restore_signal_mask (void *set) { - return (sigprocmask (SIG_SETMASK, set, (sigset_t *)NULL)); + sigprocmask (SIG_SETMASK, set, NULL); } #endif /* JOB_CONTROL */ @@ -1103,7 +1103,7 @@ execute_command_internal (COMMAND *command, int asynchronous, int pipe_in, int p { nfifo = num_fifos (); if (nfifo > ofifo) - close_new_fifos ((void *)ofifo_list, osize); + close_new_fifos (ofifo_list, osize); free (ofifo_list); discard_unwind_frame ("internal_fifos"); } @@ -4908,8 +4908,11 @@ execute_builtin (sh_builtin_func_t *builtin, WORD_LIST *words, int flags, int su } static void -maybe_restore_getopt_state (sh_getopt_state_t *gs) +maybe_restore_getopt_state (void *arg) { + sh_getopt_state_t *gs; + + gs = arg; /* If we have a local copy of OPTIND and it's at the right (current) context, then we restore getopt's internal state. If not, we just let it go. We know there is a local OPTIND if gs->gs_flags & 1. diff --git a/general.h b/general.h index b92c3e23..16d7c093 100644 --- a/general.h +++ b/general.h @@ -249,11 +249,7 @@ typedef int sh_builtin_func_t (WORD_LIST *); /* sh_wlist_func_t */ #define HIGH_FD_MAX 256 /* The type of function passed as the fourth argument to qsort(3). */ -#ifdef __STDC__ typedef int QSFUNC (const void *, const void *); -#else -typedef int QSFUNC (); -#endif /* Some useful definitions for Unix pathnames. Argument convention: x == string, c == character */ diff --git a/include/memalloc.h b/include/memalloc.h index 6a08ac9a..e850e8a1 100644 --- a/include/memalloc.h +++ b/include/memalloc.h @@ -46,11 +46,7 @@ # endif /* !IBMESA */ # else /* !HAVE_ALLOCA_H || C_ALLOCA */ # if !defined (alloca) -# if defined (__STDC__) extern void *alloca (size_t); -# else -extern char *alloca (); -# endif /* !__STDC__ */ # endif /* !alloca */ # endif /* !HAVE_ALLOCA_H || C_ALLOCA */ #endif /* !__GNUC__ || C_ALLOCA */ diff --git a/include/stdc.h b/include/stdc.h index d9bcc6e0..7948b4f8 100644 --- a/include/stdc.h +++ b/include/stdc.h @@ -1,7 +1,7 @@ /* stdc.h -- macros to make source compile on both ANSI C and K&R C compilers. */ -/* Copyright (C) 1993-2021 Free Software Foundation, Inc. +/* Copyright (C) 1993-2021,2023 Free Software Foundation, Inc. This file is part of GNU Bash, the Bourne Again SHell. @@ -86,10 +86,4 @@ # define INLINE #endif -#if defined (PREFER_STDARG) -# define SH_VA_START(va, arg) va_start(va, arg) -#else -# define SH_VA_START(va, arg) va_start(va) -#endif - #endif /* !_STDC_H_ */ diff --git a/jobs.h b/jobs.h index de5a9ecf..2beee642 100644 --- a/jobs.h +++ b/jobs.h @@ -1,6 +1,6 @@ /* jobs.h -- structures and definitions used by the jobs.c file. */ -/* Copyright (C) 1993-2022 Free Software Foundation, Inc. +/* Copyright (C) 1993-2023 Free Software Foundation, Inc. This file is part of GNU Bash, the Bourne Again SHell. @@ -257,7 +257,7 @@ extern void terminate_stopped_jobs (void); extern void hangup_all_jobs (void); extern void kill_current_pipeline (void); -#if defined (__STDC__) && defined (pid_t) +#if defined (pid_t) extern int get_job_by_pid (int, int, PROCESS **); extern void describe_pid (int); #else diff --git a/lib/malloc/alloca.c b/lib/malloc/alloca.c index 7627e164..0a12b063 100644 --- a/lib/malloc/alloca.c +++ b/lib/malloc/alloca.c @@ -57,11 +57,7 @@ long i00afunc (); #define ADDRESS_FUNCTION(arg) &(arg) #endif /* CRAY && CRAY_STACKSEG_END */ -#if __STDC__ typedef void *pointer; -#else -typedef char *pointer; -#endif #define NULL 0 diff --git a/lib/malloc/imalloc.h b/lib/malloc/imalloc.h index 16c0c671..00f23a32 100644 --- a/lib/malloc/imalloc.h +++ b/lib/malloc/imalloc.h @@ -39,11 +39,7 @@ /* Generic pointer type. */ #ifndef PTR_T -# if defined (__STDC__) -# define PTR_T void * -# else -# define PTR_T char * -# endif +# define PTR_T void * #endif #if !defined (NULL) @@ -72,14 +68,6 @@ # endif /* HAVE_BCOPY */ #endif /* !__GNUC__ */ -#if !defined (PARAMS) -# if defined (__STDC__) || defined (__GNUC__) || defined (__cplusplus) || defined (PROTOTYPES) -# define PARAMS(protos) protos -# else -# define PARAMS(protos) () -# endif -#endif - /* Use Duff's device for good zeroing/copying performance. DO NOT call the Duff's device macros with NBYTES == 0. */ diff --git a/lib/malloc/malloc.c b/lib/malloc/malloc.c index 180c3dc4..f57e3aea 100644 --- a/lib/malloc/malloc.c +++ b/lib/malloc/malloc.c @@ -387,7 +387,7 @@ xbotch (PTR_T mem, int e, const char *s, const char *file, int line) assumed to not be busy; the caller (morecore()) checks for this. BUSY[NU] must be set to 1. */ static void -bcoalesce (register int nu) +bcoalesce (int nu) { register union mhead *mp, *mp1, *mp2; register int nbuck; @@ -455,7 +455,7 @@ bcoalesce (register int nu) is assumed to be empty. Must be called with signals blocked (e.g., by morecore()). BUSY[NU] must be set to 1. */ static void -bsplit (register int nu) +bsplit (int nu) { register union mhead *mp; int nbuck, nblks, split_max; @@ -616,7 +616,7 @@ morecore (int nu) sigset_t set, oset; int blocked_sigs; - /* Block all signals in case we are executed from a signal handler. */ + /* Block signals in case we are executed from a signal handler. */ blocked_sigs = 0; #ifdef SHELL # if defined (SIGCHLD) diff --git a/lib/malloc/shmalloc.h b/lib/malloc/shmalloc.h index 1213169d..5ea2c56e 100644 --- a/lib/malloc/shmalloc.h +++ b/lib/malloc/shmalloc.h @@ -24,16 +24,9 @@ /* Generic pointer type. */ #ifndef PTR_T - -#if defined (__STDC__) # define PTR_T void * -#else -# define PTR_T char * -#endif - #endif /* PTR_T */ - extern PTR_T sh_malloc (size_t, const char *, int); extern PTR_T sh_realloc (PTR_T, size_t, const char *, int); extern void sh_free (PTR_T, const char *, int); diff --git a/lib/malloc/xmalloc.c b/lib/malloc/xmalloc.c index de8f3834..59759834 100644 --- a/lib/malloc/xmalloc.c +++ b/lib/malloc/xmalloc.c @@ -33,13 +33,7 @@ /* Generic pointer type. */ #ifndef PTR_T - -#if defined (__STDC__) # define PTR_T void * -#else -# define PTR_T char * -#endif - #endif /* PTR_T */ /* **************************************************************** */ diff --git a/lib/readline/bind.c b/lib/readline/bind.c index 524ef34a..ee6d6e17 100644 --- a/lib/readline/bind.c +++ b/lib/readline/bind.c @@ -65,20 +65,12 @@ extern int errno; #include "rlshell.h" #include "xmalloc.h" -#if !defined (strchr) && !defined (__STDC__) -extern char *strchr (), *strrchr (); -#endif /* !strchr && !__STDC__ */ - /* Variables exported by this file. */ Keymap rl_binding_keymap; static int _rl_skip_to_delim (char *, int, int); -#if defined (USE_VARARGS) && defined (PREFER_STDARG) static void _rl_init_file_error (const char *, ...) __attribute__((__format__ (printf, 1, 2))); -#else -static void _rl_init_file_error (); -#endif static rl_command_func_t *_rl_function_of_keyseq_internal (const char *, size_t, Keymap, int *); @@ -1129,25 +1121,11 @@ _rl_read_init_file (const char *filename, int include_level) } static void -#if defined (PREFER_STDARG) _rl_init_file_error (const char *format, ...) -#else -_rl_init_file_error (va_alist) - va_dcl -#endif { va_list args; -#if defined (PREFER_VARARGS) - char *format; -#endif -#if defined (PREFER_STDARG) va_start (args, format); -#else - va_start (args); - format = va_arg (args, char *); -#endif - fprintf (stderr, "readline: "); if (currently_reading_init_file) fprintf (stderr, "%s: line %d: ", current_readline_init_file, diff --git a/lib/readline/complete.c b/lib/readline/complete.c index ce9b8cd0..bf7cc856 100644 --- a/lib/readline/complete.c +++ b/lib/readline/complete.c @@ -77,11 +77,7 @@ extern int errno; # include "colors.h" #endif -#ifdef __STDC__ typedef int QSFUNC (const void *, const void *); -#else -typedef int QSFUNC (); -#endif #ifdef HAVE_LSTAT # define LSTAT lstat diff --git a/lib/readline/display.c b/lib/readline/display.c index ce9dacd8..fb10c60a 100644 --- a/lib/readline/display.c +++ b/lib/readline/display.c @@ -1,6 +1,6 @@ /* display.c -- readline redisplay facility. */ -/* Copyright (C) 1987-2022 Free Software Foundation, Inc. +/* Copyright (C) 1987-2023 Free Software Foundation, Inc. This file is part of the GNU Readline Library (Readline), a library for reading lines of text with interactive input and history editing. @@ -59,10 +59,6 @@ #include "rlprivate.h" #include "xmalloc.h" -#if !defined (strchr) && !defined (__STDC__) -extern char *strchr (), *strrchr (); -#endif /* !strchr && !__STDC__ */ - static void putc_face (int, int, char *); static void puts_face (const char *, const char *, int); static void norm_face (char *, int); @@ -3019,29 +3015,15 @@ rl_character_len (int c, int pos) mini-modeline. */ static int msg_saved_prompt = 0; -#if defined (USE_VARARGS) int -#if defined (PREFER_STDARG) rl_message (const char *format, ...) -#else -rl_message (va_alist) - va_dcl -#endif { va_list args; -#if defined (PREFER_VARARGS) - char *format; -#endif #if defined (HAVE_VSNPRINTF) int bneed; #endif -#if defined (PREFER_STDARG) va_start (args, format); -#else - va_start (args); - format = va_arg (args, char *); -#endif if (msg_buf == 0) msg_buf = xmalloc (msg_bufsiz = 128); @@ -3054,12 +3036,7 @@ rl_message (va_alist) msg_buf = xrealloc (msg_buf, msg_bufsiz); va_end (args); -#if defined (PREFER_STDARG) va_start (args, format); -#else - va_start (args); - format = va_arg (args, char *); -#endif vsnprintf (msg_buf, msg_bufsiz - 1, format, args); } #else @@ -3090,40 +3067,6 @@ rl_message (va_alist) return 0; } -#else /* !USE_VARARGS */ -int -rl_message (format, arg1, arg2) - char *format; -{ - if (msg_buf == 0) - msg_buf = xmalloc (msg_bufsiz = 128); - - sprintf (msg_buf, format, arg1, arg2); - msg_buf[msg_bufsiz - 1] = '\0'; /* overflow? */ - - rl_display_prompt = msg_buf; - if (saved_local_prompt == 0) - { - rl_save_prompt (); - msg_saved_prompt = 1; - } - else if (local_prompt != saved_local_prompt) - { - FREE (local_prompt); - FREE (local_prompt_prefix); - local_prompt = (char *)NULL; - } - local_prompt = expand_prompt (msg_buf, 0, &prompt_visible_length, - &prompt_last_invisible, - &prompt_invis_chars_first_line, - &prompt_physical_chars); - local_prompt_prefix = (char *)NULL; - local_prompt_len = local_prompt ? strlen (local_prompt) : 0; - (*rl_redisplay_function) (); - - return 0; -} -#endif /* !USE_VARARGS */ /* How to clear things from the "echo-area". */ int diff --git a/lib/readline/examples/rl.c b/lib/readline/examples/rl.c index 39e5b8eb..e04bbd6a 100644 --- a/lib/readline/examples/rl.c +++ b/lib/readline/examples/rl.c @@ -5,7 +5,7 @@ * usage: rl [-p prompt] [-u unit] [-d default] [-n nchars] */ -/* Copyright (C) 1987-2009 Free Software Foundation, Inc. +/* Copyright (C) 1987-2023 Free Software Foundation, Inc. This file is part of the GNU Readline Library (Readline), a library for reading lines of text with interactive input and history editing. @@ -55,10 +55,6 @@ extern void exit(); extern int optind; extern char *optarg; -#if !defined (strchr) && !defined (__STDC__) -extern char *strrchr(); -#endif - static char *progname; static char *deftext; diff --git a/lib/readline/funmap.c b/lib/readline/funmap.c index 0095c6bf..affa0fdc 100644 --- a/lib/readline/funmap.c +++ b/lib/readline/funmap.c @@ -40,11 +40,7 @@ #include "xmalloc.h" -#ifdef __STDC__ typedef int QSFUNC (const void *, const void *); -#else -typedef int QSFUNC (); -#endif extern int _rl_qsort_string_compare (char **, char **); diff --git a/lib/readline/histlib.h b/lib/readline/histlib.h index 7189a07c..da8e6533 100644 --- a/lib/readline/histlib.h +++ b/lib/readline/histlib.h @@ -56,9 +56,6 @@ #endif #ifndef member -# if !defined (strchr) && !defined (__STDC__) -extern char *strchr (); -# endif /* !strchr && !__STDC__ */ #define member(c, s) ((c) ? ((char *)strchr ((s), (c)) != (char *)NULL) : 0) #endif diff --git a/lib/readline/parens.c b/lib/readline/parens.c index 38b5e703..7f1e93f4 100644 --- a/lib/readline/parens.c +++ b/lib/readline/parens.c @@ -47,10 +47,6 @@ # include #endif /* !HAVE_STRING_H */ -#if !defined (strchr) && !defined (__STDC__) -extern char *strchr (), *strrchr (); -#endif /* !strchr && !__STDC__ */ - #include "readline.h" #include "rlprivate.h" diff --git a/lib/readline/readline.h b/lib/readline/readline.h index 259e6b4b..48f1210a 100644 --- a/lib/readline/readline.h +++ b/lib/readline/readline.h @@ -1,6 +1,6 @@ /* Readline.h -- the names of functions callable from within readline. */ -/* Copyright (C) 1987-2022 Free Software Foundation, Inc. +/* Copyright (C) 1987-2023 Free Software Foundation, Inc. This file is part of the GNU Readline Library (Readline), a library for reading lines of text with interactive input and history editing. @@ -404,11 +404,7 @@ extern void rl_activate_mark (void); extern void rl_deactivate_mark (void); extern int rl_mark_active_p (void); -#if defined (USE_VARARGS) && defined (PREFER_STDARG) extern int rl_message (const char *, ...) __attribute__((__format__ (printf, 1, 2))); -#else -extern int rl_message (); -#endif extern int rl_show_char (int); diff --git a/lib/readline/rldefs.h b/lib/readline/rldefs.h index c67b3857..1ef0fbf7 100644 --- a/lib/readline/rldefs.h +++ b/lib/readline/rldefs.h @@ -63,17 +63,7 @@ # include #endif /* !HAVE_STRING_H */ -#if !defined (strchr) && !defined (__STDC__) -extern char *strchr (), *strrchr (); -#endif /* !strchr && !__STDC__ */ - -#if defined (PREFER_STDARG) -# include -#else -# if defined (PREFER_VARARGS) -# include -# endif -#endif +#include #if defined (HAVE_STRCASECMP) #define _rl_stricmp strcasecmp diff --git a/lib/readline/rlprivate.h b/lib/readline/rlprivate.h index e97ea90e..5c0592b9 100644 --- a/lib/readline/rlprivate.h +++ b/lib/readline/rlprivate.h @@ -1,7 +1,7 @@ /* rlprivate.h -- functions and variables global to the readline library, but not intended for use by applications. */ -/* Copyright (C) 1999-2022 Free Software Foundation, Inc. +/* Copyright (C) 1999-2023 Free Software Foundation, Inc. This file is part of the GNU Readline Library (Readline), a library for reading lines of text with interactive input and history editing. @@ -459,15 +459,9 @@ extern UNDO_LIST *_rl_copy_undo_list (UNDO_LIST *); extern void _rl_free_undo_list (UNDO_LIST *); /* util.c */ -#if defined (USE_VARARGS) && defined (PREFER_STDARG) extern void _rl_ttymsg (const char *, ...) __attribute__((__format__ (printf, 1, 2))); extern void _rl_errmsg (const char *, ...) __attribute__((__format__ (printf, 1, 2))); extern void _rl_trace (const char *, ...) __attribute__((__format__ (printf, 1, 2))); -#else -extern void _rl_ttymsg (); -extern void _rl_errmsg (); -extern void _rl_trace (); -#endif extern void _rl_audit_tty (char *); extern int _rl_tropen (void); diff --git a/lib/readline/rlstdc.h b/lib/readline/rlstdc.h index 2aaa30ba..0e5c4f47 100644 --- a/lib/readline/rlstdc.h +++ b/lib/readline/rlstdc.h @@ -1,6 +1,6 @@ /* stdc.h -- macros to make source compile on both ANSI C and K&R C compilers. */ -/* Copyright (C) 1993-2009 Free Software Foundation, Inc. +/* Copyright (C) 1993-2009,2023 Free Software Foundation, Inc. This file is part of the GNU Readline Library (Readline), a library for reading lines of text with interactive input and history editing. @@ -42,16 +42,4 @@ # endif #endif -/* Moved from config.h.in because readline.h:rl_message depends on these - defines. */ -#if defined (__STDC__) && defined (HAVE_STDARG_H) -# define PREFER_STDARG -# define USE_VARARGS -#else -# if defined (HAVE_VARARGS_H) -# define PREFER_VARARGS -# define USE_VARARGS -# endif -#endif - #endif /* !_RL_STDC_H_ */ diff --git a/lib/readline/util.c b/lib/readline/util.c index b68abdc6..61c40be5 100644 --- a/lib/readline/util.c +++ b/lib/readline/util.c @@ -229,26 +229,12 @@ rl_tilde_expand (int ignore, int key) return (0); } -#if defined (USE_VARARGS) void -#if defined (PREFER_STDARG) _rl_ttymsg (const char *format, ...) -#else -_rl_ttymsg (va_alist) - va_dcl -#endif { va_list args; -#if defined (PREFER_VARARGS) - char *format; -#endif -#if defined (PREFER_STDARG) va_start (args, format); -#else - va_start (args); - format = va_arg (args, char *); -#endif fprintf (stderr, "readline: "); vfprintf (stderr, format, args); @@ -261,24 +247,11 @@ _rl_ttymsg (va_alist) } void -#if defined (PREFER_STDARG) _rl_errmsg (const char *format, ...) -#else -_rl_errmsg (va_alist) - va_dcl -#endif { va_list args; -#if defined (PREFER_VARARGS) - char *format; -#endif -#if defined (PREFER_STDARG) va_start (args, format); -#else - va_start (args); - format = va_arg (args, char *); -#endif fprintf (stderr, "readline: "); vfprintf (stderr, format, args); @@ -288,28 +261,6 @@ _rl_errmsg (va_alist) va_end (args); } -#else /* !USE_VARARGS */ -void -_rl_ttymsg (format, arg1, arg2) - char *format; -{ - fprintf (stderr, "readline: "); - fprintf (stderr, format, arg1, arg2); - fprintf (stderr, "\n"); - - rl_forced_update_display (); -} - -void -_rl_errmsg (format, arg1, arg2) - char *format; -{ - fprintf (stderr, "readline: "); - fprintf (stderr, format, arg1, arg2); - fprintf (stderr, "\n"); -} -#endif /* !USE_VARARGS */ - /* **************************************************************** */ /* */ /* String Utility Functions */ @@ -507,28 +458,14 @@ _rl_savestring (const char *s) } #if defined (DEBUG) -#if defined (USE_VARARGS) static FILE *_rl_tracefp; void -#if defined (PREFER_STDARG) _rl_trace (const char *format, ...) -#else -_rl_trace (va_alist) - va_dcl -#endif { va_list args; -#if defined (PREFER_VARARGS) - char *format; -#endif -#if defined (PREFER_STDARG) va_start (args, format); -#else - va_start (args); - format = va_arg (args, char *); -#endif if (_rl_tracefp == 0) _rl_tropen (); @@ -574,7 +511,6 @@ _rl_settracefp (FILE *fp) { _rl_tracefp = fp; } -#endif #endif /* DEBUG */ diff --git a/lib/sh/dprintf.c b/lib/sh/dprintf.c index 9d95834c..1e345a9f 100644 --- a/lib/sh/dprintf.c +++ b/lib/sh/dprintf.c @@ -1,6 +1,6 @@ /* dprintf -- printf to a file descriptor */ -/* Copyright (C) 2008-2010,2022 Free Software Foundation, Inc. +/* Copyright (C) 2008-2010,2022,2023 Free Software Foundation, Inc. This file is part of GNU Bash, the Bourne Again SHell. @@ -28,12 +28,7 @@ # include #endif -#if defined (PREFER_STDARG) -# include -#else -# include -#endif - +#include #include int @@ -52,7 +47,7 @@ dprintf(int fd, const char *format, ...) return -1; } - SH_VA_START (args, format); + va_start (args, format); rc = vfprintf (fp, format, args); fflush (fp); va_end (args); diff --git a/lib/sh/fdprintf.c b/lib/sh/fdprintf.c deleted file mode 100644 index 27d3a4b0..00000000 --- a/lib/sh/fdprintf.c +++ /dev/null @@ -1,70 +0,0 @@ -/* fdprintf -- printf to a file descriptor */ - -/* Copyright (C) 2008,2009 Free Software Foundation, Inc. - - This file is part of GNU Bash, the Bourne Again SHell. - - Bash is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - Bash is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Bash. If not, see . -*/ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include - -#if defined (HAVE_UNISTD_H) -# include -#endif - -#if defined (PREFER_STDARG) -# include -#else -# include -#endif - -#include - -int -#if defined (PREFER_STDARG) -fdprintf(int fd, const char *format, ...) -#else -fdprintf(fd, format, va_alist) - int fd; - const char *format; - va_dcl -#endif -{ - FILE *fp; - int fd2, rc, r2; - va_list args; - - if ((fd2 = dup(fd)) < 0) - return -1; - fp = fdopen (fd2, "w"); - if (fp == 0) - { - close (fd2); - return -1; - } - - SH_VA_START (args, format); - rc = vfprintf (fp, format, args); - fflush (fp); - va_end (args); - - r2 = fclose (fp); /* check here */ - - return rc; -} diff --git a/lib/sh/snprintf.c b/lib/sh/snprintf.c index 68258e46..a356cb70 100644 --- a/lib/sh/snprintf.c +++ b/lib/sh/snprintf.c @@ -77,7 +77,6 @@ #endif #define HAVE_ISINF_IN_LIBC #define HAVE_ISNAN_IN_LIBC -#define PREFER_STDARG #define HAVE_STRINGIZE #define HAVE_LIMITS_H #define HAVE_STDDEF_H @@ -89,11 +88,7 @@ #include -#if defined(PREFER_STDARG) -# include -#else -# include -#endif +#include #ifdef HAVE_LIMITS_H # include @@ -1669,7 +1664,7 @@ snprintf(char *string, size_t length, const char * format, ...) int rval; va_list args; - SH_VA_START(args, format); + va_start(args, format); if (string == 0 && length != 0) return 0; @@ -1705,7 +1700,7 @@ asprintf(char **stringp, const char * format, ...) int rval; va_list args; - SH_VA_START(args, format); + va_start(args, format); rval = vasprintf (stringp, format, args); diff --git a/lib/sh/vprint.c b/lib/sh/vprint.c index b4c09e89..1d60e4f2 100644 --- a/lib/sh/vprint.c +++ b/lib/sh/vprint.c @@ -25,11 +25,7 @@ #include #if !defined (NULL) -# if defined (__STDC__) -# define NULL ((void *)0) -# else -# define NULL 0x0 -# endif /* __STDC__ */ +# define NULL 0 #endif /* !NULL */ /* diff --git a/lib/termcap/termcap.h b/lib/termcap/termcap.h index b0e3061f..a12a5c70 100644 --- a/lib/termcap/termcap.h +++ b/lib/termcap/termcap.h @@ -1,6 +1,6 @@ /* termcap.h - public declarations for termcap library. */ -/* Copyright (C) 1991, 1992, 1995, 2001, 2005, 2006, 2008,2009 Free Software Foundation, Inc. +/* Copyright (C) 1991-2009,2023 Free Software Foundation, Inc. Bash is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -19,8 +19,6 @@ #ifndef _TERMCAP_H #define _TERMCAP_H 1 -#if __STDC__ - extern int tgetent (char *buffer, const char *termtype); extern int tgetnum (const char *name); @@ -38,26 +36,4 @@ extern char *BC; extern char *tgoto (const char *cstring, int hpos, int vpos); -#else /* not __STDC__ */ - -extern int tgetent (); - -extern int tgetnum (); -extern int tgetflag (); -extern char *tgetstr (); - -extern char PC; -extern short ospeed; - -extern void tputs (); - -extern char *tparam (); - -extern char *UP; -extern char *BC; - -extern char *tgoto (); - -#endif /* not __STDC__ */ - #endif /* not _TERMCAP_H */ diff --git a/m4/iconv.m4 b/m4/iconv.m4 index a285e9da..2485b6bb 100644 --- a/m4/iconv.m4 +++ b/m4/iconv.m4 @@ -258,11 +258,7 @@ extern #ifdef __cplusplus "C" #endif -#if defined(__STDC__) || defined(_MSC_VER) || defined(__cplusplus) size_t iconv (iconv_t cd, char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft); -#else -size_t iconv(); -#endif ]], [[]])], [am_cv_proto_iconv_arg1=""], diff --git a/pcomplete.c b/pcomplete.c index ecdf4475..b9ca25b1 100644 --- a/pcomplete.c +++ b/pcomplete.c @@ -31,11 +31,7 @@ #include -#if defined (PREFER_STDARG) -# include -#else -# include -#endif +#include #include "posixtime.h" @@ -198,7 +194,7 @@ debug_printf (const char *format, ...) if (progcomp_debug == 0) return; - SH_VA_START (args, format); + va_start (args, format); fprintf (stdout, "DEBUG: "); vfprintf (stdout, format, args); diff --git a/print_cmd.c b/print_cmd.c index 1aefead4..2410b8a2 100644 --- a/print_cmd.c +++ b/print_cmd.c @@ -29,11 +29,7 @@ # include #endif -#if defined (PREFER_STDARG) -# include -#else -# include -#endif +#include #include "bashansi.h" #include "bashintl.h" @@ -1446,7 +1442,7 @@ cprintf (const char *control, ...) size_t arg_len; va_list args; - SH_VA_START (args, control); + va_start (args, control); arg_len = strlen (control); the_printed_command_resize (arg_len + 1); @@ -1544,28 +1540,13 @@ the_printed_command_resize (size_t length) } } -#if defined (HAVE_VPRINTF) -/* ``If vprintf is available, you may assume that vfprintf and vsprintf are - also available.'' */ - static void xprintf (const char *format, ...) { va_list args; - SH_VA_START (args, format); + va_start (args, format); vfprintf (stdout, format, args); va_end (args); } - -#else - -static void -xprintf (format, arg1, arg2, arg3, arg4, arg5) - const char *format; -{ - printf (format, arg1, arg2, arg3, arg4, arg5); -} - -#endif /* !HAVE_VPRINTF */ diff --git a/unwind_prot.c b/unwind_prot.c index c471b98a..c0d384fe 100644 --- a/unwind_prot.c +++ b/unwind_prot.c @@ -3,7 +3,7 @@ /* I can't stand it anymore! Please can't we just write the whole Unix system in lisp or something? */ -/* Copyright (C) 1987-2022 Free Software Foundation, Inc. +/* Copyright (C) 1987-2023 Free Software Foundation, Inc. This file is part of GNU Bash, the Bourne Again SHell. @@ -77,13 +77,12 @@ typedef union uwp { } sv; } UNWIND_ELT; -static void without_interrupts (VFunction *, char *, char *); -static void unwind_frame_discard_internal (char *, char *); -static void unwind_frame_run_internal (char *, char *); +static void unwind_frame_discard_internal (char *); +static void unwind_frame_run_internal (char *); static void add_unwind_protect_internal (Function *, char *); -static void remove_unwind_protect_internal (char *, char *); -static void run_unwind_protects_internal (char *, char *); -static void clear_unwind_protects_internal (char *, char *); +static void remove_unwind_protect_internal (void); +static void run_unwind_protects_internal (void); +static void clear_unwind_protects_internal (int); static inline void restore_variable (SAVED_VAR *); static void unwind_protect_mem_internal (char *, char *); @@ -108,19 +107,11 @@ uwp_init (void) ocache_create (uwcache, UNWIND_ELT, UWCACHESIZE); } -/* Run a function without interrupts. This relies on the fact that the - FUNCTION cannot call QUIT (). */ -static void -without_interrupts (VFunction *function, char *arg1, char *arg2) -{ - (*function)(arg1, arg2); -} - /* Start the beginning of a region. */ void begin_unwind_frame (char *tag) { - add_unwind_protect ((Function *)NULL, tag); + add_unwind_protect (NULL, tag); } /* Discard the unwind protects back to TAG. */ @@ -128,7 +119,7 @@ void discard_unwind_frame (char *tag) { if (unwind_protect_list) - without_interrupts (unwind_frame_discard_internal, tag, (char *)NULL); + unwind_frame_discard_internal (tag); } /* Run the unwind protects back to TAG. */ @@ -136,14 +127,14 @@ void run_unwind_frame (char *tag) { if (unwind_protect_list) - without_interrupts (unwind_frame_run_internal, tag, (char *)NULL); + unwind_frame_run_internal (tag); } /* Add the function CLEANUP with ARG to the list of unwindable things. */ void add_unwind_protect (Function *cleanup, char *arg) { - without_interrupts (add_unwind_protect_internal, (char *)cleanup, arg); + add_unwind_protect_internal (cleanup, arg); } /* Remove the top unwind protect from the list. */ @@ -151,8 +142,7 @@ void remove_unwind_protect (void) { if (unwind_protect_list) - without_interrupts - (remove_unwind_protect_internal, (char *)NULL, (char *)NULL); + remove_unwind_protect_internal (); } /* Run the list of cleanup functions in unwind_protect_list. */ @@ -160,22 +150,15 @@ void run_unwind_protects (void) { if (unwind_protect_list) - without_interrupts - (run_unwind_protects_internal, (char *)NULL, (char *)NULL); + run_unwind_protects_internal (); } /* Erase the unwind-protect list. If flags is 1, free the elements. */ void clear_unwind_protect_list (int flags) { - char *flag; - if (unwind_protect_list) - { - flag = flags ? "" : (char *)NULL; - without_interrupts - (clear_unwind_protects_internal, flag, (char *)NULL); - } + clear_unwind_protects_internal (flags); } int @@ -218,7 +201,7 @@ add_unwind_protect_internal (Function *cleanup, char *arg) } static void -remove_unwind_protect_internal (char *ignore1, char *ignore2) +remove_unwind_protect_internal (void) { UNWIND_ELT *elt; @@ -231,24 +214,24 @@ remove_unwind_protect_internal (char *ignore1, char *ignore2) } static void -run_unwind_protects_internal (char *ignore1, char *ignore2) +run_unwind_protects_internal (void) { - unwind_frame_run_internal ((char *) NULL, (char *) NULL); + unwind_frame_run_internal (NULL); } static void -clear_unwind_protects_internal (char *flag, char *ignore) +clear_unwind_protects_internal (int flag) { if (flag) { while (unwind_protect_list) - remove_unwind_protect_internal ((char *)NULL, (char *)NULL); + remove_unwind_protect_internal (); } unwind_protect_list = (UNWIND_ELT *)NULL; } static void -unwind_frame_discard_internal (char *tag, char *ignore) +unwind_frame_discard_internal (char *tag) { UNWIND_ELT *elt; int found; @@ -281,7 +264,7 @@ restore_variable (SAVED_VAR *sv) } static void -unwind_frame_run_internal (char *tag, char *ignore) +unwind_frame_run_internal (char *tag) { UNWIND_ELT *elt; int found; @@ -341,7 +324,7 @@ unwind_protect_mem_internal (char *var, char *psize) void unwind_protect_mem (char *var, int size) { - without_interrupts (unwind_protect_mem_internal, var, (char *) &size); + unwind_protect_mem_internal (var, (char *) &size); } #if defined (DEBUG) diff --git a/unwind_prot.h b/unwind_prot.h index 7493c22e..27fb8206 100644 --- a/unwind_prot.h +++ b/unwind_prot.h @@ -1,6 +1,6 @@ /* unwind_prot.h - Macros and functions for hacking unwind protection. */ -/* Copyright (C) 1993-2020 Free Software Foundation, Inc. +/* Copyright (C) 1993-2023 Free Software Foundation, Inc. This file is part of GNU Bash, the Bourne Again SHell. @@ -21,6 +21,14 @@ #if !defined (_UNWIND_PROT_H) #define _UNWIND_PROT_H +/* Generic function type void (*) (void *) for all unwind cleanups. A + cleanup function does not return a value and takes a single generic + pointer argument. This type works fine for arbitrary pointers; if a + cleanup function needs to take an int argument, it's passed through + a cast to intptr_t, an integer type that's safe to convert to and + from a pointer. */ +typedef void sh_uwfunc_t (void *); + extern void uwp_init (void); /* Run a function without interrupts. */ @@ -39,6 +47,7 @@ extern int unwind_protect_tag_on_stack (const char *); /* How to protect a variable. */ #define unwind_protect_var(X) unwind_protect_mem ((char *)&(X), sizeof (X)) + extern void unwind_protect_mem (char *, int); /* Backwards compatibility */