From: Alan Mackenzie Date: Mon, 15 Aug 2022 12:18:01 +0000 (+0000) Subject: Enhance safe_run_hooks_1 and safe_run_hook_funcall to handle more arguments X-Git-Tag: emacs-29.0.90~1447^2~139 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=629f980fad0bee97ff63c5f684b472cc71061eea;p=emacs.git Enhance safe_run_hooks_1 and safe_run_hook_funcall to handle more arguments This fixes bug #57179. * src/keyboard.c (safe_run_hooks_1, safe_run_hook_funcall): Enhance these functions so that nargs == 3 or 4 is handled as well as nargs == 2. This allows them to be used to call hooks with 1 or 2 arguments. --- diff --git a/src/keyboard.c b/src/keyboard.c index 8a2b7d58c4b..1d7125a0a3e 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -1832,8 +1832,16 @@ adjust_point_for_property (ptrdiff_t last_pt, bool modified) static Lisp_Object safe_run_hooks_1 (ptrdiff_t nargs, Lisp_Object *args) { - eassert (nargs == 2); - return call0 (args[1]); + eassert (nargs >= 2 && nargs <= 4); + switch (nargs) + { + case 2: + return call0 (args[1]); + case 3: + return call1 (args[1], args[2]); + default: + return call2 (args[1], args[2], args[3]); + } } /* Subroutine for safe_run_hooks: handle an error by clearing out the function @@ -1878,11 +1886,27 @@ safe_run_hooks_error (Lisp_Object error, ptrdiff_t nargs, Lisp_Object *args) static Lisp_Object safe_run_hook_funcall (ptrdiff_t nargs, Lisp_Object *args) { - eassert (nargs == 2); + eassert (nargs >= 2 && nargs <= 4); /* Yes, run_hook_with_args works with args in the other order. */ - internal_condition_case_n (safe_run_hooks_1, - 2, ((Lisp_Object []) {args[1], args[0]}), - Qt, safe_run_hooks_error); + switch (nargs) + { + case 2: + internal_condition_case_n (safe_run_hooks_1, + 2, ((Lisp_Object []) {args[1], args[0]}), + Qt, safe_run_hooks_error); + break; + case 3: + internal_condition_case_n (safe_run_hooks_1, + 3, ((Lisp_Object []) {args[1], args[0], args[2]}), + Qt, safe_run_hooks_error); + break; + default: + internal_condition_case_n (safe_run_hooks_1, + 4, ((Lisp_Object []) + {args[1], args[0], args[2], args[3]}), + Qt, safe_run_hooks_error); + break; + } return Qnil; }