diff options
Diffstat (limited to 'include/ruby')
-rw-r--r-- | include/ruby/internal/core/rdata.h | 9 | ||||
-rw-r--r-- | include/ruby/internal/core/rtypeddata.h | 26 |
2 files changed, 19 insertions, 16 deletions
diff --git a/include/ruby/internal/core/rdata.h b/include/ruby/internal/core/rdata.h index e4c146a716..cab412af72 100644 --- a/include/ruby/internal/core/rdata.h +++ b/include/ruby/internal/core/rdata.h @@ -133,6 +133,12 @@ struct RData { */ RUBY_DATA_FUNC dmark; + /** Pointer to the actual C level struct that you want to wrap. + * This is in between dmark and dfree to allow DATA_PTR to continue + * to work for both RData and non-embedded RTypedData. + */ + void *data; + /** * This function is called when the object is no longer used. You need to * do whatever necessary to avoid memory leaks. @@ -141,9 +147,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. */ - void *data; }; RBIMPL_SYMBOL_EXPORT_BEGIN() diff --git a/include/ruby/internal/core/rtypeddata.h b/include/ruby/internal/core/rtypeddata.h index 6c19576c20..b576be779f 100644 --- a/include/ruby/internal/core/rtypeddata.h +++ b/include/ruby/internal/core/rtypeddata.h @@ -114,7 +114,10 @@ #define RUBY_TYPED_PROMOTED1 RUBY_TYPED_PROMOTED1 /** @endcond */ -#define TYPED_DATA_EMBEDDED 2 +#define IS_TYPED_DATA ((VALUE)1) +#define TYPED_DATA_EMBEDDED ((VALUE)2) +#define TYPED_DATA_PTR_FLAGS ((VALUE)3) +#define TYPED_DATA_PTR_MASK (~TYPED_DATA_PTR_FLAGS) /** * @private @@ -353,18 +356,16 @@ struct RTypedData { struct RBasic basic; /** + * This is a `const rb_data_type_t *const` value, with the low bits set: + * + * 1: Always set, to differentiate RTypedData from RData. + * 2: Set if object is embedded. + * * This field stores various information about how Ruby should handle a * data. This roughly resembles a Ruby level class (apart from method * definition etc.) */ - const rb_data_type_t *const type; - - /** - * This has to be always 1. - * - * @internal - */ - const VALUE typed_flag; + const VALUE type; /** Pointer to the actual C level struct that you want to wrap. */ void *data; @@ -525,7 +526,7 @@ RTYPEDDATA_EMBEDDED_P(VALUE obj) } #endif - return RTYPEDDATA(obj)->typed_flag & TYPED_DATA_EMBEDDED; + return (RTYPEDDATA(obj)->type) & TYPED_DATA_EMBEDDED; } static inline void * @@ -561,8 +562,7 @@ RBIMPL_ATTR_ARTIFICIAL() static inline bool rbimpl_rtypeddata_p(VALUE obj) { - VALUE typed_flag = RTYPEDDATA(obj)->typed_flag; - return typed_flag != 0 && typed_flag <= 3; + return RTYPEDDATA(obj)->type & IS_TYPED_DATA; } RBIMPL_ATTR_PURE_UNLESS_DEBUG() @@ -608,7 +608,7 @@ RTYPEDDATA_TYPE(VALUE obj) } #endif - return RTYPEDDATA(obj)->type; + return (const struct rb_data_type_struct *)(RTYPEDDATA(obj)->type & TYPED_DATA_PTR_MASK); } /** |