mirror of
				https://github.com/ruby/ruby.git
				synced 2022-11-09 12:17:21 -05:00 
			
		
		
		
	Revert "don't embed full-path."
This reverts commit dfac2e9eb3.
It does not work if cwd is different from builddir...
			
			
This commit is contained in:
		
							parent
							
								
									dfac2e9eb3
								
							
						
					
					
						commit
						b5d8849220
					
				
					 4 changed files with 6 additions and 27 deletions
				
			
		| 
						 | 
					@ -18,7 +18,7 @@ builtin_lookup(const char *feature, size_t *psize)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void
 | 
					void
 | 
				
			||||||
rb_load_with_builtin_functions(const char *feature_name, const struct rb_builtin_function *table)
 | 
					rb_load_with_builtin_functions(const char *feature_name, const char *fname, const struct rb_builtin_function *table)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    // search binary
 | 
					    // search binary
 | 
				
			||||||
    size_t size;
 | 
					    size_t size;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -12,7 +12,7 @@ struct rb_builtin_function {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define RB_BUILTIN_FUNCTION(_i, _name, _arity) { .name = #_name, .func_ptr = (void *)_name, .argc = _arity, .index = _i }
 | 
					#define RB_BUILTIN_FUNCTION(_i, _name, _arity) { .name = #_name, .func_ptr = (void *)_name, .argc = _arity, .index = _i }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void rb_load_with_builtin_functions(const char *feature_name, const struct rb_builtin_function *table);
 | 
					void rb_load_with_builtin_functions(const char *feature_name, const char *fname, const struct rb_builtin_function *table);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifndef VM_CORE_H_EC_DEFINED
 | 
					#ifndef VM_CORE_H_EC_DEFINED
 | 
				
			||||||
typedef struct rb_execution_context_struct rb_execution_context_t;
 | 
					typedef struct rb_execution_context_struct rb_execution_context_t;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -36,23 +36,12 @@ read_file(const char *fname, size_t *psize)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static struct st_table *loaded_builtin_table;
 | 
					static struct st_table *loaded_builtin_table;
 | 
				
			||||||
static char srcdir[0x200];
 | 
					 | 
				
			||||||
static const char fname[] = "mini_builtin.c";
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static const char *
 | 
					 | 
				
			||||||
feature_path(const char *name)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    static char path[0x200];
 | 
					 | 
				
			||||||
    snprintf(path, 0x200-1, "%s%s.rb", srcdir, name);
 | 
					 | 
				
			||||||
    // fprintf(stderr, "srcdir:%s, path:%s, PATH_SEP_CHAR:%c\n", srcdir, path, PATH_SEP_CHAR);
 | 
					 | 
				
			||||||
    return path;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
void
 | 
					void
 | 
				
			||||||
rb_load_with_builtin_functions(const char *feature_name, const struct rb_builtin_function *table)
 | 
					rb_load_with_builtin_functions(const char *feature_name, const char *fname, const struct rb_builtin_function *table)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    size_t fsize;
 | 
					    size_t fsize;
 | 
				
			||||||
    const char *code = read_file(feature_path(feature_name), &fsize);
 | 
					    const char *code = read_file(fname, &fsize);
 | 
				
			||||||
    VALUE code_str = rb_utf8_str_new_static(code, fsize);
 | 
					    VALUE code_str = rb_utf8_str_new_static(code, fsize);
 | 
				
			||||||
    VALUE name_str = rb_sprintf("<internal:%s>", feature_name);
 | 
					    VALUE name_str = rb_sprintf("<internal:%s>", feature_name);
 | 
				
			||||||
    rb_obj_hide(code_str);
 | 
					    rb_obj_hide(code_str);
 | 
				
			||||||
| 
						 | 
					@ -97,15 +86,4 @@ Init_builtin(void)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    rb_define_singleton_method(rb_cRubyVM, "each_builtin", each_builtin, 0);
 | 
					    rb_define_singleton_method(rb_cRubyVM, "each_builtin", each_builtin, 0);
 | 
				
			||||||
    loaded_builtin_table = st_init_strtable();
 | 
					    loaded_builtin_table = st_init_strtable();
 | 
				
			||||||
 | 
					 | 
				
			||||||
    // check srcdir
 | 
					 | 
				
			||||||
    // assume __FILE__ encoding is ASCII compatible.
 | 
					 | 
				
			||||||
    int pos = strlen(__FILE__) - strlen(fname);
 | 
					 | 
				
			||||||
    if (pos < 0) rb_bug("strlen(%s) - strlen(%s) < 0", __FILE__, fname);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    if (strcmp(__FILE__ + pos, fname) != 0) {
 | 
					 | 
				
			||||||
        rb_bug("%s does not terminate with %s\n", __FILE__, fname);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    strncpy(srcdir, __FILE__, 0x200-1);
 | 
					 | 
				
			||||||
    srcdir[pos] = 0;
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -67,9 +67,10 @@ def mk_builtin_header file
 | 
				
			||||||
    f.puts "COMPILER_WARNING_POP"
 | 
					    f.puts "COMPILER_WARNING_POP"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    path = File.expand_path(file)
 | 
				
			||||||
    f.puts
 | 
					    f.puts
 | 
				
			||||||
    f.puts "  // load"
 | 
					    f.puts "  // load"
 | 
				
			||||||
    f.puts "  rb_load_with_builtin_functions(\"#{base}\", #{table});"
 | 
					    f.puts "  rb_load_with_builtin_functions(\"#{base}\", \"#{file}\", #{table});"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    f.puts "}"
 | 
					    f.puts "}"
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue