[#34911] erb still treats $KCODE — "Yusuke ENDOH" <mame@...>

遠藤です。

16 messages 2008/06/03

[#34923] open() and encodings — "NARUSE, Yui" <naruse@...>

成瀬です。

53 messages 2008/06/03
[#34924] Re: open() and encodings — Yukihiro Matsumoto <matz@...> 2008/06/04

まつもと ゆきひろです

[#34931] Re: open() and encodings — "NARUSE, Yui" <naruse@...> 2008/06/04

成瀬です。

[#34934] Re: open() and encodings — Yukihiro Matsumoto <matz@...> 2008/06/05

まつもと ゆきひろです

[#34935] Re: open() and encodings — "U.Nakamura" <usa@...> 2008/06/05

こんにちは、なかむら(う)です。

[#34936] Re: open() and encodings — Yukihiro Matsumoto <matz@...> 2008/06/05

まつもと ゆきひろです

[#34937] Re: open() and encodings — "U.Nakamura" <usa@...> 2008/06/05

こんにちは、なかむら(う)です。

[#34948] Re: open() and encodings — Hidetoshi NAGAI <nagai@...> 2008/06/05

永井@知能.九工大です.

[#34961] Re: open() and encodings — "NARUSE, Yui" <naruse@...> 2008/06/05

成瀬です。

[#34997] Re: [ruby-changes:5517] Ruby:r17021 (trunk): * vm_insnhelper.c, vm.c, proc.c (proc_call): allow call method with — SASADA Koichi <ko1@...>

 ささだです.

19 messages 2008/06/08
[#34998] Re: [ruby-changes:5517] Ruby:r17021 (trunk): * vm_insnhelper.c, vm.c, proc.c (proc_call): allow call method with — Yukihiro Matsumoto <matz@...> 2008/06/08

まつもと ゆきひろです

[#34999] Re: [ruby-changes:5517] Ruby:r17021 (trunk): * vm_insnhelper.c, vm.c, proc.c (proc_call): allow call method with — SASADA Koichi <ko1@...> 2008/06/08

 ささだです.

[#35000] Re: [ruby-changes:5517] Ruby:r17021 (trunk): * vm_insnhelper.c, vm.c, proc.c (proc_call): allow call method with — Yukihiro Matsumoto <matz@...> 2008/06/08

まつもと ゆきひろです

[#35001] Re: [ruby-changes:5517] Ruby:r17021 (trunk): * vm_insnhelper.c, vm.c, proc.c (proc_call): allow call method with — SASADA Koichi <ko1@...> 2008/06/08

 ささだです.

[#35003] Re: [ruby-changes:5517] Ruby:r17021 (trunk): * vm_insnhelper.c, vm.c, proc.c (proc_call): allow call method with — Yukihiro Matsumoto <matz@...> 2008/06/08

まつもと ゆきひろです

[#35007] Re: [ruby-changes:5517] Ruby:r17021 (trunk): * vm_insnhelper.c, vm.c, proc.c (proc_call): allow call method with — "Yusuke ENDOH" <mame@...> 2008/06/09

遠藤です。

[#35013] Re: [ruby-changes:5517] Ruby:r17021 (trunk): * vm_insnhelper.c, vm.c, proc.c (proc_call): allow call method with — Yukihiro Matsumoto <matz@...> 2008/06/09

まつもと ゆきひろです

[#35019] Re: [ruby-changes:5517] Ruby:r17021 (trunk): * vm_insnhelper.c, vm.c, proc.c (proc_call): allow call method with — "Yusuke ENDOH" <mame@...> 2008/06/09

遠藤です。

[#35021] Re: [ruby-changes:5517] Ruby:r17021 (trunk): * vm_insnhelper.c, vm.c, proc.c (proc_call): allow call method with — Yukihiro Matsumoto <matz@...> 2008/06/09

まつもと ゆきひろです

[#35020] Ruby 1.8.7-p17 has been released — "Akinori MUSHA" <knu@...>

 Ruby 1.8.7-p17 をリリースしました。

13 messages 2008/06/09

[#35044] deadlock detection for 1.9 — "Yusuke ENDOH" <mame@...>

遠藤です。

14 messages 2008/06/10

[#35108] Re: [ruby-list:44988] Re: 各ブランチの計画 — Urabe Shyouhei <shyouhei@...>

卜部です。

15 messages 2008/06/15

[#35200] Win32 Unicode console output — Tietew <tietew@...>

Tietew です。

22 messages 2008/06/22
[#35270] Re: Win32 Unicode console output — "NARUSE, Yui" <naruse@...> 2008/06/29

[#35226] [PATCH] freeze required_paths in gem_prelude.rb — "Keita Yamaguchi" <keita.yamaguchi@...>

山口と申します。

14 messages 2008/06/25
[#35228] Re: [PATCH] freeze required_paths in gem_prelude.rb — "Yusuke ENDOH" <mame@...> 2008/06/25

遠藤です。

[#35230] Re: [PATCH] freeze required_paths in gem_prelude.rb — Yukihiro Matsumoto <matz@...> 2008/06/25

まつもと ゆきひろです

[#35227] [Bug:trunk] Re: [ruby-cvs:24798] Ruby:r17573 (trunk): * parse.y (primary): make functional-style not operator to act — "U.Nakamura" <usa@...>

こんにちは、なかむら(う)です。

7 messages 2008/06/25

[#35247] Re: [ruby-list:45128] Re: Ruby 1.9.0/1.8.7/1.8.6/1.8.5 new releases (Security Fix) — Urabe Shyouhei <shyouhei@...>

卜部です。-devに振ります。ひょっとしてこんなパッチでSEGVのほうはおさまっ

13 messages 2008/06/26
[#35250] Re: [ruby-list:45128] Re: Ruby 1.9.0/1.8.7/1.8.6/1.8.5 new releases (Security Fix) — Yukihiro Matsumoto <matz@...> 2008/06/26

まつもと ゆきひろです

[#35273] $SAFEの今後 — Urabe Shyouhei <shyouhei@...>

〜これまでのあらすじ〜

24 messages 2008/06/30
[#35293] Re: $SAFEの今後 — Yukihiro Matsumoto <matz@...> 2008/07/01

まつもと ゆきひろです

[#35298] Re: $SAFEの今後 — Urabe Shyouhei <shyouhei@...> 2008/07/01

卜部です。

[#35303] Re: $SAFEの今後 — Yukihiro Matsumoto <matz@...> 2008/07/01

まつもと ゆきひろです

[#35304] Re: $SAFEの今後 — Urabe Shyouhei <shyouhei@...> 2008/07/01

卜部です。

[#35305] Re: $SAFEの今後 — Yukihiro Matsumoto <matz@...> 2008/07/01

まつもと ゆきひろです

[#35306] Re: $SAFEの今後 — "Shugo Maeda" <shugo@...> 2008/07/02

前田です。

[#35278] [BUG] test_win32ole_event.rb in trunk — Masaki Suketa <masaki.suketa@...>

助田です。

22 messages 2008/06/30
[#35281] Re: [BUG] test_win32ole_event.rb in trunk — "U.Nakamura" <usa@...> 2008/06/30

こんにちは、なかむら(う)です。

[#35282] Re: [BUG] test_win32ole_event.rb in trunk — arton <artonx@...> 2008/06/30

artonです。

[#35295] Re: [BUG] test_win32ole_event.rb in trunk — Masaki Suketa <masaki.suketa@...> 2008/07/01

助田です。

[ruby-dev:35019] Re: [ruby-changes:5517] Ruby:r17021 (trunk): * vm_insnhelper.c, vm.c, proc.c (proc_call): allow call method with

From: "Yusuke ENDOH" <mame@...>
Date: 2008-06-09 13:08:37 UTC
List: ruby-dev #35019
遠藤です。

2008/06/09 18:22 Yukihiro Matsumoto <matz@ruby-lang.org>:
> rb_block_call_funcにはブロック引数があるかどうかの情報は含ま
> れていないような気がするんですが、それはrb_block_call_funcそ
> のものを今後拡張すると言う意味でしょうか。

そういう意味です。


> その辺がクリアになれば(若干のCレベルでの非互換性が発生します
> が)、変更してもかまわないような気がして来ました。

試しにやってみました。

http://www.atdot.net/sp/view/97572k

やたらでかいですが、ほとんどは blockptr を受け取る仮引数の
追加と、rb_block_call_func と型が異なる引数のキャストです。



ところで。
このパッチを書いた後に気づいたのですが、Ruby では以下の C の
コードで bar() が 101 を返すことを仮定しているのでしょうか。

    int foo(int i) {
        return i + 100;
    }

    int bar() {
        int (*func)();
        func = foo;
        return func(1, 2); /* 引数の数が異なる */
    }

これはたぶん C の仕様としては保証されなさそうなのですが、
Ruby のソースコード中にはこれを仮定したコードが多数含まれて
います。
enumerator.c の each_slice_i(VALUE val, VALUE *memo) とか。
でもこういうコードが実際いろんな環境で動いているわけで、
わりと仮定していい性質なんでしょうか。よくわかりません。


もしこの性質を今後も仮定するなら、rb_block_call でブロックを
呼び出すときに最後にブロックを持たせるだけで、互換性を保証?
しつつ、問題が解決できそうです。

以下は Proc#curry だけやってみたパッチです。

$ ./ruby -e '
c = proc {|x, y, &b| x + y + b.call }.curry
c = c.call(1) { 100 } #=> warning: given block not used
r = c.call(2) { 200 }
p r  #=> 203
'


Index: include/ruby/ruby.h
===================================================================
--- include/ruby/ruby.h	(revision 17060)
+++ include/ruby/ruby.h	(working copy)
@@ -824,6 +824,8 @@
 PRINTF_ARGS(void rb_warn(const char*, ...), 1, 2);
 PRINTF_ARGS(void rb_compile_warn(const char *, int, const char*, ...), 3, 4);

+typedef struct rb_block_struct *rb_blockptr;
+
 typedef VALUE rb_block_call_func(VALUE, VALUE, int, VALUE*);

 VALUE rb_each(VALUE);
Index: vm_core.h
===================================================================
--- vm_core.h	(revision 17060)
+++ vm_core.h	(working copy)
@@ -345,7 +345,7 @@
     VALUE prof_time_chld;       /* cfp[13] */
 } rb_control_frame_t;

-typedef struct {
+typedef struct rb_block_struct {
     VALUE self;			/* share with method frame if it's only block */
     VALUE *lfp;			/* share with method frame if it's only block */
     VALUE *dfp;			/* share with method frame if it's only block */
Index: proc.c
===================================================================
--- proc.c	(revision 17060)
+++ proc.c	(working copy)
@@ -490,7 +490,7 @@
     rb_block_t *blockptr = 0;
     GetProcPtr(procval, proc);

-    if (BUILTIN_TYPE(proc->block.iseq) != T_NODE &&
+    if (BUILTIN_TYPE(proc->block.iseq) == T_NODE ||
 	proc->block.iseq->arg_block != -1) {

 	if (rb_block_given_p()) {
@@ -506,15 +506,21 @@
 			  argc, argv, blockptr);
 }

-VALUE
-rb_proc_call(VALUE self, VALUE args)
+static VALUE
+rb_proc_call_with_block(VALUE self, VALUE args, rb_blockptr blockptr)
 {
     rb_proc_t *proc;
     GetProcPtr(self, proc);
     return vm_invoke_proc(GET_THREAD(), proc, proc->block.self,
-			  RARRAY_LEN(args), RARRAY_PTR(args), 0);
+			  RARRAY_LEN(args), RARRAY_PTR(args), blockptr);
 }

+VALUE
+rb_proc_call(VALUE self, VALUE args)
+{
+    return rb_proc_call_with_block(self, args, 0);
+}
+
 /*
  *  call-seq:
  *     prc.arity -> fixnum
@@ -1584,7 +1590,7 @@
     return bindval;
 }

-static VALUE curry(VALUE dummy, VALUE args, int argc, VALUE *argv);
+static VALUE curry(VALUE dummy, VALUE args, int argc, VALUE *argv,
rb_blockptr blockptr);

 static VALUE
 make_curry_proc(VALUE proc, VALUE passed, VALUE arity)
@@ -1600,7 +1606,7 @@
 }

 static VALUE
-curry(VALUE dummy, VALUE args, int argc, VALUE *argv)
+curry(VALUE dummy, VALUE args, int argc, VALUE *argv, rb_blockptr blockptr)
 {
     VALUE proc, passed, arity;
     proc = RARRAY_PTR(args)[0];
@@ -1610,10 +1616,13 @@
     passed = rb_ary_plus(passed, rb_ary_new4(argc, argv));
     rb_ary_freeze(passed);
     if(RARRAY_LEN(passed) < FIX2INT(arity)) {
+	if (blockptr) {
+	    rb_warn("given block not used");
+	}
 	arity = make_curry_proc(proc, passed, arity);
 	return arity;
     }
-    arity = rb_proc_call(proc, passed);
+    arity = rb_proc_call_with_block(proc, passed, blockptr);
     return arity;
 }

Index: vm.c
===================================================================
--- vm.c	(revision 17060)
+++ vm.c	(working copy)
@@ -448,7 +448,7 @@
 	return vm_eval_body(th);
     }
     else {
-	return vm_yield_with_cfunc(th, block, self, argc, argv);
+	return vm_yield_with_cfunc(th, block, self, argc, argv, blockptr);
     }
 }

Index: vm_insnhelper.c
===================================================================
--- vm_insnhelper.c	(revision 17060)
+++ vm_insnhelper.c	(working copy)
@@ -651,7 +651,8 @@

 static inline VALUE
 vm_yield_with_cfunc(rb_thread_t *th, const rb_block_t *block,
-		    VALUE self, int argc, const VALUE *argv)
+		    VALUE self, int argc, const VALUE *argv,
+		    const rb_block_t *blockptr)
 {
     NODE *ifunc = (NODE *) block->iseq;
     VALUE val;
@@ -672,7 +673,7 @@
 		  self, (VALUE)block->dfp,
 		  0, th->cfp->sp, block->lfp, 1);

-    val = (*ifunc->nd_cfnc) (arg, ifunc->nd_tval, argc, argv);
+    val = (*ifunc->nd_cfnc) (arg, ifunc->nd_tval, argc, argv, blockptr);

     th->cfp++;
     return val;
@@ -831,7 +832,7 @@
 	return Qundef;
     }
     else {
-	VALUE val = vm_yield_with_cfunc(th, block, block->self, argc,
STACK_ADDR_FROM_TOP(argc));
+	VALUE val = vm_yield_with_cfunc(th, block, block->self, argc,
STACK_ADDR_FROM_TOP(argc), 0);
 	POPN(argc); /* TODO: should put before C/yield? */
 	return val;
     }

-- 
Yusuke ENDOH <mame@tsg.ne.jp>

In This Thread