@@ -596,6 +596,7 @@ rb_find_global_entry(ID id)
596596 }
597597
598598 if (UNLIKELY (!rb_ractor_main_p ()) && (!entry || !entry -> ractor_local )) {
599+ if (RB_VM_LOCKED_P ()) RB_VM_UNLOCK_ALL ();
599600 rb_raise (rb_eRactorIsolationError , "can not access global variable %s from non-main Ractor" , rb_id2name (id ));
600601 }
601602
@@ -653,7 +654,11 @@ rb_global_entry(ID id)
653654VALUE
654655rb_gvar_undef_getter (ID id , VALUE * _ )
655656{
656- rb_warning ("global variable '%" PRIsVALUE "' not initialized" , QUOTE_ID (id ));
657+ RB_VM_UNLOCK ();
658+ {
659+ rb_warning ("global variable '%" PRIsVALUE "' not initialized" , QUOTE_ID (id ));
660+ }
661+ RB_VM_LOCK ();
657662
658663 return Qnil ;
659664}
@@ -732,6 +737,7 @@ rb_gvar_var_marker(VALUE *var)
732737void
733738rb_gvar_readonly_setter (VALUE v , ID id , VALUE * _ )
734739{
740+ RB_VM_UNLOCK ();
735741 rb_name_error (id , "%" PRIsVALUE " is a read-only variable" , QUOTE_ID (id ));
736742}
737743
@@ -1165,6 +1171,7 @@ rb_alias_variable(ID name1, ID name2)
11651171 else if ((entry1 = (struct rb_global_entry * )data1 )-> var != entry2 -> var ) {
11661172 struct rb_global_variable * var = entry1 -> var ;
11671173 if (var -> block_trace ) {
1174+ RB_VM_UNLOCK ();
11681175 rb_raise (rb_eRuntimeError , "can't alias in tracer" );
11691176 }
11701177 var -> counter -- ;
@@ -3857,7 +3864,6 @@ static void
38573864const_added (VALUE klass , ID const_name )
38583865{
38593866 if (GET_VM ()-> running ) {
3860- ASSERT_vm_unlocking ();
38613867 VALUE name = ID2SYM (const_name );
38623868 rb_funcallv (klass , idConst_added , 1 , & name );
38633869 }
@@ -3992,14 +3998,28 @@ const_tbl_update(struct autoload_const *ac, int autoload_force)
39923998 else {
39933999 VALUE name = QUOTE_ID (id );
39944000 visibility = ce -> flag ;
3995- if (klass == rb_cObject )
3996- rb_warn ("already initialized constant %" PRIsVALUE "" , name );
3997- else
3998- rb_warn ("already initialized constant %" PRIsVALUE "::%" PRIsVALUE "" ,
3999- rb_class_name (klass ), name );
4001+ if (klass == rb_cObject ) {
4002+ RB_VM_UNLOCK ();
4003+ {
4004+ rb_warn ("already initialized constant %" PRIsVALUE "" , name );
4005+ }
4006+ RB_VM_LOCK ();
4007+ }
4008+ else {
4009+ RB_VM_UNLOCK ();
4010+ {
4011+ rb_warn ("already initialized constant %" PRIsVALUE "::%" PRIsVALUE "" ,
4012+ rb_class_name (klass ), name );
4013+ }
4014+ RB_VM_LOCK ();
4015+ }
40004016 if (!NIL_P (ce -> file ) && ce -> line ) {
4001- rb_compile_warn (RSTRING_PTR (ce -> file ), ce -> line ,
4002- "previous definition of %" PRIsVALUE " was here" , name );
4017+ RB_VM_UNLOCK ();
4018+ {
4019+ rb_compile_warn (RSTRING_PTR (ce -> file ), ce -> line ,
4020+ "previous definition of %" PRIsVALUE " was here" , name );
4021+ }
4022+ RB_VM_LOCK ();
40034023 }
40044024 }
40054025 rb_clear_constant_cache_for_id (id );
0 commit comments