From: Paul Eggert Date: Wed, 29 Dec 2010 04:41:30 +0000 (-0800) Subject: alloca: one step towards thread-safety X-Git-Tag: v0.1~3434 X-Git-Url: http://erislabs.org.uk/gitweb/?a=commitdiff_plain;h=6f5772995bee8b337fdd2fea5aea6f3fcb59fa36;p=gnulib.git 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 index 2c9d4c71e..5c95bc4e7 100644 --- 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 index b652765fd..2f5e27ec6 100644 --- a/lib/alloca.c +++ b/lib/alloca.c @@ -94,21 +94,20 @@ static int stack_dir; /* 1 or -1 once known. */ # 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 @@ alloca (size_t size) # 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