unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Re: Simplify internal_catch()
@ 2016-12-28  6:33 Chris Gregory
  2016-12-28  8:48 ` Andreas Schwab
  2016-12-28 16:45 ` Stefan Monnier
  0 siblings, 2 replies; 9+ messages in thread
From: Chris Gregory @ 2016-12-28  6:33 UTC (permalink / raw)


Here is the updated patch.  I replaced the if statement with a ternary
operator.

> Why place the declaration of `val` between the two?
I'm unsure as to the style desired for Emacs source code.  I've seen
both used in it.  I'll use the declaration initialization in the future
as I also prefer that.
-- 
Chris Gregory

diff --git a/src/eval.c b/src/eval.c
index e50e26a..54c09df 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -1084,22 +1084,16 @@ internal_catch (Lisp_Object tag,
 {
   /* This structure is made part of the chain `catchlist'.  */
   struct handler *c = push_handler (tag, CATCHER);
-
-  /* Call FUNC.  */
-  if (! sys_setjmp (c->jmp))
-    {
-      Lisp_Object val = func (arg);
-      clobbered_eassert (handlerlist == c);
-      handlerlist = handlerlist->next;
-      return val;
-    }
-  else
-    { /* Throw works by a longjmp that comes right here.  */
-      Lisp_Object val = handlerlist->val;
-      clobbered_eassert (handlerlist == c);
-      handlerlist = handlerlist->next;
-      return val;
-    }
+  Lisp_Object val = (sys_setjmp (c->jmp)
+                     /* Call FUNC */
+                     ? func (arg)
+                     /* Throw works by a longjmp that comes here,
+                        setting this side */
+                     : handlerlist->val);
+
+  clobbered_eassert (handlerlist == c);
+  handlerlist = handlerlist->next;
+  return val;
 }
 
 /* Unwind the specbind, catch, and handler stacks back to CATCH, and



^ permalink raw reply related	[flat|nested] 9+ messages in thread
* Re: [no subject]
@ 2016-12-28  7:34 Chris Gregory
  2016-12-28  7:42 ` Simplify internal_catch () Paul Eggert
  0 siblings, 1 reply; 9+ messages in thread
From: Chris Gregory @ 2016-12-28  7:34 UTC (permalink / raw)


Oops meant to reply to `Simplify internal_catch()'.

Anyway here is another patch with the same thing.
-- 
Chris Gregory

diff --git a/src/eval.c b/src/eval.c
index e50e26a..edb41b6 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -1337,20 +1337,12 @@ internal_condition_case_1 (Lisp_Object (*bfun) (Lisp_Object), Lisp_Object arg,
 			   Lisp_Object (*hfun) (Lisp_Object))
 {
   struct handler *c = push_handler (handlers, CONDITION_CASE);
-  if (sys_setjmp (c->jmp))
-    {
-      Lisp_Object val = handlerlist->val;
-      clobbered_eassert (handlerlist == c);
-      handlerlist = handlerlist->next;
-      return hfun (val);
-    }
-  else
-    {
-      Lisp_Object val = bfun (arg);
-      clobbered_eassert (handlerlist == c);
-      handlerlist = handlerlist->next;
-      return val;
-    }
+  bool is_returning = sys_setjmp (c->jmp);
+  Lisp_Object val = is_returning ? handlerlist->val : bfun (arg);
+
+  clobbered_eassert (handlerlist == c);
+  handlerlist = handlerlist->next;
+  return is_returning ? hfun (val) : val;
 }
 
 /* Like internal_condition_case_1 but call BFUN with ARG1 and ARG2 as



^ permalink raw reply related	[flat|nested] 9+ messages in thread
* Simplify internal_catch()
@ 2016-12-28  1:54 Chris Gregory
  2016-12-28  2:50 ` Stefan Monnier
  0 siblings, 1 reply; 9+ messages in thread
From: Chris Gregory @ 2016-12-28  1:54 UTC (permalink / raw)
  To: emacs-devel

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

This patch simplifies the structure of the internal_catch function.
If my change to prog_ignore is accepted (shown below), use the diff_with.  Otherwise
use diff_without.

THIS IS NOT THE DIFF FOR THIS PATCH!
diff --git a/src/eval.c b/src/eval.c
index e50e26a..abd4028 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -458,7 +458,11 @@ usage: (progn BODY...)  */)
 void
 prog_ignore (Lisp_Object body)
 {
-  Fprogn (body);
+  while (CONSP (body))
+    {
+      eval_sub (XCAR (body));
+      body = XCDR (body);
+    }
 }

THE DIFF FOR THIS PATCH is in the attachments.

-- 
Chris Gregory


[-- Attachment #2: diff_with --]
[-- Type: application/octet-stream, Size: 1146 bytes --]

diff --git a/src/eval.c b/src/eval.c
index abd4028..53e1f59 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -1087,23 +1087,20 @@ internal_catch (Lisp_Object tag,
 		Lisp_Object (*func) (Lisp_Object), Lisp_Object arg)
 {
   /* This structure is made part of the chain `catchlist'.  */
-  struct handler *c = push_handler (tag, CATCHER);
+  struct handler *c;
+  Lisp_Object val;
+
+  c = push_handler (tag, CATCHER);
 
-  /* Call FUNC.  */
   if (! sys_setjmp (c->jmp))
-    {
-      Lisp_Object val = func (arg);
-      clobbered_eassert (handlerlist == c);
-      handlerlist = handlerlist->next;
-      return val;
-    }
+    /* Call FUNC.  */
+    val = func (arg);
   else
-    { /* Throw works by a longjmp that comes right here.  */
-      Lisp_Object val = handlerlist->val;
-      clobbered_eassert (handlerlist == c);
-      handlerlist = handlerlist->next;
-      return val;
-    }
+    /* Throw works by a longjmp that comes right here.  */
+    val = handlerlist->val;
+  clobbered_eassert (handlerlist == c);
+  handlerlist = handlerlist->next;
+  return val;
 }
 
 /* Unwind the specbind, catch, and handler stacks back to CATCH, and

[-- Attachment #3: diff_without --]
[-- Type: application/octet-stream, Size: 1146 bytes --]

diff --git a/src/eval.c b/src/eval.c
index e50e26a..29a479a 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -1083,23 +1083,20 @@ internal_catch (Lisp_Object tag,
 		Lisp_Object (*func) (Lisp_Object), Lisp_Object arg)
 {
   /* This structure is made part of the chain `catchlist'.  */
-  struct handler *c = push_handler (tag, CATCHER);
+  struct handler *c;
+  Lisp_Object val;
+
+  c = push_handler (tag, CATCHER);
 
-  /* Call FUNC.  */
   if (! sys_setjmp (c->jmp))
-    {
-      Lisp_Object val = func (arg);
-      clobbered_eassert (handlerlist == c);
-      handlerlist = handlerlist->next;
-      return val;
-    }
+    /* Call FUNC.  */
+    val = func (arg);
   else
-    { /* Throw works by a longjmp that comes right here.  */
-      Lisp_Object val = handlerlist->val;
-      clobbered_eassert (handlerlist == c);
-      handlerlist = handlerlist->next;
-      return val;
-    }
+    /* Throw works by a longjmp that comes right here.  */
+    val = handlerlist->val;
+  clobbered_eassert (handlerlist == c);
+  handlerlist = handlerlist->next;
+  return val;
 }
 
 /* Unwind the specbind, catch, and handler stacks back to CATCH, and

^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2016-12-31 21:29 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-12-28  6:33 Simplify internal_catch() Chris Gregory
2016-12-28  8:48 ` Andreas Schwab
2016-12-28 16:45 ` Stefan Monnier
2016-12-28 19:24   ` Paul Eggert
2016-12-28 19:28     ` Stefan Monnier
2016-12-31 21:29       ` Paul Eggert
  -- strict thread matches above, loose matches on Subject: below --
2016-12-28  7:34 [no subject] Chris Gregory
2016-12-28  7:42 ` Simplify internal_catch () Paul Eggert
2016-12-28  1:54 Simplify internal_catch() Chris Gregory
2016-12-28  2:50 ` Stefan Monnier

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).