diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2023-03-08 12:16:05 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2023-03-08 13:59:21 +0900 |
commit | 677c3228d09eaeaa57ad18396f52841f31411b6a (patch) | |
tree | e2f7fb62794eb022c5cd90a8bb3a5b63b91d7da9 | |
parent | 5889cbd7de4d7e9d8d340ae553f994e231ecc8ef (diff) | |
download | ruby-677c3228d09eaeaa57ad18396f52841f31411b6a.tar.gz |
Check loading built-in binaries
-rw-r--r-- | builtin.c | 1 | ||||
-rw-r--r-- | mini_builtin.c | 5 | ||||
-rw-r--r-- | template/builtin_binary.inc.tmpl | 10 | ||||
-rw-r--r-- | template/prelude.c.tmpl | 6 |
4 files changed, 14 insertions, 8 deletions
@@ -48,6 +48,7 @@ rb_load_with_builtin_functions(const char *feature_name, const struct rb_builtin vm->builtin_function_table = table; vm->builtin_inline_index = 0; const rb_iseq_t *iseq = rb_iseq_ibf_load_bytes((const char *)bin, size); + ASSUME(iseq); // otherwise an exception should have raised vm->builtin_function_table = NULL; // exec diff --git a/mini_builtin.c b/mini_builtin.c index c263d1ee71..1818f18cba 100644 --- a/mini_builtin.c +++ b/mini_builtin.c @@ -21,6 +21,11 @@ builtin_iseq_load(const char *feature_name, const struct rb_builtin_function *ta rb_ast_t *ast = rb_builtin_ast(feature_name, &name_str); rb_vm_t *vm = GET_VM(); + if (!ast) { + rb_fatal("builtin_iseq_load: can not find %s; " + "probably miniprelude.c is out of date", + feature_name); + } vm->builtin_function_table = table; vm->builtin_inline_index = 0; static const rb_compile_option_t optimization = { diff --git a/template/builtin_binary.inc.tmpl b/template/builtin_binary.inc.tmpl index 787ced5f3d..2c2f071705 100644 --- a/template/builtin_binary.inc.tmpl +++ b/template/builtin_binary.inc.tmpl @@ -10,19 +10,19 @@ static const unsigned char <%= feature %>_bin[] = { % iseq \ % . to_binary \ % . each_byte \ -% . map(&:ord) \ -% . map{ '0x%02x' % _1 } \ % . each_slice(12) {|a| - <%= a.join(', ') %>, + <%= a.map{ '0x%02x,' % _1 }.join(' ') %> % } }; % } +#define BUILTIN_BIN(feature) \ + { #feature, feature ## _bin, sizeof(feature ## _bin), } static const struct builtin_binary builtin_binary[] = { % ary.each{|feature, | - { <%= feature.dump %>, <%= feature %>_bin, sizeof(<%= feature %>_bin), }, + BUILTIN_BIN(<%= feature %>), % } - { NULL, },<%# dummy entry %> + { NULL, },/* sentinel */ }; #define BUILTIN_BINARY_SIZE <%= ary.size %> diff --git a/template/prelude.c.tmpl b/template/prelude.c.tmpl index 428c9f4d01..ebf9bc0693 100644 --- a/template/prelude.c.tmpl +++ b/template/prelude.c.tmpl @@ -140,8 +140,8 @@ static rb_ast_t * prelude_ast(VALUE name, VALUE code, int line) { rb_ast_t *ast = rb_parser_compile_string_path(rb_parser_new(), name, code, line); - if (!ast->body.root) { - rb_ast_dispose(ast); + if (!ast || !ast->body.root) { + if (ast) rb_ast_dispose(ast); rb_exc_raise(rb_errinfo()); } return ast; @@ -208,7 +208,7 @@ Init_<%=init_name%><%=%>(void) %unless @prelude_count.zero? % preludes.each do |i, prelude, lines, sub, start_line| % next if sub - prelude_eval(PRELUDE_CODE(<%=i%><%=%>), PRELUDE_NAME(<%=i%><%=%>), <%=start_line%>); + prelude_eval(PRELUDE_CODE(<%=i%><%=%>), PRELUDE_NAME(<%=i%><%=%>), <%=start_line%><%=%>); % end #if 0 |