Skip to content

Commit 03c86b0

Browse files
committed
Move IS_TYPED_DATA in RBasic.flags
Ref: ruby#14134 (comment) We can't safely use low-bit pointer tagging anymore because `RTypedData.type` lines up with `RData.dfree` and there is no aligment guarantee on function pointers, as evidenced by `memcached` and `gpgme` gems. We also can't use FL_USER* for this, because extensions may use these for other purposes. Using a general flag for this is a bit unfortunate, as general flags are hard to come by, however I recently freed several of them, and we still have two or three free ones left.
1 parent e5a6e95 commit 03c86b0

File tree

5 files changed

+10
-12
lines changed

5 files changed

+10
-12
lines changed

gc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1062,7 +1062,7 @@ typed_data_alloc(VALUE klass, VALUE typed_flag, void *datap, const rb_data_type_
10621062
RBIMPL_NONNULL_ARG(type);
10631063
if (klass) rb_data_object_check(klass);
10641064
bool wb_protected = (type->flags & RUBY_FL_WB_PROTECTED) || !type->function.dmark;
1065-
return newobj_of(GET_RACTOR(), klass, T_DATA, 0, ((VALUE)type) | IS_TYPED_DATA | typed_flag, (VALUE)datap, wb_protected, size);
1065+
return newobj_of(GET_RACTOR(), klass, T_DATA | RUBY_TYPED_FL_IS_TYPED_DATA, 0, ((VALUE)type) | typed_flag, (VALUE)datap, wb_protected, size);
10661066
}
10671067

10681068
VALUE

include/ruby/internal/core/rtypeddata.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,8 @@
115115
#define RUBY_TYPED_PROMOTED1 RUBY_TYPED_PROMOTED1
116116
/** @endcond */
117117

118-
#define IS_TYPED_DATA ((VALUE)1)
119-
#define TYPED_DATA_EMBEDDED ((VALUE)2)
120-
#define TYPED_DATA_PTR_FLAGS ((VALUE)3)
121-
#define TYPED_DATA_PTR_MASK (~TYPED_DATA_PTR_FLAGS)
118+
#define TYPED_DATA_EMBEDDED ((VALUE)1)
119+
#define TYPED_DATA_PTR_MASK (~(TYPED_DATA_EMBEDDED))
122120

123121
/**
124122
* @private
@@ -181,9 +179,9 @@ rbimpl_typeddata_flags {
181179
RUBY_TYPED_WB_PROTECTED = RUBY_FL_WB_PROTECTED, /* THIS FLAG DEPENDS ON Ruby version */
182180

183181
/**
184-
* This flag no longer in use
182+
* This flag is used to distinguish RTypedData from deprecated RData objects.
185183
*/
186-
RUBY_TYPED_UNUSED = RUBY_FL_UNUSED6,
184+
RUBY_TYPED_FL_IS_TYPED_DATA = RUBY_FL_USERPRIV0,
187185

188186
/**
189187
* This flag determines whether marking and compaction should be carried out
@@ -569,7 +567,7 @@ RBIMPL_ATTR_ARTIFICIAL()
569567
static inline bool
570568
rbimpl_rtypeddata_p(VALUE obj)
571569
{
572-
return RTYPEDDATA(obj)->type & IS_TYPED_DATA;
570+
return FL_TEST_RAW(obj, RUBY_TYPED_FL_IS_TYPED_DATA);
573571
}
574572

575573
RBIMPL_ATTR_PURE_UNLESS_DEBUG()

include/ruby/internal/fl_type.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,11 +217,11 @@ ruby_fl_type {
217217
RUBY_FL_PROMOTED = (1<<5),
218218

219219
/**
220-
* This flag is no longer in use
220+
* This flag meaning is type dependent, currently only used by T_DATA.
221221
*
222222
* @internal
223223
*/
224-
RUBY_FL_UNUSED6 = (1<<6),
224+
RUBY_FL_USERPRIV0 = (1<<6),
225225

226226
/**
227227
* This flag has something to do with finalisers. A ruby object can have

yjit/src/cruby_bindings.inc.rs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

zjit/src/cruby_bindings.inc.rs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)