@@ -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 ;
@@ -2973,35 +2973,19 @@ rb_wb_protected_newobj_of(rb_execution_context_t *ec, VALUE klass, VALUE flags,
2973
2973
static inline void
2974
2974
rb_data_object_check (VALUE klass )
2975
2975
{
2976
- if (klass != rb_cObject && (rb_get_alloc_func (klass ) == rb_class_allocate_instance )) {
2977
- rb_undef_alloc_func (klass );
2978
- rb_warn ("undefining the allocator of T_DATA class %" PRIsVALUE , klass );
2979
- }
2980
- }
2981
-
2982
- VALUE
2983
- rb_data_object_wrap (VALUE klass , void * datap , RUBY_DATA_FUNC dmark , RUBY_DATA_FUNC dfree )
2984
- {
2985
- RUBY_ASSERT_ALWAYS (dfree != (RUBY_DATA_FUNC )1 );
2986
- if (klass ) rb_data_object_check (klass );
2987
- return newobj_of (GET_RACTOR (), klass , T_DATA , (VALUE )dmark , (VALUE )dfree , (VALUE )datap , !dmark , sizeof (struct RTypedData ));
2988
- }
2989
-
2990
- VALUE
2991
- rb_data_object_zalloc (VALUE klass , size_t size , RUBY_DATA_FUNC dmark , RUBY_DATA_FUNC dfree )
2992
- {
2993
- VALUE obj = rb_data_object_wrap (klass , 0 , dmark , dfree );
2994
- DATA_PTR (obj ) = xcalloc (1 , size );
2995
- return obj ;
2976
+ if (klass != rb_cObject && (rb_get_alloc_func (klass ) == rb_class_allocate_instance )) {
2977
+ rb_undef_alloc_func (klass );
2978
+ rb_warn ("undefining the allocator of T_DATA class %" PRIsVALUE , klass );
2979
+ }
2996
2980
}
2997
2981
2998
2982
static VALUE
2999
- typed_data_alloc (VALUE klass , VALUE typed_flag , void * datap , const rb_data_type_t * type , size_t size )
2983
+ typed_data_alloc (VALUE klass , const rb_data_type_t * type , void * datap , size_t size )
3000
2984
{
3001
2985
RBIMPL_NONNULL_ARG (type );
3002
2986
if (klass ) rb_data_object_check (klass );
3003
2987
bool wb_protected = (type -> flags & RUBY_FL_WB_PROTECTED ) || !type -> function .dmark ;
3004
- return newobj_of (GET_RACTOR (), klass , T_DATA , (VALUE )type , 1 | typed_flag , (VALUE )datap , wb_protected , size );
2988
+ return newobj_of (GET_RACTOR (), klass , T_DATA , (VALUE )type , (VALUE )datap , 0 , wb_protected , size );
3005
2989
}
3006
2990
3007
2991
VALUE
@@ -3011,7 +2995,7 @@ rb_data_typed_object_wrap(VALUE klass, void *datap, const rb_data_type_t *type)
3011
2995
rb_raise (rb_eTypeError , "Cannot wrap an embeddable TypedData" );
3012
2996
}
3013
2997
3014
- return typed_data_alloc (klass , 0 , datap , type , sizeof (struct RTypedData ));
2998
+ return typed_data_alloc (klass , type , datap , sizeof (struct RTypedData ));
3015
2999
}
3016
3000
3017
3001
VALUE
@@ -3024,13 +3008,14 @@ rb_data_typed_object_zalloc(VALUE klass, size_t size, const rb_data_type_t *type
3024
3008
3025
3009
size_t embed_size = offsetof(struct RTypedData , data ) + size ;
3026
3010
if (rb_gc_size_allocatable_p (embed_size )) {
3027
- VALUE obj = typed_data_alloc (klass , TYPED_DATA_EMBEDDED , 0 , type , embed_size );
3011
+ VALUE obj = typed_data_alloc (klass , type , NULL , embed_size );
3028
3012
memset ((char * )obj + offsetof(struct RTypedData , data ), 0 , size );
3013
+ FL_SET_RAW (obj , TYPED_DATA_FL_EMBEDDED );
3029
3014
return obj ;
3030
3015
}
3031
3016
}
3032
3017
3033
- VALUE obj = typed_data_alloc (klass , 0 , NULL , type , sizeof (struct RTypedData ));
3018
+ VALUE obj = typed_data_alloc (klass , type , NULL , sizeof (struct RTypedData ));
3034
3019
DATA_PTR (obj ) = xcalloc (1 , size );
3035
3020
return obj ;
3036
3021
}
@@ -3043,7 +3028,7 @@ rb_objspace_data_type_memsize(VALUE obj)
3043
3028
const rb_data_type_t * type = RTYPEDDATA_TYPE (obj );
3044
3029
const void * ptr = RTYPEDDATA_GET_DATA (obj );
3045
3030
3046
- if (RTYPEDDATA_TYPE (obj )-> flags & RUBY_TYPED_EMBEDDABLE && !RTYPEDDATA_EMBEDDED_P (obj )) {
3031
+ if (RTYPEDDATA_TYPE (obj )-> flags & RUBY_TYPED_EMBEDDABLE && !rbimpl_rtypeddata_embedded_p (obj )) {
3047
3032
#ifdef HAVE_MALLOC_USABLE_SIZE
3048
3033
size += malloc_usable_size ((void * )ptr );
3049
3034
#endif
@@ -3068,6 +3053,56 @@ rb_objspace_data_type_name(VALUE obj)
3068
3053
}
3069
3054
}
3070
3055
3056
+ static void
3057
+ mark_deprecated_rdata_object (void * ptr )
3058
+ {
3059
+ struct RData * rdata = (struct RData * )ptr ;
3060
+ if (rdata -> dmark ) {
3061
+ rdata -> dmark (rdata );
3062
+ }
3063
+ }
3064
+
3065
+ static size_t
3066
+ memsize_deprecated_rdata_object (const void * ptr )
3067
+ {
3068
+ return sizeof (struct RData );
3069
+ }
3070
+
3071
+ #define DEPRECATED_DATA_FREE RBIMPL_DATA_FUNC(-3)
3072
+
3073
+ const rb_data_type_t deprecated_rdata_type = {
3074
+ .wrap_struct_name = "RDATA(deprecated)" ,
3075
+ .function = {
3076
+ .dmark = mark_deprecated_rdata_object ,
3077
+ .dfree = DEPRECATED_DATA_FREE ,
3078
+ .dsize = memsize_deprecated_rdata_object ,
3079
+ },
3080
+ };
3081
+
3082
+ VALUE
3083
+ rb_data_object_wrap (VALUE klass , void * datap , RUBY_DATA_FUNC dmark , RUBY_DATA_FUNC dfree )
3084
+ {
3085
+ RUBY_ASSERT_ALWAYS (dfree != (RUBY_DATA_FUNC )1 );
3086
+ if (klass ) rb_data_object_check (klass );
3087
+
3088
+ VALUE obj = rb_data_typed_object_zalloc (klass , sizeof (struct RData ), & deprecated_rdata_type );
3089
+
3090
+ struct RData * rdata = (struct RData * )obj ;
3091
+ rdata -> dmark = dmark ;
3092
+ rdata -> dfree = dfree ;
3093
+ rdata -> data = datap ;
3094
+ return obj ;
3095
+ }
3096
+
3097
+ VALUE
3098
+ rb_data_object_zalloc (VALUE klass , size_t size , RUBY_DATA_FUNC dmark , RUBY_DATA_FUNC dfree )
3099
+ {
3100
+ VALUE obj = rb_data_object_wrap (klass , 0 , dmark , dfree );
3101
+ struct RData * rdata = (struct RData * )obj ;
3102
+ rdata -> data = xcalloc (1 , size );
3103
+ return obj ;
3104
+ }
3105
+
3071
3106
static int
3072
3107
ptr_in_page_body_p (const void * ptr , const void * memb )
3073
3108
{
@@ -3190,31 +3225,29 @@ obj_free_object_id(rb_objspace_t *objspace, VALUE obj)
3190
3225
}
3191
3226
3192
3227
static bool
3193
- rb_data_free (rb_objspace_t * objspace , VALUE obj )
3228
+ rb_typeddata_free (rb_objspace_t * objspace , VALUE obj )
3194
3229
{
3195
- void * data = RTYPEDDATA_P ( obj ) ? RTYPEDDATA_GET_DATA ( obj ) : DATA_PTR (obj );
3230
+ void * data = RTYPEDDATA_GET_DATA (obj );
3196
3231
if (data ) {
3197
3232
int free_immediately = false;
3198
- void (* dfree )(void * );
3199
3233
3200
- if (RTYPEDDATA_P (obj )) {
3201
- free_immediately = (RANY (obj )-> as .typeddata .type -> flags & RUBY_TYPED_FREE_IMMEDIATELY ) != 0 ;
3202
- dfree = RANY (obj )-> as .typeddata .type -> function .dfree ;
3203
- }
3204
- else {
3205
- dfree = RANY (obj )-> as .data .dfree ;
3234
+ free_immediately = (RANY (obj )-> as .typeddata .type -> flags & RUBY_TYPED_FREE_IMMEDIATELY ) != 0 ;
3235
+
3236
+ RUBY_DATA_FUNC dfree = RANY (obj )-> as .typeddata .type -> function .dfree ;
3237
+ if (UNLIKELY (dfree == DEPRECATED_DATA_FREE )) {
3238
+ dfree = RDATA (obj )-> dfree ;
3206
3239
}
3207
3240
3208
3241
if (dfree ) {
3209
3242
if (dfree == RUBY_DEFAULT_FREE ) {
3210
- if (!RTYPEDDATA_EMBEDDED_P (obj )) {
3243
+ if (!rbimpl_rtypeddata_embedded_p (obj )) {
3211
3244
xfree (data );
3212
3245
RB_DEBUG_COUNTER_INC (obj_data_xfree );
3213
3246
}
3214
3247
}
3215
3248
else if (free_immediately ) {
3216
3249
(* dfree )(data );
3217
- if (RTYPEDDATA_TYPE (obj )-> flags & RUBY_TYPED_EMBEDDABLE && !RTYPEDDATA_EMBEDDED_P (obj )) {
3250
+ if (RTYPEDDATA_TYPE (obj )-> flags & RUBY_TYPED_EMBEDDABLE && !rbimpl_rtypeddata_embedded_p (obj )) {
3218
3251
xfree (data );
3219
3252
}
3220
3253
@@ -3372,7 +3405,7 @@ obj_free(rb_objspace_t *objspace, VALUE obj)
3372
3405
}
3373
3406
break ;
3374
3407
case T_DATA :
3375
- if (!rb_data_free (objspace , obj )) return false;
3408
+ if (!rb_typeddata_free (objspace , obj )) return false;
3376
3409
break ;
3377
3410
case T_MATCH :
3378
3411
{
@@ -4339,7 +4372,7 @@ rb_objspace_call_finalizer_i(VALUE obj, void *data)
4339
4372
4340
4373
switch (BUILTIN_TYPE (obj )) {
4341
4374
case T_DATA :
4342
- if (!rb_free_at_exit && (!DATA_PTR (obj ) || !RANY (obj )-> as . data . dfree )) break ;
4375
+ if (!rb_free_at_exit && (!DATA_PTR (obj ) || !RDATA (obj )-> dfree )) break ;
4343
4376
if (rb_obj_is_thread (obj )) break ;
4344
4377
if (rb_obj_is_mutex (obj )) break ;
4345
4378
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