Skip to content

Commit

Permalink
proc.c: cfunc_proc_t
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
nobu committed Nov 10, 2015
1 parent a56b0f8 commit bda0e2f
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 11 deletions.
9 changes: 9 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 2 additions & 0 deletions internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
41 changes: 30 additions & 11 deletions proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit bda0e2f

Please sign in to comment.