]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix thinko in last change
authorPo Lu <luangruo@yahoo.com>
Wed, 27 Jul 2022 11:56:43 +0000 (19:56 +0800)
committerPo Lu <luangruo@yahoo.com>
Wed, 27 Jul 2022 12:01:53 +0000 (20:01 +0800)
* src/print.c (PRINTPREPARE): Also remove `print_free_buffer'.
Record unwind protect instead.
(PRINTFINISH): Stop freeing the print buffer.  (bug#56773)

src/print.c

index 6218c76224c3551f894b5c0144bd9acfeb870e36..384a639b3178ebc45ba395fa565663173fe3e1ed 100644 (file)
@@ -101,7 +101,6 @@ bool print_output_debug_flag EXTERNALLY_VISIBLE = 1;
    ptrdiff_t old_point = -1, start_point = -1;                         \
    ptrdiff_t old_point_byte = -1, start_point_byte = -1;               \
    specpdl_ref specpdl_count = SPECPDL_INDEX ();                       \
-   bool free_print_buffer = 0;                                         \
    bool multibyte                                                      \
      = !NILP (BVAR (current_buffer, enable_multibyte_characters));     \
    Lisp_Object original = printcharfun;                                        \
@@ -153,7 +152,7 @@ bool print_output_debug_flag EXTERNALLY_VISIBLE = 1;
           int new_size = 1000;                                         \
           print_buffer = xmalloc (new_size);                           \
           print_buffer_size = new_size;                                \
-          free_print_buffer = 1;                                       \
+          record_unwind_protect_void (print_free_buffer);              \
         }                                                              \
        print_buffer_pos = 0;                                           \
        print_buffer_pos_byte = 0;                                      \
@@ -180,11 +179,6 @@ bool print_output_debug_flag EXTERNALLY_VISIBLE = 1;
                        print_buffer_pos_byte, 0, 1, 0);                \
        signal_after_change (PT - print_buffer_pos, 0, print_buffer_pos);\
      }                                                                 \
-   if (free_print_buffer)                                              \
-     {                                                                 \
-       xfree (print_buffer);                                           \
-       print_buffer = 0;                                               \
-     }                                                                 \
    unbind_to (specpdl_count, Qnil);                                    \
    if (MARKERP (original))                                             \
      set_marker_both (original, Qnil, PT, PT_BYTE);                    \
@@ -194,6 +188,16 @@ bool print_output_debug_flag EXTERNALLY_VISIBLE = 1;
                  old_point_byte + (old_point_byte >= start_point_byte  \
                                    ? PT_BYTE - start_point_byte : 0));
 
+/* This is used to free the print buffer; we don't simply record xfree
+   since print_buffer can be reallocated during the printing.  */
+
+static void
+print_free_buffer (void)
+{
+  xfree (print_buffer);
+  print_buffer = NULL;
+}
+
 /* This is used to restore the saved contents of print_buffer
    when there is a recursive call to print.  */