From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from kankan.nagaokaut.ac.jp (kankan.nagaokaut.ac.jp [133.44.2.24]) by blade.nagaokaut.ac.jp (8.12.3/8.12.3/Debian-6.6) with ESMTP id l3T4bdrU028380 for ; Sun, 29 Apr 2007 13:37:39 +0900 Received: from funfun.nagaokaut.ac.jp (funfun.nagaokaut.ac.jp [133.44.2.201]) by kankan.nagaokaut.ac.jp (Postfix) with ESMTP id 10C9D60D0 for ; Sun, 29 Apr 2007 13:37:39 +0900 (JST) Received: from localhost (localhost.nagaokaut.ac.jp [127.0.0.1]) by funfun.nagaokaut.ac.jp (Postfix) with ESMTP id 467D1F04842 for ; Sun, 29 Apr 2007 13:37:41 +0900 (JST) Received: from voscc.nagaokaut.ac.jp (voscc.nagaokaut.ac.jp [133.44.1.100]) by funfun.nagaokaut.ac.jp (Postfix) with ESMTP id 5AEB5F04850 for ; Sun, 29 Apr 2007 13:37:39 +0900 (JST) Received: from carbon.ruby-lang.org (carbon.ruby-lang.org [221.186.184.68]) by voscc.nagaokaut.ac.jp (Postfix) with ESMTP id 9048063004D for ; Sun, 29 Apr 2007 13:37:39 +0900 (JST) Received: from beryllium.ruby-lang.org (beryllium.ruby-lang.org [127.0.0.1]) by carbon.ruby-lang.org (Postfix) with ESMTP id 6E9A33C21EB45; Sun, 29 Apr 2007 13:37:35 +0900 (JST) Received: from wr-out-0506.google.com (wr-out-0506.google.com [64.233.184.239]) by carbon.ruby-lang.org (Postfix) with ESMTP id 94F0C3C21F113 for ; Sun, 29 Apr 2007 13:37:31 +0900 (JST) Received: by wr-out-0506.google.com with SMTP id i3so754282wra for ; Sat, 28 Apr 2007 21:37:31 -0700 (PDT) Received: by 10.78.136.7 with SMTP id j7mr1494707hud.1177821450322; Sat, 28 Apr 2007 21:37:30 -0700 (PDT) Received: by 10.78.133.9 with HTTP; Sat, 28 Apr 2007 21:37:30 -0700 (PDT) Delivered-To: ruby-core@ruby-lang.org Date: Sun, 29 Apr 2007 13:37:32 +0900 Posted: Sat, 28 Apr 2007 21:37:30 -0700 From: "Adam Bozanich" Reply-To: ruby-core@ruby-lang.org Subject: Re: [patch] Re: [BUG] Proc#arity regression or bug in RDoc To: ruby-core@ruby-lang.org Message-Id: In-Reply-To: References: <20070426095541.GU17734@tux-chan> <20070426103955.GW17734@tux-chan> X-ML-Name: ruby-core X-Mail-Count: 11059 X-MLServer: fml [fml 4.0.3 release (20011202/4.0.3)]; post only (only members can post) X-ML-Info: If you have a question, send e-mail with the body "help" (without quotes) to the address ruby-core-ctl@ruby-lang.org; help= X-Spam-Checker-Version: SpamAssassin 3.1.7 (2006-10-05) on carbon.ruby-lang.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=7.0 tests=ARIN,AWL,BAYES_00, CONTENT_TYPE_PRESENT,FAKEDWORD_ONE,FAKEDWORD_VERTICALLINE, FAKEDWORD_ZERO,HTML_40_50,HTML_MESSAGE,MULTIPART_ALTERNATIVE,QENCPTR2, TOOLONGSTR autolearn=disabled version=3.1.7 X-Original-To: ruby-core@ruby-lang.org DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:references; b=KswzuqjsVlz/i6jKKvgF5ZvtYvIX+wvIEnjGMzhxZmQzYantyrBT3mYjuaYyEPuZZqDFSRUnlsYWQEhajCrhg/3vkdJ8ajX+HeMX11ZGSEcF1/yc7G+4+/QGF7hyVfgIqwq1zkIGQ9qlVUNCyfRKnCe6LvC7dZZtz9kjxkHj/50= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:references; b=doi2bXCyr+TQyJLXrZkSMax0ck26yNDK9dOctD3BZyFwUX+XODXXXubfhfjwSNzxjaA1ze++x96Pwh4ybovnWEUYZSjvB/LnnZKhyTcM+Mk2C0FSQZjVhGQOuhiM03dTiLGJhN8wPTN5M8gXNzn8R6VvZDkO0TioJliMrKzzUtY= Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_167011_11558811.1177821450244" Precedence: bulk List-Id: ruby-core.ruby-lang.org List-Software: fml [fml 4.0.3 release (20011202/4.0.3)] List-Post: List-Owner: List-Help: List-Unsubscribe: X-Virus-Scanned: by amavisd 0.1 ------=_Part_167011_11558811.1177821450244 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline Cleaned it up a bit & added some tests to sample/test.rb. Not sure where you guys prefer the unit tests to go. Is there a specific policy? Also, is it better to submit small patches like this to rubyforge or directly this list? -Adam Index: proc.c =================================================================== --- proc.c (revision 12228) +++ proc.c (working copy) @@ -434,9 +434,9 @@ GetProcPtr(self, proc); iseq = proc->block.iseq; if (iseq && BUILTIN_TYPE(iseq) != T_NODE) { - if (iseq->arg_rest == 0 && iseq->arg_opts == 0) { - return INT2FIX(iseq->argc); - } + if( iseq->arg_rest < 0 ) { + return INT2FIX(iseq->argc); + } else { return INT2FIX(-iseq->argc - 1); } Index: sample/test.rb =================================================================== --- sample/test.rb (revision 12228) +++ sample/test.rb (working copy) @@ -1283,6 +1283,36 @@ lambda(&method(:test_ok)).call(true) lambda(&block_get{|a,n| test_ok(a,n)}).call(true, 2) +# Proc#arity +test_ok( Proc.new {}.arity , 0 ) +test_ok( Proc.new {||}.arity , 0 ) +test_ok( Proc.new {|a|}.arity , 1 ) +test_ok( Proc.new {|a,b|}.arity , 2 ) +test_ok( Proc.new {|a,b,c|}.arity , 3 ) +test_ok( Proc.new {|*a|}.arity , -1 ) +test_ok( Proc.new {|a,*b|}.arity , -2 ) + +# Method#arity +class C + def one; end + def two(a); end + def three(*a); end + def four(a, b); end + def five(a, b, *c); end + def six(a, b, *c, &d); end +end +c = C.new +test_ok( c.method(:one).arity , 0 ) +test_ok( c.method(:two).arity , 1 ) +test_ok( c.method(:three).arity , -1 ) +test_ok( c.method(:four).arity , 2 ) +test_ok( c.method(:five).arity , -3 ) +test_ok( c.method(:six).arity , -3 ) +test_ok( "cat".method(:size).arity , 0 ) +test_ok( "cat".method(:replace).arity , 1 ) +test_ok( "cat".method(:squeeze).arity , -1 ) +test_ok( "cat".method(:count).arity , -1 ) + class ITER_TEST1 def a block_given? On 4/26/07, Adam Bozanich wrote: > > > On 4/26/07, Mauricio Fernandez wrote: > > > > On Thu, Apr 26, 2007 at 06:55:46PM +0900, Mauricio Fernandez wrote: > > > $ ruby19 -v -e "p proc{}.arity" > > > ruby 1.9.0 (2007-02-07 patchlevel 0) [i686-linux] > > > 0 > > > $ ./ruby19 -v -e "p proc{}.arity" > > > ruby 1.9.0 (2007-04-26 patchlevel 0) [i686-linux] > > > -1 > > > > > > However, the RDoc documentation attached to proc_arity still says that > > it > > > should return 0, so there's a bug, either in the code (wrong > > iseq->argc ?) or > > > in the docs (if the latter, the patch below should do). > > > > It seems it's a regression after all; no time to fix it now, but I've > > found > > when it happened: > > > > ruby-trunk-12116$ ./ruby -v -e "p proc{}.arity" > > ruby 1.9.0 (2007-03-21 patchlevel 0) [i686-linux] > > 0 > > > > ruby-trunk-12117$ ./ruby -v -e "p proc{}.arity" > > ruby 1.9.0 (2007-03-21 patchlevel 0) [i686-linux] > > -1 > > > > > This makes arity behave like the docs specify for both method.arity and > proc.arity. I'm sure it's naive, but it seems to work. > > -Adam > > Index: proc.c > =================================================================== > --- proc.c (revision 12226) > +++ proc.c (working copy) > @@ -434,11 +434,11 @@ > GetProcPtr(self, proc); > iseq = proc->block.iseq; > if (iseq && BUILTIN_TYPE(iseq) != T_NODE) { > - if (iseq->arg_rest == 0 && iseq->arg_opts == 0) { > - return INT2FIX(iseq->argc); > - } > + if( iseq->arg_rest < 0 ) { > + return INT2FIX(iseq->argc); > + } > else { > - return INT2FIX(-iseq->argc - 1); > + return INT2FIX(-(iseq->argc + 1)); > } > } > else { > > ------=_Part_167011_11558811.1177821450244 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Cleaned it up a bit & added some tests to sample/test.rb.  Not sure where you guys prefer the unit tests to go.  Is there a specific policy?  Also, is it better to submit small patches like this to rubyforge or directly this list?

-Adam

Index: proc.c
===================================================================
--- proc.c      (revision 12228)
+++ proc.c      (working copy)
@@ -434,9 +434,9 @@
     GetProcPtr(self, proc);
     iseq = proc->block.iseq;
     if (iseq && BUILTIN_TYPE(iseq) != T_NODE) {
-       if (iseq->arg_rest == 0 && iseq->arg_opts == 0) {
-           return INT2FIX(iseq->argc);
-       }
+       if( iseq->arg_rest < 0 ) {
+               return INT2FIX(iseq->argc);
+       }    
        else {
            return INT2FIX(-iseq->argc - 1);
        }
Index: sample/test.rb
===================================================================
--- sample/test.rb      (revision 12228)
+++ sample/test.rb      (working copy)
@@ -1283,6 +1283,36 @@
 lambda(&method(:test_ok)).call(true)
 lambda(&block_get{|a,n| test_ok(a,n)}).call(true, 2)
 
+# Proc#arity
+test_ok( Proc.new {}.arity        ,  0 )
+test_ok( Proc.new {||}.arity      ,  0 )
+test_ok( Proc.new {|a|}.arity     ,  1 )
+test_ok( Proc.new {|a,b|}.arity   ,  2 )
+test_ok( Proc.new {|a,b,c|}.arity ,  3 )
+test_ok( Proc.new {|*a|}.arity    , -1 )
+test_ok( Proc.new {|a,*b|}.arity  , -2 )
+
+# Method#arity
+class C
+  def one;    end
+  def two(a); end
+  def three(*a);  end
+  def four(a, b); end
+  def five(a, b, *c);    end
+  def six(a, b, *c, &d); end
+end
+c = C.new
+test_ok( c.method(:one).arity   , 0 )
+test_ok( c.method(:two).arity   , 1 )
+test_ok( c.method(:three).arity , -1 )
+test_ok( c.method(:four).arity  , 2 )
+test_ok( c.method(:five).arity  , -3 )
+test_ok( c.method(:six).arity   , -3 )
+test_ok( "cat".method(:size).arity    , 0 )
+test_ok( "cat".method(:replace).arity , 1 )
+test_ok( "cat".method(:squeeze).arity , -1 )
+test_ok( "cat".method(:count).arity   , -1 )
+
 class ITER_TEST1
    def a
      block_given?


On 4/26/07, Adam Bozanich <adam.boz@gmail.com> wrote:

On 4/26/07, Mauricio Fernandez <mfp@acm.org > wrote:
On Thu, Apr 26, 2007 at 06:55:46PM +0900, Mauricio Fernandez wrote:
> $ ruby19 -v -e "p proc{}.arity"
> ruby 1.9.0 (2007-02-07 patchlevel 0) [i686-linux]
> 0
> $ ./ruby19 -v -e "p proc{}.arity"
> ruby 1.9.0 (2007-04-26 patchlevel 0) [i686-linux]
> -1
>
> However, the RDoc documentation attached to proc_arity still says that it
> should return 0, so there's a bug, either in the code (wrong iseq->argc ?) or
> in the docs (if the latter, the patch below should do).

It seems it's a regression after all; no time to fix it now, but I've found
when it happened:

ruby-trunk-12116$ ./ruby -v -e "p proc{}.arity"
ruby 1.9.0 (2007-03-21 patchlevel 0) [i686-linux]
0

ruby-trunk-12117$ ./ruby -v -e "p proc{}.arity"
ruby 1.9.0 (2007-03-21 patchlevel 0) [i686-linux]
-1


This makes arity behave like the docs specify for both method.arity and proc.arity.  I'm sure it's naive, but it seems to work.

-Adam

Index: proc.c
===================================================================
--- proc.c      (revision 12226)
+++ proc.c      (working copy)
@@ -434,11 +434,11 @@
     GetProcPtr(self, proc);
     iseq = proc->block.iseq;
     if (iseq && BUILTIN_TYPE(iseq) != T_NODE) {
-       if (iseq->arg_rest == 0 && iseq->arg_opts == 0) {
-           return INT2FIX(iseq->argc);
-       }
+       if( iseq->arg_rest < 0 ) {
+               return INT2FIX(iseq->argc);
+       }    
        else {
-           return INT2FIX(-iseq->argc - 1);
+           return INT2FIX(-(iseq->argc + 1));
        }
     }
     else {


------=_Part_167011_11558811.1177821450244--