aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSamuel Williams <samuel.williams@oriontransfer.co.nz>2019-06-19 18:47:15 +1200
committerSamuel Williams <samuel.williams@oriontransfer.co.nz>2019-06-19 20:39:10 +1200
commitcb5da39f20a17bd73e791dca1e7e1832f0adbc53 (patch)
treea8cbf20a2f94b3e184e1517b9a68fe5fd005d8f1
parent714703805370767efb859078d5095a014417a692 (diff)
downloadruby-cb5da39f20a17bd73e791dca1e7e1832f0adbc53.tar.gz
Use shared implementation of `rb_ec_initialize_vm_stack`.
-rw-r--r--cont.c14
-rw-r--r--thread.c11
-rw-r--r--vm.c28
-rw-r--r--vm_core.h7
4 files changed, 26 insertions, 34 deletions
diff --git a/cont.c b/cont.c
index e3db1b32d2..accf93aba0 100644
--- a/cont.c
+++ b/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;
diff --git a/thread.c b/thread.c
index cf418da0e4..df6ca01c9d 100644
--- a/thread.c
+++ b/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);
diff --git a/vm.c b/vm.c
index 4b4b037b4f..439464a42f 100644
--- a/vm.c
+++ b/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);
diff --git a/vm_core.h b/vm_core.h
index a0f9388df7..7860c2d505 100644
--- a/vm_core.h
+++ b/vm_core.h
@@ -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;