summaryrefslogtreecommitdiff
path: root/ruby.c
diff options
context:
space:
mode:
authorko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-12-28 18:45:24 +0000
committerko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-12-28 18:45:24 +0000
commitec5283e691a31d466099bc274169d3b0568ca840 (patch)
treebb7e1518c7ed5bf619697096a73cba0673c415d8 /ruby.c
parentf5189c3f142701ffa5c0162485650c49c50defa9 (diff)
* 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
Diffstat (limited to 'ruby.c')
-rw-r--r--ruby.c38
1 files changed, 27 insertions, 11 deletions
diff --git a/ruby.c b/ruby.c
index 2c70d71686..68d9fc739c 100644
--- a/ruby.c
+++ b/ruby.c
@@ -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));