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

ruby-changes:62644

From: =E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3 <ko1@a...>
Date: Wed, 19 Aug 2020 14:31:16 +0900 (JST)
Subject: [ruby-changes:62644] 6649677eb9 (master): ROBJECT_IV_INDEX_TBL: convert into an inline function

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

From 6649677eb93a101a5411a942ca1b84b541262537 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: Mon, 17 Aug 2020 13:51:23 +0900
Subject: ROBJECT_IV_INDEX_TBL: convert into an inline function

Former ROBJECT_IV_INDEX_TBL macro included RCLASS_IV_INDEX_TBL, which is
not disclosed to extension libraies.  The macro was kind of broken.  Why
not just deprecate it, and convert the internal use into an inline
function.

diff --git a/include/ruby/internal/core/robject.h b/include/ruby/internal/core/robject.h
index 60c31fd..e6e946c 100644
--- a/include/ruby/internal/core/robject.h
+++ b/include/ruby/internal/core/robject.h
@@ -27,6 +27,7 @@ https://github.com/ruby/ruby/blob/trunk/include/ruby/internal/core/robject.h#L27
 #endif
 
 #include "ruby/internal/attr/artificial.h"
+#include "ruby/internal/attr/deprecated.h"
 #include "ruby/internal/attr/pure.h"
 #include "ruby/internal/cast.h"
 #include "ruby/internal/fl_type.h"
@@ -39,24 +40,31 @@ https://github.com/ruby/ruby/blob/trunk/include/ruby/internal/core/robject.h#L40
 /** @cond INTERNAL_MACRO */
 #define ROBJECT_NUMIV         ROBJECT_NUMIV
 #define ROBJECT_IVPTR         ROBJECT_IVPTR
+#define ROBJECT_IV_INDEX_TBL  ROBJECT_IV_INDEX_TBL
 /** @endcond */
 
 enum ruby_robject_flags { ROBJECT_EMBED = RUBY_FL_USER1 };
 
 enum ruby_robject_consts { ROBJECT_EMBED_LEN_MAX = RBIMPL_EMBED_LEN_MAX_OF(VALUE) };
 
+struct st_table;
+
 struct RObject {
     struct RBasic basic;
     union {
         struct {
             uint32_t numiv;
             VALUE *ivptr;
-            void *iv_index_tbl; /* shortcut for RCLASS_IV_INDEX_TBL(rb_obj_class(obj)) */
+            struct st_table *iv_index_tbl; /* shortcut for RCLASS_IV_INDEX_TBL(rb_obj_class(obj)) */
         } heap;
         VALUE ary[ROBJECT_EMBED_LEN_MAX];
     } as;
 };
 
+RBIMPL_SYMBOL_EXPORT_BEGIN()
+struct st_table *rb_obj_iv_index_tbl(const struct RObject *obj);
+RBIMPL_SYMBOL_EXPORT_END()
+
 RBIMPL_ATTR_PURE_UNLESS_DEBUG()
 RBIMPL_ATTR_ARTIFICIAL()
 static inline uint32_t
@@ -89,9 +97,17 @@ ROBJECT_IVPTR(VALUE obj) https://github.com/ruby/ruby/blob/trunk/include/ruby/internal/core/robject.h#L97
     }
 }
 
-#define ROBJECT_IV_INDEX_TBL(o) \
-    ((RBASIC(o)->flags & ROBJECT_EMBED) ? \
-     RCLASS_IV_INDEX_TBL(rb_obj_class(o)) : \
-     ROBJECT(o)->as.heap.iv_index_tbl)
+RBIMPL_ATTR_DEPRECATED(("Whoever have used it before?  Just tell us so.  We can stop deleting it."))
+RBIMPL_ATTR_PURE_UNLESS_DEBUG()
+RBIMPL_ATTR_ARTIFICIAL()
+static inline struct st_table *
+ROBJECT_IV_INDEX_TBL(VALUE obj)
+{
+    RBIMPL_ASSERT_TYPE(obj, RUBY_T_OBJECT);
+
+    struct RObject *const ptr = ROBJECT(obj);
+
+    return rb_obj_iv_index_tbl(ptr);
+}
 
 #endif /* RBIMPL_ROBJECT_H */
diff --git a/internal.h b/internal.h
index 303029a..9d4478b 100644
--- a/internal.h
+++ b/internal.h
@@ -47,6 +47,9 @@ https://github.com/ruby/ruby/blob/trunk/internal.h#L47
 #undef RHASH_IFNONE
 #undef RHASH_SIZE
 
+/* internal/object.h */
+#undef ROBJECT_IV_INDEX_TBL
+
 /* internal/struct.h */
 #undef RSTRUCT_LEN
 #undef RSTRUCT_PTR
diff --git a/internal/object.h b/internal/object.h
index d34f498..aa82012 100644
--- a/internal/object.h
+++ b/internal/object.h
@@ -10,6 +10,11 @@ https://github.com/ruby/ruby/blob/trunk/internal/object.h#L10
  * @brief      Internal header for Object.
  */
 #include "ruby/ruby.h"          /* for VALUE */
+#include "internal/class.h"     /* for RCLASS_IV_INDEX_TBL */
+
+#ifdef ROBJECT_IV_INDEX_TBL
+# undef ROBJECT_IV_INDEX_TBL
+#endif
 
 /* object.c */
 VALUE rb_class_search_ancestor(VALUE klass, VALUE super);
@@ -22,6 +27,7 @@ int rb_bool_expected(VALUE, const char *); https://github.com/ruby/ruby/blob/trunk/internal/object.h#L27
 static inline void RBASIC_CLEAR_CLASS(VALUE obj);
 static inline void RBASIC_SET_CLASS_RAW(VALUE obj, VALUE klass);
 static inline void RBASIC_SET_CLASS(VALUE obj, VALUE klass);
+static inline struct st_table *ROBJECT_IV_INDEX_TBL_inline(VALUE obj);
 
 RUBY_SYMBOL_EXPORT_BEGIN
 /* object.c (export) */
@@ -58,4 +64,20 @@ RBASIC_SET_CLASS(VALUE obj, VALUE klass) https://github.com/ruby/ruby/blob/trunk/internal/object.h#L64
     RBASIC_SET_CLASS_RAW(obj, klass);
     RB_OBJ_WRITTEN(obj, oldv, klass);
 }
+
+RBIMPL_ATTR_PURE()
+static inline struct st_table *
+ROBJECT_IV_INDEX_TBL_inline(VALUE obj)
+{
+    if (RB_FL_ANY_RAW(obj, ROBJECT_EMBED)) {
+        VALUE klass = rb_obj_class(obj);
+        return RCLASS_IV_INDEX_TBL(klass);
+    }
+    else {
+        const struct RObject *const ptr = ROBJECT(obj);
+        return ptr->as.heap.iv_index_tbl;
+    }
+}
+#define ROBJECT_IV_INDEX_TBL ROBJECT_IV_INDEX_TBL_inline
+
 #endif /* INTERNAL_OBJECT_H */
diff --git a/object.c b/object.c
index 9fb1481..08fec85 100644
--- a/object.c
+++ b/object.c
@@ -320,6 +320,14 @@ rb_obj_singleton_class(VALUE obj) https://github.com/ruby/ruby/blob/trunk/object.c#L320
     return rb_singleton_class(obj);
 }
 
+struct st_table *
+rb_obj_iv_index_tbl(const struct RObject *obj)
+{
+    /* This is a function that practically never gets used.  Just to keep
+     * backwards compatibility to ruby 2.x. */
+    return ROBJECT_IV_INDEX_TBL((VALUE)obj);
+}
+
 /*! \private */
 MJIT_FUNC_EXPORTED void
 rb_obj_copy_ivar(VALUE dest, VALUE obj)
diff --git a/variable.c b/variable.c
index 4f66ad3..26928ca 100644
--- a/variable.c
+++ b/variable.c
@@ -25,6 +25,7 @@ https://github.com/ruby/ruby/blob/trunk/variable.c#L25
 #include "internal/error.h"
 #include "internal/eval.h"
 #include "internal/hash.h"
+#include "internal/object.h"
 #include "internal/re.h"
 #include "internal/symbol.h"
 #include "internal/thread.h"
-- 
cgit v0.10.2


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

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