mirror of
				https://github.com/ruby/ruby.git
				synced 2022-11-09 12:17:21 -05:00 
			
		
		
		
	@@cv is not accessible from non-main ractors
Class variables (@@cv) is not accessible from non-main ractors. But without this patch cached @@cv can be read. fix [Bug #18128]
This commit is contained in:
		
							parent
							
								
									e029560b22
								
							
						
					
					
						commit
						6050e3e2a6
					
				
				
				Notes:
				
					git
				
				2021-12-24 13:52:21 +09:00 
				
			
			
			
		
		
					 2 changed files with 25 additions and 1 deletions
				
			
		| 
						 | 
				
			
			@ -1101,6 +1101,28 @@ assert_equal 'can not access class variables from non-main Ractors', %q{
 | 
			
		|||
  end
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
# also cached cvar in shareable-objects are not allowed to access from non-main Ractor
 | 
			
		||||
assert_equal 'can not access class variables from non-main Ractors', %q{
 | 
			
		||||
  class C
 | 
			
		||||
    @@cv = 'str'
 | 
			
		||||
    def self.cv
 | 
			
		||||
      @@cv
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  C.cv # cache
 | 
			
		||||
 | 
			
		||||
  r = Ractor.new do
 | 
			
		||||
    C.cv
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  begin
 | 
			
		||||
    r.take
 | 
			
		||||
  rescue Ractor::RemoteError => e
 | 
			
		||||
    e.cause.message
 | 
			
		||||
  end
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
# Getting non-shareable objects via constants by other Ractors is not allowed
 | 
			
		||||
assert_equal 'can not access non-shareable objects in constant C::CONST by non-main Ractor.', %q{
 | 
			
		||||
  class C
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1320,7 +1320,9 @@ vm_getclassvariable(const rb_iseq_t *iseq, const rb_control_frame_t *reg_cfp, ID
 | 
			
		|||
        VALUE v = Qundef;
 | 
			
		||||
        RB_DEBUG_COUNTER_INC(cvar_read_inline_hit);
 | 
			
		||||
 | 
			
		||||
        if (st_lookup(RCLASS_IV_TBL(ic->entry->class_value), (st_data_t)id, &v)) {
 | 
			
		||||
        if (st_lookup(RCLASS_IV_TBL(ic->entry->class_value), (st_data_t)id, &v) &&
 | 
			
		||||
            LIKELY(rb_ractor_main_p())) {
 | 
			
		||||
 | 
			
		||||
            return v;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue