@@ -2036,28 +2036,54 @@ ruby_stack_check(void)
20362036
20372037/* ==================== Marking ==================== */
20382038
2039+ static inline void
2040+ gc_mark_internal (void * objspace , VALUE obj )
2041+ {
2042+ if (RB_SPECIAL_CONST_P (obj )) return ;
2043+
2044+ rb_gc_impl_mark (objspace , obj );
2045+ }
2046+
20392047void
20402048rb_gc_mark_movable (VALUE obj )
20412049{
2042- rb_gc_impl_mark (rb_gc_get_objspace (), obj );
2050+ gc_mark_internal (rb_gc_get_objspace (), obj );
20432051}
20442052
20452053void
20462054rb_gc_mark_and_move (VALUE * ptr )
20472055{
2056+ if (SPECIAL_CONST_P (* ptr )) return ;
2057+
20482058 rb_gc_impl_mark_and_move (rb_gc_get_objspace (), ptr );
20492059}
20502060
2061+ static inline void
2062+ gc_mark_and_pin_internal (void * objspace , VALUE obj )
2063+ {
2064+ if (RB_SPECIAL_CONST_P (obj )) return ;
2065+
2066+ rb_gc_impl_mark_and_pin (objspace , obj );
2067+ }
2068+
20512069void
20522070rb_gc_mark (VALUE obj )
20532071{
2054- rb_gc_impl_mark_and_pin (rb_gc_get_objspace (), obj );
2072+ gc_mark_and_pin_internal (rb_gc_get_objspace (), obj );
2073+ }
2074+
2075+ static inline void
2076+ gc_mark_maybe_internal (void * objspace , VALUE obj )
2077+ {
2078+ if (RB_SPECIAL_CONST_P (obj )) return ;
2079+
2080+ rb_gc_impl_mark_maybe (objspace , obj );
20552081}
20562082
20572083void
20582084rb_gc_mark_maybe (VALUE obj )
20592085{
2060- rb_gc_impl_mark_maybe (rb_gc_get_objspace (), obj );
2086+ gc_mark_maybe_internal (rb_gc_get_objspace (), obj );
20612087}
20622088
20632089void
@@ -2097,22 +2123,22 @@ gc_mark_locations(void *objspace, const VALUE *start, const VALUE *end, void (*c
20972123void
20982124rb_gc_mark_locations (const VALUE * start , const VALUE * end )
20992125{
2100- gc_mark_locations (rb_gc_get_objspace (), start , end , rb_gc_impl_mark_maybe );
2126+ gc_mark_locations (rb_gc_get_objspace (), start , end , gc_mark_maybe_internal );
21012127}
21022128
21032129void
21042130rb_gc_mark_values (long n , const VALUE * values )
21052131{
21062132 for (long i = 0 ; i < n ; i ++ ) {
2107- rb_gc_impl_mark (rb_gc_get_objspace (), values [i ]);
2133+ gc_mark_internal (rb_gc_get_objspace (), values [i ]);
21082134 }
21092135}
21102136
21112137void
21122138rb_gc_mark_vm_stack_values (long n , const VALUE * values )
21132139{
21142140 for (long i = 0 ; i < n ; i ++ ) {
2115- rb_gc_impl_mark_and_pin (rb_gc_get_objspace (), values [i ]);
2141+ gc_mark_and_pin_internal (rb_gc_get_objspace (), values [i ]);
21162142 }
21172143}
21182144
@@ -2121,7 +2147,7 @@ mark_key(st_data_t key, st_data_t value, st_data_t data)
21212147{
21222148 void * objspace = (void * )data ;
21232149
2124- rb_gc_impl_mark_and_pin (objspace , (VALUE )key );
2150+ gc_mark_and_pin_internal (objspace , (VALUE )key );
21252151
21262152 return ST_CONTINUE ;
21272153}
@@ -2139,8 +2165,8 @@ mark_keyvalue(st_data_t key, st_data_t value, st_data_t data)
21392165{
21402166 void * objspace = (void * )data ;
21412167
2142- rb_gc_impl_mark (objspace , (VALUE )key );
2143- rb_gc_impl_mark (objspace , (VALUE )value );
2168+ gc_mark_internal (objspace , (VALUE )key );
2169+ gc_mark_internal (objspace , (VALUE )value );
21442170
21452171 return ST_CONTINUE ;
21462172}
@@ -2150,8 +2176,8 @@ pin_key_pin_value(st_data_t key, st_data_t value, st_data_t data)
21502176{
21512177 void * objspace = (void * )data ;
21522178
2153- rb_gc_impl_mark_and_pin (objspace , (VALUE )key );
2154- rb_gc_impl_mark_and_pin (objspace , (VALUE )value );
2179+ gc_mark_and_pin_internal (objspace , (VALUE )key );
2180+ gc_mark_and_pin_internal (objspace , (VALUE )value );
21552181
21562182 return ST_CONTINUE ;
21572183}
@@ -2161,8 +2187,8 @@ pin_key_mark_value(st_data_t key, st_data_t value, st_data_t data)
21612187{
21622188 void * objspace = (void * )data ;
21632189
2164- rb_gc_impl_mark_and_pin (objspace , (VALUE )key );
2165- rb_gc_impl_mark (objspace , (VALUE )value );
2190+ gc_mark_and_pin_internal (objspace , (VALUE )key );
2191+ gc_mark_internal (objspace , (VALUE )value );
21662192
21672193 return ST_CONTINUE ;
21682194}
@@ -2177,7 +2203,7 @@ mark_hash(void *objspace, VALUE hash)
21772203 rb_hash_stlike_foreach (hash , mark_keyvalue , (st_data_t )objspace );
21782204 }
21792205
2180- rb_gc_impl_mark (objspace , RHASH (hash )-> ifnone );
2206+ gc_mark_internal (objspace , RHASH (hash )-> ifnone );
21812207}
21822208
21832209void
@@ -2191,7 +2217,7 @@ rb_mark_hash(st_table *tbl)
21912217static enum rb_id_table_iterator_result
21922218mark_method_entry_i (VALUE me , void * objspace )
21932219{
2194- rb_gc_impl_mark (objspace , me );
2220+ gc_mark_internal (objspace , me );
21952221
21962222 return ID_TABLE_CONTINUE ;
21972223}
@@ -2239,7 +2265,7 @@ gc_mark_machine_stack_location_maybe(void *data, VALUE obj)
22392265{
22402266 void * objspace = ((struct mark_machine_stack_location_maybe_data * )data )-> objspace ;
22412267
2242- rb_gc_impl_mark_maybe (objspace , obj );
2268+ gc_mark_maybe_internal (objspace , obj );
22432269
22442270#ifdef RUBY_ASAN_ENABLED
22452271 const rb_execution_context_t * ec = ((struct mark_machine_stack_location_maybe_data * )data )-> ec ;
@@ -2251,7 +2277,7 @@ gc_mark_machine_stack_location_maybe(void *data, VALUE obj)
22512277 & fake_frame_start , & fake_frame_end
22522278 );
22532279 if (is_fake_frame ) {
2254- each_stack_location (objspace , ec , fake_frame_start , fake_frame_end , rb_gc_impl_mark_maybe );
2280+ each_stack_location (objspace , ec , fake_frame_start , fake_frame_end , gc_mark_maybe_internal );
22552281 }
22562282#endif
22572283}
@@ -2274,10 +2300,10 @@ static void
22742300mark_current_machine_context (void * objspace , rb_execution_context_t * ec )
22752301{
22762302 emscripten_scan_stack (rb_mark_locations );
2277- each_stack_location (objspace , ec , rb_stack_range_tmp [0 ], rb_stack_range_tmp [1 ], rb_gc_impl_mark_maybe );
2303+ each_stack_location (objspace , ec , rb_stack_range_tmp [0 ], rb_stack_range_tmp [1 ], gc_mark_maybe_internal );
22782304
22792305 emscripten_scan_registers (rb_mark_locations );
2280- each_stack_location (objspace , ec , rb_stack_range_tmp [0 ], rb_stack_range_tmp [1 ], rb_gc_impl_mark_maybe );
2306+ each_stack_location (objspace , ec , rb_stack_range_tmp [0 ], rb_stack_range_tmp [1 ], gc_mark_maybe_internal );
22812307}
22822308# else // use Asyncify version
22832309
@@ -2287,10 +2313,10 @@ mark_current_machine_context(void *objspace, rb_execution_context_t *ec)
22872313 VALUE * stack_start , * stack_end ;
22882314 SET_STACK_END ;
22892315 GET_STACK_BOUNDS (stack_start , stack_end , 1 );
2290- each_stack_location (objspace , ec , stack_start , stack_end , rb_gc_impl_mark_maybe );
2316+ each_stack_location (objspace , ec , stack_start , stack_end , gc_mark_maybe_internal );
22912317
22922318 rb_wasm_scan_locals (rb_mark_locations );
2293- each_stack_location (objspace , ec , rb_stack_range_tmp [0 ], rb_stack_range_tmp [1 ], rb_gc_impl_mark_maybe );
2319+ each_stack_location (objspace , ec , rb_stack_range_tmp [0 ], rb_stack_range_tmp [1 ], gc_mark_maybe_internal );
22942320}
22952321
22962322# endif
@@ -2354,7 +2380,7 @@ rb_mark_tbl_i(st_data_t key, st_data_t value, st_data_t data)
23542380{
23552381 void * objspace = (void * )data ;
23562382
2357- rb_gc_impl_mark_and_pin (objspace , (VALUE )value );
2383+ gc_mark_and_pin_internal (objspace , (VALUE )value );
23582384
23592385 return ST_CONTINUE ;
23602386}
@@ -2389,7 +2415,7 @@ mark_cvc_tbl_i(VALUE cvc_entry, void *objspace)
23892415 entry = (struct rb_cvar_class_tbl_entry * )cvc_entry ;
23902416
23912417 RUBY_ASSERT (entry -> cref == 0 || (BUILTIN_TYPE ((VALUE )entry -> cref ) == T_IMEMO && IMEMO_TYPE_P (entry -> cref , imemo_cref )));
2392- rb_gc_impl_mark (objspace , (VALUE )entry -> cref );
2418+ gc_mark_internal (objspace , (VALUE )entry -> cref );
23932419
23942420 return ID_TABLE_CONTINUE ;
23952421}
@@ -2414,8 +2440,8 @@ mark_const_table_i(VALUE value, void *objspace)
24142440{
24152441 const rb_const_entry_t * ce = (const rb_const_entry_t * )value ;
24162442
2417- rb_gc_impl_mark (objspace , ce -> value );
2418- rb_gc_impl_mark (objspace , ce -> file );
2443+ gc_mark_internal (objspace , ce -> value );
2444+ gc_mark_internal (objspace , ce -> file );
24192445
24202446 return ID_TABLE_CONTINUE ;
24212447}
@@ -2432,7 +2458,7 @@ rb_gc_mark_roots(void *objspace, const char **categoryp)
24322458
24332459 MARK_CHECKPOINT ("vm" );
24342460 rb_vm_mark (vm );
2435- if (vm -> self ) rb_gc_impl_mark (objspace , vm -> self );
2461+ if (vm -> self ) gc_mark_internal (objspace , vm -> self );
24362462
24372463 MARK_CHECKPOINT ("machine_context" );
24382464 mark_current_machine_context (objspace , ec );
@@ -2490,17 +2516,17 @@ rb_gc_mark_children(void *objspace, VALUE obj)
24902516 break ;
24912517 }
24922518
2493- rb_gc_impl_mark (objspace , RBASIC (obj )-> klass );
2519+ gc_mark_internal (objspace , RBASIC (obj )-> klass );
24942520
24952521 switch (BUILTIN_TYPE (obj )) {
24962522 case T_CLASS :
24972523 if (FL_TEST (obj , FL_SINGLETON )) {
2498- rb_gc_impl_mark (objspace , RCLASS_ATTACHED_OBJECT (obj ));
2524+ gc_mark_internal (objspace , RCLASS_ATTACHED_OBJECT (obj ));
24992525 }
25002526 // Continue to the shared T_CLASS/T_MODULE
25012527 case T_MODULE :
25022528 if (RCLASS_SUPER (obj )) {
2503- rb_gc_impl_mark (objspace , RCLASS_SUPER (obj ));
2529+ gc_mark_internal (objspace , RCLASS_SUPER (obj ));
25042530 }
25052531
25062532 mark_m_tbl (objspace , RCLASS_M_TBL (obj ));
@@ -2511,27 +2537,27 @@ rb_gc_mark_children(void *objspace, VALUE obj)
25112537 }
25122538 else {
25132539 for (attr_index_t i = 0 ; i < RCLASS_IV_COUNT (obj ); i ++ ) {
2514- rb_gc_impl_mark (objspace , RCLASS_IVPTR (obj )[i ]);
2540+ gc_mark_internal (objspace , RCLASS_IVPTR (obj )[i ]);
25152541 }
25162542 }
25172543
25182544 if (RCLASS_CONST_TBL (obj )) {
25192545 rb_id_table_foreach_values (RCLASS_CONST_TBL (obj ), mark_const_table_i , objspace );
25202546 }
25212547
2522- rb_gc_impl_mark (objspace , RCLASS_EXT (obj )-> classpath );
2548+ gc_mark_internal (objspace , RCLASS_EXT (obj )-> classpath );
25232549 break ;
25242550
25252551 case T_ICLASS :
25262552 if (RICLASS_OWNS_M_TBL_P (obj )) {
25272553 mark_m_tbl (objspace , RCLASS_M_TBL (obj ));
25282554 }
25292555 if (RCLASS_SUPER (obj )) {
2530- rb_gc_impl_mark (objspace , RCLASS_SUPER (obj ));
2556+ gc_mark_internal (objspace , RCLASS_SUPER (obj ));
25312557 }
25322558
25332559 if (RCLASS_INCLUDER (obj )) {
2534- rb_gc_impl_mark (objspace , RCLASS_INCLUDER (obj ));
2560+ gc_mark_internal (objspace , RCLASS_INCLUDER (obj ));
25352561 }
25362562 mark_m_tbl (objspace , RCLASS_CALLABLE_M_TBL (obj ));
25372563 rb_cc_table_mark (obj );
@@ -2540,13 +2566,13 @@ rb_gc_mark_children(void *objspace, VALUE obj)
25402566 case T_ARRAY :
25412567 if (ARY_SHARED_P (obj )) {
25422568 VALUE root = ARY_SHARED_ROOT (obj );
2543- rb_gc_impl_mark (objspace , root );
2569+ gc_mark_internal (objspace , root );
25442570 }
25452571 else {
25462572 long len = RARRAY_LEN (obj );
25472573 const VALUE * ptr = RARRAY_CONST_PTR (obj );
25482574 for (long i = 0 ; i < len ; i ++ ) {
2549- rb_gc_impl_mark (objspace , ptr [i ]);
2575+ gc_mark_internal (objspace , ptr [i ]);
25502576 }
25512577 }
25522578 break ;
@@ -2562,10 +2588,10 @@ rb_gc_mark_children(void *objspace, VALUE obj)
25622588 * points into the slot of the shared string. There may be code
25632589 * using the RSTRING_PTR on the stack, which would pin this
25642590 * string but not pin the shared string, causing it to move. */
2565- rb_gc_impl_mark_and_pin (objspace , RSTRING (obj )-> as .heap .aux .shared );
2591+ gc_mark_and_pin_internal (objspace , RSTRING (obj )-> as .heap .aux .shared );
25662592 }
25672593 else {
2568- rb_gc_impl_mark (objspace , RSTRING (obj )-> as .heap .aux .shared );
2594+ gc_mark_internal (objspace , RSTRING (obj )-> as .heap .aux .shared );
25692595 }
25702596 }
25712597 break ;
@@ -2578,7 +2604,7 @@ rb_gc_mark_children(void *objspace, VALUE obj)
25782604 size_t * offset_list = (size_t * )RTYPEDDATA (obj )-> type -> function .dmark ;
25792605
25802606 for (size_t offset = * offset_list ; offset != RUBY_REF_END ; offset = * offset_list ++ ) {
2581- rb_gc_impl_mark (objspace , * (VALUE * )((char * )ptr + offset ));
2607+ gc_mark_internal (objspace , * (VALUE * )((char * )ptr + offset ));
25822608 }
25832609 }
25842610 else {
@@ -2603,7 +2629,7 @@ rb_gc_mark_children(void *objspace, VALUE obj)
26032629
26042630 uint32_t len = ROBJECT_IV_COUNT (obj );
26052631 for (uint32_t i = 0 ; i < len ; i ++ ) {
2606- rb_gc_impl_mark (objspace , ptr [i ]);
2632+ gc_mark_internal (objspace , ptr [i ]);
26072633 }
26082634 }
26092635
@@ -2622,44 +2648,44 @@ rb_gc_mark_children(void *objspace, VALUE obj)
26222648
26232649 case T_FILE :
26242650 if (RFILE (obj )-> fptr ) {
2625- rb_gc_impl_mark (objspace , RFILE (obj )-> fptr -> self );
2626- rb_gc_impl_mark (objspace , RFILE (obj )-> fptr -> pathv );
2627- rb_gc_impl_mark (objspace , RFILE (obj )-> fptr -> tied_io_for_writing );
2628- rb_gc_impl_mark (objspace , RFILE (obj )-> fptr -> writeconv_asciicompat );
2629- rb_gc_impl_mark (objspace , RFILE (obj )-> fptr -> writeconv_pre_ecopts );
2630- rb_gc_impl_mark (objspace , RFILE (obj )-> fptr -> encs .ecopts );
2631- rb_gc_impl_mark (objspace , RFILE (obj )-> fptr -> write_lock );
2632- rb_gc_impl_mark (objspace , RFILE (obj )-> fptr -> timeout );
2651+ gc_mark_internal (objspace , RFILE (obj )-> fptr -> self );
2652+ gc_mark_internal (objspace , RFILE (obj )-> fptr -> pathv );
2653+ gc_mark_internal (objspace , RFILE (obj )-> fptr -> tied_io_for_writing );
2654+ gc_mark_internal (objspace , RFILE (obj )-> fptr -> writeconv_asciicompat );
2655+ gc_mark_internal (objspace , RFILE (obj )-> fptr -> writeconv_pre_ecopts );
2656+ gc_mark_internal (objspace , RFILE (obj )-> fptr -> encs .ecopts );
2657+ gc_mark_internal (objspace , RFILE (obj )-> fptr -> write_lock );
2658+ gc_mark_internal (objspace , RFILE (obj )-> fptr -> timeout );
26332659 }
26342660 break ;
26352661
26362662 case T_REGEXP :
2637- rb_gc_impl_mark (objspace , RREGEXP (obj )-> src );
2663+ gc_mark_internal (objspace , RREGEXP (obj )-> src );
26382664 break ;
26392665
26402666 case T_MATCH :
2641- rb_gc_impl_mark (objspace , RMATCH (obj )-> regexp );
2667+ gc_mark_internal (objspace , RMATCH (obj )-> regexp );
26422668 if (RMATCH (obj )-> str ) {
2643- rb_gc_impl_mark (objspace , RMATCH (obj )-> str );
2669+ gc_mark_internal (objspace , RMATCH (obj )-> str );
26442670 }
26452671 break ;
26462672
26472673 case T_RATIONAL :
2648- rb_gc_impl_mark (objspace , RRATIONAL (obj )-> num );
2649- rb_gc_impl_mark (objspace , RRATIONAL (obj )-> den );
2674+ gc_mark_internal (objspace , RRATIONAL (obj )-> num );
2675+ gc_mark_internal (objspace , RRATIONAL (obj )-> den );
26502676 break ;
26512677
26522678 case T_COMPLEX :
2653- rb_gc_impl_mark (objspace , RCOMPLEX (obj )-> real );
2654- rb_gc_impl_mark (objspace , RCOMPLEX (obj )-> imag );
2679+ gc_mark_internal (objspace , RCOMPLEX (obj )-> real );
2680+ gc_mark_internal (objspace , RCOMPLEX (obj )-> imag );
26552681 break ;
26562682
26572683 case T_STRUCT : {
26582684 const long len = RSTRUCT_LEN (obj );
26592685 const VALUE * const ptr = RSTRUCT_CONST_PTR (obj );
26602686
26612687 for (long i = 0 ; i < len ; i ++ ) {
2662- rb_gc_impl_mark (objspace , ptr [i ]);
2688+ gc_mark_internal (objspace , ptr [i ]);
26632689 }
26642690
26652691 break ;
0 commit comments