aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Mackenzie2022-08-15 12:18:01 +0000
committerAlan Mackenzie2022-08-15 12:18:01 +0000
commit629f980fad0bee97ff63c5f684b472cc71061eea (patch)
tree99bc142ea761903067badeb66a8aa7246425b294
parentd5ee49c25c8f59ab17c40eebdf38a769c2f5588b (diff)
downloademacs-629f980fad0bee97ff63c5f684b472cc71061eea.tar.gz
emacs-629f980fad0bee97ff63c5f684b472cc71061eea.zip
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)
1832static Lisp_Object 1832static Lisp_Object
1833safe_run_hooks_1 (ptrdiff_t nargs, Lisp_Object *args) 1833safe_run_hooks_1 (ptrdiff_t nargs, Lisp_Object *args)
1834{ 1834{
1835 eassert (nargs == 2); 1835 eassert (nargs >= 2 && nargs <= 4);
1836 return call0 (args[1]); 1836 switch (nargs)
1837 {
1838 case 2:
1839 return call0 (args[1]);
1840 case 3:
1841 return call1 (args[1], args[2]);
1842 default:
1843 return call2 (args[1], args[2], args[3]);
1844 }
1837} 1845}
1838 1846
1839/* Subroutine for safe_run_hooks: handle an error by clearing out the function 1847/* 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)
1878static Lisp_Object 1886static Lisp_Object
1879safe_run_hook_funcall (ptrdiff_t nargs, Lisp_Object *args) 1887safe_run_hook_funcall (ptrdiff_t nargs, Lisp_Object *args)
1880{ 1888{
1881 eassert (nargs == 2); 1889 eassert (nargs >= 2 && nargs <= 4);
1882 /* Yes, run_hook_with_args works with args in the other order. */ 1890 /* Yes, run_hook_with_args works with args in the other order. */
1883 internal_condition_case_n (safe_run_hooks_1, 1891 switch (nargs)
1884 2, ((Lisp_Object []) {args[1], args[0]}), 1892 {
1885 Qt, safe_run_hooks_error); 1893 case 2:
1894 internal_condition_case_n (safe_run_hooks_1,
1895 2, ((Lisp_Object []) {args[1], args[0]}),
1896 Qt, safe_run_hooks_error);
1897 break;
1898 case 3:
1899 internal_condition_case_n (safe_run_hooks_1,
1900 3, ((Lisp_Object []) {args[1], args[0], args[2]}),
1901 Qt, safe_run_hooks_error);
1902 break;
1903 default:
1904 internal_condition_case_n (safe_run_hooks_1,
1905 4, ((Lisp_Object [])
1906 {args[1], args[0], args[2], args[3]}),
1907 Qt, safe_run_hooks_error);
1908 break;
1909 }
1886 return Qnil; 1910 return Qnil;
1887} 1911}
1888 1912