unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Use  internal_condition_case_n in safe_run_hooks?
@ 2014-08-01 10:49 Dmitry Antipov
  0 siblings, 0 replies; only message in thread
From: Dmitry Antipov @ 2014-08-01 10:49 UTC (permalink / raw)
  To: Emacs development discussions

[-- Attachment #1: Type: text/plain, Size: 96 bytes --]

Is that correct?  If yes, this looks a bit cleaner than consing around Vinhibit_quit...

Dmitry

[-- Attachment #2: safe_run_hooks.patch --]
[-- Type: text/x-patch, Size: 2443 bytes --]

=== modified file 'src/keyboard.c'
--- src/keyboard.c	2014-07-27 13:21:30 +0000
+++ src/keyboard.c	2014-08-01 10:44:22 +0000
@@ -1852,30 +1852,32 @@
     }
 }
 
-/* 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)
+safe_run_hooks_error (Lisp_Object error, ptrdiff_t nargs, Lisp_Object *args)
 {
-  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);
+  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 @@
 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]);
-
-  internal_condition_case (safe_run_hooks_1, Qt, safe_run_hooks_error);
-  return Qnil;
+  iargs[0] = Vinhibit_quit;
+  iargs[1] = args[0];
+
+  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,9 +1931,6 @@
 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);
 


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2014-08-01 10:49 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-01 10:49 Use internal_condition_case_n in safe_run_hooks? Dmitry Antipov

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).