summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Mackenzie <acm@muc.de>2022-08-15 12:18:01 +0000
committerAlan Mackenzie <acm@muc.de>2022-08-15 12:18:01 +0000
commit629f980fad0bee97ff63c5f684b472cc71061eea (patch)
tree99bc142ea761903067badeb66a8aa7246425b294
parentd5ee49c25c8f59ab17c40eebdf38a769c2f5588b (diff)
downloademacs-629f980fad0bee97ff63c5f684b472cc71061eea.tar.gz
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.
-rw-r--r--src/keyboard.c36
1 files changed, 30 insertions, 6 deletions
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;
}