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

ruby-changes:59720

From: Kenta <ko1@a...>
Date: Fri, 17 Jan 2020 10:07:20 +0900 (JST)
Subject: [ruby-changes:59720] 07ce51c5aa (master): internal/rational.h: insert assertions in RATIONAL_SET_{NUM, DEN}

https://git.ruby-lang.org/ruby.git/commit/?id=07ce51c5aa

From 07ce51c5aaf25a5a184a35074a40138256a0c099 Mon Sep 17 00:00:00 2001
From: Kenta Murata <mrkn@m...>
Date: Fri, 17 Jan 2020 09:55:50 +0900
Subject: internal/rational.h: insert assertions in RATIONAL_SET_{NUM,DEN}


diff --git a/internal/numeric.h b/internal/numeric.h
index 609b0c5..a5875fb 100644
--- a/internal/numeric.h
+++ b/internal/numeric.h
@@ -89,6 +89,7 @@ static inline double rb_float_flonum_value(VALUE v); https://github.com/ruby/ruby/blob/trunk/internal/numeric.h#L89
 static inline double rb_float_noflonum_value(VALUE v);
 static inline double rb_float_value_inline(VALUE v);
 static inline VALUE rb_float_new_inline(double d);
+static inline bool INT_POSITIVE_P(VALUE num);
 static inline bool INT_NEGATIVE_P(VALUE num);
 static inline bool FLOAT_ZERO_P(VALUE num);
 #define rb_float_value rb_float_value_inline
@@ -109,6 +110,17 @@ VALUE rb_fix_aref(VALUE fix, VALUE idx); https://github.com/ruby/ruby/blob/trunk/internal/numeric.h#L110
 MJIT_SYMBOL_EXPORT_END
 
 static inline bool
+INT_POSITIVE_P(VALUE num)
+{
+    if (FIXNUM_P(num)) {
+        return FIXNUM_POSITIVE_P(num);
+    }
+    else {
+        return BIGNUM_POSITIVE_P(num);
+    }
+}
+
+static inline bool
 INT_NEGATIVE_P(VALUE num)
 {
     if (FIXNUM_P(num)) {
diff --git a/internal/rational.h b/internal/rational.h
index 028fc4c..d514050 100644
--- a/internal/rational.h
+++ b/internal/rational.h
@@ -12,6 +12,8 @@ https://github.com/ruby/ruby/blob/trunk/internal/rational.h#L12
 #include "ruby/config.h"        /* for HAVE_LIBGMP */
 #include "ruby/ruby.h"          /* for struct RBasic */
 #include "internal/gc.h"        /* for RB_OBJ_WRITE */
+#include "internal/numeric.h"   /* for INT_POSITIVE_P */
+#include "ruby_assert.h"        /* for assert */
 
 struct RRational {
     struct RBasic basic;
@@ -51,12 +53,15 @@ RUBY_SYMBOL_EXPORT_END https://github.com/ruby/ruby/blob/trunk/internal/rational.h#L53
 static inline void
 RATIONAL_SET_NUM(VALUE r, VALUE n)
 {
+    assert(RB_INTEGER_TYPE_P(n));
     RB_OBJ_WRITE(r, &RRATIONAL(r)->num, n);
 }
 
 static inline void
 RATIONAL_SET_DEN(VALUE r, VALUE d)
 {
+    assert(RB_INTEGER_TYPE_P(d));
+    assert(INT_POSITIVE_P(d));
     RB_OBJ_WRITE(r, &RRATIONAL(r)->den, d);
 }
 
diff --git a/rational.c b/rational.c
index 0f98416..f483c6d 100644
--- a/rational.c
+++ b/rational.c
@@ -37,7 +37,6 @@ https://github.com/ruby/ruby/blob/trunk/rational.c#L37
 
 #define GMP_GCD_DIGITS 1
 
-#define INT_POSITIVE_P(x) (FIXNUM_P(x) ? FIXNUM_POSITIVE_P(x) : BIGNUM_POSITIVE_P(x))
 #define INT_ZERO_P(x) (FIXNUM_P(x) ? FIXNUM_ZERO_P(x) : rb_bigzero_p(x))
 
 VALUE rb_cRational;
-- 
cgit v0.10.2


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

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