diff --git a/eval.c b/eval.c index 2596921..7852cf5 100644 --- a/eval.c +++ b/eval.c @@ -604,8 +604,7 @@ rb_block_given_p(void) { rb_thread_t *th = GET_THREAD(); - if ((th->cfp->lfp[0] & 0x02) == 0 && - GC_GUARDED_PTR_REF(th->cfp->lfp[0])) { + if (!IN_CLASS_DEF(th->cfp) && BLOCK_PTR_REF(th->cfp)) { return TRUE; } else { @@ -980,12 +979,12 @@ errinfo_place(rb_thread_t *th) while (RUBY_VM_VALID_CONTROL_FRAME_P(cfp, end_cfp)) { if (RUBY_VM_NORMAL_ISEQ_P(cfp->iseq)) { if (cfp->iseq->type == ISEQ_TYPE_RESCUE) { - return &cfp->dfp[-2]; + return &ERRINFO(cfp); } else if (cfp->iseq->type == ISEQ_TYPE_ENSURE && - TYPE(cfp->dfp[-2]) != T_NODE && - !FIXNUM_P(cfp->dfp[-2])) { - return &cfp->dfp[-2]; + TYPE(ERRINFO(cfp)) != T_NODE && + !FIXNUM_P(ERRINFO(cfp))) { + return &ERRINFO(cfp); } } cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp); diff --git a/eval_intern.h b/eval_intern.h index 549953a..de1a2dc 100644 --- a/eval_intern.h +++ b/eval_intern.h @@ -5,7 +5,7 @@ #include "vm_core.h" #define PASS_PASSED_BLOCK_TH(th) do { \ - (th)->passed_block = GC_GUARDED_PTR_REF((rb_block_t *)(th)->cfp->lfp[0]); \ + (th)->passed_block = BLOCK_PTR_REF((th)->cfp); \ (th)->cfp->flag |= VM_FRAME_FLAG_PASSED; \ } while (0) diff --git a/proc.c b/proc.c index 0489dd9..78152c4 100644 --- a/proc.c +++ b/proc.c @@ -384,16 +384,16 @@ proc_new(VALUE klass, int is_lambda) rb_control_frame_t *cfp = th->cfp; rb_block_t *block; - if ((GC_GUARDED_PTR_REF(cfp->lfp[0])) != 0) { + if (BLOCK_PTR_REF(cfp) != 0) { - block = GC_GUARDED_PTR_REF(cfp->lfp[0]); + block = BLOCK_PTR_REF(cfp); } else { cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp); - if ((GC_GUARDED_PTR_REF(cfp->lfp[0])) != 0) { + if (BLOCK_PTR_REF(cfp) != 0) { - block = GC_GUARDED_PTR_REF(cfp->lfp[0]); + block = BLOCK_PTR_REF(cfp); if (is_lambda) { rb_warn("tried to create Proc object without a block"); diff --git a/vm.c b/vm.c index e62c9a4..bed2684 100644 --- a/vm.c +++ b/vm.c @@ -69,7 +69,7 @@ static inline VALUE rb_vm_set_finish_env(rb_thread_t * th) { vm_push_frame(th, 0, VM_FRAME_MAGIC_FINISH, - Qnil, th->cfp->lfp[0], 0, + Qnil, BLOCK_PTR_RAW(th->cfp), 0, th->cfp->sp, 0, 1); th->cfp->pc = (VALUE *)&finish_insn_seq[0]; return Qtrue; @@ -109,7 +109,7 @@ vm_set_eval_stack(rb_thread_t * th, VALUE iseqval, const NODE *cref) th->cfp->sp, block->lfp, iseq->local_size); if (cref) { - th->cfp->dfp[-1] = (VALUE)cref; + CREF(th->cfp) = (VALUE)cref; } CHECK_STACK_OVERFLOW(th->cfp, iseq->stack_max); @@ -476,7 +476,7 @@ rb_vm_make_proc(rb_thread_t *th, const rb_block_t *block, VALUE klass) rb_bug("rb_vm_make_proc: Proc value is already created."); } - if (GC_GUARDED_PTR_REF(cfp->lfp[0])) { + if (BLOCK_PTR_REF(cfp)) { rb_proc_t *p; blockprocval = vm_make_proc_from_block( @@ -551,7 +551,7 @@ invoke_block_from_c(rb_thread_t *th, const rb_block_t *block, th->passed_me = 0; if (cref) { - th->cfp->dfp[-1] = (VALUE)cref; + CREF(th->cfp) = (VALUE)cref; } return vm_exec(th); @@ -564,7 +564,7 @@ invoke_block_from_c(rb_thread_t *th, const rb_block_t *block, static inline const rb_block_t * check_block(rb_thread_t *th) { - const rb_block_t *blockptr = GC_GUARDED_PTR_REF(th->cfp->lfp[0]); + const rb_block_t *blockptr = BLOCK_PTR_REF(th->cfp); if (blockptr == 0) { rb_vm_localjump_error("no block given", Qnil, 0); diff --git a/vm_core.h b/vm_core.h index dea19fa..0dbe0f5 100644 --- a/vm_core.h +++ b/vm_core.h @@ -707,4 +707,12 @@ int rb_thread_check_trap_pending(void); #pragma GCC visibility pop #endif +#define BLOCK_PTR_RAW(cfp) (cfp)->lfp[0] +#define BLOCK_PTR_REF(cfp) (GC_GUARDED_PTR_REF(BLOCK_PTR_RAW(cfp))) +#define IN_CLASS_DEF(cfp) (BLOCK_PTR_RAW(cfp) & 0x02) +#define SET_BLOCK_PTR(cfp, ptr) BLOCK_PTR_RAW(cfp) = GC_GUARDED_PTR(ptr) +#define ERRINFO(cfp) (cfp)->dfp[-2] +#define CREF(cfp) (cfp)->dfp[-1] +#define PREV_DFP_REF(cfp) GC_GUARDED_PTR_REF((cfp)->dfp[0]) + #endif /* RUBY_VM_CORE_H */ diff --git a/vm_eval.c b/vm_eval.c index 122837b..02f9955 100644 --- a/vm_eval.c +++ b/vm_eval.c @@ -845,7 +845,7 @@ rb_iterate(VALUE (* it_proc) (VALUE), VALUE data1, blockptr->proc = 0; } else { - blockptr = GC_GUARDED_PTR_REF(th->cfp->lfp[0]); + blockptr = BLOCK_PTR_REF(th->cfp); } th->passed_block = blockptr; } @@ -1195,10 +1195,10 @@ yield_under(VALUE under, VALUE self, VALUE values) rb_block_t block, *blockptr; NODE *cref; - if ((blockptr = GC_GUARDED_PTR_REF(th->cfp->lfp[0])) != 0) { + if ((blockptr = BLOCK_PTR_REF(th->cfp)) != 0) { block = *blockptr; block.self = self; - th->cfp->lfp[0] = GC_GUARDED_PTR(&block); + SET_BLOCK_PTR(th->cfp, &block); } cref = vm_cref_push(th, under, NOEX_PUBLIC, blockptr); cref->flags |= NODE_FL_CREF_PUSHED_BY_EVAL; @@ -1673,7 +1673,7 @@ rb_f_local_variables(void) } if (cfp->lfp != cfp->dfp) { /* block */ - VALUE *dfp = GC_GUARDED_PTR_REF(cfp->dfp[0]); + VALUE *dfp = PREV_DFP_REF(cfp); if (vm_collect_local_variables_in_heap(th, dfp, ary)) { break; @@ -1721,8 +1721,8 @@ rb_f_block_given_p(void) cfp = vm_get_ruby_level_caller_cfp(th, RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp)); if (cfp != 0 && - (cfp->lfp[0] & 0x02) == 0 && - GC_GUARDED_PTR_REF(cfp->lfp[0])) { + !IN_CLASS_DEF(cfp) && + BLOCK_PTR_REF(cfp)) { return Qtrue; } else {