33 |
#endif |
#endif |
34 |
|
|
35 |
#ifdef emacs |
#ifdef emacs |
36 |
|
# include "lisp.h" |
37 |
# include "blockinput.h" |
# include "blockinput.h" |
38 |
|
# define xalloc_die() memory_full () |
39 |
|
# ifdef EMACS_FREE |
40 |
|
# undef free |
41 |
|
# define free EMACS_FREE |
42 |
|
# endif |
43 |
|
#else |
44 |
|
# include <xalloc.h> |
45 |
#endif |
#endif |
46 |
|
|
47 |
/* If compiling with GCC 2, this file's not needed. */ |
/* If compiling with GCC 2, this file's not needed. */ |
61 |
you |
you |
62 |
lose |
lose |
63 |
-- must know STACK_DIRECTION at compile-time |
-- must know STACK_DIRECTION at compile-time |
64 |
|
/* Using #error here is not wise since this file should work for |
65 |
|
old and obscure compilers. */ |
66 |
# endif /* STACK_DIRECTION undefined */ |
# endif /* STACK_DIRECTION undefined */ |
67 |
# endif /* static */ |
# endif /* static */ |
68 |
# endif /* emacs */ |
# endif /* emacs */ |
77 |
# define ADDRESS_FUNCTION(arg) &(arg) |
# define ADDRESS_FUNCTION(arg) &(arg) |
78 |
# endif |
# endif |
79 |
|
|
80 |
# if __STDC__ |
# ifndef POINTER_TYPE |
81 |
typedef void *pointer; |
# ifdef __STDC__ |
82 |
# else |
# define POINTER_TYPE void |
83 |
typedef char *pointer; |
# else |
84 |
|
# define POINTER_TYPE char |
85 |
|
# endif |
86 |
# endif |
# endif |
87 |
|
typedef POINTER_TYPE *pointer; |
88 |
|
|
89 |
# ifndef NULL |
# ifndef NULL |
90 |
# define NULL 0 |
# define NULL 0 |
91 |
# endif |
# endif |
92 |
|
|
|
/* Different portions of Emacs need to call different versions of |
|
|
malloc. The Emacs executable needs alloca to call xmalloc, because |
|
|
ordinary malloc isn't protected from input signals. On the other |
|
|
hand, the utilities in lib-src need alloca to call malloc; some of |
|
|
them are very simple, and don't have an xmalloc routine. |
|
|
|
|
|
Non-Emacs programs expect this to call xmalloc. |
|
|
|
|
|
Callers below should use malloc. */ |
|
|
|
|
|
# ifndef emacs |
|
|
# undef malloc |
|
|
# define malloc xmalloc |
|
|
# endif |
|
|
extern pointer malloc (); |
|
|
|
|
93 |
/* Define STACK_DIRECTION if you know the direction of stack |
/* Define STACK_DIRECTION if you know the direction of stack |
94 |
growth for your system; otherwise it will be automatically |
growth for your system; otherwise it will be automatically |
95 |
deduced at run-time. |
deduced at run-time. |
166 |
implementations of C, for example under Gould's UTX/32. */ |
implementations of C, for example under Gould's UTX/32. */ |
167 |
|
|
168 |
pointer |
pointer |
169 |
alloca (size_t size) |
alloca (size) |
170 |
|
size_t size; |
171 |
{ |
{ |
172 |
auto char probe; /* Probes stack depth: */ |
auto char probe; /* Probes stack depth: */ |
173 |
register char *depth = ADDRESS_FUNCTION (probe); |
register char *depth = ADDRESS_FUNCTION (probe); |
213 |
/* Allocate combined header + user data storage. */ |
/* Allocate combined header + user data storage. */ |
214 |
|
|
215 |
{ |
{ |
|
register pointer new = malloc (sizeof (header) + size); |
|
216 |
/* Address of header. */ |
/* Address of header. */ |
217 |
|
register pointer new; |
218 |
|
|
219 |
|
size_t combined_size = sizeof (header) + size; |
220 |
|
if (combined_size < sizeof (header)) |
221 |
|
xalloc_die (); |
222 |
|
|
223 |
|
new = xmalloc (combined_size); |
224 |
|
|
225 |
if (new == 0) |
if (new == 0) |
226 |
abort(); |
abort(); |