diff options
-rw-r--r-- | object.c | 17 | ||||
-rw-r--r-- | test/ruby/test_object.rb | 4 |
2 files changed, 19 insertions, 2 deletions
@@ -297,6 +297,19 @@ init_copy(VALUE dest, VALUE obj) } } +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, VALUE obj) } } - 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) { VALUE dup; - if (rb_special_const_p(obj)) { + if (special_object_p(obj)) { return obj; } dup = rb_obj_alloc(rb_obj_class(obj)); diff --git a/test/ruby/test_object.rb b/test/ruby/test_object.rb index dbe7e442ba..c1721de39c 100644 --- a/test/ruby/test_object.rb +++ b/test/ruby/test_object.rb @@ -23,6 +23,8 @@ class TestObject < Test::Unit::TestCase 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 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)} |