@@ -2015,41 +2015,29 @@ object_id_to_ref(void *objspace_ptr, VALUE object_id)
2015
2015
static inline void
2016
2016
obj_free_object_id (VALUE obj )
2017
2017
{
2018
- if (RB_BUILTIN_TYPE (obj ) == T_IMEMO ) {
2019
- return ;
2020
- }
2021
-
2022
- #if RUBY_DEBUG
2023
- switch (BUILTIN_TYPE (obj )) {
2024
- case T_CLASS :
2025
- case T_MODULE :
2026
- break ;
2027
- default :
2028
- if (rb_shape_obj_has_id (obj )) {
2029
- VALUE id = object_id_get (obj , RBASIC_SHAPE_ID (obj )); // Crash if missing
2030
- if (!(FIXNUM_P (id ) || RB_TYPE_P (id , T_BIGNUM ))) {
2031
- rb_p (obj );
2032
- rb_bug ("Corrupted object_id" );
2033
- }
2034
- }
2035
- break ;
2036
- }
2037
- #endif
2038
-
2039
2018
VALUE obj_id = 0 ;
2040
2019
if (RB_UNLIKELY (id2ref_tbl )) {
2041
2020
switch (BUILTIN_TYPE (obj )) {
2042
2021
case T_CLASS :
2043
2022
case T_MODULE :
2044
2023
obj_id = RCLASS (obj )-> object_id ;
2045
2024
break ;
2046
- default : {
2025
+ case T_IMEMO :
2026
+ if (!IMEMO_TYPE_P (obj , imemo_fields )) {
2027
+ return ;
2028
+ }
2029
+ // fallthrough
2030
+ case T_OBJECT :
2031
+ {
2047
2032
shape_id_t shape_id = RBASIC_SHAPE_ID (obj );
2048
2033
if (rb_shape_has_object_id (shape_id )) {
2049
2034
obj_id = object_id_get (obj , shape_id );
2050
2035
}
2051
2036
break ;
2052
2037
}
2038
+ default :
2039
+ // For generic_fields, the T_IMEMO/fields is responsible for freeing the id.
2040
+ return ;
2053
2041
}
2054
2042
2055
2043
if (RB_UNLIKELY (obj_id )) {
@@ -2316,10 +2304,6 @@ rb_obj_memsize_of(VALUE obj)
2316
2304
return 0 ;
2317
2305
}
2318
2306
2319
- if (rb_obj_exivar_p (obj )) {
2320
- size += rb_generic_ivar_memsize (obj );
2321
- }
2322
-
2323
2307
switch (BUILTIN_TYPE (obj )) {
2324
2308
case T_OBJECT :
2325
2309
if (rb_shape_obj_too_complex_p (obj )) {
@@ -3936,38 +3920,6 @@ vm_weak_table_foreach_update_weak_value(st_data_t *key, st_data_t *value, st_dat
3936
3920
return iter_data -> update_callback ((VALUE * )value , iter_data -> data );
3937
3921
}
3938
3922
3939
- static void
3940
- free_gen_fields_tbl (VALUE obj , struct gen_fields_tbl * fields_tbl )
3941
- {
3942
- if (UNLIKELY (rb_shape_obj_too_complex_p (obj ))) {
3943
- st_free_table (fields_tbl -> as .complex .table );
3944
- }
3945
-
3946
- xfree (fields_tbl );
3947
- }
3948
-
3949
- static int
3950
- vm_weak_table_gen_fields_foreach_too_complex_i (st_data_t _key , st_data_t value , st_data_t data , int error )
3951
- {
3952
- struct global_vm_table_foreach_data * iter_data = (struct global_vm_table_foreach_data * )data ;
3953
-
3954
- GC_ASSERT (!iter_data -> weak_only );
3955
-
3956
- if (SPECIAL_CONST_P ((VALUE )value )) return ST_CONTINUE ;
3957
-
3958
- return iter_data -> callback ((VALUE )value , iter_data -> data );
3959
- }
3960
-
3961
- static int
3962
- vm_weak_table_gen_fields_foreach_too_complex_replace_i (st_data_t * _key , st_data_t * value , st_data_t data , int existing )
3963
- {
3964
- struct global_vm_table_foreach_data * iter_data = (struct global_vm_table_foreach_data * )data ;
3965
-
3966
- GC_ASSERT (!iter_data -> weak_only );
3967
-
3968
- return iter_data -> update_callback ((VALUE * )value , iter_data -> data );
3969
- }
3970
-
3971
3923
struct st_table * rb_generic_fields_tbl_get (void );
3972
3924
3973
3925
static int
@@ -4004,60 +3956,50 @@ vm_weak_table_gen_fields_foreach(st_data_t key, st_data_t value, st_data_t data)
4004
3956
4005
3957
int ret = iter_data -> callback ((VALUE )key , iter_data -> data );
4006
3958
3959
+ VALUE new_value = (VALUE )value ;
3960
+ VALUE new_key = (VALUE )key ;
3961
+
4007
3962
switch (ret ) {
4008
3963
case ST_CONTINUE :
4009
3964
break ;
4010
3965
4011
3966
case ST_DELETE :
4012
- free_gen_fields_tbl ((VALUE )key , (struct gen_fields_tbl * )value );
4013
3967
RBASIC_SET_SHAPE_ID ((VALUE )key , ROOT_SHAPE_ID );
4014
3968
return ST_DELETE ;
4015
3969
4016
3970
case ST_REPLACE : {
4017
- VALUE new_key = (VALUE )key ;
4018
3971
ret = iter_data -> update_callback (& new_key , iter_data -> data );
4019
- if (key != new_key ) ret = ST_DELETE ;
4020
- DURING_GC_COULD_MALLOC_REGION_START ();
4021
- {
4022
- st_insert (rb_generic_fields_tbl_get (), (st_data_t )new_key , value );
3972
+ if (key != new_key ) {
3973
+ ret = ST_DELETE ;
4023
3974
}
4024
- DURING_GC_COULD_MALLOC_REGION_END ();
4025
- key = (st_data_t )new_key ;
4026
3975
break ;
4027
3976
}
4028
3977
4029
3978
default :
4030
- return ret ;
3979
+ rb_bug ( "vm_weak_table_gen_fields_foreach: return value %d not supported" , ret ) ;
4031
3980
}
4032
3981
4033
3982
if (!iter_data -> weak_only ) {
4034
- struct gen_fields_tbl * fields_tbl = (struct gen_fields_tbl * )value ;
3983
+ int ivar_ret = iter_data -> callback (new_value , iter_data -> data );
3984
+ switch (ivar_ret ) {
3985
+ case ST_CONTINUE :
3986
+ break ;
4035
3987
4036
- if (rb_shape_obj_too_complex_p ((VALUE )key )) {
4037
- st_foreach_with_replace (
4038
- fields_tbl -> as .complex .table ,
4039
- vm_weak_table_gen_fields_foreach_too_complex_i ,
4040
- vm_weak_table_gen_fields_foreach_too_complex_replace_i ,
4041
- data
4042
- );
3988
+ case ST_REPLACE :
3989
+ iter_data -> update_callback (& new_value , iter_data -> data );
3990
+ break ;
3991
+
3992
+ default :
3993
+ rb_bug ("vm_weak_table_gen_fields_foreach: return value %d not supported" , ivar_ret );
4043
3994
}
4044
- else {
4045
- uint32_t fields_count = RSHAPE_LEN (RBASIC_SHAPE_ID ((VALUE )key ));
4046
- for (uint32_t i = 0 ; i < fields_count ; i ++ ) {
4047
- if (SPECIAL_CONST_P (fields_tbl -> as .shape .fields [i ])) continue ;
3995
+ }
4048
3996
4049
- int ivar_ret = iter_data -> callback (fields_tbl -> as .shape .fields [i ], iter_data -> data );
4050
- switch (ivar_ret ) {
4051
- case ST_CONTINUE :
4052
- break ;
4053
- case ST_REPLACE :
4054
- iter_data -> update_callback (& fields_tbl -> as .shape .fields [i ], iter_data -> data );
4055
- break ;
4056
- default :
4057
- rb_bug ("vm_weak_table_gen_fields_foreach: return value %d not supported" , ivar_ret );
4058
- }
4059
- }
3997
+ if (key != new_key || value != new_value ) {
3998
+ DURING_GC_COULD_MALLOC_REGION_START ();
3999
+ {
4000
+ st_insert (rb_generic_fields_tbl_get (), (st_data_t )new_key , new_value );
4060
4001
}
4002
+ DURING_GC_COULD_MALLOC_REGION_END ();
4061
4003
}
4062
4004
4063
4005
return ret ;
0 commit comments