From e2588fa52fd7761e252361c341d8565790b3d1f2 Mon Sep 17 00:00:00 2001 From: Dmitry Antipov Date: Tue, 9 Sep 2014 15:43:22 +0400 Subject: [PATCH] Cleanup last change and make all new stuff conditional. * lisp.h (build_local_string): Rename to ... (make_local_string): ... this macro. (build_local_string, scoped_list1, scoped_list3): New macros. (toplevel) [USE_STACK_LISP_OBJECTS]: Define all new macros and functions as such, use regular fallbacks otherwise. * alloc.c (verify_alloca) [USE_STACK_LISP_OBJECTS]: Define conditionally. --- src/ChangeLog | 9 +++++++++ src/alloc.c | 8 ++++++-- src/lisp.h | 34 +++++++++++++++++++++++++++++++--- 3 files changed, 46 insertions(+), 5 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index d1e8314b172..b94ac53051a 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -17,6 +17,15 @@ * alloc.c (verify_alloca) [ENABLE_CHECKING]: New function. (init_alloc_once): Call it. + Cleanup last change and make all new stuff conditional. + * lisp.h (build_local_string): Rename to ... + (make_local_string): ... this macro. + (build_local_string, scoped_list1, scoped_list3): New macros. + (toplevel) [USE_STACK_LISP_OBJECTS]: Define all new macros + and functions as such, use regular fallbacks otherwise. + * alloc.c (verify_alloca) [USE_STACK_LISP_OBJECTS]: Define + conditionally. + 2014-09-08 Eli Zaretskii * dispnew.c (prepare_desired_row): When MODE_LINE_P is zero, diff --git a/src/alloc.c b/src/alloc.c index 13043d6d9d7..5c7ce31cad8 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -7118,6 +7118,10 @@ die (const char *msg, const char *file, int line) terminate_due_to_signal (SIGABRT, INT_MAX); } +#endif /* ENABLE_CHECKING */ + +#if defined (ENABLE_CHECKING) && defined (USE_STACK_LISP_OBJECTS) + /* Stress alloca with inconveniently sized requests and check whether all allocated areas may be used for Lisp_Object. */ @@ -7134,11 +7138,11 @@ verify_alloca (void) } } -#else /* not ENABLE_CHECKING */ +#else /* not (ENABLE_CHECKING && USE_STACK_LISP_OBJECTS) */ #define verify_alloca() ((void) 0) -#endif /* ENABLE_CHECKING */ +#endif /* ENABLE_CHECKING && USE_STACK_LISP_OBJECTS */ /* Initialization. */ diff --git a/src/lisp.h b/src/lisp.h index a89e80729cd..cbb4c30bea1 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -4546,6 +4546,12 @@ extern void *record_xmalloc (size_t) ATTRIBUTE_ALLOC_SIZE ((1)); memory_full (SIZE_MAX); \ } while (false) +/* This feature is experimental and requires very careful debugging. + Brave user should compile with CPPFLAGS='-DUSE_STACK_LISP_OBJECTS' + to get into the game. */ + +#ifdef USE_STACK_LISP_OBJECTS + /* Use the following functions to allocate temporary (function- or block-scoped) conses, vectors, and strings. These objects are not managed by GC, and passing them out of their scope @@ -4582,9 +4588,12 @@ scoped_cons_init (void *ptr, Lisp_Object x, Lisp_Object y) #endif /* __GNUC__ etc... */ -/* Convenient utility macro similar to list2. */ +/* Convenient utility macros similar to listX functions. */ +#define scoped_list1(x) scoped_cons (x, Qnil) #define scoped_list2(x, y) scoped_cons (x, scoped_cons (y, Qnil)) +#define scoped_list3(x, y, z) \ + scoped_cons (x, scoped_cons (y, scoped_cons (z, Qnil))) /* True if Lisp_Object may be placed at P. Used only under ENABLE_CHECKING and optimized away otherwise. */ @@ -4622,7 +4631,7 @@ local_vector_init (uintptr_t addr, ptrdiff_t length, Lisp_Object init) ((size) * word_size + header_size)), \ obj = local_vector_init ((uintptr_t) XLI (obj), (size), (init)))) -/* Helper function for build_local_string, see below. */ +/* Helper function for make_local_string, see below. */ INLINE Lisp_Object local_string_init (uintptr_t addr, const char *data, ptrdiff_t size) @@ -4648,13 +4657,32 @@ local_string_init (uintptr_t addr, const char *data, ptrdiff_t size) with contents DATA of length NBYTES. Otherwise create regular GC-managed string. */ -#define build_local_string(obj, data, nbytes) \ +#define make_local_string(obj, data, nbytes) \ (MAX_ALLOCA < (nbytes) + sizeof (struct Lisp_String) \ ? obj = make_string ((data), (nbytes)) \ : (obj = XIL ((uintptr_t) alloca \ ((nbytes) + sizeof (struct Lisp_String))), \ obj = local_string_init ((uintptr_t) XLI (obj), data, nbytes))) +/* We want an interface similar to make_string and build_string, right? */ + +#define build_local_string(obj, data) \ + make_local_string (obj, data, strlen (data)) + +#else /* not USE_STACK_LISP_OBJECTS */ + +#define scoped_cons(x, y) Fcons ((x), (y)) +#define scoped_list1(x) list1 (x) +#define scoped_list2(x, y) list2 ((x), (y)) +#define scoped_list3(x, y, z) list3 ((x), (y), (z)) +#define build_local_vector(obj, size, init) \ + (obj = Fmake_vector (make_number ((size), (init)))) +#define make_local_string(obj, data, nbytes) \ + (obj = make_string ((data), (nbytes))) +#define build_local_string(obj, data) (obj = build_string (data)) + +#endif /* USE_STACK_LISP_OBJECTS */ + /* Loop over all tails of a list, checking for cycles. FIXME: Make tortoise and n internal declarations. FIXME: Unroll the loop body so we don't need `n'. */ -- 2.39.5