]> git.eshelyaron.com Git - emacs.git/commitdiff
Remove unused XMALLOC_BLOCK_INPUT_CHECK debug facility
authorStefan Kangas <stefankangas@gmail.com>
Mon, 14 Apr 2025 18:40:49 +0000 (20:40 +0200)
committerEshel Yaron <me@eshelyaron.com>
Wed, 16 Apr 2025 07:34:29 +0000 (09:34 +0200)
The compile-time option XMALLOC_BLOCK_INPUT_CHECK was added in
2012 (commit 4d7e6e51dd4acecff) to allow blocking input during
malloc-family calls, in case any issues arose from related
changes in Emacs 24.3.  However, it has not been referenced on
emacs-devel or the bug tracker in over a decade.

It is clear that we do not need it, as our signal handlers do not
allocate memory.  Removing it simplifies the allocation function
wrappers and eliminates dead debug code.

Ref: https://debbugs.gnu.org/12450

* src/alloc.c [XMALLOC_BLOCK_INPUT_CHECK]
(malloc_block_input, malloc_unblock_input): Delete functions.
(MALLOC_BLOCK_INPUT, MALLOC_UNBLOCK_INPUT): Delete macros.  Update
all callers.

(cherry picked from commit a7f5d183a8c13dfb7fb43777abdf96233df0ca0c)

src/alloc.c

index c0d68e6c9643666db132595b0cf8b2fef6ecad05..167be74d2f78954b77bd021e2b89c79a0bf81a47 100644 (file)
@@ -635,39 +635,6 @@ static_assert (LISP_ALIGNMENT % GCALIGNMENT == 0);
 enum { MALLOC_IS_LISP_ALIGNED = alignof (max_align_t) % LISP_ALIGNMENT == 0 };
 static_assert (MALLOC_IS_LISP_ALIGNED);
 
-/* If compiled with XMALLOC_BLOCK_INPUT_CHECK, define a symbol
-   BLOCK_INPUT_IN_MEMORY_ALLOCATORS that is visible to the debugger.
-   If that variable is set, block input while in one of Emacs's memory
-   allocation functions.  There should be no need for this debugging
-   option, since signal handlers do not allocate memory, but Emacs
-   formerly allocated memory in signal handlers and this compile-time
-   option remains as a way to help debug the issue should it rear its
-   ugly head again.  */
-#ifdef XMALLOC_BLOCK_INPUT_CHECK
-bool block_input_in_memory_allocators EXTERNALLY_VISIBLE;
-static void
-malloc_block_input (void)
-{
-  if (block_input_in_memory_allocators)
-    block_input ();
-}
-static void
-malloc_unblock_input (void)
-{
-  if (block_input_in_memory_allocators)
-    {
-      int err = errno;
-      unblock_input ();
-      errno = err;
-    }
-}
-# define MALLOC_BLOCK_INPUT malloc_block_input ()
-# define MALLOC_UNBLOCK_INPUT malloc_unblock_input ()
-#else
-# define MALLOC_BLOCK_INPUT ((void) 0)
-# define MALLOC_UNBLOCK_INPUT ((void) 0)
-#endif
-
 #define MALLOC_PROBE(size)                     \
   do {                                         \
     if (profiler_memory_running)               \
@@ -679,12 +646,7 @@ malloc_unblock_input (void)
 void *
 xmalloc (size_t size)
 {
-  void *val;
-
-  MALLOC_BLOCK_INPUT;
-  val = malloc (size);
-  MALLOC_UNBLOCK_INPUT;
-
+  void *val = malloc (size);
   if (!val)
     memory_full (size);
   MALLOC_PROBE (size);
@@ -696,12 +658,7 @@ xmalloc (size_t size)
 void *
 xzalloc (size_t size)
 {
-  void *val;
-
-  MALLOC_BLOCK_INPUT;
-  val = calloc (1, size);
-  MALLOC_UNBLOCK_INPUT;
-
+  void *val = calloc (1, size);
   if (!val)
     memory_full (size);
   MALLOC_PROBE (size);
@@ -713,12 +670,7 @@ xzalloc (size_t size)
 void *
 xrealloc (void *block, size_t size)
 {
-  void *val;
-
-  MALLOC_BLOCK_INPUT;
-  val = realloc (block, size);
-  MALLOC_UNBLOCK_INPUT;
-
+  void *val = realloc (block, size);
   if (!val)
     memory_full (size);
   MALLOC_PROBE (size);
@@ -735,9 +687,7 @@ xfree (void *block)
     return;
   if (pdumper_object_p (block))
     return;
-  MALLOC_BLOCK_INPUT;
   free (block);
-  MALLOC_UNBLOCK_INPUT;
   /* We don't call refill_memory_reserve here
      because in practice the call in r_alloc_free seems to suffice.  */
 }
@@ -922,15 +872,11 @@ void *lisp_malloc_loser EXTERNALLY_VISIBLE;
 static void *
 lisp_malloc (size_t nbytes, bool clearit, enum mem_type type)
 {
-  register void *val;
-
-  MALLOC_BLOCK_INPUT;
-
 #ifdef GC_MALLOC_CHECK
   allocated_mem_type = type;
 #endif
 
-  val = clearit ? calloc (1, nbytes) : malloc (nbytes);
+  void *val = clearit ? calloc (1, nbytes) : malloc (nbytes);
 
 #if ! USE_LSB_TAG
   /* If the memory just allocated cannot be addressed thru a Lisp
@@ -954,7 +900,6 @@ lisp_malloc (size_t nbytes, bool clearit, enum mem_type type)
     mem_insert (val, (char *) val + nbytes, type);
 #endif
 
-  MALLOC_UNBLOCK_INPUT;
   if (!val)
     memory_full (nbytes);
   MALLOC_PROBE (nbytes);
@@ -970,7 +915,6 @@ lisp_free (void *block)
   if (pdumper_object_p (block))
     return;
 
-  MALLOC_BLOCK_INPUT;
 #ifndef GC_MALLOC_CHECK
   struct mem_node *m = mem_find (block);
 #endif
@@ -978,7 +922,6 @@ lisp_free (void *block)
 #ifndef GC_MALLOC_CHECK
   mem_delete (m);
 #endif
-  MALLOC_UNBLOCK_INPUT;
 }
 
 /*****  Allocation of aligned blocks of memory to store Lisp data.  *****/
@@ -1116,8 +1059,6 @@ lisp_align_malloc (size_t nbytes, enum mem_type type)
 
   eassert (nbytes <= BLOCK_BYTES);
 
-  MALLOC_BLOCK_INPUT;
-
 #ifdef GC_MALLOC_CHECK
   allocated_mem_type = type;
 #endif
@@ -1141,10 +1082,7 @@ lisp_align_malloc (size_t nbytes, enum mem_type type)
 #endif
 
       if (base == 0)
-       {
-         MALLOC_UNBLOCK_INPUT;
-         memory_full (ABLOCKS_BYTES);
-       }
+       memory_full (ABLOCKS_BYTES);
 
       aligned = (base == abase);
       if (!aligned)
@@ -1168,7 +1106,6 @@ lisp_align_malloc (size_t nbytes, enum mem_type type)
            {
              lisp_malloc_loser = base;
              free (base);
-             MALLOC_UNBLOCK_INPUT;
              memory_full (SIZE_MAX);
            }
        }
@@ -1205,8 +1142,6 @@ lisp_align_malloc (size_t nbytes, enum mem_type type)
     mem_insert (val, (char *) val + nbytes, type);
 #endif
 
-  MALLOC_UNBLOCK_INPUT;
-
   MALLOC_PROBE (nbytes);
 
   eassert (0 == ((uintptr_t) val) % BLOCK_ALIGN);
@@ -1219,7 +1154,6 @@ lisp_align_free (void *block)
   struct ablock *ablock = block;
   struct ablocks *abase = ABLOCK_ABASE (ablock);
 
-  MALLOC_BLOCK_INPUT;
 #ifndef GC_MALLOC_CHECK
   mem_delete (mem_find (block));
 #endif
@@ -1259,7 +1193,6 @@ lisp_align_free (void *block)
 #endif
       free (ABLOCKS_BASE (abase));
     }
-  MALLOC_UNBLOCK_INPUT;
 }
 
 \f
@@ -1322,8 +1255,6 @@ make_interval (void)
 {
   INTERVAL val;
 
-  MALLOC_BLOCK_INPUT;
-
   if (interval_free_list)
     {
       val = interval_free_list;
@@ -1346,8 +1277,6 @@ make_interval (void)
       ASAN_UNPOISON_INTERVAL (val);
     }
 
-  MALLOC_UNBLOCK_INPUT;
-
   tally_consing (sizeof (struct interval));
   intervals_consed++;
   RESET_INTERVAL (val);
@@ -1735,8 +1664,6 @@ allocate_string (void)
 {
   struct Lisp_String *s;
 
-  MALLOC_BLOCK_INPUT;
-
   /* If the free-list is empty, allocate a new string_block, and
      add all the Lisp_Strings in it to the free-list.  */
   if (string_free_list == NULL)
@@ -1765,8 +1692,6 @@ allocate_string (void)
   ASAN_UNPOISON_STRING (s);
   string_free_list = NEXT_FREE_LISP_STRING (s);
 
-  MALLOC_UNBLOCK_INPUT;
-
   ++strings_consed;
   tally_consing (sizeof *s);
 
@@ -1810,8 +1735,6 @@ allocate_string_data (struct Lisp_String *s,
      of string data.  */
   ptrdiff_t needed = sdata_size (nbytes);
 
-  MALLOC_BLOCK_INPUT;
-
   if (nbytes > LARGE_STRING_BYTES || immovable)
     {
       size_t size = FLEXSIZEOF (struct sblock, data, needed);
@@ -1875,8 +1798,6 @@ allocate_string_data (struct Lisp_String *s,
   b->next_free = (sdata *) ((char *) data + needed + GC_STRING_EXTRA);
   eassert ((uintptr_t) b->next_free % alignof (sdata) == 0);
 
-  MALLOC_UNBLOCK_INPUT;
-
   s->u.s.data = SDATA_DATA (data);
 #ifdef GC_CHECK_STRING_BYTES
   SDATA_NBYTES (data) = nbytes;
@@ -2606,8 +2527,6 @@ make_float (double float_value)
 {
   register Lisp_Object val;
 
-  MALLOC_BLOCK_INPUT;
-
   if (float_free_list)
     {
       XSETFLOAT (val, float_free_list);
@@ -2631,8 +2550,6 @@ make_float (double float_value)
       float_block_index++;
     }
 
-  MALLOC_UNBLOCK_INPUT;
-
   XFLOAT_INIT (val, float_value);
   eassert (!XFLOAT_MARKED_P (XFLOAT (val)));
   tally_consing (sizeof (struct Lisp_Float));
@@ -2730,8 +2647,6 @@ DEFUN ("cons", Fcons, Scons, 2, 2, 0,
 {
   register Lisp_Object val;
 
-  MALLOC_BLOCK_INPUT;
-
   if (cons_free_list)
     {
       ASAN_UNPOISON_CONS (cons_free_list);
@@ -2755,8 +2670,6 @@ DEFUN ("cons", Fcons, Scons, 2, 2, 0,
       cons_block_index++;
     }
 
-  MALLOC_UNBLOCK_INPUT;
-
   XSETCAR (val, car);
   XSETCDR (val, cdr);
   eassert (!XCONS_MARKED_P (XCONS (val)));
@@ -3488,8 +3401,6 @@ allocate_vectorlike (ptrdiff_t len, bool clearit)
   ptrdiff_t nbytes = header_size + len * word_size;
   struct Lisp_Vector *p;
 
-  MALLOC_BLOCK_INPUT;
-
 #ifdef DOUG_LEA_MALLOC
   if (!mmap_lisp_allowed_p ())
     mallopt (M_MMAP_MAX, 0);
@@ -3518,8 +3429,6 @@ allocate_vectorlike (ptrdiff_t len, bool clearit)
   tally_consing (nbytes);
   vector_cells_consed += len;
 
-  MALLOC_UNBLOCK_INPUT;
-
   return p;
 }
 
@@ -3817,8 +3726,6 @@ Its value is void, and its function definition and property list are nil.  */)
 
   CHECK_STRING (name);
 
-  MALLOC_BLOCK_INPUT;
-
   if (symbol_free_list)
     {
       ASAN_UNPOISON_SYMBOL (symbol_free_list);
@@ -3842,8 +3749,6 @@ Its value is void, and its function definition and property list are nil.  */)
       symbol_block_index++;
     }
 
-  MALLOC_UNBLOCK_INPUT;
-
   init_symbol (val, name);
   tally_consing (sizeof (struct Lisp_Symbol));
   symbols_consed++;
@@ -4250,16 +4155,12 @@ memory_full (size_t nbytes)
   bool enough_free_memory = false;
   if (SPARE_MEMORY < nbytes)
     {
-      void *p;
-
-      MALLOC_BLOCK_INPUT;
-      p = malloc (SPARE_MEMORY);
+      void *p = malloc (SPARE_MEMORY);
       if (p)
        {
          free (p);
          enough_free_memory = true;
        }
-      MALLOC_UNBLOCK_INPUT;
     }
 
   if (! enough_free_memory)