@@ -2915,14 +2915,38 @@ rb_imemo_name(enum imemo_type type)
29152915 return "unknown" ;
29162916}
29172917
2918+ static int
2919+ rb_shareable_imemo_type (enum imemo_type type )
2920+ {
2921+ switch (type ) {
2922+ case imemo_cref :
2923+ case imemo_ifunc :
2924+ case imemo_ment :
2925+ case imemo_iseq :
2926+ case imemo_callinfo :
2927+ case imemo_callcache :
2928+ case imemo_constcache :
2929+ return 1 ;
2930+ default :
2931+ return 0 ;
2932+ }
2933+ }
2934+
29182935#undef rb_imemo_new
29192936
2937+ void add_to_shareable_tbl (VALUE obj );
2938+
29202939VALUE
29212940rb_imemo_new (enum imemo_type type , VALUE v1 , VALUE v2 , VALUE v3 , VALUE v0 )
29222941{
29232942 size_t size = sizeof (RVALUE );
29242943 VALUE flags = T_IMEMO | (type << FL_USHIFT );
2925- return newobj_of (v0 , flags , v1 , v2 , v3 , TRUE, size );
2944+ VALUE obj = newobj_of (v0 , flags , v1 , v2 , v3 , TRUE, size );
2945+ if (rb_shareable_imemo_type (type )) {
2946+ FL_SET_RAW (obj , RUBY_FL_SHAREABLE );
2947+ add_to_shareable_tbl (obj );
2948+ }
2949+ return obj ;
29262950}
29272951
29282952static VALUE
@@ -6498,14 +6522,6 @@ mark_tbl(rb_objspace_t *objspace, st_table *tbl)
64986522 st_foreach (tbl , mark_value_pin , (st_data_t )objspace );
64996523}
65006524
6501- static int
6502- mark_key (st_data_t key , st_data_t value , st_data_t data )
6503- {
6504- rb_objspace_t * objspace = (rb_objspace_t * )data ;
6505- gc_mark (objspace , (VALUE )key );
6506- return ST_CONTINUE ;
6507- }
6508-
65096525static int
65106526mark_key_pin (st_data_t key , st_data_t value , st_data_t data )
65116527{
0 commit comments