зеркало из https://github.com/github/ruby.git
proc.c: rb_proc_alloc
* proc.c (rb_proc_alloc, proc_dup): allocate rb_proc_t instead of wrapping to get rid of potential memory leak. * vm.c (rb_proc_create): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50507 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
ecbad6dfa8
Коммит
ec0a083d93
13
proc.c
13
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;
|
||||
|
|
22
vm.c
22
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) {
|
||||
|
|
|
@ -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 */
|
||||
|
|
Загрузка…
Ссылка в новой задаче