From e96be6ddd36dce8bfa885b683fbdd9354cc83d12 Mon Sep 17 00:00:00 2001 From: BT Templeton Date: Sat, 6 Jul 2013 01:01:28 -0400 Subject: [PATCH] SAFE_ALLOCA updated * src/alloc.c (record_xmalloc): Remove. All uses changed. * src/lisp.h (SAFE_ALLOCA, SAFE_NALLOCA, SAFE_ALLOCA_LISP): Use normal allocation functions and don't explicitly free memory. Remove all references to variables defined by these macros. (USE_SAFE_ALLOCA, SAFE_FREE): Now no-ops. --- src/alloc.c | 10 ---------- src/callproc.c | 4 ---- src/charset.c | 8 ++++---- src/editfns.c | 5 ----- src/lisp.h | 32 ++++++-------------------------- 5 files changed, 10 insertions(+), 49 deletions(-) diff --git a/src/alloc.c b/src/alloc.c index 1530269f24..2a89bb85bb 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -414,16 +414,6 @@ xputenv (char const *string) if (putenv ((char *) string) != 0) memory_full (0); } - -/* Return a newly allocated memory block of SIZE bytes, remembering - to free it when unwinding. */ -void * -record_xmalloc (size_t size) -{ - void *p = xmalloc (size); - record_unwind_protect_ptr (xfree, p); - return p; -} /*********************************************************************** Interval Allocation diff --git a/src/callproc.c b/src/callproc.c index 98ffc2fed0..70afbedeca 100644 --- a/src/callproc.c +++ b/src/callproc.c @@ -628,11 +628,9 @@ call_process (ptrdiff_t nargs, Lisp_Object *args, int filefd, Lisp_Object volatile coding_systems_volatile = coding_systems; Lisp_Object volatile current_dir_volatile = current_dir; bool volatile display_p_volatile = display_p; - bool volatile sa_must_free_volatile = sa_must_free; int volatile fd_error_volatile = fd_error; int volatile filefd_volatile = filefd; ptrdiff_t volatile count_volatile = count; - ptrdiff_t volatile sa_count_volatile = sa_count; char **volatile new_argv_volatile = new_argv; int volatile callproc_fd_volatile[CALLPROC_FDS]; for (i = 0; i < CALLPROC_FDS; i++) @@ -644,11 +642,9 @@ call_process (ptrdiff_t nargs, Lisp_Object *args, int filefd, coding_systems = coding_systems_volatile; current_dir = current_dir_volatile; display_p = display_p_volatile; - sa_must_free = sa_must_free_volatile; fd_error = fd_error_volatile; filefd = filefd_volatile; count = count_volatile; - sa_count = sa_count_volatile; new_argv = new_argv_volatile; for (i = 0; i < CALLPROC_FDS; i++) diff --git a/src/charset.c b/src/charset.c index ad37778153..fb285c6d7d 100644 --- a/src/charset.c +++ b/src/charset.c @@ -506,9 +506,9 @@ load_charset_map_from_file (struct charset *charset, Lisp_Object mapfile, set_unwind_protect_ptr (count, fclose_unwind, fp); unbind_to (count + 1, Qnil); - /* Use record_xmalloc, as `charset_map_entries' is - large (larger than MAX_ALLOCA). */ - head = record_xmalloc (sizeof *head); + /* Use record, as `charset_map_entries' is large (larger than + MAX_ALLOCA). */ + head = xmalloc (sizeof *head); entries = head; memset (entries, 0, sizeof (struct charset_map_entries)); @@ -539,7 +539,7 @@ load_charset_map_from_file (struct charset *charset, Lisp_Object mapfile, if (n_entries == 0x10000) { - entries->next = record_xmalloc (sizeof *entries->next); + entries->next = xmalloc (sizeof *entries->next); entries = entries->next; memset (entries, 0, sizeof (struct charset_map_entries)); n_entries = 0; diff --git a/src/editfns.c b/src/editfns.c index c89267d048..dbeb1d0ba0 100644 --- a/src/editfns.c +++ b/src/editfns.c @@ -3602,7 +3602,6 @@ usage: (format STRING &rest OBJECTS) */) ptrdiff_t bufsize = sizeof initial_buffer; ptrdiff_t max_bufsize = STRING_BYTES_BOUND + 1; char *p; - ptrdiff_t buf_save_value_index IF_LINT (= 0); char *format, *end, *format_start; ptrdiff_t formatlen, nchars; /* True if the format is multibyte. */ @@ -4210,15 +4209,11 @@ usage: (format STRING &rest OBJECTS) */) if (buf == initial_buffer) { buf = xmalloc_atomic (bufsize); - sa_must_free = true; - buf_save_value_index = SPECPDL_INDEX (); - record_unwind_protect_ptr (xfree, buf); memcpy (buf, initial_buffer, used); } else { buf = xrealloc (buf, bufsize); - set_unwind_protect_ptr (buf_save_value_index, xfree, buf); } p = buf + used; diff --git a/src/lisp.h b/src/lisp.h index 7ea21221f8..a075e1c543 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -3966,16 +3966,13 @@ extern void init_system_name (void); enum MAX_ALLOCA { MAX_ALLOCA = 16 * 1024 }; -extern void *record_xmalloc (size_t) ATTRIBUTE_ALLOC_SIZE ((1)); - -#define USE_SAFE_ALLOCA \ - ptrdiff_t sa_count = SPECPDL_INDEX (); bool sa_must_free = false +#define USE_SAFE_ALLOCA ((void) 0) /* SAFE_ALLOCA allocates a simple buffer. */ #define SAFE_ALLOCA(size) ((size) < MAX_ALLOCA \ ? alloca (size) \ - : (sa_must_free = true, record_xmalloc (size))) + : xmalloc (size)) /* SAFE_NALLOCA sets BUF to a newly allocated array of MULTIPLIER * NITEMS items, each of the same type as *BUF. MULTIPLIER must @@ -3986,23 +3983,12 @@ extern void *record_xmalloc (size_t) ATTRIBUTE_ALLOC_SIZE ((1)); if ((nitems) <= MAX_ALLOCA / sizeof *(buf) / (multiplier)) \ (buf) = alloca (sizeof *(buf) * (multiplier) * (nitems)); \ else \ - { \ - (buf) = xnmalloc (nitems, sizeof *(buf) * (multiplier)); \ - sa_must_free = true; \ - record_unwind_protect_ptr (xfree, buf); \ - } \ - } while (false) + (buf) = xnmalloc (nitems, sizeof *(buf) * (multiplier)); \ + } while (0) /* SAFE_FREE frees xmalloced memory and enables GC as needed. */ -#define SAFE_FREE() \ - do { \ - if (sa_must_free) { \ - sa_must_free = false; \ - unbind_to (sa_count, Qnil); \ - } \ - } while (false) - +#define SAFE_FREE() ((void) 0) /* SAFE_ALLOCA_LISP allocates an array of Lisp_Objects. */ @@ -4011,13 +3997,7 @@ extern void *record_xmalloc (size_t) ATTRIBUTE_ALLOC_SIZE ((1)); if ((nelt) < MAX_ALLOCA / word_size) \ (buf) = alloca ((nelt) * word_size); \ else if ((nelt) < min (PTRDIFF_MAX, SIZE_MAX) / word_size) \ - { \ - Lisp_Object arg_; \ - (buf) = xmalloc ((nelt) * word_size); \ - arg_ = make_save_memory (buf, nelt); \ - sa_must_free = true; \ - record_unwind_protect (free_save_value, arg_); \ - } \ + buf = xmalloc ((nelt) * word_size); \ else \ memory_full (SIZE_MAX); \ } while (false) -- 2.20.1