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

ruby-changes:64661

From: Kenta <ko1@a...>
Date: Tue, 29 Dec 2020 17:47:02 +0900 (JST)
Subject: [ruby-changes:64661] 13b520d578 (master): [ruby/bigdecimal] Refactor to extract VpCheckException

https://git.ruby-lang.org/ruby.git/commit/?id=13b520d578

From 13b520d578d7e4cbfb904199574fa081458a64f8 Mon Sep 17 00:00:00 2001
From: Kenta Murata <mrkn@m...>
Date: Tue, 29 Dec 2020 16:34:23 +0900
Subject: [ruby/bigdecimal] Refactor to extract VpCheckException

https://github.com/ruby/bigdecimal/commit/6fd171308b

diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c
index a7b099b..f659359 100644
--- a/ext/bigdecimal/bigdecimal.c
+++ b/ext/bigdecimal/bigdecimal.c
@@ -208,21 +208,29 @@ is_kind_of_BigDecimal(VALUE const v) https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.c#L208
     return rb_typeddata_is_kind_of(v, &BigDecimal_data_type);
 }
 
-static VALUE
-ToValue(Real *p)
+static void
+VpCheckException(Real *p, bool always)
 {
     if (VpIsNaN(p)) {
-        VpException(VP_EXCEPTION_NaN, "Computation results to 'NaN'(Not a Number)", 0);
+        VpException(VP_EXCEPTION_NaN, "Computation results to 'NaN'(Not a Number)", always);
     }
     else if (VpIsPosInf(p)) {
-        VpException(VP_EXCEPTION_INFINITY, "Computation results to 'Infinity'", 0);
+        VpException(VP_EXCEPTION_INFINITY, "Computation results to 'Infinity'", always);
     }
     else if (VpIsNegInf(p)) {
-        VpException(VP_EXCEPTION_INFINITY, "Computation results to '-Infinity'", 0);
+        VpException(VP_EXCEPTION_INFINITY, "Computation results to '-Infinity'", always);
     }
+}
+
+static VALUE
+VpCheckGetValue(Real *p)
+{
+    VpCheckException(p, false);
     return p->obj;
 }
 
+#define ToValue(p) VpCheckGetValue(p)
+
 NORETURN(static void cannot_be_coerced_into_BigDecimal(VALUE, VALUE));
 
 static void
@@ -838,15 +846,7 @@ BigDecimal_IsFinite(VALUE self) https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.c#L846
 static void
 BigDecimal_check_num(Real *p)
 {
-    if (VpIsNaN(p)) {
-	VpException(VP_EXCEPTION_NaN, "Computation results to 'NaN'(Not a Number)", 1);
-    }
-    else if (VpIsPosInf(p)) {
-	VpException(VP_EXCEPTION_INFINITY, "Computation results to 'Infinity'", 1);
-    }
-    else if (VpIsNegInf(p)) {
-	VpException(VP_EXCEPTION_INFINITY, "Computation results to '-Infinity'", 1);
-    }
+    VpCheckException(p, true);
 }
 
 static VALUE BigDecimal_split(VALUE self);
-- 
cgit v0.10.2


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

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