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

ruby-changes:63284

From: =E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3 <ko1@a...>
Date: Tue, 6 Oct 2020 14:20:29 +0900 (JST)
Subject: [ruby-changes:63284] 78e27ced97 (master): rb_rand_if: convert into an inline function

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

From 78e27ced9764e1c9c82ff71467f4851e8c6bb46b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3?=
 <shyouhei@r...>
Date: Tue, 6 Oct 2020 11:07:02 +0900
Subject: rb_rand_if: convert into an inline function

This adds more room for assertions.

diff --git a/include/ruby/random.h b/include/ruby/random.h
index 5b024b0..fb4bbf3 100644
--- a/include/ruby/random.h
+++ b/include/ruby/random.h
@@ -31,9 +31,6 @@ typedef struct { https://github.com/ruby/ruby/blob/trunk/include/ruby/random.h#L31
     rb_random_get_real_func *get_real;
 } rb_random_interface_t;
 
-#define rb_rand_if(obj) \
-    ((const rb_random_interface_t *)RTYPEDDATA_TYPE(obj)->data)
-
 #define RB_RANDOM_INTERFACE_DECLARE(prefix) \
     static void prefix##_init(rb_random_t *, const uint32_t *, size_t); \
     static unsigned int prefix##_get_int32(rb_random_t *); \
@@ -70,4 +67,16 @@ void rb_rand_bytes_int32(rb_random_get_int32_func *, rb_random_t *, void *, size https://github.com/ruby/ruby/blob/trunk/include/ruby/random.h#L67
 RUBY_EXTERN const rb_data_type_t rb_random_data_type;
 
 RBIMPL_SYMBOL_EXPORT_END()
+
+RBIMPL_ATTR_PURE_UNLESS_DEBUG()
+/* :TODO: can this function be __attribute__((returns_nonnull)) or not? */
+static inline const rb_random_interface_t *
+rb_rand_if(VALUE obj)
+{
+    RBIMPL_ASSERT_OR_ASSUME(RTYPEDDATA_P(obj));
+    const struct rb_data_type_struct *t = RTYPEDDATA_TYPE(obj);
+    const void *ret = t->data;
+    return RBIMPL_CAST((const rb_random_interface_t *)ret);
+}
+
 #endif /* RUBY_RANDOM_H */
-- 
cgit v0.10.2


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

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