Commit 9c0fa117 authored by Eli Zaretskii's avatar Eli Zaretskii

Don't run buffer-related hooks in " *code conversion work*" buffers

Note: portions of this change were mistakenly pushed as part
of an unrelated commit a35a1f6a.

* src/buffer.c (Fget_buffer_create): Set inhibit_buffer_hooks
non-zero for temporary buffers created by coding.c.  Don't run
buffer-list-update-hook for such buffers.
(Frename_buffer, Fkill_buffer, record_buffer)
(Fbury_buffer_internal): Don't run hooks for buffers whose
inhibit_buffer_hooks flag is set.
* src/buffer.h (struct buffer): New member
inhibit_buffer_hooks.
* src/pdumper.c (dump_buffer): Dump the new field.  Update the
hash value in HASH_buffer_XXX.
* src/coding.c (make_conversion_work_buffer): Function deleted;
code moved to code_conversion_save.
(code_conversion_save): Insert code from
make_conversion_work_buffer, but arrange for unwind-protecting
the current buffer before switching to the work buffer.  This
avoids leaving reused_workbuf_in_use set if user presses C-g
during encoding/decoding.
(Vcode_conversion_workbuf_name): Now external variable.
* src/coding.h (Vcode_conversion_reused_workbuf): Declare.
parent 273d7b3e
Pipeline #1111 failed with stage
in 49 minutes and 4 seconds
...@@ -37,6 +37,7 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */ ...@@ -37,6 +37,7 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
#include "window.h" #include "window.h"
#include "commands.h" #include "commands.h"
#include "character.h" #include "character.h"
#include "coding.h"
#include "buffer.h" #include "buffer.h"
#include "region-cache.h" #include "region-cache.h"
#include "indent.h" #include "indent.h"
...@@ -583,6 +584,11 @@ even if it is dead. The return value is never nil. */) ...@@ -583,6 +584,11 @@ even if it is dead. The return value is never nil. */)
set_string_intervals (name, NULL); set_string_intervals (name, NULL);
bset_name (b, name); bset_name (b, name);
if (STRINGP (Vcode_conversion_workbuf_name)
&& strncmp (SSDATA (name), SSDATA (Vcode_conversion_workbuf_name),
SBYTES (Vcode_conversion_workbuf_name)) == 0)
b->inhibit_buffer_hooks = true;
bset_undo_list (b, SREF (name, 0) != ' ' ? Qnil : Qt); bset_undo_list (b, SREF (name, 0) != ' ' ? Qnil : Qt);
reset_buffer (b); reset_buffer (b);
...@@ -595,7 +601,7 @@ even if it is dead. The return value is never nil. */) ...@@ -595,7 +601,7 @@ even if it is dead. The return value is never nil. */)
XSETBUFFER (buffer, b); XSETBUFFER (buffer, b);
Vbuffer_alist = nconc2 (Vbuffer_alist, list1 (Fcons (name, buffer))); Vbuffer_alist = nconc2 (Vbuffer_alist, list1 (Fcons (name, buffer)));
/* And run buffer-list-update-hook. */ /* And run buffer-list-update-hook. */
if (!NILP (Vrun_hooks)) if (!NILP (Vrun_hooks) && !b->inhibit_buffer_hooks)
call1 (Vrun_hooks, Qbuffer_list_update_hook); call1 (Vrun_hooks, Qbuffer_list_update_hook);
return buffer; return buffer;
...@@ -1493,7 +1499,7 @@ This does not change the name of the visited file (if any). */) ...@@ -1493,7 +1499,7 @@ This does not change the name of the visited file (if any). */)
call0 (intern ("rename-auto-save-file")); call0 (intern ("rename-auto-save-file"));
/* Run buffer-list-update-hook. */ /* Run buffer-list-update-hook. */
if (!NILP (Vrun_hooks)) if (!NILP (Vrun_hooks) && !current_buffer->inhibit_buffer_hooks)
call1 (Vrun_hooks, Qbuffer_list_update_hook); call1 (Vrun_hooks, Qbuffer_list_update_hook);
/* Refetch since that last call may have done GC. */ /* Refetch since that last call may have done GC. */
...@@ -1706,8 +1712,9 @@ cleaning up all windows currently displaying the buffer to be killed. */) ...@@ -1706,8 +1712,9 @@ cleaning up all windows currently displaying the buffer to be killed. */)
/* First run the query functions; if any query is answered no, /* First run the query functions; if any query is answered no,
don't kill the buffer. */ don't kill the buffer. */
tem = CALLN (Frun_hook_with_args_until_failure, if (!b->inhibit_buffer_hooks)
Qkill_buffer_query_functions); tem = CALLN (Frun_hook_with_args_until_failure,
Qkill_buffer_query_functions);
if (NILP (tem)) if (NILP (tem))
return unbind_to (count, Qnil); return unbind_to (count, Qnil);
...@@ -1726,7 +1733,8 @@ cleaning up all windows currently displaying the buffer to be killed. */) ...@@ -1726,7 +1733,8 @@ cleaning up all windows currently displaying the buffer to be killed. */)
return unbind_to (count, Qt); return unbind_to (count, Qt);
/* Then run the hooks. */ /* Then run the hooks. */
run_hook (Qkill_buffer_hook); if (!b->inhibit_buffer_hooks)
run_hook (Qkill_buffer_hook);
unbind_to (count, Qnil); unbind_to (count, Qnil);
} }
...@@ -1928,7 +1936,7 @@ cleaning up all windows currently displaying the buffer to be killed. */) ...@@ -1928,7 +1936,7 @@ cleaning up all windows currently displaying the buffer to be killed. */)
bset_undo_list (b, Qnil); bset_undo_list (b, Qnil);
/* Run buffer-list-update-hook. */ /* Run buffer-list-update-hook. */
if (!NILP (Vrun_hooks)) if (!NILP (Vrun_hooks) && !b->inhibit_buffer_hooks)
call1 (Vrun_hooks, Qbuffer_list_update_hook); call1 (Vrun_hooks, Qbuffer_list_update_hook);
return Qt; return Qt;
...@@ -1970,7 +1978,7 @@ record_buffer (Lisp_Object buffer) ...@@ -1970,7 +1978,7 @@ record_buffer (Lisp_Object buffer)
fset_buried_buffer_list (f, Fdelq (buffer, f->buried_buffer_list)); fset_buried_buffer_list (f, Fdelq (buffer, f->buried_buffer_list));
/* Run buffer-list-update-hook. */ /* Run buffer-list-update-hook. */
if (!NILP (Vrun_hooks)) if (!NILP (Vrun_hooks) && !XBUFFER (buffer)->inhibit_buffer_hooks)
call1 (Vrun_hooks, Qbuffer_list_update_hook); call1 (Vrun_hooks, Qbuffer_list_update_hook);
} }
...@@ -2009,7 +2017,7 @@ DEFUN ("bury-buffer-internal", Fbury_buffer_internal, Sbury_buffer_internal, ...@@ -2009,7 +2017,7 @@ DEFUN ("bury-buffer-internal", Fbury_buffer_internal, Sbury_buffer_internal,
(f, Fcons (buffer, Fdelq (buffer, f->buried_buffer_list))); (f, Fcons (buffer, Fdelq (buffer, f->buried_buffer_list)));
/* Run buffer-list-update-hook. */ /* Run buffer-list-update-hook. */
if (!NILP (Vrun_hooks)) if (!NILP (Vrun_hooks) && !XBUFFER (buffer)->inhibit_buffer_hooks)
call1 (Vrun_hooks, Qbuffer_list_update_hook); call1 (Vrun_hooks, Qbuffer_list_update_hook);
return Qnil; return Qnil;
......
...@@ -855,6 +855,13 @@ struct buffer ...@@ -855,6 +855,13 @@ struct buffer
/* Non-zero whenever the narrowing is changed in this buffer. */ /* Non-zero whenever the narrowing is changed in this buffer. */
bool_bf clip_changed : 1; bool_bf clip_changed : 1;
/* Non-zero for internally used temporary buffers that don't need to
run hooks kill-buffer-hook, buffer-list-update-hook, and
kill-buffer-query-functions. This is used in coding.c to avoid
slowing down en/decoding when there are a lot of these hooks
defined. */
bool_bf inhibit_buffer_hooks : 1;
/* List of overlays that end at or before the current center, /* List of overlays that end at or before the current center,
in order of end-position. */ in order of end-position. */
struct Lisp_Overlay *overlays_before; struct Lisp_Overlay *overlays_before;
......
...@@ -7785,7 +7785,7 @@ encode_coding (struct coding_system *coding) ...@@ -7785,7 +7785,7 @@ encode_coding (struct coding_system *coding)
/* Name (or base name) of work buffer for code conversion. */ /* Name (or base name) of work buffer for code conversion. */
static Lisp_Object Vcode_conversion_workbuf_name; Lisp_Object Vcode_conversion_workbuf_name;
/* A working buffer used by the top level conversion. Once it is /* A working buffer used by the top level conversion. Once it is
created, it is never destroyed. It has the name created, it is never destroyed. It has the name
...@@ -7797,7 +7797,6 @@ static Lisp_Object Vcode_conversion_reused_workbuf; ...@@ -7797,7 +7797,6 @@ static Lisp_Object Vcode_conversion_reused_workbuf;
/* True iff Vcode_conversion_reused_workbuf is already in use. */ /* True iff Vcode_conversion_reused_workbuf is already in use. */
static bool reused_workbuf_in_use; static bool reused_workbuf_in_use;
static void static void
code_conversion_restore (Lisp_Object arg) code_conversion_restore (Lisp_Object arg)
{ {
...@@ -7810,12 +7809,7 @@ code_conversion_restore (Lisp_Object arg) ...@@ -7810,12 +7809,7 @@ code_conversion_restore (Lisp_Object arg)
if (EQ (workbuf, Vcode_conversion_reused_workbuf)) if (EQ (workbuf, Vcode_conversion_reused_workbuf))
reused_workbuf_in_use = 0; reused_workbuf_in_use = 0;
else else
{ Fkill_buffer (workbuf);
ptrdiff_t count = SPECPDL_INDEX ();
specbind (Qbuffer_list_update_hook, Qnil);
Fkill_buffer (workbuf);
unbind_to (count, Qnil);
}
} }
set_buffer_internal (XBUFFER (current)); set_buffer_internal (XBUFFER (current));
} }
...@@ -7827,24 +7821,17 @@ code_conversion_save (bool with_work_buf, bool multibyte) ...@@ -7827,24 +7821,17 @@ code_conversion_save (bool with_work_buf, bool multibyte)
if (with_work_buf) if (with_work_buf)
{ {
ptrdiff_t count = SPECPDL_INDEX ();
if (reused_workbuf_in_use) if (reused_workbuf_in_use)
{ {
Lisp_Object name Lisp_Object name
= Fgenerate_new_buffer_name (Vcode_conversion_workbuf_name, Qnil); = Fgenerate_new_buffer_name (Vcode_conversion_workbuf_name, Qnil);
specbind (Qbuffer_list_update_hook, Qnil);
workbuf = Fget_buffer_create (name); workbuf = Fget_buffer_create (name);
unbind_to (count, Qnil);
} }
else else
{ {
if (NILP (Fbuffer_live_p (Vcode_conversion_reused_workbuf))) if (NILP (Fbuffer_live_p (Vcode_conversion_reused_workbuf)))
{ Vcode_conversion_reused_workbuf
specbind (Qbuffer_list_update_hook, Qnil); = Fget_buffer_create (Vcode_conversion_workbuf_name);
Vcode_conversion_reused_workbuf
= Fget_buffer_create (Vcode_conversion_workbuf_name);
unbind_to (count, Qnil);
}
workbuf = Vcode_conversion_reused_workbuf; workbuf = Vcode_conversion_reused_workbuf;
} }
} }
...@@ -7863,11 +7850,6 @@ code_conversion_save (bool with_work_buf, bool multibyte) ...@@ -7863,11 +7850,6 @@ code_conversion_save (bool with_work_buf, bool multibyte)
bset_enable_multibyte_characters (current_buffer, multibyte ? Qt : Qnil); bset_enable_multibyte_characters (current_buffer, multibyte ? Qt : Qnil);
if (EQ (workbuf, Vcode_conversion_reused_workbuf)) if (EQ (workbuf, Vcode_conversion_reused_workbuf))
reused_workbuf_in_use = 1; reused_workbuf_in_use = 1;
else
{
Fset (Fmake_local_variable (Qkill_buffer_query_functions), Qnil);
Fset (Fmake_local_variable (Qkill_buffer_hook), Qnil);
}
set_buffer_internal (current); set_buffer_internal (current);
} }
......
...@@ -97,6 +97,8 @@ enum define_coding_undecided_arg_index ...@@ -97,6 +97,8 @@ enum define_coding_undecided_arg_index
extern Lisp_Object Vcoding_system_hash_table; extern Lisp_Object Vcoding_system_hash_table;
/* Name (or base name) of work buffer for code conversion. */
extern Lisp_Object Vcode_conversion_workbuf_name;
/* Enumeration of index to an attribute vector of a coding system. */ /* Enumeration of index to an attribute vector of a coding system. */
......
...@@ -2761,7 +2761,7 @@ dump_hash_table (struct dump_context *ctx, ...@@ -2761,7 +2761,7 @@ dump_hash_table (struct dump_context *ctx,
static dump_off static dump_off
dump_buffer (struct dump_context *ctx, const struct buffer *in_buffer) dump_buffer (struct dump_context *ctx, const struct buffer *in_buffer)
{ {
#if CHECK_STRUCTS && !defined HASH_buffer_AE2C8CE357 #if CHECK_STRUCTS && !defined HASH_buffer_2CEE653E74
# error "buffer changed. See CHECK_STRUCTS comment." # error "buffer changed. See CHECK_STRUCTS comment."
#endif #endif
struct buffer munged_buffer = *in_buffer; struct buffer munged_buffer = *in_buffer;
...@@ -2873,6 +2873,7 @@ dump_buffer (struct dump_context *ctx, const struct buffer *in_buffer) ...@@ -2873,6 +2873,7 @@ dump_buffer (struct dump_context *ctx, const struct buffer *in_buffer)
DUMP_FIELD_COPY (out, buffer, prevent_redisplay_optimizations_p); DUMP_FIELD_COPY (out, buffer, prevent_redisplay_optimizations_p);
DUMP_FIELD_COPY (out, buffer, clip_changed); DUMP_FIELD_COPY (out, buffer, clip_changed);
DUMP_FIELD_COPY (out, buffer, inhibit_buffer_hooks);
dump_field_lv_rawptr (ctx, out, buffer, &buffer->overlays_before, dump_field_lv_rawptr (ctx, out, buffer, &buffer->overlays_before,
Lisp_Vectorlike, WEIGHT_NORMAL); Lisp_Vectorlike, WEIGHT_NORMAL);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment