mirror of
				https://github.com/ruby/ruby.git
				synced 2022-11-09 12:17:21 -05:00 
			
		
		
		
	call const_added after autoload
				
					
				
			When calling `const_added` while process in `autoload`, it can cause synchronization issue because of a thread swithcing. http://ci.rvm.jp/logfiles/brlog.trunk.20220407-152213#L489 ``` 1) Module#autoload (concurrently) raises a LoadError in each thread if the file does not exist ERROR NameError: uninitialized constant ModuleSpecs::Autoload::FileDoesNotExist ModuleSpecs::Autoload::FileDoesNotExist ^^^^^^^^^^^^^^^^^^ /tmp/ruby/v3/src/trunk/spec/ruby/core/module/autoload_spec.rb:965:in `block (5 levels) in <top (required)>' ```
This commit is contained in:
		
							parent
							
								
									798e21637f
								
							
						
					
					
						commit
						c77a31df5e
					
				
				
				Notes:
				
					git
				
				2022-04-08 21:30:52 +09:00 
				
			
			
			
		
		
					 1 changed files with 21 additions and 10 deletions
				
			
		
							
								
								
									
										17
									
								
								variable.c
									
										
									
									
									
								
							
							
						
						
									
										17
									
								
								variable.c
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -2239,6 +2239,9 @@ rb_autoload(VALUE mod, ID id, const char *file)
 | 
			
		|||
    rb_autoload_str(mod, id, rb_fstring_cstr(file));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void const_set(VALUE klass, ID id, VALUE val);
 | 
			
		||||
static void const_added(VALUE klass, ID const_name);
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
rb_autoload_str(VALUE mod, ID id, VALUE file)
 | 
			
		||||
{
 | 
			
		||||
| 
						 | 
				
			
			@ -2263,7 +2266,7 @@ rb_autoload_str(VALUE mod, ID id, VALUE file)
 | 
			
		|||
	return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    rb_const_set(mod, id, Qundef);
 | 
			
		||||
    const_set(mod, id, Qundef);
 | 
			
		||||
    tbl = RCLASS_IV_TBL(mod);
 | 
			
		||||
    if (tbl && st_lookup(tbl, (st_data_t)autoload, &av)) {
 | 
			
		||||
	tbl = check_autoload_table((VALUE)av);
 | 
			
		||||
| 
						 | 
				
			
			@ -2307,6 +2310,8 @@ rb_autoload_str(VALUE mod, ID id, VALUE file)
 | 
			
		|||
        ccan_list_add_tail(&ele->constants, &ac->cnode);
 | 
			
		||||
        st_insert(tbl, (st_data_t)id, (st_data_t)acv);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    const_added(mod, id);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
| 
						 | 
				
			
			@ -3111,8 +3116,8 @@ const_added(VALUE klass, ID const_name)
 | 
			
		|||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
rb_const_set(VALUE klass, ID id, VALUE val)
 | 
			
		||||
static void
 | 
			
		||||
const_set(VALUE klass, ID id, VALUE val)
 | 
			
		||||
{
 | 
			
		||||
    rb_const_entry_t *ce;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -3175,6 +3180,12 @@ rb_const_set(VALUE klass, ID id, VALUE val)
 | 
			
		|||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
rb_const_set(VALUE klass, ID id, VALUE val)
 | 
			
		||||
{
 | 
			
		||||
    const_set(klass, id, val);
 | 
			
		||||
    const_added(klass, id);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue