From: Dmitry Antipov Date: Mon, 4 Aug 2014 04:03:31 +0000 (+0400) Subject: * keyboard.c (safe_run_hook_funcall): Avoid consing around X-Git-Tag: emacs-25.0.90~2635^2~679^2~531 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=f045dbe6a0e173eb60383199319b35835254f452;p=emacs.git * keyboard.c (safe_run_hook_funcall): Avoid consing around Vinhibit_quit and prefer internal_condition_case_n to pass args. (safe_run_hooks_error, safe_run_hooks_1): Adjust accordingly. (safe_run_hooks): Remove comment which is not relevant any more. --- diff --git a/src/ChangeLog b/src/ChangeLog index 70f77f8f0cd..ab0ba1b6758 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,10 @@ +2014-08-04 Dmitry Antipov + + * keyboard.c (safe_run_hook_funcall): Avoid consing around + Vinhibit_quit and prefer internal_condition_case_n to pass args. + (safe_run_hooks_error, safe_run_hooks_1): Adjust accordingly. + (safe_run_hooks): Remove comment which is not relevant any more. + 2014-08-03 Paul Eggert Don't let big frames overrun the stack. diff --git a/src/keyboard.c b/src/keyboard.c index 5c7ad95f5ac..dd7e084783d 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -1852,30 +1852,32 @@ adjust_point_for_property (ptrdiff_t last_pt, bool modified) } } -/* Subroutine for safe_run_hooks: run the hook HOOK. */ +/* Subroutine for safe_run_hooks: run the hook, which is ARGS[1]. */ static Lisp_Object -safe_run_hooks_1 (void) +safe_run_hooks_1 (ptrdiff_t nargs, Lisp_Object *args) { - eassert (CONSP (Vinhibit_quit)); - return call0 (XCDR (Vinhibit_quit)); + eassert (nargs == 2); + return call0 (args[1]); } /* Subroutine for safe_run_hooks: handle an error by clearing out the function from the hook. */ static Lisp_Object -safe_run_hooks_error (Lisp_Object error_data) -{ - Lisp_Object hook - = CONSP (Vinhibit_quit) ? XCAR (Vinhibit_quit) : Vinhibit_quit; - Lisp_Object fun = CONSP (Vinhibit_quit) ? XCDR (Vinhibit_quit) : Qnil; - Lisp_Object args[4]; - args[0] = build_string ("Error in %s (%S): %S"); - args[1] = hook; - args[2] = fun; - args[3] = error_data; - Fmessage (4, args); +safe_run_hooks_error (Lisp_Object error, ptrdiff_t nargs, Lisp_Object *args) +{ + Lisp_Object hook, fun, msgargs[4]; + + eassert (nargs == 2); + hook = args[0]; + fun = args[1]; + msgargs[0] = build_string ("Error in %s (%S): %S"); + msgargs[1] = hook; + msgargs[2] = fun; + msgargs[3] = error; + Fmessage (4, msgargs); + if (SYMBOLP (hook)) { Lisp_Object val; @@ -1907,14 +1909,19 @@ safe_run_hooks_error (Lisp_Object error_data) static Lisp_Object safe_run_hook_funcall (ptrdiff_t nargs, Lisp_Object *args) { + Lisp_Object iargs[2]; + struct gcpro gcpro1; + eassert (nargs == 1); - if (CONSP (Vinhibit_quit)) - XSETCDR (Vinhibit_quit, args[0]); - else - Vinhibit_quit = Fcons (Vinhibit_quit, args[0]); + iargs[0] = Vinhibit_quit; + iargs[1] = args[0]; - internal_condition_case (safe_run_hooks_1, Qt, safe_run_hooks_error); - return Qnil; + GCPRO1 (*iargs); + gcpro1.nvars = 2; + + internal_condition_case_n (safe_run_hooks_1, 2, iargs, + Qt, safe_run_hooks_error); + RETURN_UNGCPRO (Qnil); } /* If we get an error while running the hook, cause the hook variable @@ -1924,14 +1931,10 @@ safe_run_hook_funcall (ptrdiff_t nargs, Lisp_Object *args) void safe_run_hooks (Lisp_Object hook) { - /* FIXME: our `internal_condition_case' does not provide any way to pass data - to its body or to its handlers other than via globals such as - dynamically-bound variables ;-) */ ptrdiff_t count = SPECPDL_INDEX (); - specbind (Qinhibit_quit, hook); + specbind (Qinhibit_quit, hook); run_hook_with_args (1, &hook, safe_run_hook_funcall); - unbind_to (count, Qnil); }