diff options
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); |