@@ -661,7 +661,7 @@ typedef struct RVALUE {
661
661
struct RArray array ;
662
662
struct RRegexp regexp ;
663
663
struct RHash hash ;
664
- struct RData data ;
664
+ struct RDataHeader data ;
665
665
struct RTypedData typeddata ;
666
666
struct RStruct rstruct ;
667
667
struct RBignum bignum ;
@@ -2974,35 +2974,19 @@ rb_wb_protected_newobj_of(rb_execution_context_t *ec, VALUE klass, VALUE flags,
2974
2974
static inline void
2975
2975
rb_data_object_check (VALUE klass )
2976
2976
{
2977
- if (klass != rb_cObject && (rb_get_alloc_func (klass ) == rb_class_allocate_instance )) {
2978
- rb_undef_alloc_func (klass );
2979
- rb_warn ("undefining the allocator of T_DATA class %" PRIsVALUE , klass );
2980
- }
2981
- }
2982
-
2983
- VALUE
2984
- rb_data_object_wrap (VALUE klass , void * datap , RUBY_DATA_FUNC dmark , RUBY_DATA_FUNC dfree )
2985
- {
2986
- RUBY_ASSERT_ALWAYS (dfree != (RUBY_DATA_FUNC )1 );
2987
- if (klass ) rb_data_object_check (klass );
2988
- return newobj_of (GET_RACTOR (), klass , T_DATA , (VALUE )dmark , (VALUE )dfree , (VALUE )datap , !dmark , sizeof (struct RTypedData ));
2989
- }
2990
-
2991
- VALUE
2992
- rb_data_object_zalloc (VALUE klass , size_t size , RUBY_DATA_FUNC dmark , RUBY_DATA_FUNC dfree )
2993
- {
2994
- VALUE obj = rb_data_object_wrap (klass , 0 , dmark , dfree );
2995
- DATA_PTR (obj ) = xcalloc (1 , size );
2996
- return obj ;
2977
+ if (klass != rb_cObject && (rb_get_alloc_func (klass ) == rb_class_allocate_instance )) {
2978
+ rb_undef_alloc_func (klass );
2979
+ rb_warn ("undefining the allocator of T_DATA class %" PRIsVALUE , klass );
2980
+ }
2997
2981
}
2998
2982
2999
2983
static VALUE
3000
- typed_data_alloc (VALUE klass , VALUE typed_flag , void * datap , const rb_data_type_t * type , size_t size )
2984
+ typed_data_alloc (VALUE klass , const rb_data_type_t * type , void * datap , size_t size )
3001
2985
{
3002
2986
RBIMPL_NONNULL_ARG (type );
3003
2987
if (klass ) rb_data_object_check (klass );
3004
2988
bool wb_protected = (type -> flags & RUBY_FL_WB_PROTECTED ) || !type -> function .dmark ;
3005
- return newobj_of (GET_RACTOR (), klass , T_DATA , (VALUE )type , 1 | typed_flag , (VALUE )datap , wb_protected , size );
2989
+ return newobj_of (GET_RACTOR (), klass , T_DATA , (VALUE )type , (VALUE )datap , 0 , wb_protected , size );
3006
2990
}
3007
2991
3008
2992
VALUE
@@ -3012,7 +2996,7 @@ rb_data_typed_object_wrap(VALUE klass, void *datap, const rb_data_type_t *type)
3012
2996
rb_raise (rb_eTypeError , "Cannot wrap an embeddable TypedData" );
3013
2997
}
3014
2998
3015
- return typed_data_alloc (klass , 0 , datap , type , sizeof (struct RTypedData ));
2999
+ return typed_data_alloc (klass , type , datap , sizeof (struct RTypedData ));
3016
3000
}
3017
3001
3018
3002
VALUE
@@ -3025,13 +3009,14 @@ rb_data_typed_object_zalloc(VALUE klass, size_t size, const rb_data_type_t *type
3025
3009
3026
3010
size_t embed_size = offsetof(struct RTypedData , data ) + size ;
3027
3011
if (rb_gc_size_allocatable_p (embed_size )) {
3028
- VALUE obj = typed_data_alloc (klass , TYPED_DATA_EMBEDDED , 0 , type , embed_size );
3012
+ VALUE obj = typed_data_alloc (klass , type , NULL , embed_size );
3029
3013
memset ((char * )obj + offsetof(struct RTypedData , data ), 0 , size );
3014
+ FL_SET_RAW (obj , TYPED_DATA_FL_EMBEDDED );
3030
3015
return obj ;
3031
3016
}
3032
3017
}
3033
3018
3034
- VALUE obj = typed_data_alloc (klass , 0 , NULL , type , sizeof (struct RTypedData ));
3019
+ VALUE obj = typed_data_alloc (klass , type , NULL , sizeof (struct RTypedData ));
3035
3020
DATA_PTR (obj ) = xcalloc (1 , size );
3036
3021
return obj ;
3037
3022
}
@@ -3044,7 +3029,7 @@ rb_objspace_data_type_memsize(VALUE obj)
3044
3029
const rb_data_type_t * type = RTYPEDDATA_TYPE (obj );
3045
3030
const void * ptr = RTYPEDDATA_GET_DATA (obj );
3046
3031
3047
- if (RTYPEDDATA_TYPE (obj )-> flags & RUBY_TYPED_EMBEDDABLE && !RTYPEDDATA_EMBEDDED_P (obj )) {
3032
+ if (RTYPEDDATA_TYPE (obj )-> flags & RUBY_TYPED_EMBEDDABLE && !rbimpl_rtypeddata_embedded_p (obj )) {
3048
3033
#ifdef HAVE_MALLOC_USABLE_SIZE
3049
3034
size += malloc_usable_size ((void * )ptr );
3050
3035
#endif
@@ -3069,6 +3054,56 @@ rb_objspace_data_type_name(VALUE obj)
3069
3054
}
3070
3055
}
3071
3056
3057
+ static void
3058
+ mark_deprecated_rdata_object (void * ptr )
3059
+ {
3060
+ struct RData * rdata = (struct RData * )ptr ;
3061
+ if (rdata -> dmark ) {
3062
+ rdata -> dmark (rdata );
3063
+ }
3064
+ }
3065
+
3066
+ static size_t
3067
+ memsize_deprecated_rdata_object (const void * ptr )
3068
+ {
3069
+ return sizeof (struct RData );
3070
+ }
3071
+
3072
+ #define DEPRECATED_DATA_FREE RBIMPL_DATA_FUNC(-3)
3073
+
3074
+ const rb_data_type_t deprecated_rdata_type = {
3075
+ .wrap_struct_name = "RDATA(deprecated)" ,
3076
+ .function = {
3077
+ .dmark = mark_deprecated_rdata_object ,
3078
+ .dfree = DEPRECATED_DATA_FREE ,
3079
+ .dsize = memsize_deprecated_rdata_object ,
3080
+ },
3081
+ };
3082
+
3083
+ VALUE
3084
+ rb_data_object_wrap (VALUE klass , void * datap , RUBY_DATA_FUNC dmark , RUBY_DATA_FUNC dfree )
3085
+ {
3086
+ RUBY_ASSERT_ALWAYS (dfree != (RUBY_DATA_FUNC )1 );
3087
+ if (klass ) rb_data_object_check (klass );
3088
+
3089
+ VALUE obj = rb_data_typed_object_zalloc (klass , sizeof (struct RData ), & deprecated_rdata_type );
3090
+
3091
+ struct RData * rdata = (struct RData * )obj ;
3092
+ rdata -> dmark = dmark ;
3093
+ rdata -> dfree = dfree ;
3094
+ rdata -> data = datap ;
3095
+ return obj ;
3096
+ }
3097
+
3098
+ VALUE
3099
+ rb_data_object_zalloc (VALUE klass , size_t size , RUBY_DATA_FUNC dmark , RUBY_DATA_FUNC dfree )
3100
+ {
3101
+ VALUE obj = rb_data_object_wrap (klass , 0 , dmark , dfree );
3102
+ struct RData * rdata = (struct RData * )obj ;
3103
+ rdata -> data = xcalloc (1 , size );
3104
+ return obj ;
3105
+ }
3106
+
3072
3107
static int
3073
3108
ptr_in_page_body_p (const void * ptr , const void * memb )
3074
3109
{
@@ -3191,31 +3226,29 @@ obj_free_object_id(rb_objspace_t *objspace, VALUE obj)
3191
3226
}
3192
3227
3193
3228
static bool
3194
- rb_data_free (rb_objspace_t * objspace , VALUE obj )
3229
+ rb_typeddata_free (rb_objspace_t * objspace , VALUE obj )
3195
3230
{
3196
- void * data = RTYPEDDATA_P ( obj ) ? RTYPEDDATA_GET_DATA ( obj ) : DATA_PTR (obj );
3231
+ void * data = RTYPEDDATA_GET_DATA (obj );
3197
3232
if (data ) {
3198
3233
int free_immediately = false;
3199
- void (* dfree )(void * );
3200
3234
3201
- if (RTYPEDDATA_P (obj )) {
3202
- free_immediately = (RANY (obj )-> as .typeddata .type -> flags & RUBY_TYPED_FREE_IMMEDIATELY ) != 0 ;
3203
- dfree = RANY (obj )-> as .typeddata .type -> function .dfree ;
3204
- }
3205
- else {
3206
- dfree = RANY (obj )-> as .data .dfree ;
3235
+ free_immediately = (RANY (obj )-> as .typeddata .type -> flags & RUBY_TYPED_FREE_IMMEDIATELY ) != 0 ;
3236
+
3237
+ RUBY_DATA_FUNC dfree = RANY (obj )-> as .typeddata .type -> function .dfree ;
3238
+ if (UNLIKELY (dfree == DEPRECATED_DATA_FREE )) {
3239
+ dfree = RDATA (obj )-> dfree ;
3207
3240
}
3208
3241
3209
3242
if (dfree ) {
3210
3243
if (dfree == RUBY_DEFAULT_FREE ) {
3211
- if (!RTYPEDDATA_EMBEDDED_P (obj )) {
3244
+ if (!rbimpl_rtypeddata_embedded_p (obj )) {
3212
3245
xfree (data );
3213
3246
RB_DEBUG_COUNTER_INC (obj_data_xfree );
3214
3247
}
3215
3248
}
3216
3249
else if (free_immediately ) {
3217
3250
(* dfree )(data );
3218
- if (RTYPEDDATA_TYPE (obj )-> flags & RUBY_TYPED_EMBEDDABLE && !RTYPEDDATA_EMBEDDED_P (obj )) {
3251
+ if (RTYPEDDATA_TYPE (obj )-> flags & RUBY_TYPED_EMBEDDABLE && !rbimpl_rtypeddata_embedded_p (obj )) {
3219
3252
xfree (data );
3220
3253
}
3221
3254
@@ -3373,7 +3406,7 @@ obj_free(rb_objspace_t *objspace, VALUE obj)
3373
3406
}
3374
3407
break ;
3375
3408
case T_DATA :
3376
- if (!rb_data_free (objspace , obj )) return false;
3409
+ if (!rb_typeddata_free (objspace , obj )) return false;
3377
3410
break ;
3378
3411
case T_MATCH :
3379
3412
{
@@ -4330,7 +4363,7 @@ rb_objspace_call_finalizer_i(VALUE obj, void *data)
4330
4363
4331
4364
switch (BUILTIN_TYPE (obj )) {
4332
4365
case T_DATA :
4333
- if (!rb_free_at_exit && (!DATA_PTR (obj ) || !RANY (obj )-> as . data . dfree )) break ;
4366
+ if (!rb_free_at_exit && (!DATA_PTR (obj ) || !RDATA (obj )-> dfree )) break ;
4334
4367
if (rb_obj_is_thread (obj )) break ;
4335
4368
if (rb_obj_is_mutex (obj )) break ;
4336
4369
if (rb_obj_is_fiber (obj )) break ;
@@ -6954,20 +6987,18 @@ gc_mark_children(rb_objspace_t *objspace, VALUE obj)
6954
6987
6955
6988
case T_DATA :
6956
6989
{
6957
- void * const ptr = RTYPEDDATA_P ( obj ) ? RTYPEDDATA_GET_DATA ( obj ) : DATA_PTR (obj );
6990
+ void * const ptr = RTYPEDDATA_GET_DATA (obj );
6958
6991
6959
6992
if (ptr ) {
6960
- if (RTYPEDDATA_P ( obj ) && gc_declarative_marking_p (any -> as .typeddata .type )) {
6993
+ if (gc_declarative_marking_p (any -> as .typeddata .type )) {
6961
6994
size_t * offset_list = (size_t * )RANY (obj )-> as .typeddata .type -> function .dmark ;
6962
6995
6963
6996
for (size_t offset = * offset_list ; offset != RUBY_REF_END ; offset = * offset_list ++ ) {
6964
6997
rb_gc_mark_movable (* (VALUE * )((char * )ptr + offset ));
6965
6998
}
6966
6999
}
6967
7000
else {
6968
- RUBY_DATA_FUNC mark_func = RTYPEDDATA_P (obj ) ?
6969
- any -> as .typeddata .type -> function .dmark :
6970
- any -> as .data .dmark ;
7001
+ RUBY_DATA_FUNC mark_func = any -> as .typeddata .type -> function .dmark ;
6971
7002
if (mark_func ) (* mark_func )(ptr );
6972
7003
}
6973
7004
}
@@ -10170,9 +10201,9 @@ gc_update_object_references(rb_objspace_t *objspace, VALUE obj)
10170
10201
case T_DATA :
10171
10202
/* Call the compaction callback, if it exists */
10172
10203
{
10173
- void * const ptr = RTYPEDDATA_P ( obj ) ? RTYPEDDATA_GET_DATA ( obj ) : DATA_PTR (obj );
10204
+ void * const ptr = RTYPEDDATA_GET_DATA (obj );
10174
10205
if (ptr ) {
10175
- if (RTYPEDDATA_P ( obj ) && gc_declarative_marking_p (any -> as .typeddata .type )) {
10206
+ if (gc_declarative_marking_p (any -> as .typeddata .type )) {
10176
10207
size_t * offset_list = (size_t * )RANY (obj )-> as .typeddata .type -> function .dmark ;
10177
10208
10178
10209
for (size_t offset = * offset_list ; offset != RUBY_REF_END ; offset = * offset_list ++ ) {
@@ -10181,7 +10212,7 @@ gc_update_object_references(rb_objspace_t *objspace, VALUE obj)
10181
10212
* ref = rb_gc_location (* ref );
10182
10213
}
10183
10214
}
10184
- else if ( RTYPEDDATA_P ( obj )) {
10215
+ else {
10185
10216
RUBY_DATA_FUNC compact_func = any -> as .typeddata .type -> function .dcompact ;
10186
10217
if (compact_func ) (* compact_func )(ptr );
10187
10218
}
@@ -13306,7 +13337,7 @@ rb_raw_obj_info_buitin_type(char *const buff, const size_t buff_size, const VALU
13306
13337
rb_raw_iseq_info (BUFF_ARGS , iseq );
13307
13338
}
13308
13339
else if (rb_ractor_p (obj )) {
13309
- rb_ractor_t * r = (void * )DATA_PTR (obj );
13340
+ rb_ractor_t * r = (void * )RTYPEDDATA_GET_DATA (obj );
13310
13341
if (r ) {
13311
13342
APPEND_F ("r:%d" , r -> pub .id );
13312
13343
}
0 commit comments