[前][次][番号順一覧][スレッド一覧]

ruby-changes:58660

From: Koichi <ko1@a...>
Date: Sat, 9 Nov 2019 07:03:51 +0900 (JST)
Subject: [ruby-changes:58660] dfac2e9eb3 (master): don't embed full-path.

https://git.ruby-lang.org/ruby.git/commit/?id=dfac2e9eb3

From dfac2e9eb3d697e56d91151584f1d3cf9d2c79c9 Mon Sep 17 00:00:00 2001
From: Koichi Sasada <ko1@a...>
Date: Sat, 9 Nov 2019 06:55:38 +0900
Subject: don't embed full-path.

miniruby load *.rb from srcdir. To specify file path,
tool/mk_builtin_loader.rb embed full path of each *.rb file.
However it prevent to pre-generation of required files for tarball.
This patch generate srcdir/*.rb from __FILE__ information.

diff --git a/builtin.c b/builtin.c
index bcc5dc6..d936d1c 100644
--- a/builtin.c
+++ b/builtin.c
@@ -18,7 +18,7 @@ builtin_lookup(const char *feature, size_t *psize) https://github.com/ruby/ruby/blob/trunk/builtin.c#L18
 }
 
 void
-rb_load_with_builtin_functions(const char *feature_name, const char *fname, const struct rb_builtin_function *table)
+rb_load_with_builtin_functions(const char *feature_name, const struct rb_builtin_function *table)
 {
     // search binary
     size_t size;
diff --git a/builtin.h b/builtin.h
index ef6ff82..ee99e21 100644
--- a/builtin.h
+++ b/builtin.h
@@ -12,7 +12,7 @@ struct rb_builtin_function { https://github.com/ruby/ruby/blob/trunk/builtin.h#L12
 
 #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 char *fname, const struct rb_builtin_function *table);
+void rb_load_with_builtin_functions(const char *feature_name, const struct rb_builtin_function *table);
 
 #ifndef VM_CORE_H_EC_DEFINED
 typedef struct rb_execution_context_struct rb_execution_context_t;
diff --git a/mini_builtin.c b/mini_builtin.c
index dc95919..060c955 100644
--- a/mini_builtin.c
+++ b/mini_builtin.c
@@ -36,12 +36,23 @@ read_file(const char *fname, size_t *psize) https://github.com/ruby/ruby/blob/trunk/mini_builtin.c#L36
 }
 
 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
-rb_load_with_builtin_functions(const char *feature_name, const char *fname, const struct rb_builtin_function *table)
+rb_load_with_builtin_functions(const char *feature_name, const struct rb_builtin_function *table)
 {
     size_t fsize;
-    const char *code = read_file(fname, &fsize);
+    const char *code = read_file(feature_path(feature_name), &fsize);
     VALUE code_str = rb_utf8_str_new_static(code, fsize);
     VALUE name_str = rb_sprintf("<internal:%s>", feature_name);
     rb_obj_hide(code_str);
@@ -86,4 +97,15 @@ Init_builtin(void) https://github.com/ruby/ruby/blob/trunk/mini_builtin.c#L97
 {
     rb_define_singleton_method(rb_cRubyVM, "each_builtin", each_builtin, 0);
     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;
 }
diff --git a/tool/mk_builtin_loader.rb b/tool/mk_builtin_loader.rb
index 87b5e2a..f00e2fe 100644
--- a/tool/mk_builtin_loader.rb
+++ b/tool/mk_builtin_loader.rb
@@ -67,10 +67,9 @@ def mk_builtin_header file https://github.com/ruby/ruby/blob/trunk/tool/mk_builtin_loader.rb#L67
     f.puts "COMPILER_WARNING_POP"
 
 
-    path = File.expand_path(file)
     f.puts
     f.puts "  // load"
-    f.puts "  rb_load_with_builtin_functions(\"#{base}\", \"#{file}\", #{table});"
+    f.puts "  rb_load_with_builtin_functions(\"#{base}\", #{table});"
 
     f.puts "}"
   }
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]