[前][次][番号順一覧][スレッド一覧]

ruby-changes:40442

From: nobu <ko1@a...>
Date: Tue, 10 Nov 2015 18:25:14 +0900 (JST)
Subject: [ruby-changes:40442] nobu:r52523 (trunk): proc.c: cfunc_proc_t

nobu	2015-11-10 18:24:41 +0900 (Tue, 10 Nov 2015)

  New Revision: 52523

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=52523

  Log:
    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.

  Modified files:
    trunk/ChangeLog
    trunk/internal.h
    trunk/proc.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 52522)
+++ ChangeLog	(revision 52523)
@@ -1,3 +1,12 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Tue Nov 10 18:23:35 2015  Nobuyoshi Nakada  <nobu@r...>
+
+	* 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@g...>
 
 	* bootstraptest/test_fork.rb ([ruby-dev:37934]): :NPROC (RLIMIT_NPROC)
Index: proc.c
===================================================================
--- proc.c	(revision 52522)
+++ proc.c	(revision 52523)
@@ -62,15 +62,15 @@ proc_mark(void *ptr) https://github.com/ruby/ruby/blob/trunk/proc.c#L62
 
 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) https://github.com/ruby/ruby/blob/trunk/proc.c#L582
 }
 
 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
Index: internal.h
===================================================================
--- internal.h	(revision 52522)
+++ internal.h	(revision 52523)
@@ -1013,6 +1013,8 @@ ID rb_id_attrget(ID id); https://github.com/ruby/ruby/blob/trunk/internal.h#L1013
 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)

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]