summaryrefslogtreecommitdiff
path: root/internal/object.h
diff options
context:
space:
mode:
author卜部昌平 <shyouhei@ruby-lang.org>2020-08-17 13:51:23 +0900
committer卜部昌平 <shyouhei@ruby-lang.org>2020-08-19 14:30:57 +0900
commit6649677eb93a101a5411a942ca1b84b541262537 (patch)
tree63c8e41c4bcb5ffed7782ca1651b3019796c5276 /internal/object.h
parente2c2283a80843f6011a3d7665725ff0c5aed27c5 (diff)
downloadruby-6649677eb93a101a5411a942ca1b84b541262537.tar.gz
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.
Diffstat (limited to 'internal/object.h')
-rw-r--r--internal/object.h22
1 files changed, 22 insertions, 0 deletions
diff --git a/internal/object.h b/internal/object.h
index d34f498ee1..aa820128c7 100644
--- a/internal/object.h
+++ b/internal/object.h
@@ -10,6 +10,11 @@
* @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 *);
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)
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 */