/[emacs]/emacs/src/alloca.c
ViewVC logotype

Diff of /emacs/src/alloca.c

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

revision 1.20 by fx, Thu Aug 17 13:57:01 2000 UTC revision 1.20.20.1 by miles, Fri Apr 4 06:20:56 2003 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  #ifdef HAVE_STRING_H
29  #include <string.h>  # include <string.h>
30  #endif  #endif
31  #ifdef HAVE_STDLIB_H  #ifdef HAVE_STDLIB_H
32  #include <stdlib.h>  # include <stdlib.h>
33  #endif  #endif
34    
35  #ifdef emacs  #ifdef emacs
36  #include "lisp.h"  # include "lisp.h"
37  #include "blockinput.h"  # include "blockinput.h"
38  #endif  #endif
39    
40  /* If compiling with GCC 2, this file's not needed.  */  /* If compiling with GCC 2, this file's not needed.  */
# Line 42  Line 42 
42    
43  /* If someone has defined alloca as a macro,  /* If someone has defined alloca as a macro,
44     there must be some other way alloca is supposed to work.  */     there must be some other way alloca is supposed to work.  */
45  #ifndef alloca  # ifndef alloca
46    
47  #ifdef emacs  #  ifdef emacs
48  #ifdef static  #   ifdef static
49  /* actually, only want this if static is defined as ""  /* actually, only want this if static is defined as ""
50     -- this is for usg, in which emacs must undefine static     -- this is for usg, in which emacs must undefine static
51     in order to make unexec workable     in order to make unexec workable
52     */     */
53  #ifndef STACK_DIRECTION  #    ifndef STACK_DIRECTION
54    #error "Must know STACK_DIRECTION at compile-time"  you
55  #endif /* STACK_DIRECTION undefined */  lose
56  #endif /* static */  -- must know STACK_DIRECTION at compile-time
57  #endif /* emacs */  /* Using #error here is not wise since this file is for
58       old and obscure compilers.  */
59    #    endif /* STACK_DIRECTION undefined */
60    #   endif /* static */
61    #  endif /* emacs */
62    
63  /* If your stack is a linked list of frames, you have to  /* If your stack is a linked list of frames, you have to
64     provide an "address metric" ADDRESS_FUNCTION macro.  */     provide an "address metric" ADDRESS_FUNCTION macro.  */
65    
66  #if defined (CRAY) && defined (CRAY_STACKSEG_END)  #  if defined (CRAY) && defined (CRAY_STACKSEG_END)
67  long i00afunc ();  long i00afunc ();
68  #define ADDRESS_FUNCTION(arg) (char *) i00afunc (&(arg))  #   define ADDRESS_FUNCTION(arg) (char *) i00afunc (&(arg))
69  #else  #  else
70  #define ADDRESS_FUNCTION(arg) &(arg)  #   define ADDRESS_FUNCTION(arg) &(arg)
71  #endif  #  endif
72    
73  #ifdef POINTER_TYPE  #  ifdef POINTER_TYPE
74  typedef POINTER_TYPE *pointer;  typedef POINTER_TYPE *pointer;
75  #else  #  else /* not POINTER_TYPE */
76  #if __STDC__  #   if __STDC__
77  typedef void *pointer;  typedef void *pointer;
78  #else  #   else /* not __STDC__ */
79  typedef char *pointer;  typedef char *pointer;
80  #endif /*__STDC__*/  #   endif /* not __STDC__ */
81  #endif /*POINTER_TYPE*/  #  endif /* not POINTER_TYPE */
82    
83    #  ifndef NULL
84  #ifndef NULL  #   define NULL 0
85  #define NULL    0  #  endif
 #endif  
86    
87  /* Different portions of Emacs need to call different versions of  /* Different portions of Emacs need to call different versions of
88     malloc.  The Emacs executable needs alloca to call xmalloc, because     malloc.  The Emacs executable needs alloca to call xmalloc, because
# Line 87  typedef char *pointer; Line 90  typedef char *pointer;
90     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
91     them are very simple, and don't have an xmalloc routine.     them are very simple, and don't have an xmalloc routine.
92    
93     Non-Emacs programs expect this to call use xmalloc.     Non-Emacs programs expect this to call xmalloc.
94    
95     Callers below should use malloc.  */     Callers below should use malloc.  */
96    
97  #ifdef emacs  #  ifdef emacs
98  #define malloc xmalloc  #   undef malloc
99  #ifdef EMACS_FREE  #   define malloc xmalloc
100  #define free EMACS_FREE  #   ifdef EMACS_FREE
101  #endif  #    define free EMACS_FREE
102  #endif  #   endif
103    #  endif
104  extern pointer malloc ();  extern pointer malloc ();
105    
106  /* Define STACK_DIRECTION if you know the direction of stack  /* Define STACK_DIRECTION if you know the direction of stack
# Line 107  extern pointer malloc (); Line 111  extern pointer malloc ();
111     STACK_DIRECTION < 0 => grows toward lower addresses     STACK_DIRECTION < 0 => grows toward lower addresses
112     STACK_DIRECTION = 0 => direction of growth unknown  */     STACK_DIRECTION = 0 => direction of growth unknown  */
113    
114  #ifndef STACK_DIRECTION  #  ifndef STACK_DIRECTION
115  #define STACK_DIRECTION 0       /* Direction unknown.  */  #   define STACK_DIRECTION      0       /* Direction unknown.  */
116  #endif  #  endif
117    
118  #if STACK_DIRECTION != 0  #  if STACK_DIRECTION != 0
119    
120  #define STACK_DIR       STACK_DIRECTION /* Known at compile-time.  */  #   define STACK_DIR    STACK_DIRECTION /* Known at compile-time.  */
121    
122  #else /* STACK_DIRECTION == 0; need run-time code.  */  #  else /* STACK_DIRECTION == 0; need run-time code.  */
123    
124  static int stack_dir;           /* 1 or -1 once known.  */  static int stack_dir;           /* 1 or -1 once known.  */
125  #define STACK_DIR       stack_dir  #   define STACK_DIR    stack_dir
126    
127  static void  static void
128  find_stack_direction ()  find_stack_direction ()
# Line 142  find_stack_direction () Line 146  find_stack_direction ()
146      }      }
147  }  }
148    
149  #endif /* STACK_DIRECTION == 0 */  #  endif /* STACK_DIRECTION == 0 */
150    
151  /* An "alloca header" is used to:  /* An "alloca header" is used to:
152     (a) chain together all alloca'ed blocks;     (a) chain together all alloca'ed blocks;
# Line 151  find_stack_direction () Line 155  find_stack_direction ()
155     It is very important that sizeof(header) agree with malloc     It is very important that sizeof(header) agree with malloc
156     alignment chunk size.  The following default should work okay.  */     alignment chunk size.  The following default should work okay.  */
157    
158  #ifndef ALIGN_SIZE  #  ifndef       ALIGN_SIZE
159  #define ALIGN_SIZE      sizeof(double)  #   define ALIGN_SIZE   sizeof(double)
160  #endif  #  endif
161    
162  typedef union hdr  typedef union hdr
163  {  {
# Line 181  alloca (size) Line 185  alloca (size)
185    auto char probe;              /* Probes stack depth: */    auto char probe;              /* Probes stack depth: */
186    register char *depth = ADDRESS_FUNCTION (probe);    register char *depth = ADDRESS_FUNCTION (probe);
187    
188  #if STACK_DIRECTION == 0  #  if STACK_DIRECTION == 0
189    if (STACK_DIR == 0)           /* Unknown growth direction.  */    if (STACK_DIR == 0)           /* Unknown growth direction.  */
190      find_stack_direction ();      find_stack_direction ();
191  #endif  #  endif
192    
193    /* Reclaim garbage, defined as all alloca'd storage that    /* Reclaim garbage, defined as all alloca'd storage that
194       was allocated from deeper in the stack than currently.  */       was allocated from deeper in the stack than currently.  */
# Line 192  alloca (size) Line 196  alloca (size)
196    {    {
197      register header *hp;        /* Traverses linked list.  */      register header *hp;        /* Traverses linked list.  */
198    
199  #ifdef emacs  #  ifdef emacs
200      BLOCK_INPUT;      BLOCK_INPUT;
201  #endif  #  endif
202    
203      for (hp = last_alloca_header; hp != NULL;)      for (hp = last_alloca_header; hp != NULL;)
204        if ((STACK_DIR > 0 && hp->h.deep > depth)        if ((STACK_DIR > 0 && hp->h.deep > depth)
# Line 211  alloca (size) Line 215  alloca (size)
215    
216      last_alloca_header = hp;    /* -> last valid storage.  */      last_alloca_header = hp;    /* -> last valid storage.  */
217    
218  #ifdef emacs  #  ifdef emacs
219      UNBLOCK_INPUT;      UNBLOCK_INPUT;
220  #endif  #  endif
221    }    }
222    
223    if (size == 0)    if (size == 0)
# Line 239  alloca (size) Line 243  alloca (size)
243    }    }
244  }  }
245    
246  #if defined (CRAY) && defined (CRAY_STACKSEG_END)  #  if defined (CRAY) && defined (CRAY_STACKSEG_END)
247    
248  #ifdef DEBUG_I00AFUNC  #   ifdef DEBUG_I00AFUNC
249  #include <stdio.h>  #    include <stdio.h>
250  #endif  #   endif
251    
252  #ifndef CRAY_STACK  #   ifndef CRAY_STACK
253  #define CRAY_STACK  #    define CRAY_STACK
254  #ifndef CRAY2  #    ifndef CRAY2
255  /* Stack structures for CRAY-1, CRAY X-MP, and CRAY Y-MP */  /* Stack structures for CRAY-1, CRAY X-MP, and CRAY Y-MP */
256  struct stack_control_header  struct stack_control_header
257    {    {
# Line 299  struct stack_segment_linkage Line 303  struct stack_segment_linkage
303      long sss7;      long sss7;
304    };    };
305    
306  #else /* CRAY2 */  #    else /* CRAY2 */
307  /* The following structure defines the vector of words  /* The following structure defines the vector of words
308     returned by the STKSTAT library routine.  */     returned by the STKSTAT library routine.  */
309  struct stk_stat  struct stk_stat
# Line 352  struct stk_trailer Line 356  struct stk_trailer
356      long unknown14;      long unknown14;
357    };    };
358    
359  #endif /* CRAY2 */  #    endif /* CRAY2 */
360  #endif /* not CRAY_STACK */  #   endif /* not CRAY_STACK */
361    
362  #ifdef CRAY2  #   ifdef CRAY2
363  /* Determine a "stack measure" for an arbitrary ADDRESS.  /* Determine a "stack measure" for an arbitrary ADDRESS.
364     I doubt that "lint" will like this much.  */     I doubt that "lint" will like this much.  */
365    
# Line 426  i00afunc (long *address) Line 430  i00afunc (long *address)
430    return (result);    return (result);
431  }  }
432    
433  #else /* not CRAY2 */  #   else /* not CRAY2 */
434  /* 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.
435     Determine the number of the cell within the stack,     Determine the number of the cell within the stack,
436     given the address of the cell.  The purpose of this     given the address of the cell.  The purpose of this
# Line 471  i00afunc (long address) Line 475  i00afunc (long address)
475    
476    while (!(this_segment <= address && address <= stkl))    while (!(this_segment <= address && address <= stkl))
477      {      {
478  #ifdef DEBUG_I00AFUNC  #    ifdef DEBUG_I00AFUNC
479        fprintf (stderr, "%011o %011o %011o\n", this_segment, address, stkl);        fprintf (stderr, "%011o %011o %011o\n", this_segment, address, stkl);
480  #endif  #    endif
481        if (pseg == 0)        if (pseg == 0)
482          break;          break;
483        stkl = stkl - pseg;        stkl = stkl - pseg;
# Line 492  i00afunc (long address) Line 496  i00afunc (long address)
496    
497    while (pseg != 0)    while (pseg != 0)
498      {      {
499  #ifdef DEBUG_I00AFUNC  #    ifdef DEBUG_I00AFUNC
500        fprintf (stderr, "%011o %011o\n", pseg, size);        fprintf (stderr, "%011o %011o\n", pseg, size);
501  #endif  #    endif
502        stkl = stkl - pseg;        stkl = stkl - pseg;
503        ssptr = (struct stack_segment_linkage *) stkl;        ssptr = (struct stack_segment_linkage *) stkl;
504        size = ssptr->sssize;        size = ssptr->sssize;
# Line 504  i00afunc (long address) Line 508  i00afunc (long address)
508    return (result);    return (result);
509  }  }
510    
511  #endif /* not CRAY2 */  #   endif /* not CRAY2 */
512  #endif /* CRAY */  #  endif /* CRAY */
513    
514  #endif /* no alloca */  # endif /* no alloca */
515  #endif /* not GCC version 2 */  #endif /* not GCC version 2 */

Legend:
Removed from v.1.20  
changed lines
  Added in v.1.20.20.1

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