summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-11-10 09:24:41 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-11-10 09:24:41 +0000
commitbda0e2fd84340e34dee0804e250f531893da763a (patch)
treee42ef6b671f9453899283457738ff84ce8383c38
parenta56b0f8b29b3be1323ebfde50cab94808ac65375 (diff)
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
-rw-r--r--ChangeLog9
-rw-r--r--internal.h2
-rw-r--r--proc.c41
3 files changed, 41 insertions, 11 deletions
diff --git a/ChangeLog b/ChangeLog
index 51348f2..656c4b5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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)
diff --git a/internal.h b/internal.h
index 3c2be8c..dfd02e9 100644
--- a/internal.h
+++ b/internal.h
@@ -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)
diff --git a/proc.c b/proc.c
index 5ba4b61..6cbe08c 100644
--- a/proc.c
+++ b/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