Skip to content

Commit 131ded1

Browse files
committed
Remove use of RTYPEDDATA_P and rbimpl_rtypeddata_p
1 parent d8fed16 commit 131ded1

File tree

12 files changed

+34
-78
lines changed

12 files changed

+34
-78
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
@@ -610,26 +610,7 @@ RBIMPL_ATTR_ARTIFICIAL()
610610
/**
611611
* @private
612612
*
613-
* This is an implementation detail of Check_Type(). People don't use it
614-
* directly.
615-
*
616-
* @param[in] obj Object in question
617-
* @retval true
618-
* @pre `obj` must be a Ruby object of ::RUBY_T_DATA.
619-
*/
620-
static inline bool
621-
rbimpl_rtypeddata_p(VALUE obj)
622-
{
623-
return true;
624-
}
625-
626-
RBIMPL_ATTR_PURE()
627-
RBIMPL_ATTR_ARTIFICIAL()
628-
/**
629-
* @private
630-
*
631-
* Identical to rbimpl_rtypeddata_p(), except it is allowed to call on non-data
632-
* objects.
613+
* Checks whether the passed object is ::RTypedData.
633614
*
634615
* This is an implementation detail of inline functions defined in this file.
635616
* People don't use it directly.
@@ -641,7 +622,7 @@ RBIMPL_ATTR_ARTIFICIAL()
641622
static inline bool
642623
rbimpl_obj_typeddata_p(VALUE obj)
643624
{
644-
return RB_TYPE_P(obj, RUBY_T_DATA) && rbimpl_rtypeddata_p(obj);
625+
return RB_TYPE_P(obj, RUBY_T_DATA);
645626
}
646627

647628
RBIMPL_ATTR_PURE_UNLESS_DEBUG()
@@ -658,7 +639,7 @@ RTYPEDDATA_P(VALUE obj)
658639
{
659640
RBIMPL_TYPEDDATA_PRECONDITION(obj, RBIMPL_UNREACHABLE_RETURN(false));
660641

661-
return rbimpl_rtypeddata_p(obj);
642+
return true;
662643
}
663644

664645
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 */

include/ruby/random.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,6 @@ static inline const rb_random_interface_t *
333333
rb_rand_if(VALUE obj)
334334
{
335335
RBIMPL_ASSERT_OR_ASSUME(RB_TYPE_P(obj, T_DATA));
336-
RBIMPL_ASSERT_OR_ASSUME(RTYPEDDATA_P(obj));
337336
RUBY_ASSERT(rb_typeddata_is_kind_of(obj, &rb_random_data_type));
338337
const struct rb_data_type_struct *t = RTYPEDDATA_TYPE(obj);
339338
const void *ret = t->data;

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;

shape.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -458,8 +458,7 @@ rb_obj_using_gen_fields_table_p(VALUE obj)
458458
{
459459
switch (BUILTIN_TYPE(obj)) {
460460
case T_DATA:
461-
if (RTYPEDDATA_P(obj)) return false;
462-
break;
461+
return false;
463462

464463
case T_STRUCT:
465464
if (!FL_TEST_RAW(obj, RSTRUCT_GEN_FIELDS)) return false;

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

0 commit comments

Comments
 (0)