mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Use shared implementation of rb_ec_initialize_vm_stack
.
This commit is contained in:
parent
7147038053
commit
cb5da39f20
4 changed files with 26 additions and 34 deletions
14
cont.c
14
cont.c
|
@ -1530,19 +1530,7 @@ fiber_init(VALUE fibval, VALUE proc)
|
|||
vm_stack = ruby_xmalloc(fib_stack_bytes);
|
||||
}
|
||||
cont->free_vm_stack = 1;
|
||||
rb_ec_set_vm_stack(sec, vm_stack, fib_stack_bytes / sizeof(VALUE));
|
||||
sec->cfp = (void *)(sec->vm_stack + sec->vm_stack_size);
|
||||
|
||||
rb_vm_push_frame(sec,
|
||||
NULL,
|
||||
VM_FRAME_MAGIC_DUMMY | VM_ENV_FLAG_LOCAL | VM_FRAME_FLAG_FINISH | VM_FRAME_FLAG_CFRAME,
|
||||
Qnil, /* self */
|
||||
VM_BLOCK_HANDLER_NONE,
|
||||
0, /* specval */
|
||||
NULL, /* pc */
|
||||
sec->vm_stack, /* sp */
|
||||
0, /* local_size */
|
||||
0);
|
||||
rb_ec_initialize_vm_stack(sec, vm_stack, fib_stack_bytes / sizeof(VALUE));
|
||||
|
||||
sec->tag = NULL;
|
||||
sec->local_storage = NULL;
|
||||
|
|
11
thread.c
11
thread.c
|
@ -728,16 +728,7 @@ thread_start_func_2(rb_thread_t *th, VALUE *stack_start, VALUE *register_stack_s
|
|||
}
|
||||
|
||||
vm_stack = alloca(size * sizeof(VALUE));
|
||||
rb_ec_set_vm_stack(th->ec, vm_stack, size);
|
||||
th->ec->cfp = (void *)(th->ec->vm_stack + th->ec->vm_stack_size);
|
||||
|
||||
rb_vm_push_frame(th->ec,
|
||||
0 /* dummy iseq */,
|
||||
VM_FRAME_MAGIC_DUMMY | VM_ENV_FLAG_LOCAL | VM_FRAME_FLAG_FINISH | VM_FRAME_FLAG_CFRAME /* dummy frame */,
|
||||
Qnil /* dummy self */, VM_BLOCK_HANDLER_NONE /* dummy block ptr */,
|
||||
0 /* dummy cref/me */,
|
||||
0 /* dummy pc */, th->ec->vm_stack, 0, 0
|
||||
);
|
||||
rb_ec_initialize_vm_stack(th->ec, vm_stack, size);
|
||||
|
||||
ruby_thread_set_native(th);
|
||||
|
||||
|
|
28
vm.c
28
vm.c
|
@ -2685,6 +2685,22 @@ thread_alloc(VALUE klass)
|
|||
return obj;
|
||||
}
|
||||
|
||||
void
|
||||
rb_ec_initialize_vm_stack(rb_execution_context_t *ec, VALUE *stack, size_t size)
|
||||
{
|
||||
rb_ec_set_vm_stack(ec, stack, size);
|
||||
|
||||
ec->cfp = (void *)(ec->vm_stack + ec->vm_stack_size);
|
||||
|
||||
rb_vm_push_frame(ec,
|
||||
NULL /* dummy iseq */,
|
||||
VM_FRAME_MAGIC_DUMMY | VM_ENV_FLAG_LOCAL | VM_FRAME_FLAG_FINISH | VM_FRAME_FLAG_CFRAME /* dummy frame */,
|
||||
Qnil /* dummy self */, VM_BLOCK_HANDLER_NONE /* dummy block ptr */,
|
||||
0 /* dummy cref/me */,
|
||||
0 /* dummy pc */, ec->vm_stack, 0, 0
|
||||
);
|
||||
}
|
||||
|
||||
static void
|
||||
th_init(rb_thread_t *th, VALUE self)
|
||||
{
|
||||
|
@ -2693,17 +2709,7 @@ th_init(rb_thread_t *th, VALUE self)
|
|||
|
||||
if (self == 0) {
|
||||
size_t size = th->vm->default_params.thread_vm_stack_size / sizeof(VALUE);
|
||||
rb_ec_set_vm_stack(th->ec, ALLOC_N(VALUE, size), size);
|
||||
|
||||
th->ec->cfp = (void *)(th->ec->vm_stack + th->ec->vm_stack_size);
|
||||
|
||||
rb_vm_push_frame(th->ec,
|
||||
0 /* dummy iseq */,
|
||||
VM_FRAME_MAGIC_DUMMY | VM_ENV_FLAG_LOCAL | VM_FRAME_FLAG_FINISH | VM_FRAME_FLAG_CFRAME /* dummy frame */,
|
||||
Qnil /* dummy self */, VM_BLOCK_HANDLER_NONE /* dummy block ptr */,
|
||||
0 /* dummy cref/me */,
|
||||
0 /* dummy pc */, th->ec->vm_stack, 0, 0
|
||||
);
|
||||
rb_ec_initialize_vm_stack(th->ec, ALLOC_N(VALUE, size), size);
|
||||
} else {
|
||||
VM_ASSERT(th->ec->cfp == NULL);
|
||||
VM_ASSERT(th->ec->vm_stack == NULL);
|
||||
|
|
|
@ -903,8 +903,15 @@ typedef struct rb_execution_context_struct {
|
|||
} machine;
|
||||
} rb_execution_context_t;
|
||||
|
||||
// Set the vm_stack pointer in the execution context.
|
||||
void rb_ec_set_vm_stack(rb_execution_context_t *ec, VALUE *stack, size_t size);
|
||||
|
||||
// Initialize the vm_stack pointer in the execution context and push the initial stack frame.
|
||||
// @param ec the execution context to update.
|
||||
// @param stack a pointer to the stack to use.
|
||||
// @param size the size of the stack, as in `VALUE stack[size]`.
|
||||
void rb_ec_initialize_vm_stack(rb_execution_context_t *ec, VALUE *stack, size_t size);
|
||||
|
||||
typedef struct rb_thread_struct {
|
||||
struct list_node vmlt_node;
|
||||
VALUE self;
|
||||
|
|
Loading…
Add table
Reference in a new issue