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

ruby-changes:72654

From: Yusuke <ko1@a...>
Date: Fri, 22 Jul 2022 23:10:44 +0900 (JST)
Subject: [ruby-changes:72654] e763b1118b (master): Move enum definitions out of struct definition

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

From e763b1118ba1fada81d37da558f9d8e4da99f144 Mon Sep 17 00:00:00 2001
From: Yusuke Endoh <mame@r...>
Date: Fri, 22 Jul 2022 16:49:08 +0900
Subject: Move enum definitions out of struct definition

---
 include/ruby/io.h | 59 ++++++++++++++++++++--------------------
 iseq.h            | 43 ++++++++++++++---------------
 ractor_core.h     | 81 ++++++++++++++++++++++++++++---------------------------
 vm_core.h         | 25 +++++++++--------
 4 files changed, 107 insertions(+), 101 deletions(-)

diff --git a/include/ruby/io.h b/include/ruby/io.h
index b5e33c1cf9..dc4c8becf6 100644
--- a/include/ruby/io.h
+++ b/include/ruby/io.h
@@ -98,6 +98,34 @@ PACKED_STRUCT_UNALIGNED(struct rb_io_buffer_t { https://github.com/ruby/ruby/blob/trunk/include/ruby/io.h#L98
 /** @alias{rb_io_buffer_t} */
 typedef struct rb_io_buffer_t rb_io_buffer_t;
 
+/** Decomposed encoding flags (e.g. `"enc:enc2""`). */
+/*
+ * enc  enc2 read action                      write action
+ * NULL NULL force_encoding(default_external) write the byte sequence of str
+ * e1   NULL force_encoding(e1)               convert str.encoding to e1
+ * e1   e2   convert from e2 to e1            convert str.encoding to e2
+ */
+struct rb_io_enc_t {
+    /** Internal encoding. */
+    rb_encoding *enc;
+    /** External encoding. */
+    rb_encoding *enc2;
+    /**
+     * Flags.
+     *
+     * @see enum ::ruby_econv_flag_type
+     */
+    int ecflags;
+    /**
+     * Flags as Ruby hash.
+     *
+     * @internal
+     *
+     * This is set.  But used from nowhere maybe?
+     */
+    VALUE ecopts;
+};
+
 /** Ruby's IO, metadata and buffers. */
 typedef struct rb_io_t {
 
@@ -141,36 +169,7 @@ typedef struct rb_io_t { https://github.com/ruby/ruby/blob/trunk/include/ruby/io.h#L169
      */
     VALUE tied_io_for_writing;
 
-    /** Decomposed encoding flags (e.g. `"enc:enc2""`). */
-    /*
-     * enc  enc2 read action                      write action
-     * NULL NULL force_encoding(default_external) write the byte sequence of str
-     * e1   NULL force_encoding(e1)               convert str.encoding to e1
-     * e1   e2   convert from e2 to e1            convert str.encoding to e2
-     */
-    struct rb_io_enc_t {
-        /** Internal encoding. */
-        rb_encoding *enc;
-
-        /** External encoding. */
-        rb_encoding *enc2;
-
-        /**
-         * Flags.
-         *
-         * @see enum ::ruby_econv_flag_type
-         */
-        int ecflags;
-
-        /**
-         * Flags as Ruby hash.
-         *
-         * @internal
-         *
-         * This is set.  But used from nowhere maybe?
-         */
-        VALUE ecopts;
-    } encs; /**< Decomposed encoding flags. */
+    struct rb_io_enc_t encs; /**< Decomposed encoding flags. */
 
     /** Encoding converter used when reading from this IO. */
     rb_econv_t *readconv;
diff --git a/iseq.h b/iseq.h
index 63991d95ff..062ed33d86 100644
--- a/iseq.h
+++ b/iseq.h
@@ -241,28 +241,29 @@ struct iseq_insn_info_entry { https://github.com/ruby/ruby/blob/trunk/iseq.h#L241
     rb_event_flag_t events;
 };
 
+/*
+ * iseq type:
+ *   CATCH_TYPE_RESCUE, CATCH_TYPE_ENSURE:
+ *     use iseq as continuation.
+ *
+ *   CATCH_TYPE_BREAK (iter):
+ *     use iseq as key.
+ *
+ *   CATCH_TYPE_BREAK (while), CATCH_TYPE_RETRY,
+ *   CATCH_TYPE_REDO, CATCH_TYPE_NEXT:
+ *     NULL.
+ */
+enum catch_type {
+    CATCH_TYPE_RESCUE = INT2FIX(1),
+    CATCH_TYPE_ENSURE = INT2FIX(2),
+    CATCH_TYPE_RETRY  = INT2FIX(3),
+    CATCH_TYPE_BREAK  = INT2FIX(4),
+    CATCH_TYPE_REDO   = INT2FIX(5),
+    CATCH_TYPE_NEXT   = INT2FIX(6)
+};
+
 struct iseq_catch_table_entry {
-    enum catch_type {
-        CATCH_TYPE_RESCUE = INT2FIX(1),
-        CATCH_TYPE_ENSURE = INT2FIX(2),
-        CATCH_TYPE_RETRY  = INT2FIX(3),
-        CATCH_TYPE_BREAK  = INT2FIX(4),
-        CATCH_TYPE_REDO   = INT2FIX(5),
-        CATCH_TYPE_NEXT   = INT2FIX(6)
-    } type;
-
-    /*
-     * iseq type:
-     *   CATCH_TYPE_RESCUE, CATCH_TYPE_ENSURE:
-     *     use iseq as continuation.
-     *
-     *   CATCH_TYPE_BREAK (iter):
-     *     use iseq as key.
-     *
-     *   CATCH_TYPE_BREAK (while), CATCH_TYPE_RETRY,
-     *   CATCH_TYPE_REDO, CATCH_TYPE_NEXT:
-     *     NULL.
-     */
+    enum catch_type type;
     rb_iseq_t *iseq;
 
     unsigned int start;
diff --git a/ractor_core.h b/ractor_core.h
index dd1b73b331..b35a59e9c5 100644
--- a/ractor_core.h
+++ b/ractor_core.h
@@ -40,6 +40,24 @@ struct rb_ractor_waiting_list { https://github.com/ruby/ruby/blob/trunk/ractor_core.h#L40
     rb_ractor_t **ractors;
 };
 
+enum ractor_wait_status {
+    wait_none      = 0x00,
+    wait_receiving = 0x01,
+    wait_taking    = 0x02,
+    wait_yielding  = 0x04,
+    wait_moving    = 0x08,
+};
+
+enum ractor_wakeup_status {
+    wakeup_none,
+    wakeup_by_send,
+    wakeup_by_yield,
+    wakeup_by_take,
+    wakeup_by_close,
+    wakeup_by_interrupt,
+    wakeup_by_retry,
+};
+
 struct rb_ractor_sync {
     // ractor lock
     rb_nativethread_lock_t lock;
@@ -56,29 +74,34 @@ struct rb_ractor_sync { https://github.com/ruby/ruby/blob/trunk/ractor_core.h#L74
     bool outgoing_port_closed;
 
     struct ractor_wait {
-        enum ractor_wait_status {
-            wait_none      = 0x00,
-            wait_receiving = 0x01,
-            wait_taking    = 0x02,
-            wait_yielding  = 0x04,
-            wait_moving    = 0x08,
-        } status;
-
-        enum ractor_wakeup_status {
-            wakeup_none,
-            wakeup_by_send,
-            wakeup_by_yield,
-            wakeup_by_take,
-            wakeup_by_close,
-            wakeup_by_interrupt,
-            wakeup_by_retry,
-        } wakeup_status;
-
+        enum ractor_wait_status status;
+        enum ractor_wakeup_status wakeup_status;
         struct rb_ractor_basket yielded_basket;
         struct rb_ractor_basket taken_basket;
     } wait;
 };
 
+// created
+//   | ready to run
+// ====================== inserted to vm->ractor
+//   v
+// blocking <---+ all threads are blocking
+//   |          |
+//   v          |
+// running -----+
+//   | all threads are terminated.
+// ====================== removed from vm->ractor
+//   v
+// terminated
+//
+// status is protected by VM lock (global state)
+enum ractor_status {
+    ractor_created,
+    ractor_running,
+    ractor_blocking,
+    ractor_terminated,
+};
+
 struct rb_ractor_struct {
     struct rb_ractor_pub pub;
 
@@ -104,27 +127,7 @@ struct rb_ractor_struct { https://github.com/ruby/ruby/blob/trunk/ractor_core.h#L127
     VALUE name;
     VALUE loc;
 
-    // created
-    //   | ready to run
-    // ====================== inserted to vm->ractor
-    //   v
-    // blocking <---+ all threads are blocking
-    //   |          |
-    //   v          |
-    // running -----+
-    //   | all threads are terminated.
-    // ====================== removed from vm->ractor
-    //   v
-    // terminated
-    //
-    // status is protected by VM lock (global state)
-
-    enum ractor_status {
-        ractor_created,
-        ractor_running,
-        ractor_blocking,
-        ractor_terminated,
-    } status_;
+    enum ractor_status status_;
 
     struct ccan_list_node vmlr_node;
 
diff --git a/vm_core.h b/vm_core.h
index 025dc76798..82a4af0e5c 100644
--- a/vm_core.h
+++ b/vm_core.h
@@ -339,18 +339,21 @@ typedef uintptr_t iseq_bits_t; https://github.com/ruby/ruby/blob/trunk/vm_core.h#L339
 
 #define ISEQ_IS_SIZE(body) (body->ic_size + body->ivc_size + body->ise_size + body->icvarc_size)
 
+/* instruction sequence type */
+enum iseq_type {
+    ISEQ_TYPE_TOP,
+    ISEQ_TYPE_METHOD,
+    ISEQ_TYPE_BLOCK,
+    ISEQ_TYPE_CLASS,
+    ISEQ_TYPE_RESCUE,
+    ISEQ_TYPE_ENSURE,
+    ISEQ_TYPE_EVAL,
+    ISEQ_TYPE_MAIN,
+    ISEQ_TYPE_PLAIN
+};
+
 struct rb_iseq_constant_body {
-    enum iseq_type {
-        ISEQ_TYPE_TOP,
-        ISEQ_TYPE_METHOD,
-        ISEQ_TYPE_BLOCK,
-        ISEQ_TYPE_CLASS,
-        ISEQ_TYPE_RESCUE,
-        ISEQ_TYPE_ENSURE,
-        ISEQ_TYPE_EVAL,
-        ISEQ_TYPE_MAIN,
-        ISEQ_TYPE_PLAIN
-    } type;              /* instruction sequence type */
+    enum iseq_type type;
 
     unsigned int iseq_size;
     VALUE *iseq_encoded; /* encoded iseq (insn addr and operands) */
-- 
cgit v1.2.1


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

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