mirror of
git://git.sv.gnu.org/emacs.git
synced 2026-04-27 16:51:06 -07:00
(MAX_ALLOCA): Define here.
(safe_alloca_unwind): Add prototype. (USE_SAFE_ALLOCA, SAFE_ALLOCA, SAFE_FREE): New macros.
This commit is contained in:
parent
e6263643ad
commit
79518a8dfa
1 changed files with 31 additions and 0 deletions
31
src/lisp.h
31
src/lisp.h
|
|
@ -3246,6 +3246,37 @@ extern Lisp_Object Vdirectory_sep_char;
|
|||
: Fcons ((el), (check)))))
|
||||
|
||||
|
||||
/* SAFE_ALLOCA normally allocates memory on the stack, but if size is
|
||||
larger than MAX_ALLOCA, use xmalloc to avoid overflowing the stack. */
|
||||
|
||||
#define MAX_ALLOCA 16*1024
|
||||
|
||||
extern Lisp_Object safe_alloca_unwind (Lisp_Object);
|
||||
|
||||
#define USE_SAFE_ALLOCA \
|
||||
int sa_count = SPECPDL_INDEX ()
|
||||
|
||||
#define SAFE_ALLOCA(buf, type, size) \
|
||||
do { \
|
||||
if ((size) < MAX_ALLOCA) \
|
||||
buf = (type) alloca (size); \
|
||||
else \
|
||||
{ \
|
||||
buf = (type) xmalloc (size); \
|
||||
record_unwind_protect (safe_alloca_unwind, \
|
||||
make_save_value (buf, 0)); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define SAFE_FREE(size) \
|
||||
do { \
|
||||
if ((size) >= MAX_ALLOCA) \
|
||||
unbind_to (sa_count, Qnil); \
|
||||
} while (0)
|
||||
|
||||
|
||||
|
||||
|
||||
#endif /* EMACS_LISP_H */
|
||||
|
||||
/* arch-tag: 9b2ed020-70eb-47ac-94ee-e1c2a5107d5e
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue