diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2019-11-09 19:28:45 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2019-11-09 19:28:45 +0900 |
commit | dfaac2b37253ff25ec873c2fbd93abfa7f789248 (patch) | |
tree | 6517f137f767bba6811e711462d05c7dc3141c96 /mini_builtin.c | |
parent | 4dc4b1890499d6a836655957e78908ee891a42ce (diff) |
Embed builtin ruby scripts in miniprelude.c
Instead of reading from the files by the full-path at runtime. As
rbinc files need to be included in distributed tarballs, the
full-paths at the packaging are unavailable at compilation times.
Diffstat (limited to 'mini_builtin.c')
-rw-r--r-- | mini_builtin.c | 42 |
1 files changed, 4 insertions, 38 deletions
diff --git a/mini_builtin.c b/mini_builtin.c index dc95919da2..290a4b335e 100644 --- a/mini_builtin.c +++ b/mini_builtin.c @@ -5,55 +5,21 @@ // include from miniinits.c -static const char * -read_file(const char *fname, size_t *psize) -{ - struct stat st; - char *code; - FILE *fp; - - if (stat(fname, &st) != 0) { - rb_bug("stat fails: %s", fname); - } - - size_t fsize = st.st_size; - if ((code = malloc(fsize + 1)) == NULL) { - rb_bug("can't allocate memory: %s (%d)", fname, (int)fsize); - } - - if ((fp = fopen(fname, "rb")) == NULL) { - rb_bug("can't open file: %s", fname); - } - - size_t read_size = fread(code, 1, fsize, fp); - if (read_size != fsize) { - rb_bug("can't read file enough: %s (expect %d but was %d)", fname, (int)fsize, (int)read_size); - } - - code[fsize] = 0; - *psize = fsize; - return code; -} - static struct st_table *loaded_builtin_table; +rb_ast_t *rb_builtin_ast(const char *feature_name, VALUE *name_str); + void rb_load_with_builtin_functions(const char *feature_name, const char *fname, const struct rb_builtin_function *table) { - size_t fsize; - const char *code = read_file(fname, &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); - - rb_ast_t *ast = rb_parser_compile_string_path(rb_parser_new(), name_str, code_str, 1); + VALUE name_str = 0; + rb_ast_t *ast = rb_builtin_ast(feature_name, &name_str); GET_VM()->builtin_function_table = table; const rb_iseq_t *iseq = rb_iseq_new(&ast->body, name_str, name_str, Qnil, NULL, ISEQ_TYPE_TOP); GET_VM()->builtin_function_table = NULL; rb_ast_dispose(ast); - free((void *)code); // code_str becomes broken. // register (loaded iseq will not be freed) st_insert(loaded_builtin_table, (st_data_t)feature_name, (st_data_t)iseq); |