Bash-5.3-alpha release

This commit is contained in:
Chet Ramey
2024-04-22 10:33:38 -04:00
parent f3b6bd1945
commit 622d318652
700 changed files with 136534 additions and 96420 deletions
+47 -92
View File
@@ -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-2021 Free Software Foundation, Inc.
/* Copyright (C) 1987-2024 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -35,14 +35,6 @@
# include <unistd.h>
#endif
#if defined (HAVE_STDDEF_H)
# include <stddef.h>
#endif
#ifndef offsetof
# define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
#endif
#include "command.h"
#include "general.h"
#include "unwind_prot.h"
@@ -65,11 +57,11 @@ typedef struct {
typedef union uwp {
struct uwp_head {
union uwp *next;
Function *cleanup;
sh_uwfunc_t *cleanup;
} head;
struct {
struct uwp_head uwp_head;
char *v;
void *v;
} arg;
struct {
struct uwp_head uwp_head;
@@ -77,15 +69,14 @@ typedef union uwp {
} sv;
} UNWIND_ELT;
static void without_interrupts PARAMS((VFunction *, char *, char *));
static void unwind_frame_discard_internal PARAMS((char *, char *));
static void unwind_frame_run_internal PARAMS((char *, char *));
static void add_unwind_protect_internal PARAMS((Function *, char *));
static void remove_unwind_protect_internal PARAMS((char *, char *));
static void run_unwind_protects_internal PARAMS((char *, char *));
static void clear_unwind_protects_internal PARAMS((char *, char *));
static inline void restore_variable PARAMS((SAVED_VAR *));
static void unwind_protect_mem_internal PARAMS((char *, char *));
static void unwind_frame_discard_internal (char *);
static void unwind_frame_run_internal (char *);
static void add_unwind_protect_internal (sh_uwfunc_t *, void *);
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 (void *);
static void unwind_protect_mem_internal (void *, int);
static UNWIND_ELT *unwind_protect_list = (UNWIND_ELT *)NULL;
@@ -103,98 +94,73 @@ sh_obj_cache_t uwcache = {0, 0, 0};
#endif
void
uwp_init ()
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 (function, arg1, arg2)
VFunction *function;
char *arg1, *arg2;
{
(*function)(arg1, arg2);
}
/* Start the beginning of a region. */
void
begin_unwind_frame (tag)
char *tag;
begin_unwind_frame (char *tag)
{
add_unwind_protect ((Function *)NULL, tag);
add_unwind_protect (NULL, tag);
}
/* Discard the unwind protects back to TAG. */
void
discard_unwind_frame (tag)
char *tag;
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. */
void
run_unwind_frame (tag)
char *tag;
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 (cleanup, arg)
Function *cleanup;
char *arg;
add_unwind_protect (sh_uwfunc_t *cleanup, void *arg)
{
without_interrupts (add_unwind_protect_internal, (char *)cleanup, arg);
add_unwind_protect_internal (cleanup, arg);
}
/* Remove the top unwind protect from the list. */
void
remove_unwind_protect ()
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. */
void
run_unwind_protects ()
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 (flags)
int flags;
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
have_unwind_protects ()
have_unwind_protects (void)
{
return (unwind_protect_list != 0);
}
int
unwind_protect_tag_on_stack (tag)
const char *tag;
unwind_protect_tag_on_stack (const char *tag)
{
UNWIND_ELT *elt;
@@ -215,9 +181,7 @@ unwind_protect_tag_on_stack (tag)
/* **************************************************************** */
static void
add_unwind_protect_internal (cleanup, arg)
Function *cleanup;
char *arg;
add_unwind_protect_internal (sh_uwfunc_t *cleanup, void *arg)
{
UNWIND_ELT *elt;
@@ -229,8 +193,7 @@ add_unwind_protect_internal (cleanup, arg)
}
static void
remove_unwind_protect_internal (ignore1, ignore2)
char *ignore1, *ignore2;
remove_unwind_protect_internal (void)
{
UNWIND_ELT *elt;
@@ -243,27 +206,24 @@ remove_unwind_protect_internal (ignore1, ignore2)
}
static void
run_unwind_protects_internal (ignore1, ignore2)
char *ignore1, *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 (flag, ignore)
char *flag, *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 (tag, ignore)
char *tag, *ignore;
unwind_frame_discard_internal (char *tag)
{
UNWIND_ELT *elt;
int found;
@@ -290,15 +250,15 @@ unwind_frame_discard_internal (tag, ignore)
sv->desired_setting is a block of memory SIZE bytes long holding the
value itself. This block of memory is copied back into the variable. */
static inline void
restore_variable (sv)
SAVED_VAR *sv;
restore_variable (void *arg)
{
SAVED_VAR *sv;
sv = arg;
FASTCOPY (sv->desired_setting, sv->variable, sv->size);
}
static void
unwind_frame_run_internal (tag, ignore)
char *tag, *ignore;
unwind_frame_run_internal (char *tag)
{
UNWIND_ELT *elt;
int found;
@@ -320,7 +280,7 @@ unwind_frame_run_internal (tag, ignore)
}
else
{
if (elt->head.cleanup == (Function *) restore_variable)
if (elt->head.cleanup == restore_variable)
restore_variable (&elt->sv.v);
else
(*(elt->head.cleanup)) (elt->arg.v);
@@ -333,20 +293,17 @@ unwind_frame_run_internal (tag, ignore)
}
static void
unwind_protect_mem_internal (var, psize)
char *var;
char *psize;
unwind_protect_mem_internal (void *var, int size)
{
int size, allocated;
size_t allocated;
UNWIND_ELT *elt;
size = *(int *) psize;
allocated = size + offsetof (UNWIND_ELT, sv.v.desired_setting[0]);
if (allocated < sizeof (UNWIND_ELT))
allocated = sizeof (UNWIND_ELT);
elt = (UNWIND_ELT *)xmalloc (allocated);
elt->head.next = unwind_protect_list;
elt->head.cleanup = (Function *) restore_variable;
elt->head.cleanup = restore_variable;
elt->sv.v.variable = var;
elt->sv.v.size = size;
FASTCOPY (var, elt->sv.v.desired_setting, size);
@@ -357,18 +314,16 @@ unwind_protect_mem_internal (var, psize)
are run. VAR is a pointer to the variable. SIZE is the size in
bytes of VAR. */
void
unwind_protect_mem (var, size)
char *var;
int size;
unwind_protect_mem (char *var, int size)
{
without_interrupts (unwind_protect_mem_internal, var, (char *) &size);
unwind_protect_mem_internal (var, size);
}
#if defined (DEBUG)
#include <stdio.h>
void
print_unwind_protect_tags ()
print_unwind_protect_tags (void)
{
UNWIND_ELT *elt;
@@ -376,7 +331,7 @@ print_unwind_protect_tags ()
while (elt)
{
if (elt->head.cleanup == 0)
fprintf(stderr, "tag: %s\n", elt->arg.v);
fprintf(stderr, "tag: %s\n", (char *)elt->arg.v);
elt = elt->head.next;
}
}