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; \
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; \
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); \
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. */