Mercurial > hg > octave-kai > gnulib-hg
changeset 14053:f3a03b79bd9b
alloca: one step towards thread-safety
* lib/alloca.c (find_stack_direction): New arg PTR, to avoid the
need for a static variable. All callers changed. This does not
make the alloca replacement thread-safe, but it's one step.
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Tue, 28 Dec 2010 20:41:30 -0800 |
parents | ce397caf9dbb |
children | 14832bf034b8 |
files | ChangeLog lib/alloca.c |
diffstat | 2 files changed, 14 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2010-12-28 Paul Eggert <eggert@cs.ucla.edu> + alloca: one step towards thread-safety + * lib/alloca.c (find_stack_direction): New arg PTR, to avoid the + need for a static variable. All callers changed. This does not + make the alloca replacement thread-safe, but it's one step. + tests: minor indenting change * tests/init.sh: Sync from coreutils housekeeping patch <http://lists.gnu.org/archive/html/coreutils/2010-12/msg00116.html>
--- a/lib/alloca.c +++ b/lib/alloca.c @@ -94,21 +94,20 @@ # define STACK_DIR stack_dir static void -find_stack_direction (void) +find_stack_direction (char **ptr) { - static char *addr = NULL; /* Address of first `dummy', once known. */ auto char dummy; /* To get stack address. */ - if (addr == NULL) + if (*ptr == NULL) { /* Initial entry. */ - addr = ADDRESS_FUNCTION (dummy); + *ptr = ADDRESS_FUNCTION (dummy); - find_stack_direction (); /* Recurse once. */ + find_stack_direction (ptr); /* Recurse once. */ } else { /* Second entry. */ - if (ADDRESS_FUNCTION (dummy) > addr) + if (ADDRESS_FUNCTION (dummy) > *ptr) stack_dir = 1; /* Stack grew upward. */ else stack_dir = -1; /* Stack grew downward. */ @@ -155,7 +154,10 @@ # if STACK_DIRECTION == 0 if (STACK_DIR == 0) /* Unknown growth direction. */ - find_stack_direction (); + { + char *addr = NULL; /* Address of first `dummy', once known. */ + find_stack_direction (&addr); + } # endif /* Reclaim garbage, defined as all alloca'd storage that