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

ruby-changes:44860

From: nobu <ko1@a...>
Date: Wed, 30 Nov 2016 00:34:35 +0900 (JST)
Subject: [ruby-changes:44860] nobu:r56933 (trunk): object.c: no TypeError at special const

nobu	2016-11-30 00:34:31 +0900 (Wed, 30 Nov 2016)

  New Revision: 56933

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

  Log:
    object.c: no TypeError at special const
    
    * object.c (special_object_p): no longer raise a TypeError for
      Integer and Float, and return itself instead.  [Feature#12979]

  Modified files:
    trunk/object.c
    trunk/test/ruby/test_object.rb
Index: test/ruby/test_object.rb
===================================================================
--- test/ruby/test_object.rb	(revision 56932)
+++ test/ruby/test_object.rb	(revision 56933)
@@ -23,6 +23,8 @@ class TestObject < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_object.rb#L23
     assert_equal true, true.dup
     assert_equal nil, nil.dup
     assert_equal false, false.dup
+    x = 1 << 64; assert_equal x, x.dup
+    x = 1.72723e-77; assert_equal x, x.dup
 
     assert_raise(TypeError) do
       Object.new.instance_eval { initialize_copy(1) }
@@ -49,6 +51,8 @@ class TestObject < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_object.rb#L51
     assert_equal true, true.clone
     assert_equal nil, nil.clone
     assert_equal false, false.clone
+    x = 1 << 64; assert_equal x, x.clone
+    x = 1.72723e-77; assert_equal x, x.clone
     assert_raise(ArgumentError) {1.clone(freeze: false)}
     assert_raise(ArgumentError) {true.clone(freeze: false)}
     assert_raise(ArgumentError) {nil.clone(freeze: false)}
Index: object.c
===================================================================
--- object.c	(revision 56932)
+++ object.c	(revision 56933)
@@ -297,6 +297,19 @@ init_copy(VALUE dest, VALUE obj) https://github.com/ruby/ruby/blob/trunk/object.c#L297
     }
 }
 
+static inline int
+special_object_p(VALUE obj)
+{
+    if (SPECIAL_CONST_P(obj)) return TRUE;
+    switch (BUILTIN_TYPE(obj)) {
+      case T_BIGNUM:
+      case T_FLOAT:
+	return TRUE;
+      default:
+	return FALSE;
+    }
+}
+
 /*
  *  call-seq:
  *     obj.clone(freeze: true) -> an_object
@@ -345,7 +358,7 @@ rb_obj_clone2(int argc, VALUE *argv, VAL https://github.com/ruby/ruby/blob/trunk/object.c#L358
 	}
     }
 
-    if (rb_special_const_p(obj)) {
+    if (special_object_p(obj)) {
 	if (kwfreeze == Qfalse)
 	    rb_raise(rb_eArgError, "can't unfreeze %s", rb_obj_classname(obj));
 	return obj;
@@ -424,7 +437,7 @@ rb_obj_dup(VALUE obj) https://github.com/ruby/ruby/blob/trunk/object.c#L437
 {
     VALUE dup;
 
-    if (rb_special_const_p(obj)) {
+    if (special_object_p(obj)) {
 	return obj;
     }
     dup = rb_obj_alloc(rb_obj_class(obj));

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

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