ruby-changes:61271
From: Nobuyoshi <ko1@a...>
Date: Sat, 16 May 2020 17:41:49 +0900 (JST)
Subject: [ruby-changes:61271] 2c3c6c96cf (master): Defer initialization
https://git.ruby-lang.org/ruby.git/commit/?id=2c3c6c96cf From 2c3c6c96cfc31eb387c643990375e6e1d67b409d Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Sat, 16 May 2020 17:37:28 +0900 Subject: Defer initialization Defer initialization of extension libraries, loading prelude files and requiring files, and skip if dump options are given. diff --git a/inits.c b/inits.c index 92cec6f..4e5d65a 100644 --- a/inits.c +++ b/inits.c @@ -75,7 +75,11 @@ rb_call_inits(void) https://github.com/ruby/ruby/blob/trunk/inits.c#L75 // enable builtin loading CALL(builtin); +} +void +rb_call_builtin_inits(void) +{ #define BUILTIN(n) CALL(builtin_##n) BUILTIN(gc); BUILTIN(io); diff --git a/ruby.c b/ruby.c index ba515bf..922d806 100644 --- a/ruby.c +++ b/ruby.c @@ -1481,6 +1481,28 @@ ruby_init_prelude(void) https://github.com/ruby/ruby/blob/trunk/ruby.c#L1481 rb_const_remove(rb_cObject, rb_intern_const("TMP_RUBY_PREFIX")); } +void rb_call_builtin_inits(void); + +static void +ruby_opt_init(ruby_cmdline_options_t *opt) +{ + if (opt->dump & dump_exit_bits) return; + + if (opt->features.set & FEATURE_BIT(gems)) { + rb_define_module("Gem"); + if (opt->features.set & FEATURE_BIT(did_you_mean)) { + rb_define_module("DidYouMean"); + } + } + + Init_ext(); /* load statically linked extensions before rubygems */ + rb_call_builtin_inits(); + ruby_init_prelude(); + + ruby_set_script_name(opt->script_name); + require_libraries(&opt->req_list); +} + static int opt_enc_index(VALUE enc_name) { @@ -1851,14 +1873,7 @@ process_options(int argc, char **argv, ruby_cmdline_options_t *opt) https://github.com/ruby/ruby/blob/trunk/ruby.c#L1873 rb_ary_replace(vm->load_path_snapshot, load_path); } } - Init_ext(); /* load statically linked extensions before rubygems */ - if (opt->features.set & FEATURE_BIT(gems)) { - rb_define_module("Gem"); - if (opt->features.set & FEATURE_BIT(did_you_mean)) { - rb_define_module("DidYouMean"); - } - } - ruby_init_prelude(); + if (opt->features.mask & COMPILATION_FEATURES) { VALUE option = rb_hash_new(); #define SET_COMPILE_OPTION(h, o, name) \ @@ -1892,10 +1907,7 @@ process_options(int argc, char **argv, ruby_cmdline_options_t *opt) https://github.com/ruby/ruby/blob/trunk/ruby.c#L1907 } #endif rb_enc_associate(opt->e_script, eenc); - if (!(opt->dump & ~DUMP_BIT(version_v))) { - ruby_set_script_name(opt->script_name); - require_libraries(&opt->req_list); - } + ruby_opt_init(opt); ruby_set_script_name(progname); rb_parser_set_options(parser, opt->do_print, opt->do_loop, opt->do_line, opt->do_split); @@ -2122,10 +2134,7 @@ load_file_internal(VALUE argp_v) https://github.com/ruby/ruby/blob/trunk/ruby.c#L2134 if (NIL_P(c)) { argp->f = f = Qnil; } - if (!(opt->dump & ~DUMP_BIT(version_v))) { - ruby_set_script_name(opt->script_name); - require_libraries(&opt->req_list); /* Why here? unnatural */ - } + ruby_opt_init(opt); } if (opt->src.enc.index >= 0) { enc = rb_enc_from_index(opt->src.enc.index); -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/