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

ruby-changes:28024

From: nobu <ko1@a...>
Date: Wed, 3 Apr 2013 16:34:59 +0900 (JST)
Subject: [ruby-changes:28024] nobu:r40076 (trunk): bignum.c: Bignum zero comparison

nobu	2013-04-03 16:34:31 +0900 (Wed, 03 Apr 2013)

  New Revision: 40076

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

  Log:
    bignum.c: Bignum zero comparison
    
    * bignum.c (rb_big_eq): test as Fixnum if possible and get rid of zero
      length Bignum.  [ruby-core:53893] [Bug #8204]

  Added directories:
    trunk/ext/-test-/bignum/
    trunk/test/-ext-/bignum/
  Added files:
    trunk/ext/-test-/bignum/bigzero.c
    trunk/ext/-test-/bignum/extconf.rb
    trunk/ext/-test-/bignum/init.c
    trunk/test/-ext-/bignum/test_bigzero.rb
  Modified files:
    trunk/ChangeLog
    trunk/bignum.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 40075)
+++ ChangeLog	(revision 40076)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed Apr  3 16:34:24 2013  Nobuyoshi Nakada  <nobu@r...>
+
+	* bignum.c (rb_big_eq): test as Fixnum if possible and get rid of zero
+	  length Bignum.  [ruby-core:53893] [Bug #8204]
+
 Tue Apr  2 23:56:03 2013  Tanaka Akira  <akr@f...>
 
 	* lib/securerandom.rb (SecureRandom.random_bytes): Use
Index: ext/-test-/bignum/bigzero.c
===================================================================
--- ext/-test-/bignum/bigzero.c	(revision 0)
+++ ext/-test-/bignum/bigzero.c	(revision 40076)
@@ -0,0 +1,16 @@ https://github.com/ruby/ruby/blob/trunk/ext/-test-/bignum/bigzero.c#L1
+#include "ruby.h"
+
+static VALUE
+bug_big_zero(VALUE self, VALUE length)
+{
+    long len = NUM2ULONG(length);
+    VALUE z = rb_big_new(len, 1);
+    MEMZERO(RBIGNUM_DIGITS(z), BDIGIT, len);
+    return z;
+}
+
+void
+Init_bigzero(VALUE klass)
+{
+    rb_define_singleton_method(klass, "zero", bug_big_zero, 1);
+}

Property changes on: ext/-test-/bignum/bigzero.c
___________________________________________________________________
Added: svn:eol-style
   + LF

Index: ext/-test-/bignum/init.c
===================================================================
--- ext/-test-/bignum/init.c	(revision 0)
+++ ext/-test-/bignum/init.c	(revision 40076)
@@ -0,0 +1,11 @@ https://github.com/ruby/ruby/blob/trunk/ext/-test-/bignum/init.c#L1
+#include "ruby.h"
+
+#define init(n) {void Init_##n(VALUE klass); Init_##n(klass);}
+
+void
+Init_bignum(void)
+{
+    VALUE mBug = rb_define_module("Bug");
+    VALUE klass = rb_define_class_under(mBug, "Bignum", rb_cString);
+    TEST_INIT_FUNCS(init);
+}

Property changes on: ext/-test-/bignum/init.c
___________________________________________________________________
Added: svn:eol-style
   + LF

Index: ext/-test-/bignum/extconf.rb
===================================================================
--- ext/-test-/bignum/extconf.rb	(revision 0)
+++ ext/-test-/bignum/extconf.rb	(revision 40076)
@@ -0,0 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ext/-test-/bignum/extconf.rb#L1
+$srcs = Dir[File.join($srcdir, "*.{#{SRC_EXT.join(%q{,})}}")]
+inits = $srcs.map {|s| File.basename(s, ".*")}
+inits.delete("init")
+inits.map! {|s|"X(#{s})"}
+$defs << "-DTEST_INIT_FUNCS(X)=\"#{inits.join(' ')}\""
+create_makefile("-test-/bignum")

Property changes on: ext/-test-/bignum/extconf.rb
___________________________________________________________________
Added: svn:eol-style
   + LF

Index: bignum.c
===================================================================
--- bignum.c	(revision 40075)
+++ bignum.c	(revision 40076)
@@ -1686,6 +1686,7 @@ rb_big_eq(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/bignum.c#L1686
 {
     switch (TYPE(y)) {
       case T_FIXNUM:
+	if (bignorm(x) == y) return Qtrue;
 	y = rb_int2big(FIX2LONG(y));
 	break;
       case T_BIGNUM:
Index: test/-ext-/bignum/test_bigzero.rb
===================================================================
--- test/-ext-/bignum/test_bigzero.rb	(revision 0)
+++ test/-ext-/bignum/test_bigzero.rb	(revision 40076)
@@ -0,0 +1,13 @@ https://github.com/ruby/ruby/blob/trunk/test/-ext-/bignum/test_bigzero.rb#L1
+require 'test/unit'
+require "-test-/bignum"
+
+class TestBignum < Test::Unit::TestCase
+  class TestBigZero < Test::Unit::TestCase
+    def test_equal_0
+      bug8204 = '[ruby-core:53893] [Bug #8204]'
+      (0..10).each do |i|
+        assert_equal(0, Bug::Bignum.zero(i), "#{bug8204} Bignum.zero(#{i})")
+      end
+    end
+  end
+end

Property changes on: test/-ext-/bignum/test_bigzero.rb
___________________________________________________________________
Added: svn:eol-style
   + LF


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

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