summaryrefslogtreecommitdiff
path: root/vm_eval.c
diff options
context:
space:
mode:
authorko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-06-22 09:32:56 +0000
committerko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-06-22 09:32:56 +0000
commitc4bc9b575898ba352d0fea8289ebcaf8921dacd1 (patch)
tree5974195d1c0a004072980018cbdfda08b831e727 /vm_eval.c
parent471d8d2586d984fd70f6837b117d6f275201204b (diff)
* iseq.c, vm_eval.c: set th->base_block properly.
th->base_block is information for (a) parsing, (b) compiling and (c) setting up the frame to execute the program passed by `eval' method. For example, (1) parser need to know up-level variables to detect it is variable or method without paren. Befor (a), (b) and (c), VM set th->base_block by passed bindng (or previous frame information). After execute (a), (b) and (c), VM should clear th->base_block. However, if (a), (b) or (c) raises an exception, then th->base_block is not cleared. Problem is that the uncleared value th->balo_block is used for irrelevant iseq compilation. It causes SEGV or critical error. I tried to solve this problem: to clear them before exception, but finally I found out that it is difficult to do it (Ruby program can be run in many places). Because of this background, I set th->base_block before compiling iseq and restore it after compiling. Basically, th->base_block is dirty hack (similar to global variable) and this patch is also dirty. * bootstraptest/test_eval.rb: add a test for above. * internal.h: remove unused decl. * iseq.c (rb_iseq_compile_with_option): add base_block parameter. set th->base_block before compation and restore it after compilation. * ruby.c (require_libraries): pass 0 as base_block instead of setting th->base_block * tool/compile_prelude.rb (prelude_eval): apply above changes. * vm.c, vm_eval.c: ditto. * vm_core.h: add comments. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36179 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'vm_eval.c')
-rw-r--r--vm_eval.c17
1 files changed, 8 insertions, 9 deletions
diff --git a/vm_eval.c b/vm_eval.c
index 457143c2bc..7ec768f7f6 100644
--- a/vm_eval.c
+++ b/vm_eval.c
@@ -16,7 +16,7 @@ static inline VALUE vm_yield_with_cref(rb_thread_t *th, int argc, const VALUE *a
static inline VALUE vm_yield(rb_thread_t *th, int argc, const VALUE *argv);
static NODE *vm_cref_push(rb_thread_t *th, VALUE klass, int noex, rb_block_t *blockptr);
static VALUE vm_exec(rb_thread_t *th);
-static void vm_set_eval_stack(rb_thread_t * th, VALUE iseqval, const NODE *cref);
+static void vm_set_eval_stack(rb_thread_t * th, VALUE iseqval, const NODE *cref, rb_block_t *base_block);
static int vm_collect_local_variables_in_heap(rb_thread_t *th, VALUE *dfp, VALUE ary);
/* vm_backtrace.c */
@@ -996,7 +996,7 @@ eval_string_with_cref(VALUE self, VALUE src, VALUE scope, NODE *cref, const char
rb_binding_t *bind = 0;
rb_thread_t *th = GET_THREAD();
rb_env_t *env = NULL;
- rb_block_t block;
+ rb_block_t block, *base_block;
volatile int parse_in_eval;
volatile int mild_compile_error;
@@ -1027,16 +1027,16 @@ eval_string_with_cref(VALUE self, VALUE src, VALUE scope, NODE *cref, const char
rb_obj_classname(scope));
}
GetEnvPtr(envval, env);
- th->base_block = &env->block;
+ base_block = &env->block;
}
else {
rb_control_frame_t *cfp = rb_vm_get_ruby_level_next_cfp(th, th->cfp);
if (cfp != 0) {
block = *RUBY_VM_GET_BLOCK_PTR_IN_CFP(cfp);
- th->base_block = &block;
- th->base_block->self = self;
- th->base_block->iseq = cfp->iseq; /* TODO */
+ base_block = &block;
+ base_block->self = self;
+ base_block->iseq = cfp->iseq; /* TODO */
}
else {
rb_raise(rb_eRuntimeError, "Can't eval on top of Fiber or Thread");
@@ -1046,12 +1046,11 @@ eval_string_with_cref(VALUE self, VALUE src, VALUE scope, NODE *cref, const char
/* make eval iseq */
th->parse_in_eval++;
th->mild_compile_error++;
- iseqval = rb_iseq_compile(src, rb_str_new2(file), INT2FIX(line));
+ iseqval = rb_iseq_compile_on_base(src, rb_str_new2(file), INT2FIX(line), base_block);
th->mild_compile_error--;
th->parse_in_eval--;
- vm_set_eval_stack(th, iseqval, cref);
- th->base_block = 0;
+ vm_set_eval_stack(th, iseqval, cref, base_block);
if (0) { /* for debug */
VALUE disasm = rb_iseq_disasm(iseqval);