[前][次][番号順一覧][スレッド一覧]

ruby-changes:65664

From: S.H <ko1@a...>
Date: Sat, 27 Mar 2021 16:39:21 +0900 (JST)
Subject: [ruby-changes:65664] 89fa5b1348 (master): Add rb_exc_exception function

https://git.ruby-lang.org/ruby.git/commit/?id=89fa5b1348

From 89fa5b1348400892eaf37083fc6a6eb70d959f63 Mon Sep 17 00:00:00 2001
From: "S.H" <gamelinks007@g...>
Date: Sat, 27 Mar 2021 16:39:01 +0900
Subject: Add rb_exc_exception function

`rb_exc_raise` and `rb_fatal` func have similar code(in `eval.c`).
I think that better cut out and replace these code like `rb_exc_exception`
function.
---
 eval.c | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)

diff --git a/eval.c b/eval.c
index f6a51d2..9268773 100644
--- a/eval.c
+++ b/eval.c
@@ -701,6 +701,17 @@ rb_longjmp(rb_execution_context_t *ec, int tag, volatile VALUE mesg, VALUE cause https://github.com/ruby/ruby/blob/trunk/eval.c#L701
 
 static VALUE make_exception(int argc, const VALUE *argv, int isstr);
 
+NORETURN(static void rb_exc_exception(VALUE mesg, int tag, VALUE cause));
+
+static void
+rb_exc_exception(VALUE mesg, int tag, VALUE cause)
+{
+    if (!NIL_P(mesg)) {
+	mesg = make_exception(1, &mesg, FALSE);
+    }
+    rb_longjmp(GET_EC(), tag, mesg, cause);
+}
+
 /*!
  * Raises an exception in the current thread.
  * \param[in] mesg an Exception class or an \c Exception object.
@@ -711,10 +722,7 @@ static VALUE make_exception(int argc, const VALUE *argv, int isstr); https://github.com/ruby/ruby/blob/trunk/eval.c#L722
 void
 rb_exc_raise(VALUE mesg)
 {
-    if (!NIL_P(mesg)) {
-	mesg = make_exception(1, &mesg, FALSE);
-    }
-    rb_longjmp(GET_EC(), TAG_RAISE, mesg, Qundef);
+    rb_exc_exception(mesg, TAG_RAISE, Qundef);
 }
 
 /*!
@@ -727,10 +735,7 @@ rb_exc_raise(VALUE mesg) https://github.com/ruby/ruby/blob/trunk/eval.c#L735
 void
 rb_exc_fatal(VALUE mesg)
 {
-    if (!NIL_P(mesg)) {
-	mesg = make_exception(1, &mesg, FALSE);
-    }
-    rb_longjmp(GET_EC(), TAG_FATAL, mesg, Qnil);
+    rb_exc_exception(mesg, TAG_FATAL, Qnil);
 }
 
 /*!
-- 
cgit v1.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]