summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--proc.c13
-rw-r--r--vm.c22
-rw-r--r--vm_core.h2
3 files changed, 16 insertions, 21 deletions
diff --git a/proc.c b/proc.c
index 44ec281..b062a4a 100644
--- a/proc.c
+++ b/proc.c
@@ -71,11 +71,10 @@ static const rb_data_type_t proc_data_type = {
};
VALUE
-rb_proc_wrap(VALUE klass, rb_proc_t *proc)
+rb_proc_alloc(VALUE klass)
{
- proc->block.proc = TypedData_Wrap_Struct(klass, &proc_data_type, proc);
-
- return proc->block.proc;
+ rb_proc_t *proc;
+ return TypedData_Make_Struct(klass, rb_proc_t, &proc_data_type, proc);
}
VALUE
@@ -95,11 +94,13 @@ proc_dup(VALUE self)
{
VALUE procval;
rb_proc_t *src;
- rb_proc_t *dst = ALLOC(rb_proc_t);
+ rb_proc_t *dst;
GetProcPtr(self, src);
+ procval = rb_proc_alloc(rb_cProc);
+ GetProcPtr(procval, dst);
*dst = *src;
- procval = rb_proc_wrap(rb_cProc, dst);
+ dst->block.proc = procval;
RB_GC_GUARD(self); /* for: body = proc_dup(body) */
return procval;
diff --git a/vm.c b/vm.c
index ff80e4c..fda3ec5 100644
--- a/vm.c
+++ b/vm.c
@@ -658,24 +658,18 @@ vm_make_proc_from_block(rb_thread_t *th, rb_block_t *block)
}
static inline VALUE
-rb_proc_alloc(VALUE klass, const rb_block_t *block,
- VALUE envval, VALUE blockprocval,
- int8_t safe_level, int8_t is_from_method, int8_t is_lambda)
+rb_proc_create(VALUE klass, const rb_block_t *block,
+ VALUE envval, VALUE blockprocval,
+ int8_t safe_level, int8_t is_from_method, int8_t is_lambda)
{
- VALUE procval;
- rb_proc_t *proc = ALLOC(rb_proc_t);
+ VALUE procval = rb_proc_alloc(klass);
+ rb_proc_t *proc = RTYPEDDATA_DATA(procval);
proc->block = *block;
+ proc->block.proc = procval;
proc->safe_level = safe_level;
proc->is_from_method = is_from_method;
proc->is_lambda = is_lambda;
-
- procval = rb_proc_wrap(klass, proc);
-
- /*
- * ensure VALUEs are markable here as rb_proc_wrap may trigger allocation
- * and clobber envval + blockprocval
- */
proc->envval = envval;
proc->blockprocval = blockprocval;
@@ -704,8 +698,8 @@ rb_vm_make_proc_lambda(rb_thread_t *th, const rb_block_t *block, VALUE klass, in
check_env_value(envval);
}
- procval = rb_proc_alloc(klass, block, envval, blockprocval,
- (int8_t)th->safe_level, 0, is_lambda);
+ procval = rb_proc_create(klass, block, envval, blockprocval,
+ (int8_t)th->safe_level, 0, is_lambda);
if (VMDEBUG) {
if (th->stack < block->ep && block->ep < th->stack + th->stack_size) {
diff --git a/vm_core.h b/vm_core.h
index 97df64f..6fead58 100644
--- a/vm_core.h
+++ b/vm_core.h
@@ -920,7 +920,7 @@ rb_block_t *rb_vm_control_frame_block_ptr(const rb_control_frame_t *cfp);
/* VM related object allocate functions */
VALUE rb_thread_alloc(VALUE klass);
-VALUE rb_proc_wrap(VALUE klass, rb_proc_t *); /* may use with rb_proc_alloc */
+VALUE rb_proc_alloc(VALUE klass);
VALUE rb_binding_alloc(VALUE klass);
/* for debug */