# HG changeset patch # User Paul Eggert # Date 1293597690 28800 # Node ID f3a03b79bd9b1bc1b5156d7a03bdf8a27ba0f611 # Parent ce397caf9dbbd79ef121fc41d39bbab1261748c1 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. diff --git a/ChangeLog b/ChangeLog --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2010-12-28 Paul Eggert + 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 diff --git a/lib/alloca.c b/lib/alloca.c --- 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