* lib/alloca.c: Update, from fileutils.

This commit is contained in:
Akim Demaille
2001-11-23 14:56:30 +00:00
parent 5b0d29bb52
commit c64a20f3dc
2 changed files with 70 additions and 67 deletions

View File

@@ -1,3 +1,7 @@
2001-11-23 Akim Demaille <akim@epita.fr>
* lib/alloca.c: Update, from fileutils.
2001-11-23 Akim Demaille <akim@epita.fr> 2001-11-23 Akim Demaille <akim@epita.fr>
* lib/Makefile.am (libbison_a_LIBADD): Add @ALLOCA@. * lib/Makefile.am (libbison_a_LIBADD): Add @ALLOCA@.
@@ -15,7 +19,6 @@
* src/closure.c (itemsetsize): Likewise. * src/closure.c (itemsetsize): Likewise.
* src/reader.c (symbol_list_new): Static. * src/reader.c (symbol_list_new): Static.
2001-11-23 Akim Demaille <akim@epita.fr> 2001-11-23 Akim Demaille <akim@epita.fr>
Attaching lineno to buckets is stupid, since only one copy of each Attaching lineno to buckets is stupid, since only one copy of each

View File

@@ -22,18 +22,18 @@
your main control loop, etc. to force garbage collection. */ your main control loop, etc. to force garbage collection. */
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include <config.h> # include <config.h>
#endif #endif
#ifdef HAVE_STRING_H #if HAVE_STRING_H
#include <string.h> # include <string.h>
#endif #endif
#ifdef HAVE_STDLIB_H #if HAVE_STDLIB_H
#include <stdlib.h> # include <stdlib.h>
#endif #endif
#ifdef emacs #ifdef emacs
#include "blockinput.h" # include "blockinput.h"
#endif #endif
/* If compiling with GCC 2, this file's not needed. */ /* If compiling with GCC 2, this file's not needed. */
@@ -41,41 +41,41 @@
/* If someone has defined alloca as a macro, /* If someone has defined alloca as a macro,
there must be some other way alloca is supposed to work. */ there must be some other way alloca is supposed to work. */
#ifndef alloca # ifndef alloca
#ifdef emacs # ifdef emacs
#ifdef static # ifdef static
/* actually, only want this if static is defined as "" /* actually, only want this if static is defined as ""
-- this is for usg, in which emacs must undefine static -- this is for usg, in which emacs must undefine static
in order to make unexec workable in order to make unexec workable
*/ */
#ifndef STACK_DIRECTION # ifndef STACK_DIRECTION
you you
lose lose
-- must know STACK_DIRECTION at compile-time -- must know STACK_DIRECTION at compile-time
#endif /* STACK_DIRECTION undefined */ # endif /* STACK_DIRECTION undefined */
#endif /* static */ # endif /* static */
#endif /* emacs */ # endif /* emacs */
/* If your stack is a linked list of frames, you have to /* If your stack is a linked list of frames, you have to
provide an "address metric" ADDRESS_FUNCTION macro. */ provide an "address metric" ADDRESS_FUNCTION macro. */
#if defined (CRAY) && defined (CRAY_STACKSEG_END) # if defined (CRAY) && defined (CRAY_STACKSEG_END)
long i00afunc (); long i00afunc ();
#define ADDRESS_FUNCTION(arg) (char *) i00afunc (&(arg)) # define ADDRESS_FUNCTION(arg) (char *) i00afunc (&(arg))
#else # else
#define ADDRESS_FUNCTION(arg) &(arg) # define ADDRESS_FUNCTION(arg) &(arg)
#endif # endif
#if __STDC__ # if __STDC__
typedef void *pointer; typedef void *pointer;
#else # else
typedef char *pointer; typedef char *pointer;
#endif # endif
#ifndef NULL # ifndef NULL
#define NULL 0 # define NULL 0
#endif # endif
/* Different portions of Emacs need to call different versions of /* Different portions of Emacs need to call different versions of
malloc. The Emacs executable needs alloca to call xmalloc, because malloc. The Emacs executable needs alloca to call xmalloc, because
@@ -83,13 +83,14 @@ typedef char *pointer;
hand, the utilities in lib-src need alloca to call malloc; some of hand, the utilities in lib-src need alloca to call malloc; some of
them are very simple, and don't have an xmalloc routine. them are very simple, and don't have an xmalloc routine.
Non-Emacs programs expect this to call use xmalloc. Non-Emacs programs expect this to call xmalloc.
Callers below should use malloc. */ Callers below should use malloc. */
#ifndef emacs # ifndef emacs
#define malloc xmalloc # undef malloc
#endif # define malloc xmalloc
# endif
extern pointer malloc (); extern pointer malloc ();
/* Define STACK_DIRECTION if you know the direction of stack /* Define STACK_DIRECTION if you know the direction of stack
@@ -100,18 +101,18 @@ extern pointer malloc ();
STACK_DIRECTION < 0 => grows toward lower addresses STACK_DIRECTION < 0 => grows toward lower addresses
STACK_DIRECTION = 0 => direction of growth unknown */ STACK_DIRECTION = 0 => direction of growth unknown */
#ifndef STACK_DIRECTION # ifndef STACK_DIRECTION
#define STACK_DIRECTION 0 /* Direction unknown. */ # define STACK_DIRECTION 0 /* Direction unknown. */
#endif # endif
#if STACK_DIRECTION != 0 # if STACK_DIRECTION != 0
#define STACK_DIR STACK_DIRECTION /* Known at compile-time. */ # define STACK_DIR STACK_DIRECTION /* Known at compile-time. */
#else /* STACK_DIRECTION == 0; need run-time code. */ # else /* STACK_DIRECTION == 0; need run-time code. */
static int stack_dir; /* 1 or -1 once known. */ static int stack_dir; /* 1 or -1 once known. */
#define STACK_DIR stack_dir # define STACK_DIR stack_dir
static void static void
find_stack_direction () find_stack_direction ()
@@ -135,7 +136,7 @@ find_stack_direction ()
} }
} }
#endif /* STACK_DIRECTION == 0 */ # endif /* STACK_DIRECTION == 0 */
/* An "alloca header" is used to: /* An "alloca header" is used to:
(a) chain together all alloca'ed blocks; (a) chain together all alloca'ed blocks;
@@ -144,9 +145,9 @@ find_stack_direction ()
It is very important that sizeof(header) agree with malloc It is very important that sizeof(header) agree with malloc
alignment chunk size. The following default should work okay. */ alignment chunk size. The following default should work okay. */
#ifndef ALIGN_SIZE # ifndef ALIGN_SIZE
#define ALIGN_SIZE sizeof(double) # define ALIGN_SIZE sizeof(double)
#endif # endif
typedef union hdr typedef union hdr
{ {
@@ -168,16 +169,15 @@ static header *last_alloca_header = NULL; /* -> last alloca header. */
implementations of C, for example under Gould's UTX/32. */ implementations of C, for example under Gould's UTX/32. */
pointer pointer
alloca (size) alloca (size_t size)
unsigned size;
{ {
auto char probe; /* Probes stack depth: */ auto char probe; /* Probes stack depth: */
register char *depth = ADDRESS_FUNCTION (probe); register char *depth = ADDRESS_FUNCTION (probe);
#if STACK_DIRECTION == 0 # if STACK_DIRECTION == 0
if (STACK_DIR == 0) /* Unknown growth direction. */ if (STACK_DIR == 0) /* Unknown growth direction. */
find_stack_direction (); find_stack_direction ();
#endif # endif
/* Reclaim garbage, defined as all alloca'd storage that /* Reclaim garbage, defined as all alloca'd storage that
was allocated from deeper in the stack than currently. */ was allocated from deeper in the stack than currently. */
@@ -185,9 +185,9 @@ alloca (size)
{ {
register header *hp; /* Traverses linked list. */ register header *hp; /* Traverses linked list. */
#ifdef emacs # ifdef emacs
BLOCK_INPUT; BLOCK_INPUT;
#endif # endif
for (hp = last_alloca_header; hp != NULL;) for (hp = last_alloca_header; hp != NULL;)
if ((STACK_DIR > 0 && hp->h.deep > depth) if ((STACK_DIR > 0 && hp->h.deep > depth)
@@ -204,9 +204,9 @@ alloca (size)
last_alloca_header = hp; /* -> last valid storage. */ last_alloca_header = hp; /* -> last valid storage. */
#ifdef emacs # ifdef emacs
UNBLOCK_INPUT; UNBLOCK_INPUT;
#endif # endif
} }
if (size == 0) if (size == 0)
@@ -232,15 +232,15 @@ alloca (size)
} }
} }
#if defined (CRAY) && defined (CRAY_STACKSEG_END) # if defined (CRAY) && defined (CRAY_STACKSEG_END)
#ifdef DEBUG_I00AFUNC # ifdef DEBUG_I00AFUNC
#include <stdio.h> # include <stdio.h>
#endif # endif
#ifndef CRAY_STACK # ifndef CRAY_STACK
#define CRAY_STACK # define CRAY_STACK
#ifndef CRAY2 # ifndef CRAY2
/* Stack structures for CRAY-1, CRAY X-MP, and CRAY Y-MP */ /* Stack structures for CRAY-1, CRAY X-MP, and CRAY Y-MP */
struct stack_control_header struct stack_control_header
{ {
@@ -292,7 +292,7 @@ struct stack_segment_linkage
long sss7; long sss7;
}; };
#else /* CRAY2 */ # else /* CRAY2 */
/* The following structure defines the vector of words /* The following structure defines the vector of words
returned by the STKSTAT library routine. */ returned by the STKSTAT library routine. */
struct stk_stat struct stk_stat
@@ -345,10 +345,10 @@ struct stk_trailer
long unknown14; long unknown14;
}; };
#endif /* CRAY2 */ # endif /* CRAY2 */
#endif /* not CRAY_STACK */ # endif /* not CRAY_STACK */
#ifdef CRAY2 # ifdef CRAY2
/* Determine a "stack measure" for an arbitrary ADDRESS. /* Determine a "stack measure" for an arbitrary ADDRESS.
I doubt that "lint" will like this much. */ I doubt that "lint" will like this much. */
@@ -419,7 +419,7 @@ i00afunc (long *address)
return (result); return (result);
} }
#else /* not CRAY2 */ # else /* not CRAY2 */
/* Stack address function for a CRAY-1, CRAY X-MP, or CRAY Y-MP. /* Stack address function for a CRAY-1, CRAY X-MP, or CRAY Y-MP.
Determine the number of the cell within the stack, Determine the number of the cell within the stack,
given the address of the cell. The purpose of this given the address of the cell. The purpose of this
@@ -464,9 +464,9 @@ i00afunc (long address)
while (!(this_segment <= address && address <= stkl)) while (!(this_segment <= address && address <= stkl))
{ {
#ifdef DEBUG_I00AFUNC # ifdef DEBUG_I00AFUNC
fprintf (stderr, "%011o %011o %011o\n", this_segment, address, stkl); fprintf (stderr, "%011o %011o %011o\n", this_segment, address, stkl);
#endif # endif
if (pseg == 0) if (pseg == 0)
break; break;
stkl = stkl - pseg; stkl = stkl - pseg;
@@ -485,9 +485,9 @@ i00afunc (long address)
while (pseg != 0) while (pseg != 0)
{ {
#ifdef DEBUG_I00AFUNC # ifdef DEBUG_I00AFUNC
fprintf (stderr, "%011o %011o\n", pseg, size); fprintf (stderr, "%011o %011o\n", pseg, size);
#endif # endif
stkl = stkl - pseg; stkl = stkl - pseg;
ssptr = (struct stack_segment_linkage *) stkl; ssptr = (struct stack_segment_linkage *) stkl;
size = ssptr->sssize; size = ssptr->sssize;
@@ -497,8 +497,8 @@ i00afunc (long address)
return (result); return (result);
} }
#endif /* not CRAY2 */ # endif /* not CRAY2 */
#endif /* CRAY */ # endif /* CRAY */
#endif /* no alloca */ # endif /* no alloca */
#endif /* not GCC version 2 */ #endif /* not GCC version 2 */