From 4a19cb828031f1672fffe07c24c470d8acd53f6e Mon Sep 17 00:00:00 2001 From: nobu Date: Tue, 29 Nov 2016 15:34:31 +0000 Subject: 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] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56933 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- object.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'object.c') diff --git a/object.c b/object.c index a1dcf830e7..5f0055fb5a 100644 --- a/object.c +++ b/object.c @@ -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)); -- cgit v1.2.3