mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
proc.c: cfunc_proc_t
* proc.c (cfunc_proc_t): add room for me. * proc.c (cfunc_proc_new): generalise for cfunc proc without env. * proc.c (rb_func_proc_new, rb_func_lambda_new): new functions to make proc/lambda without env from cfunc. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52523 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
a56b0f8b29
commit
bda0e2fd84
3 changed files with 41 additions and 11 deletions
|
@ -1,3 +1,12 @@
|
|||
Tue Nov 10 18:23:35 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* proc.c (cfunc_proc_t): add room for me.
|
||||
|
||||
* proc.c (cfunc_proc_new): generalise for cfunc proc without env.
|
||||
|
||||
* proc.c (rb_func_proc_new, rb_func_lambda_new): new functions to
|
||||
make proc/lambda without env from cfunc.
|
||||
|
||||
Tue Nov 10 17:32:35 2015 Naohisa Goto <ngotogenome@gmail.com>
|
||||
|
||||
* bootstraptest/test_fork.rb ([ruby-dev:37934]): :NPROC (RLIMIT_NPROC)
|
||||
|
|
|
@ -1013,6 +1013,8 @@ ID rb_id_attrget(ID id);
|
|||
VALUE rb_proc_location(VALUE self);
|
||||
st_index_t rb_hash_proc(st_index_t hash, VALUE proc);
|
||||
int rb_block_arity(void);
|
||||
VALUE rb_func_proc_new(rb_block_call_func_t func, VALUE val);
|
||||
VALUE rb_func_lambda_new(rb_block_call_func_t func, VALUE val);
|
||||
|
||||
/* process.c */
|
||||
#define RB_MAX_GROUPS (65536)
|
||||
|
|
41
proc.c
41
proc.c
|
@ -62,15 +62,15 @@ proc_mark(void *ptr)
|
|||
|
||||
typedef struct {
|
||||
rb_proc_t basic;
|
||||
VALUE env[2]; /* specval, envval */
|
||||
} sym_proc_t;
|
||||
VALUE env[3]; /* me, specval, envval */
|
||||
} cfunc_proc_t;
|
||||
|
||||
static size_t
|
||||
proc_memsize(const void *ptr)
|
||||
{
|
||||
const rb_proc_t *proc = ptr;
|
||||
if (proc->block.ep == ((const sym_proc_t *)ptr)->env)
|
||||
return sizeof(sym_proc_t);
|
||||
if (proc->block.ep == ((const cfunc_proc_t *)ptr)->env+1)
|
||||
return sizeof(cfunc_proc_t);
|
||||
return sizeof(rb_proc_t);
|
||||
}
|
||||
|
||||
|
@ -582,19 +582,38 @@ bind_receiver(VALUE bindval)
|
|||
}
|
||||
|
||||
static VALUE
|
||||
sym_proc_new(VALUE klass, VALUE sym)
|
||||
cfunc_proc_new(VALUE klass, VALUE ifunc, int8_t is_lambda)
|
||||
{
|
||||
rb_proc_t *proc;
|
||||
sym_proc_t *symproc;
|
||||
VALUE procval = TypedData_Make_Struct(klass, sym_proc_t, &proc_data_type, symproc);
|
||||
symproc->env[0] = VM_ENVVAL_BLOCK_PTR(0);
|
||||
proc = &symproc->basic;
|
||||
proc->block.ep = symproc->env;
|
||||
proc->block.iseq = (rb_iseq_t *)sym;
|
||||
cfunc_proc_t *sproc;
|
||||
VALUE procval = TypedData_Make_Struct(klass, cfunc_proc_t, &proc_data_type, sproc);
|
||||
sproc->env[1] = VM_ENVVAL_BLOCK_PTR(0);
|
||||
proc = &sproc->basic;
|
||||
proc->block.ep = sproc->env+1;
|
||||
proc->block.iseq = (rb_iseq_t *)ifunc;
|
||||
proc->block.proc = procval;
|
||||
proc->is_lambda = is_lambda;
|
||||
return procval;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
sym_proc_new(VALUE klass, VALUE sym)
|
||||
{
|
||||
return cfunc_proc_new(klass, sym, 0);
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_func_proc_new(rb_block_call_func_t func, VALUE val)
|
||||
{
|
||||
return cfunc_proc_new(rb_cProc, (VALUE)IFUNC_NEW(func, val, 0), 0);
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_func_lambda_new(rb_block_call_func_t func, VALUE val)
|
||||
{
|
||||
return cfunc_proc_new(rb_cProc, (VALUE)IFUNC_NEW(func, val, 0), 1);
|
||||
}
|
||||
|
||||
static const char proc_without_block[] = "tried to create Proc object without a block";
|
||||
|
||||
static VALUE
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue