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

ruby-changes:56600

From: Yusuke <ko1@a...>
Date: Fri, 19 Jul 2019 23:53:21 +0900 (JST)
Subject: [ruby-changes:56600] Yusuke Endoh: 0a16ff9f83 (master): array.c: use assert in macro instead of in a function

https://git.ruby-lang.org/ruby.git/commit/?id=0a16ff9f83

From 0a16ff9f8366fd0d751191bd9c6eaa47f0ae33c8 Mon Sep 17 00:00:00 2001
From: Yusuke Endoh <mame@r...>
Date: Fri, 19 Jul 2019 23:50:30 +0900
Subject: array.c: use assert in macro instead of in a function

The old code lost information of lineno.  Now, an assertion error will
output a correct lineno (but now gcc 8 requires 250 MB, unfortunately).

diff --git a/array.c b/array.c
index a4652e6..0c5ea0a 100644
--- a/array.c
+++ b/array.c
@@ -34,19 +34,19 @@ VALUE rb_cArray; https://github.com/ruby/ruby/blob/trunk/array.c#L34
 #define ARY_MAX_SIZE (LONG_MAX / (int)sizeof(VALUE))
 #define SMALL_ARRAY_LEN 16
 
-static void
-assert_T_ARRAY(VALUE ary)
+static int
+should_be_T_ARRAY(VALUE ary)
 {
-    assert(RB_TYPE_P(ary, T_ARRAY));
+    return RB_TYPE_P(ary, T_ARRAY);
 }
 
 #define ARY_SHARED_P(ary) \
-  (assert_T_ARRAY((VALUE)(ary)), \
+  (assert(should_be_T_ARRAY((VALUE)(ary))), \
    assert(!FL_TEST((ary), ELTS_SHARED) || !FL_TEST((ary), RARRAY_EMBED_FLAG)), \
    FL_TEST_RAW((ary),ELTS_SHARED)!=0)
 
 #define ARY_EMBED_P(ary) \
-  (assert_T_ARRAY((VALUE)(ary)), \
+  (assert(should_be_T_ARRAY((VALUE)(ary))), \
    assert(!FL_TEST((ary), ELTS_SHARED) || !FL_TEST((ary), RARRAY_EMBED_FLAG)), \
    FL_TEST_RAW((ary), RARRAY_EMBED_FLAG) != 0)
 
@@ -62,7 +62,7 @@ assert_T_ARRAY(VALUE ary) https://github.com/ruby/ruby/blob/trunk/array.c#L62
 	 (RARRAY_EMBED_LEN_MASK >> RARRAY_EMBED_LEN_SHIFT)))
 #define ARY_HEAP_SIZE(a) (assert(!ARY_EMBED_P(a)), assert(ARY_OWNS_HEAP_P(a)), ARY_CAPA(a) * sizeof(VALUE))
 
-#define ARY_OWNS_HEAP_P(a) (assert_T_ARRAY((VALUE)(a)), \
+#define ARY_OWNS_HEAP_P(a) (assert(should_be_T_ARRAY((VALUE)(a))), \
                             !FL_TEST_RAW((a), ELTS_SHARED|RARRAY_EMBED_FLAG))
 
 #define FL_SET_EMBED(a) do { \
@@ -138,7 +138,7 @@ assert_T_ARRAY(VALUE ary) https://github.com/ruby/ruby/blob/trunk/array.c#L138
     RB_OBJ_WRITE(_ary_, &RARRAY(_ary_)->as.heap.aux.shared_root, _value_); \
 } while (0)
 #define RARRAY_SHARED_ROOT_FLAG FL_USER5
-#define ARY_SHARED_ROOT_P(ary) (assert_T_ARRAY((VALUE)(ary)), \
+#define ARY_SHARED_ROOT_P(ary) (assert(should_be_T_ARRAY((VALUE)(ary))), \
                                 FL_TEST_RAW((ary), RARRAY_SHARED_ROOT_FLAG))
 #define ARY_SHARED_ROOT_REFCNT(ary) \
     (assert(ARY_SHARED_ROOT_P(ary)), RARRAY(ary)->as.heap.aux.capa)
-- 
cgit v0.10.2


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

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