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

move fields from th to ec.

* vm_core.h: move rb_thread_t::passed_block_handler to
  rb_execution_context_t::passed_block_handler.
  Also move rb_thread_t::passed_bmethod_me to
  rb_execution_context_t::passed_bmethod_me.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60503 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
ko1 2017-10-28 10:01:54 +00:00
parent e6f133b66a
commit f8a9d044f4
8 changed files with 42 additions and 44 deletions

View file

@ -5,23 +5,23 @@
#include "vm_core.h"
static inline void
vm_passed_block_handler_set(rb_thread_t *th, VALUE block_handler)
vm_passed_block_handler_set(rb_execution_context_t *ec, VALUE block_handler)
{
vm_block_handler_verify(block_handler);
th->passed_block_handler = block_handler;
ec->passed_block_handler = block_handler;
}
static inline void
pass_passed_block_handler(rb_thread_t *th)
pass_passed_block_handler(rb_execution_context_t *ec)
{
VALUE block_handler = rb_vm_frame_block_handler(th->ec->cfp);
VALUE block_handler = rb_vm_frame_block_handler(ec->cfp);
vm_block_handler_verify(block_handler);
vm_passed_block_handler_set(th, block_handler);
VM_ENV_FLAGS_SET(th->ec->cfp->ep, VM_FRAME_FLAG_PASSED);
vm_passed_block_handler_set(ec, block_handler);
VM_ENV_FLAGS_SET(ec->cfp->ep, VM_FRAME_FLAG_PASSED);
}
#define PASS_PASSED_BLOCK_HANDLER_TH(th) pass_passed_block_handler(th)
#define PASS_PASSED_BLOCK_HANDLER() pass_passed_block_handler(GET_THREAD())
#define PASS_PASSED_BLOCK_HANDLER_EC(ec) pass_passed_block_handler(ec)
#define PASS_PASSED_BLOCK_HANDLER() pass_passed_block_handler(GET_EC())
#ifdef HAVE_STDLIB_H
#include <stdlib.h>

2
proc.c
View file

@ -2099,7 +2099,7 @@ static inline VALUE
call_method_data(rb_thread_t *th, const struct METHOD *data,
int argc, const VALUE *argv, VALUE passed_procval)
{
vm_passed_block_handler_set(th, proc_to_block_handler(passed_procval));
vm_passed_block_handler_set(th->ec, proc_to_block_handler(passed_procval));
return rb_vm_call(th, data->recv, data->me->called_id, argc, argv,
method_callable_method_entry(data));
}

10
vm.c
View file

@ -168,10 +168,10 @@ VM_BH_FROM_CFP_P(VALUE block_handler, const rb_control_frame_t *cfp)
}
static VALUE
vm_passed_block_handler(rb_thread_t *th)
vm_passed_block_handler(rb_execution_context_t *ec)
{
VALUE block_handler = th->passed_block_handler;
th->passed_block_handler = VM_BLOCK_HANDLER_NONE;
VALUE block_handler = ec->passed_block_handler;
ec->passed_block_handler = VM_BLOCK_HANDLER_NONE;
vm_block_handler_verify(block_handler);
return block_handler;
}
@ -1018,8 +1018,8 @@ invoke_iseq_block_from_c(rb_execution_context_t *ec, const struct rb_captured_bl
VALUE type = VM_FRAME_MAGIC_BLOCK | (is_lambda ? VM_FRAME_FLAG_LAMBDA : 0);
rb_control_frame_t *cfp = ec->cfp;
VALUE *sp = cfp->sp;
const rb_callable_method_entry_t *me = th->passed_bmethod_me;
th->passed_bmethod_me = NULL;
const rb_callable_method_entry_t *me = ec->passed_bmethod_me;
ec->passed_bmethod_me = NULL;
stack_check(th);
CHECK_VM_STACK_OVERFLOW(cfp, argc);

View file

@ -806,7 +806,7 @@ refine_sym_proc_call(RB_BLOCK_CALL_FUNC_ARGLIST(yielded_arg, callback_arg))
VALUE obj;
ID mid;
const rb_callable_method_entry_t *me;
rb_thread_t *th;
rb_execution_context_t *ec;
if (argc-- < 1) {
rb_raise(rb_eArgError, "no receiver given");
@ -814,14 +814,14 @@ refine_sym_proc_call(RB_BLOCK_CALL_FUNC_ARGLIST(yielded_arg, callback_arg))
obj = *argv++;
mid = SYM2ID(callback_arg);
me = rb_callable_method_entry_with_refinements(CLASS_OF(obj), mid, NULL);
th = GET_THREAD();
ec = GET_EC();
if (!NIL_P(blockarg)) {
vm_passed_block_handler_set(th, blockarg);
vm_passed_block_handler_set(ec, blockarg);
}
if (!me) {
return method_missing(obj, mid, argc, argv, MISSING_NOENTRY);
}
return vm_call0(th->ec, obj, mid, argc, argv, me);
return vm_call0(ec, obj, mid, argc, argv, me);
}
static void

View file

@ -765,6 +765,12 @@ typedef struct rb_execution_context_struct {
rb_fiber_t *fiber;
/* for rb_iterate */
VALUE passed_block_handler;
/* for bmethod */
const rb_callable_method_entry_t *passed_bmethod_me;
/* for GC */
struct {
VALUE *stack_start;
@ -790,12 +796,6 @@ typedef struct rb_thread_struct {
VALUE last_status; /* $? */
/* for rb_iterate */
VALUE passed_block_handler;
/* for bmethod */
const rb_callable_method_entry_t *passed_bmethod_me;
/* for cfunc */
struct rb_calling_info *calling;

View file

@ -106,7 +106,7 @@ vm_call0_body(rb_execution_context_t *ec, struct rb_calling_info *calling, const
{
VALUE ret;
calling->block_handler = vm_passed_block_handler(rb_ec_thread_ptr(ec));
calling->block_handler = vm_passed_block_handler(ec);
again:
switch (cc->me->def->type) {
@ -170,7 +170,7 @@ vm_call0_body(rb_execution_context_t *ec, struct rb_calling_info *calling, const
goto again;
case VM_METHOD_TYPE_MISSING:
{
vm_passed_block_handler_set(rb_ec_thread_ptr(ec), calling->block_handler);
vm_passed_block_handler_set(ec, calling->block_handler);
return method_missing(calling->recv, ci->mid, calling->argc,
argv, MISSING_NOENTRY);
}
@ -237,7 +237,7 @@ VALUE
rb_call_super(int argc, const VALUE *argv)
{
rb_thread_t *th = GET_THREAD();
PASS_PASSED_BLOCK_HANDLER_TH(th);
PASS_PASSED_BLOCK_HANDLER_EC(th->ec);
return vm_call_super(th, argc, argv);
}
@ -703,15 +703,15 @@ static inline VALUE
method_missing(VALUE obj, ID id, int argc, const VALUE *argv, enum method_missing_reason call_status)
{
VALUE *nargv, result, work, klass;
rb_thread_t *th = GET_THREAD();
VALUE block_handler = vm_passed_block_handler(th);
rb_execution_context_t *ec = GET_EC();
VALUE block_handler = vm_passed_block_handler(ec);
const rb_callable_method_entry_t *me;
th->method_missing_reason = call_status;
rb_ec_thread_ptr(ec)->method_missing_reason = call_status;
if (id == idMethodMissing) {
missing:
raise_method_missing(th, argc, argv, obj, call_status | MISSING_MISSING);
raise_method_missing(rb_ec_thread_ptr(ec), argc, argv, obj, call_status | MISSING_MISSING);
}
nargv = ALLOCV_N(VALUE, work, argc + 1);
@ -724,8 +724,8 @@ method_missing(VALUE obj, ID id, int argc, const VALUE *argv, enum method_missin
if (!klass) goto missing;
me = rb_callable_method_entry(klass, idMethodMissing);
if (!me || METHOD_ENTRY_BASIC(me)) goto missing;
vm_passed_block_handler_set(th, block_handler);
result = vm_call0(th->ec, obj, idMethodMissing, argc, argv, me);
vm_passed_block_handler_set(ec, block_handler);
result = vm_call0(ec, obj, idMethodMissing, argc, argv, me);
if (work) ALLOCV_END(work);
return result;
}
@ -734,7 +734,7 @@ void
rb_raise_method_missing(rb_thread_t *th, int argc, const VALUE *argv,
VALUE obj, int call_status)
{
vm_passed_block_handler_set(th, VM_BLOCK_HANDLER_NONE);
vm_passed_block_handler_set(th->ec, VM_BLOCK_HANDLER_NONE);
raise_method_missing(th, argc, argv, obj, call_status | MISSING_MISSING);
}
@ -839,8 +839,7 @@ VALUE
rb_funcall_with_block(VALUE recv, ID mid, int argc, const VALUE *argv, VALUE passed_procval)
{
if (!NIL_P(passed_procval)) {
rb_thread_t *th = GET_THREAD();
vm_passed_block_handler_set(th, passed_procval);
vm_passed_block_handler_set(GET_EC(), passed_procval);
}
return rb_call(recv, mid, argc, argv, CALL_PUBLIC);
@ -907,7 +906,7 @@ send_internal(int argc, const VALUE *argv, VALUE recv, call_type scope)
else {
argv++; argc--;
}
PASS_PASSED_BLOCK_HANDLER_TH(th);
PASS_PASSED_BLOCK_HANDLER_EC(th->ec);
ret = rb_call0(recv, id, argc, argv, scope, self);
ALLOCV_END(vargv);
return ret;
@ -1128,7 +1127,7 @@ rb_iterate0(VALUE (* it_proc) (VALUE), VALUE data1,
else {
block_handler = VM_CF_BLOCK_HANDLER(cfp);
}
vm_passed_block_handler_set(th, block_handler);
vm_passed_block_handler_set(th->ec, block_handler);
}
retval = (*it_proc) (data1);
}

View file

@ -1962,7 +1962,7 @@ vm_call_bmethod_body(rb_execution_context_t *ec, struct rb_calling_info *calling
VALUE val;
/* control block frame */
rb_ec_thread_ptr(ec)->passed_bmethod_me = cc->me;
ec->passed_bmethod_me = cc->me;
GetProcPtr(cc->me->def->body.proc, proc);
val = vm_invoke_bmethod(ec, proc, calling->recv, calling->argc, argv, calling->block_handler);
@ -2503,12 +2503,11 @@ vm_yield_with_cfunc(rb_execution_context_t *ec,
const struct rb_captured_block *captured,
VALUE self, int argc, const VALUE *argv, VALUE block_handler)
{
rb_thread_t *th = rb_ec_thread_ptr(ec);
int is_lambda = FALSE; /* TODO */
VALUE val, arg, blockarg;
const struct vm_ifunc *ifunc = captured->code.ifunc;
const rb_callable_method_entry_t *me = th->passed_bmethod_me;
th->passed_bmethod_me = NULL;
const rb_callable_method_entry_t *me = ec->passed_bmethod_me;
ec->passed_bmethod_me = NULL;
if (is_lambda) {
arg = rb_ary_new4(argc, argv);

View file

@ -1890,9 +1890,9 @@ call_method_entry(rb_thread_t *th, VALUE defined_class, VALUE obj, ID id,
{
const rb_callable_method_entry_t *cme =
prepare_callable_method_entry(defined_class, id, me);
VALUE passed_block_handler = vm_passed_block_handler(th);
VALUE passed_block_handler = vm_passed_block_handler(th->ec);
VALUE result = vm_call0(th->ec, obj, id, argc, argv, cme);
vm_passed_block_handler_set(th, passed_block_handler);
vm_passed_block_handler_set(th->ec, passed_block_handler);
return result;
}