SAFE_ALLOCA updated
authorBT Templeton <bt@hcoop.net>
Sat, 6 Jul 2013 05:01:28 +0000 (01:01 -0400)
committerRobin Templeton <robin@terpri.org>
Sat, 18 Apr 2015 22:49:10 +0000 (18:49 -0400)
* 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
src/callproc.c
src/charset.c
src/editfns.c
src/lisp.h

index 1530269..2a89bb8 100644 (file)
@@ -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;
-}
 \f
 /***********************************************************************
                         Interval Allocation
index 98ffc2f..70afbed 100644 (file)
@@ -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++)
index ad37778..fb285c6 100644 (file)
@@ -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;
index c89267d..dbeb1d0 100644 (file)
@@ -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;
index 7ea2122..a075e1c 100644 (file)
@@ -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)