summaryrefslogtreecommitdiff
path: root/include/ruby/internal/core
diff options
context:
space:
mode:
Diffstat (limited to 'include/ruby/internal/core')
-rw-r--r--include/ruby/internal/core/rdata.h18
-rw-r--r--include/ruby/internal/core/rtypeddata.h1
2 files changed, 13 insertions, 6 deletions
diff --git a/include/ruby/internal/core/rdata.h b/include/ruby/internal/core/rdata.h
index cee5e7b5ea..5ebeb2473e 100644
--- a/include/ruby/internal/core/rdata.h
+++ b/include/ruby/internal/core/rdata.h
@@ -116,12 +116,24 @@ typedef void (*RUBY_DATA_FUNC)(void*);
* @shyouhei tried to add RBIMPL_ATTR_DEPRECATED for this type but that yielded
* too many warnings in the core. Maybe we want to retry later... Just add
* deprecated document for now.
+ *
+ * RData shares its initial fields with struct ::RTypedData so the VM can handle
+ * per-object fields without checking whether a T_DATA object is typed or legacy.
*/
struct RData {
/** Basic part, including flags and class. */
struct RBasic basic;
+ /** @internal Direct reference to the slots that hold instance variables, if any. */
+ VALUE fields_obj;
+
+ /** @internal Padding where ::RTypedData stores its type, so both structs place data at the same offset. */
+ VALUE _reserved;
+
+ /** Pointer to the actual C level struct that you want to wrap. */
+ void *data;
+
/**
* This function is called when the object is experiencing GC marks. If it
* contains references to other Ruby objects, you need to mark them also.
@@ -141,12 +153,6 @@ struct RData {
* impossible at that moment (that is why GC runs).
*/
RUBY_DATA_FUNC dfree;
-
- /** Pointer to the actual C level struct that you want to wrap.
- * This is after dmark and dfree to allow DATA_PTR to continue to work for
- * both RData and non-embedded RTypedData.
- */
- void *data;
};
RBIMPL_SYMBOL_EXPORT_BEGIN()
diff --git a/include/ruby/internal/core/rtypeddata.h b/include/ruby/internal/core/rtypeddata.h
index 22bf46eb03..0b189c7ef8 100644
--- a/include/ruby/internal/core/rtypeddata.h
+++ b/include/ruby/internal/core/rtypeddata.h
@@ -405,6 +405,7 @@ struct RTypedData {
};
#if !defined(__cplusplus) || __cplusplus >= 201103L
+RBIMPL_STATIC_ASSERT(fields_obj_in_rdata, offsetof(struct RData, fields_obj) == offsetof(struct RTypedData, fields_obj));
RBIMPL_STATIC_ASSERT(data_in_rtypeddata, offsetof(struct RData, data) == offsetof(struct RTypedData, data));
#endif