1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* ruby.c (process_options): set th->base_block only while

it is needed.
* ruby.c (require_libraries): clear th->base_block before
  require libraries.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@21143 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
ko1 2008-12-28 18:45:24 +00:00
parent f5189c3f14
commit ec5283e691
2 changed files with 35 additions and 11 deletions

View file

@ -1,3 +1,11 @@
Mon Dec 29 03:43:25 2008 Koichi Sasada <ko1@atdot.net>
* ruby.c (process_options): set th->base_block only while
it is needed.
* ruby.c (require_libraries): clear th->base_block before
require libraries.
Sun Dec 28 21:33:52 2008 NARUSE, Yui <naruse@ruby-lang.org>
* test/ext/dl/test_base.rb : add BSD's case.

38
ruby.c
View file

@ -456,6 +456,9 @@ require_libraries(struct cmdline_options *opt)
{
VALUE list = opt->req_list;
ID require;
rb_thread_t *th = GET_THREAD();
rb_block_t *prev_base_block = th->base_block;
th->base_block = 0;
Init_ext(); /* should be called here for some reason :-( */
CONST_ID(require, "require");
@ -464,6 +467,7 @@ require_libraries(struct cmdline_options *opt)
rb_funcall2(rb_vm_top_self(), require, 1, &feature);
}
opt->req_list = 0;
th->base_block = prev_base_block;
}
static void
@ -1336,10 +1340,16 @@ process_options(VALUE arg)
GetBindingPtr(toplevel_binding, bind);
GetEnvPtr(bind->env, env);
th->parse_in_eval++;
}
#define PREPARE_PARSE_MAIN(expr) do { \
th->parse_in_eval++; \
th->base_block = &env->block; \
expr; \
th->parse_in_eval--; \
th->base_block = 0; \
} while (0)
if (opt->e_script) {
rb_encoding *eenc;
if (opt->src.enc.index >= 0) {
@ -1351,16 +1361,18 @@ process_options(VALUE arg)
rb_enc_associate(opt->e_script, eenc);
require_libraries(opt);
th->base_block = &env->block;
tree = rb_parser_compile_string(parser, opt->script, opt->e_script, 1);
PREPARE_PARSE_MAIN({
tree = rb_parser_compile_string(parser, opt->script, opt->e_script, 1);
});
}
else {
if (opt->script[0] == '-' && !opt->script[1]) {
forbid_setid("program input from stdin");
}
th->base_block = &env->block;
tree = load_file(parser, opt->script, 1, opt);
PREPARE_PARSE_MAIN({
tree = load_file(parser, opt->script, 1, opt);
});
}
if (opt->dump & DUMP_BIT(yydebug)) return Qtrue;
@ -1389,19 +1401,23 @@ process_options(VALUE arg)
}
if (opt->do_print) {
tree = rb_parser_append_print(parser, tree);
PREPARE_PARSE_MAIN({
tree = rb_parser_append_print(parser, tree);
});
}
if (opt->do_loop) {
tree = rb_parser_while_loop(parser, tree, opt->do_line, opt->do_split);
PREPARE_PARSE_MAIN({
tree = rb_parser_while_loop(parser, tree, opt->do_line, opt->do_split);
});
rb_define_global_function("sub", rb_f_sub, -1);
rb_define_global_function("gsub", rb_f_gsub, -1);
rb_define_global_function("chop", rb_f_chop, 0);
rb_define_global_function("chomp", rb_f_chomp, -1);
}
iseq = rb_iseq_new_main(tree, opt->script_name);
th->parse_in_eval--;
th->base_block = 0;
PREPARE_PARSE_MAIN({
iseq = rb_iseq_new_main(tree, opt->script_name);
});
if (opt->dump & DUMP_BIT(insns)) {
rb_io_write(rb_stdout, ruby_iseq_disasm(iseq));