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

ruby-changes:63772

From: Nobuyoshi <ko1@a...>
Date: Fri, 27 Nov 2020 21:40:32 +0900 (JST)
Subject: [ruby-changes:63772] 039ba387aa (master): Use opaque struct pointer than void

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

From 039ba387aa3c94600c60bbc2d7a9cf448f843ca5 Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Fri, 27 Nov 2020 21:36:12 +0900
Subject: Use opaque struct pointer than void


diff --git a/include/ruby/random.h b/include/ruby/random.h
index 001f67d..56b2dd4 100644
--- a/include/ruby/random.h
+++ b/include/ruby/random.h
@@ -14,9 +14,10 @@ https://github.com/ruby/ruby/blob/trunk/include/ruby/random.h#L14
 
 RBIMPL_SYMBOL_EXPORT_BEGIN()
 
-typedef struct {
+struct rb_random_struct {
     VALUE seed;
-} rb_random_t;
+};
+typedef struct rb_random_struct rb_random_t;
 
 typedef void rb_random_init_func(rb_random_t *, const uint32_t *, size_t);
 typedef unsigned int rb_random_get_int32_func(rb_random_t *);
diff --git a/ractor.c b/ractor.c
index 58f899e..cb474d0 100644
--- a/ractor.c
+++ b/ractor.c
@@ -1773,11 +1773,11 @@ rb_ractor_stderr_set(VALUE err) https://github.com/ruby/ruby/blob/trunk/ractor.c#L1773
     }
 }
 
-void *
-rb_ractor_default_rand(void *ptr)
+struct rb_random_struct *
+rb_ractor_default_rand(struct rb_random_struct *ptr)
 {
     if (rb_ractor_main_p()) {
-        static void *default_rnd;
+        static struct rb_random_struct *default_rnd;
         if (UNLIKELY(ptr != NULL)) {
             rb_ractor_t *cr = GET_RACTOR();
             cr->default_rand = default_rnd = ptr;
diff --git a/ractor_core.h b/ractor_core.h
index dd66214..6e9a63d 100644
--- a/ractor_core.h
+++ b/ractor_core.h
@@ -36,6 +36,8 @@ struct rb_ractor_waiting_list { https://github.com/ruby/ruby/blob/trunk/ractor_core.h#L36
     rb_ractor_t **ractors;
 };
 
+struct rb_random_struct; // c.f. ruby/random.h
+
 struct rb_ractor_struct {
     // ractor lock
     rb_nativethread_lock_t lock;
@@ -127,7 +129,7 @@ struct rb_ractor_struct { https://github.com/ruby/ruby/blob/trunk/ractor_core.h#L129
     VALUE verbose;
     VALUE debug;
 
-    void *default_rand; // used in random.c
+    struct rb_random_struct *default_rand; // used in random.c
 
     // gc.c rb_objspace_reachable_objects_from
     struct gc_mark_func_data_struct {
diff --git a/random.c b/random.c
index 76183f9..6b26e2b 100644
--- a/random.c
+++ b/random.c
@@ -149,11 +149,11 @@ rand_start(rb_random_mt_t *r) https://github.com/ruby/ruby/blob/trunk/random.c#L149
 static rb_random_mt_t *
 default_rand(void)
 {
-    void *rb_ractor_default_rand(void *); // ractor.c
+    rb_random_t *rb_ractor_default_rand(rb_random_t *); // ractor.c
     rb_random_mt_t *rnd = (rb_random_mt_t *)rb_ractor_default_rand(NULL);
     if (rnd == NULL) {
         rnd = ZALLOC(rb_random_mt_t);
-        rb_ractor_default_rand(rnd);
+        rb_ractor_default_rand(&rnd->base);
     }
     return rnd;
 }
-- 
cgit v0.10.2


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

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