/[bison]/bison/lib/alloca.c
ViewVC logotype

Diff of /bison/lib/alloca.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by akim, Tue Mar 28 13:30:57 2000 UTC revision 1.1.2.1 by akim, Fri Nov 23 14:55:36 2001 UTC
# Line 22  Line 22 
22     your main control loop, etc. to force garbage collection.  */     your main control loop, etc. to force garbage collection.  */
23    
24  #ifdef HAVE_CONFIG_H  #ifdef HAVE_CONFIG_H
25  #include <config.h>  # include <config.h>
26  #endif  #endif
27    
28  #ifdef HAVE_STRING_H  #if HAVE_STRING_H
29  #include <string.h>  # include <string.h>
30  #endif  #endif
31  #ifdef HAVE_STDLIB_H  #if HAVE_STDLIB_H
32  #include <stdlib.h>  # include <stdlib.h>
33  #endif  #endif
34    
35  #ifdef emacs  #ifdef emacs
36  #include "blockinput.h"  # include "blockinput.h"
37  #endif  #endif
38    
39  /* If compiling with GCC 2, this file's not needed.  */  /* If compiling with GCC 2, this file's not needed.  */
# Line 41  Line 41 
41    
42  /* If someone has defined alloca as a macro,  /* If someone has defined alloca as a macro,
43     there must be some other way alloca is supposed to work.  */     there must be some other way alloca is supposed to work.  */
44  #ifndef alloca  # ifndef alloca
45    
46  #ifdef emacs  #  ifdef emacs
47  #ifdef static  #   ifdef static
48  /* actually, only want this if static is defined as ""  /* actually, only want this if static is defined as ""
49     -- this is for usg, in which emacs must undefine static     -- this is for usg, in which emacs must undefine static
50     in order to make unexec workable     in order to make unexec workable
51     */     */
52  #ifndef STACK_DIRECTION  #    ifndef STACK_DIRECTION
53  you  you
54  lose  lose
55  -- must know STACK_DIRECTION at compile-time  -- must know STACK_DIRECTION at compile-time
56  #endif /* STACK_DIRECTION undefined */  #    endif /* STACK_DIRECTION undefined */
57  #endif /* static */  #   endif /* static */
58  #endif /* emacs */  #  endif /* emacs */
59    
60  /* If your stack is a linked list of frames, you have to  /* If your stack is a linked list of frames, you have to
61     provide an "address metric" ADDRESS_FUNCTION macro.  */     provide an "address metric" ADDRESS_FUNCTION macro.  */
62    
63  #if defined (CRAY) && defined (CRAY_STACKSEG_END)  #  if defined (CRAY) && defined (CRAY_STACKSEG_END)
64  long i00afunc ();  long i00afunc ();
65  #define ADDRESS_FUNCTION(arg) (char *) i00afunc (&(arg))  #   define ADDRESS_FUNCTION(arg) (char *) i00afunc (&(arg))
66  #else  #  else
67  #define ADDRESS_FUNCTION(arg) &(arg)  #   define ADDRESS_FUNCTION(arg) &(arg)
68  #endif  #  endif
69    
70  #if __STDC__  #  if __STDC__
71  typedef void *pointer;  typedef void *pointer;
72  #else  #  else
73  typedef char *pointer;  typedef char *pointer;
74  #endif  #  endif
75    
76  #ifndef NULL  #  ifndef NULL
77  #define NULL    0  #   define NULL 0
78  #endif  #  endif
79    
80  /* Different portions of Emacs need to call different versions of  /* Different portions of Emacs need to call different versions of
81     malloc.  The Emacs executable needs alloca to call xmalloc, because     malloc.  The Emacs executable needs alloca to call xmalloc, because
# Line 83  typedef char *pointer; Line 83  typedef char *pointer;
83     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
84     them are very simple, and don't have an xmalloc routine.     them are very simple, and don't have an xmalloc routine.
85    
86     Non-Emacs programs expect this to call use xmalloc.     Non-Emacs programs expect this to call xmalloc.
87    
88     Callers below should use malloc.  */     Callers below should use malloc.  */
89    
90  #ifndef emacs  #  ifndef emacs
91  #define malloc xmalloc  #   undef malloc
92  #endif  #   define malloc xmalloc
93    #  endif
94  extern pointer malloc ();  extern pointer malloc ();
95    
96  /* Define STACK_DIRECTION if you know the direction of stack  /* Define STACK_DIRECTION if you know the direction of stack
# Line 100  extern pointer malloc (); Line 101  extern pointer malloc ();
101     STACK_DIRECTION < 0 => grows toward lower addresses     STACK_DIRECTION < 0 => grows toward lower addresses
102     STACK_DIRECTION = 0 => direction of growth unknown  */     STACK_DIRECTION = 0 => direction of growth unknown  */
103    
104  #ifndef STACK_DIRECTION  #  ifndef STACK_DIRECTION
105  #define STACK_DIRECTION 0       /* Direction unknown.  */  #   define STACK_DIRECTION      0       /* Direction unknown.  */
106  #endif  #  endif
107    
108  #if STACK_DIRECTION != 0  #  if STACK_DIRECTION != 0
109    
110  #define STACK_DIR       STACK_DIRECTION /* Known at compile-time.  */  #   define STACK_DIR    STACK_DIRECTION /* Known at compile-time.  */
111    
112  #else /* STACK_DIRECTION == 0; need run-time code.  */  #  else /* STACK_DIRECTION == 0; need run-time code.  */
113    
114  static int stack_dir;           /* 1 or -1 once known.  */  static int stack_dir;           /* 1 or -1 once known.  */
115  #define STACK_DIR       stack_dir  #   define STACK_DIR    stack_dir
116    
117  static void  static void
118  find_stack_direction ()  find_stack_direction ()
# Line 135  find_stack_direction () Line 136  find_stack_direction ()
136      }      }
137  }  }
138    
139  #endif /* STACK_DIRECTION == 0 */  #  endif /* STACK_DIRECTION == 0 */
140    
141  /* An "alloca header" is used to:  /* An "alloca header" is used to:
142     (a) chain together all alloca'ed blocks;     (a) chain together all alloca'ed blocks;
# Line 144  find_stack_direction () Line 145  find_stack_direction ()
145     It is very important that sizeof(header) agree with malloc     It is very important that sizeof(header) agree with malloc
146     alignment chunk size.  The following default should work okay.  */     alignment chunk size.  The following default should work okay.  */
147    
148  #ifndef ALIGN_SIZE  #  ifndef       ALIGN_SIZE
149  #define ALIGN_SIZE      sizeof(double)  #   define ALIGN_SIZE   sizeof(double)
150  #endif  #  endif
151    
152  typedef union hdr  typedef union hdr
153  {  {
# Line 168  static header *last_alloca_header = NULL Line 169  static header *last_alloca_header = NULL
169     implementations of C, for example under Gould's UTX/32.  */     implementations of C, for example under Gould's UTX/32.  */
170    
171  pointer  pointer
172  alloca (size)  alloca (size_t size)
      unsigned size;  
173  {  {
174    auto char probe;              /* Probes stack depth: */    auto char probe;              /* Probes stack depth: */
175    register char *depth = ADDRESS_FUNCTION (probe);    register char *depth = ADDRESS_FUNCTION (probe);
176    
177  #if STACK_DIRECTION == 0  #  if STACK_DIRECTION == 0
178    if (STACK_DIR == 0)           /* Unknown growth direction.  */    if (STACK_DIR == 0)           /* Unknown growth direction.  */
179      find_stack_direction ();      find_stack_direction ();
180  #endif  #  endif
181    
182    /* Reclaim garbage, defined as all alloca'd storage that    /* Reclaim garbage, defined as all alloca'd storage that
183       was allocated from deeper in the stack than currently.  */       was allocated from deeper in the stack than currently.  */
# Line 185  alloca (size) Line 185  alloca (size)
185    {    {
186      register header *hp;        /* Traverses linked list.  */      register header *hp;        /* Traverses linked list.  */
187    
188  #ifdef emacs  #  ifdef emacs
189      BLOCK_INPUT;      BLOCK_INPUT;
190  #endif  #  endif
191    
192      for (hp = last_alloca_header; hp != NULL;)      for (hp = last_alloca_header; hp != NULL;)
193        if ((STACK_DIR > 0 && hp->h.deep > depth)        if ((STACK_DIR > 0 && hp->h.deep > depth)
# Line 204  alloca (size) Line 204  alloca (size)
204    
205      last_alloca_header = hp;    /* -> last valid storage.  */      last_alloca_header = hp;    /* -> last valid storage.  */
206    
207  #ifdef emacs  #  ifdef emacs
208      UNBLOCK_INPUT;      UNBLOCK_INPUT;
209  #endif  #  endif
210    }    }
211    
212    if (size == 0)    if (size == 0)
# Line 232  alloca (size) Line 232  alloca (size)
232    }    }
233  }  }
234    
235  #if defined (CRAY) && defined (CRAY_STACKSEG_END)  #  if defined (CRAY) && defined (CRAY_STACKSEG_END)
236    
237  #ifdef DEBUG_I00AFUNC  #   ifdef DEBUG_I00AFUNC
238  #include <stdio.h>  #    include <stdio.h>
239  #endif  #   endif
240    
241  #ifndef CRAY_STACK  #   ifndef CRAY_STACK
242  #define CRAY_STACK  #    define CRAY_STACK
243  #ifndef CRAY2  #    ifndef CRAY2
244  /* Stack structures for CRAY-1, CRAY X-MP, and CRAY Y-MP */  /* Stack structures for CRAY-1, CRAY X-MP, and CRAY Y-MP */
245  struct stack_control_header  struct stack_control_header
246    {    {
# Line 292  struct stack_segment_linkage Line 292  struct stack_segment_linkage
292      long sss7;      long sss7;
293    };    };
294    
295  #else /* CRAY2 */  #    else /* CRAY2 */
296  /* The following structure defines the vector of words  /* The following structure defines the vector of words
297     returned by the STKSTAT library routine.  */     returned by the STKSTAT library routine.  */
298  struct stk_stat  struct stk_stat
# Line 345  struct stk_trailer Line 345  struct stk_trailer
345      long unknown14;      long unknown14;
346    };    };
347    
348  #endif /* CRAY2 */  #    endif /* CRAY2 */
349  #endif /* not CRAY_STACK */  #   endif /* not CRAY_STACK */
350    
351  #ifdef CRAY2  #   ifdef CRAY2
352  /* Determine a "stack measure" for an arbitrary ADDRESS.  /* Determine a "stack measure" for an arbitrary ADDRESS.
353     I doubt that "lint" will like this much.  */     I doubt that "lint" will like this much.  */
354    
# Line 419  i00afunc (long *address) Line 419  i00afunc (long *address)
419    return (result);    return (result);
420  }  }
421    
422  #else /* not CRAY2 */  #   else /* not CRAY2 */
423  /* 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.
424     Determine the number of the cell within the stack,     Determine the number of the cell within the stack,
425     given the address of the cell.  The purpose of this     given the address of the cell.  The purpose of this
# Line 464  i00afunc (long address) Line 464  i00afunc (long address)
464    
465    while (!(this_segment <= address && address <= stkl))    while (!(this_segment <= address && address <= stkl))
466      {      {
467  #ifdef DEBUG_I00AFUNC  #    ifdef DEBUG_I00AFUNC
468        fprintf (stderr, "%011o %011o %011o\n", this_segment, address, stkl);        fprintf (stderr, "%011o %011o %011o\n", this_segment, address, stkl);
469  #endif  #    endif
470        if (pseg == 0)        if (pseg == 0)
471          break;          break;
472        stkl = stkl - pseg;        stkl = stkl - pseg;
# Line 485  i00afunc (long address) Line 485  i00afunc (long address)
485    
486    while (pseg != 0)    while (pseg != 0)
487      {      {
488  #ifdef DEBUG_I00AFUNC  #    ifdef DEBUG_I00AFUNC
489        fprintf (stderr, "%011o %011o\n", pseg, size);        fprintf (stderr, "%011o %011o\n", pseg, size);
490  #endif  #    endif
491        stkl = stkl - pseg;        stkl = stkl - pseg;
492        ssptr = (struct stack_segment_linkage *) stkl;        ssptr = (struct stack_segment_linkage *) stkl;
493        size = ssptr->sssize;        size = ssptr->sssize;
# Line 497  i00afunc (long address) Line 497  i00afunc (long address)
497    return (result);    return (result);
498  }  }
499    
500  #endif /* not CRAY2 */  #   endif /* not CRAY2 */
501  #endif /* CRAY */  #  endif /* CRAY */
502    
503  #endif /* no alloca */  # endif /* no alloca */
504  #endif /* not GCC version 2 */  #endif /* not GCC version 2 */

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.1.2.1

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26