Skip to content

Commit 189727e

Browse files
committed
Remove use of RTYPEDDATA_P and rbimpl_rtypeddata_p
1 parent 776d17b commit 189727e

File tree

10 files changed

+33
-75
lines changed

10 files changed

+33
-75
lines changed

encoding.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ static const rb_data_type_t encoding_data_type = {
126126
};
127127

128128
#define is_encoding_type(obj) (RTYPEDDATA_TYPE(obj) == &encoding_data_type)
129-
#define is_data_encoding(obj) (rbimpl_rtypeddata_p(obj) && is_encoding_type(obj))
129+
#define is_data_encoding(obj) is_encoding_type(obj)
130130
#define is_obj_encoding(obj) (rbimpl_obj_typeddata_p(obj) && is_encoding_type(obj))
131131

132132
int

error.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1355,8 +1355,7 @@ rb_check_type(VALUE x, int t)
13551355
rb_bug(UNDEF_LEAKED);
13561356
}
13571357

1358-
xt = TYPE(x);
1359-
if (xt != t || (xt == T_DATA && rbimpl_rtypeddata_p(x))) {
1358+
if (t == T_DATA) {
13601359
/*
13611360
* Typed data is not simple `T_DATA`, but in a sense an
13621361
* extension of `struct RVALUE`, which are incompatible with
@@ -1365,6 +1364,10 @@ rb_check_type(VALUE x, int t)
13651364
* So it is not enough to just check `T_DATA`, it must be
13661365
* identified by its `type` using `Check_TypedStruct` instead.
13671366
*/
1367+
rb_unexpected_object_type(x, builtin_types[t]);
1368+
}
1369+
xt = TYPE(x);
1370+
if (xt != t) {
13681371
unexpected_type(x, xt, t);
13691372
}
13701373
}

ext/objspace/objspace_dump.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -573,11 +573,9 @@ dump_object(VALUE obj, struct dump_config *dc)
573573
break;
574574

575575
case T_DATA:
576-
if (RTYPEDDATA_P(obj)) {
577-
dump_append(dc, ", \"struct\":\"");
578-
dump_append(dc, RTYPEDDATA_TYPE(obj)->wrap_struct_name);
579-
dump_append(dc, "\"");
580-
}
576+
dump_append(dc, ", \"struct\":\"");
577+
dump_append(dc, RTYPEDDATA_TYPE(obj)->wrap_struct_name);
578+
dump_append(dc, "\"");
581579
break;
582580

583581
case T_FLOAT:

gc.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,7 +1176,7 @@ rb_gc_handle_weak_references(VALUE obj)
11761176
{
11771177
switch (BUILTIN_TYPE(obj)) {
11781178
case T_DATA:
1179-
if (RTYPEDDATA_P(obj)) {
1179+
{
11801180
const rb_data_type_t *type = RTYPEDDATA_TYPE(obj);
11811181

11821182
if (type->function.handle_weak_references) {
@@ -1189,9 +1189,6 @@ rb_gc_handle_weak_references(VALUE obj)
11891189
);
11901190
}
11911191
}
1192-
else {
1193-
rb_bug("rb_gc_handle_weak_references: unknown T_DATA");
1194-
}
11951192
break;
11961193

11971194
case T_IMEMO: {

include/ruby/internal/core/rtypeddata.h

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -603,26 +603,7 @@ RBIMPL_ATTR_ARTIFICIAL()
603603
/**
604604
* @private
605605
*
606-
* This is an implementation detail of Check_Type(). People don't use it
607-
* directly.
608-
*
609-
* @param[in] obj Object in question
610-
* @retval true
611-
* @pre `obj` must be a Ruby object of ::RUBY_T_DATA.
612-
*/
613-
static inline bool
614-
rbimpl_rtypeddata_p(VALUE obj)
615-
{
616-
return true;
617-
}
618-
619-
RBIMPL_ATTR_PURE()
620-
RBIMPL_ATTR_ARTIFICIAL()
621-
/**
622-
* @private
623-
*
624-
* Identical to rbimpl_rtypeddata_p(), except it is allowed to call on non-data
625-
* objects.
606+
* Checks whether the passed object is ::RTypedData.
626607
*
627608
* This is an implementation detail of inline functions defined in this file.
628609
* People don't use it directly.
@@ -634,7 +615,7 @@ RBIMPL_ATTR_ARTIFICIAL()
634615
static inline bool
635616
rbimpl_obj_typeddata_p(VALUE obj)
636617
{
637-
return RB_TYPE_P(obj, RUBY_T_DATA) && rbimpl_rtypeddata_p(obj);
618+
return RB_TYPE_P(obj, RUBY_T_DATA);
638619
}
639620

640621
RBIMPL_ATTR_PURE_UNLESS_DEBUG()
@@ -651,7 +632,7 @@ RTYPEDDATA_P(VALUE obj)
651632
{
652633
RBIMPL_TYPEDDATA_PRECONDITION(obj, RBIMPL_UNREACHABLE_RETURN(false));
653634

654-
return rbimpl_rtypeddata_p(obj);
635+
return true;
655636
}
656637

657638
RBIMPL_ATTR_PURE_UNLESS_DEBUG()

include/ruby/internal/value_type.h

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -410,14 +410,6 @@ RB_TYPE_P(VALUE obj, enum ruby_value_type t)
410410
#endif
411411
/** @endcond */
412412

413-
RBIMPL_ATTR_PURE()
414-
RBIMPL_ATTR_ARTIFICIAL()
415-
/**
416-
* @private
417-
* Defined in ruby/internal/core/rtypeddata.h
418-
*/
419-
static inline bool rbimpl_rtypeddata_p(VALUE obj);
420-
421413
RBIMPL_ATTR_ARTIFICIAL()
422414
/**
423415
* Identical to RB_TYPE_P(), except it raises exceptions on predication
@@ -432,19 +424,11 @@ RBIMPL_ATTR_ARTIFICIAL()
432424
static inline void
433425
Check_Type(VALUE v, enum ruby_value_type t)
434426
{
427+
/* Typed data is not simple `T_DATA`, see `rb_check_type` */
428+
RUBY_ASSERT_ALWAYS(t != RUBY_T_DATA);
435429
if (RB_UNLIKELY(! RB_TYPE_P(v, t))) {
436-
goto unexpected_type;
430+
rb_unexpected_type(v, RBIMPL_CAST((int)t));
437431
}
438-
else if (t == RUBY_T_DATA && rbimpl_rtypeddata_p(v)) {
439-
/* Typed data is not simple `T_DATA`, see `rb_check_type` */
440-
goto unexpected_type;
441-
}
442-
else {
443-
return;
444-
}
445-
446-
unexpected_type:
447-
rb_unexpected_type(v, RBIMPL_CAST((int)t));
448432
}
449433

450434
#endif /* RBIMPL_VALUE_TYPE_H */

ractor.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1446,7 +1446,7 @@ allow_frozen_shareable_p(VALUE obj)
14461446
if (!RB_TYPE_P(obj, T_DATA)) {
14471447
return true;
14481448
}
1449-
else if (RTYPEDDATA_P(obj)) {
1449+
else {
14501450
const rb_data_type_t *type = RTYPEDDATA_TYPE(obj);
14511451
if (type->flags & RUBY_TYPED_FROZEN_SHAREABLE) {
14521452
return true;

spec/ruby/optional/capi/ext/typed_data_spec.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,11 @@ VALUE sws_typed_rb_check_typeddata_different_type(VALUE self, VALUE obj) {
175175
return rb_check_typeddata(obj, &sample_typed_wrapped_struct_other_data_type) == DATA_PTR(obj) ? Qtrue : Qfalse;
176176
}
177177

178+
#ifndef RUBY_VERSION_IS_4_1
178179
VALUE sws_typed_RTYPEDDATA_P(VALUE self, VALUE obj) {
179180
return RTYPEDDATA_P(obj) ? Qtrue : Qfalse;
180181
}
182+
#endif
181183

182184
void Init_typed_data_spec(void) {
183185
VALUE cls = rb_define_class("CApiAllocTypedSpecs", rb_cObject);
@@ -198,7 +200,9 @@ void Init_typed_data_spec(void) {
198200
rb_define_method(cls, "rb_check_typeddata_same_type", sws_typed_rb_check_typeddata_same_type, 1);
199201
rb_define_method(cls, "rb_check_typeddata_same_type_parent", sws_typed_rb_check_typeddata_same_type_parent, 1);
200202
rb_define_method(cls, "rb_check_typeddata_different_type", sws_typed_rb_check_typeddata_different_type, 1);
203+
#ifndef RUBY_VERSION_IS_4_1
201204
rb_define_method(cls, "RTYPEDDATA_P", sws_typed_RTYPEDDATA_P, 1);
205+
#endif
202206
}
203207

204208
#ifdef __cplusplus

spec/ruby/optional/capi/typed_data_spec.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,13 @@
8686
end
8787
end
8888

89-
describe "RTYPEDDATA_P" do
90-
it "returns true for a typed data" do
91-
a = @s.typed_wrap_struct(1024)
92-
@s.RTYPEDDATA_P(a).should == true
93-
end
89+
ruby_version_is ""..."4.1" do
90+
describe "RTYPEDDATA_P" do
91+
it "returns true for a typed data" do
92+
a = @s.typed_wrap_struct(1024)
93+
@s.RTYPEDDATA_P(a).should == true
94+
end
9495

95-
ruby_version_is ""..."4.1" do
9696
it "returns false for an untyped data object" do
9797
a = @s.untyped_wrap_struct(1024)
9898
@s.RTYPEDDATA_P(a).should == false

variable.c

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,11 +1261,8 @@ rb_obj_fields(VALUE obj, ID field_name)
12611261
if (rb_shape_obj_has_fields(obj)) {
12621262
switch (BUILTIN_TYPE(obj)) {
12631263
case T_DATA:
1264-
if (LIKELY(RTYPEDDATA_P(obj))) {
1265-
fields_obj = RTYPEDDATA(obj)->fields_obj;
1266-
break;
1267-
}
1268-
goto generic_fields;
1264+
fields_obj = RTYPEDDATA(obj)->fields_obj;
1265+
break;
12691266
case T_STRUCT:
12701267
if (LIKELY(!FL_TEST_RAW(obj, RSTRUCT_GEN_FIELDS))) {
12711268
fields_obj = RSTRUCT_FIELDS_OBJ(obj);
@@ -1298,11 +1295,8 @@ rb_free_generic_ivar(VALUE obj)
12981295
st_data_t key = (st_data_t)obj, value;
12991296
switch (BUILTIN_TYPE(obj)) {
13001297
case T_DATA:
1301-
if (LIKELY(RTYPEDDATA_P(obj))) {
1302-
RB_OBJ_WRITE(obj, &RTYPEDDATA(obj)->fields_obj, 0);
1303-
break;
1304-
}
1305-
goto generic_fields;
1298+
RB_OBJ_WRITE(obj, &RTYPEDDATA(obj)->fields_obj, 0);
1299+
break;
13061300
case T_STRUCT:
13071301
if (LIKELY(!FL_TEST_RAW(obj, RSTRUCT_GEN_FIELDS))) {
13081302
RSTRUCT_SET_FIELDS_OBJ(obj, 0);
@@ -1348,11 +1342,8 @@ rb_obj_set_fields(VALUE obj, VALUE fields_obj, ID field_name, VALUE original_fie
13481342
if (fields_obj != original_fields_obj) {
13491343
switch (BUILTIN_TYPE(obj)) {
13501344
case T_DATA:
1351-
if (LIKELY(RTYPEDDATA_P(obj))) {
1352-
RB_OBJ_WRITE(obj, &RTYPEDDATA(obj)->fields_obj, fields_obj);
1353-
break;
1354-
}
1355-
goto generic_fields;
1345+
RB_OBJ_WRITE(obj, &RTYPEDDATA(obj)->fields_obj, fields_obj);
1346+
break;
13561347
case T_STRUCT:
13571348
if (LIKELY(!FL_TEST_RAW(obj, RSTRUCT_GEN_FIELDS))) {
13581349
RSTRUCT_SET_FIELDS_OBJ(obj, fields_obj);

0 commit comments

Comments
 (0)