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

ruby-changes:68138

From: Nobuyoshi <ko1@a...>
Date: Mon, 27 Sep 2021 14:48:16 +0900 (JST)
Subject: [ruby-changes:68138] f7ffe9dbde (master): Introduce `RBIMPL_NONNULL_ARG` macro

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

From f7ffe9dbdeb2bebb4c9155fc391f0bab198bfb51 Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Mon, 27 Sep 2021 14:47:52 +0900
Subject: Introduce `RBIMPL_NONNULL_ARG` macro

Runtime assertion for the argument declared as non-null.
This macro does nothing if `RBIMPL_ATTR_NONNULL` is effective,
otherwise asserts that the argument is non-null.
---
 enumerator.c                         | 8 +++-----
 gc.c                                 | 9 +--------
 include/ruby/internal/attr/nonnull.h | 2 ++
 3 files changed, 6 insertions(+), 13 deletions(-)

diff --git a/enumerator.c b/enumerator.c
index f359ab7..be469ee 100644
--- a/enumerator.c
+++ b/enumerator.c
@@ -3446,11 +3446,9 @@ rb_arithmetic_sequence_extract(VALUE obj, rb_arithmetic_sequence_components_t *c https://github.com/ruby/ruby/blob/trunk/enumerator.c#L3446
 VALUE
 rb_arithmetic_sequence_beg_len_step(VALUE obj, long *begp, long *lenp, long *stepp, long len, int err)
 {
-#if !RBIMPL_HAS_ATTRIBUTE(nonnull)
-    RUBY_ASSERT(begp != NULL);
-    RUBY_ASSERT(lenp != NULL);
-    RUBY_ASSERT(stepp != NULL);
-#endif
+    RBIMPL_NONNULL_ARG(begp);
+    RBIMPL_NONNULL_ARG(lenp);
+    RBIMPL_NONNULL_ARG(stepp);
 
     rb_arithmetic_sequence_components_t aseq;
     if (!rb_arithmetic_sequence_extract(obj, &aseq)) {
diff --git a/gc.c b/gc.c
index 40c035f..cdee81d 100644
--- a/gc.c
+++ b/gc.c
@@ -2767,21 +2767,14 @@ rb_data_object_zalloc(VALUE klass, size_t size, RUBY_DATA_FUNC dmark, RUBY_DATA_ https://github.com/ruby/ruby/blob/trunk/gc.c#L2767
     return obj;
 }
 
-COMPILER_WARNING_PUSH
-#if __has_warning("-Wnonnull-compare") || GCC_VERSION_SINCE(6, 1, 0)
-COMPILER_WARNING_IGNORED(-Wnonnull-compare)
-#endif
-
 VALUE
 rb_data_typed_object_wrap(VALUE klass, void *datap, const rb_data_type_t *type)
 {
-    RUBY_ASSERT_ALWAYS(type);
+    RBIMPL_NONNULL_ARG(type);
     if (klass) rb_data_object_check(klass);
     return newobj_of(klass, T_DATA, (VALUE)type, (VALUE)1, (VALUE)datap, type->flags & RUBY_FL_WB_PROTECTED, sizeof(RVALUE));
 }
 
-COMPILER_WARNING_POP
-
 VALUE
 rb_data_typed_object_zalloc(VALUE klass, size_t size, const rb_data_type_t *type)
 {
diff --git a/include/ruby/internal/attr/nonnull.h b/include/ruby/internal/attr/nonnull.h
index 874f423..778d5be 100644
--- a/include/ruby/internal/attr/nonnull.h
+++ b/include/ruby/internal/attr/nonnull.h
@@ -25,8 +25,10 @@ https://github.com/ruby/ruby/blob/trunk/include/ruby/internal/attr/nonnull.h#L25
 /** Wraps (or simulates) `__attribute__((nonnull))` */
 #if RBIMPL_HAS_ATTRIBUTE(nonnull)
 # define RBIMPL_ATTR_NONNULL(list) __attribute__((__nonnull__ list))
+# define RBIMPL_NONNULL_ARG(arg) RBIMPL_ASSERT_NOTHING
 #else
 # define RBIMPL_ATTR_NONNULL(list) /* void */
+# define RBIMPL_NONNULL_ARG(arg) RUBY_ASSERT(arg)
 #endif
 
 #endif /* RBIMPL_ATTR_NONNULL_H */
-- 
cgit v1.1


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

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