mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* numeric.c (rb_float_new_in_heap), include/ruby/ruby.h:
make all Float objects frozen. [ruby-dev:46081] [ruby-trunk - Feature #6936] Most part of patch by NARUSE, Yui <naruse@ruby-lang.org>. * class.c (singleton_class_of): raise TypeError when trying to define a singleton method on Float objects. * vm.c (vm_define_method): ditto. * test/ruby/marshaltestlib.rb: catch up above changes. * test/ruby/test_class.rb: ditto. * test/test_pp.rb: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37341 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
909bc583a4
commit
180c744b3b
8 changed files with 27 additions and 36 deletions
18
ChangeLog
18
ChangeLog
|
@ -1,3 +1,21 @@
|
||||||
|
Sat Oct 27 11:01:10 2012 Koichi Sasada <ko1@atdot.net>
|
||||||
|
|
||||||
|
* numeric.c (rb_float_new_in_heap), include/ruby/ruby.h:
|
||||||
|
make all Float objects frozen.
|
||||||
|
[ruby-dev:46081] [ruby-trunk - Feature #6936]
|
||||||
|
Most part of patch by NARUSE, Yui <naruse@ruby-lang.org>.
|
||||||
|
|
||||||
|
* class.c (singleton_class_of): raise TypeError when
|
||||||
|
trying to define a singleton method on Float objects.
|
||||||
|
|
||||||
|
* vm.c (vm_define_method): ditto.
|
||||||
|
|
||||||
|
* test/ruby/marshaltestlib.rb: catch up above changes.
|
||||||
|
|
||||||
|
* test/ruby/test_class.rb: ditto.
|
||||||
|
|
||||||
|
* test/test_pp.rb: ditto.
|
||||||
|
|
||||||
Sat Oct 27 10:50:53 2012 Aaron Patterson <aaron@tenderlovemaking.com>
|
Sat Oct 27 10:50:53 2012 Aaron Patterson <aaron@tenderlovemaking.com>
|
||||||
|
|
||||||
* object.c (rb_mod_const_get): make sure the constant name is
|
* object.c (rb_mod_const_get): make sure the constant name is
|
||||||
|
|
4
class.c
4
class.c
|
@ -1322,6 +1322,10 @@ singleton_class_of(VALUE obj)
|
||||||
rb_bug("unknown immediate %p", (void *)obj);
|
rb_bug("unknown immediate %p", (void *)obj);
|
||||||
return klass;
|
return klass;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
if (BUILTIN_TYPE(obj) == T_FLOAT)
|
||||||
|
rb_raise(rb_eTypeError, "can't define singleton");
|
||||||
|
}
|
||||||
|
|
||||||
if (FL_TEST(RBASIC(obj)->klass, FL_SINGLETON) &&
|
if (FL_TEST(RBASIC(obj)->klass, FL_SINGLETON) &&
|
||||||
rb_ivar_get(RBASIC(obj)->klass, id_attached) == obj) {
|
rb_ivar_get(RBASIC(obj)->klass, id_attached) == obj) {
|
||||||
|
|
|
@ -1133,7 +1133,7 @@ struct RBignum {
|
||||||
(FL_TAINT | FL_UNTRUSTED); \
|
(FL_TAINT | FL_UNTRUSTED); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define OBJ_FROZEN(x) (!!FL_TEST((x), FL_FREEZE))
|
#define OBJ_FROZEN(x) (!!(FL_ABLE(x)?(RBASIC(x)->flags&(FL_FREEZE)):FLONUM_P(x)))
|
||||||
#define OBJ_FREEZE(x) FL_SET((x), FL_FREEZE)
|
#define OBJ_FREEZE(x) FL_SET((x), FL_FREEZE)
|
||||||
|
|
||||||
#if SIZEOF_INT < SIZEOF_LONG
|
#if SIZEOF_INT < SIZEOF_LONG
|
||||||
|
|
|
@ -620,6 +620,7 @@ rb_float_new_in_heap(double d)
|
||||||
NEWOBJ_OF(flt, struct RFloat, rb_cFloat, T_FLOAT);
|
NEWOBJ_OF(flt, struct RFloat, rb_cFloat, T_FLOAT);
|
||||||
|
|
||||||
flt->float_value = d;
|
flt->float_value = d;
|
||||||
|
OBJ_FREEZE(flt);
|
||||||
return (VALUE)flt;
|
return (VALUE)flt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -207,30 +207,6 @@ module MarshalTestLib
|
||||||
marshal_equal(NegativeZero) {|o| 1.0/o}
|
marshal_equal(NegativeZero) {|o| 1.0/o}
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_float_ivar
|
|
||||||
o1 = 1.23
|
|
||||||
o1.instance_eval { @iv = 1 }
|
|
||||||
marshal_equal(o1) {|o| o.instance_eval { @iv }}
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_float_ivar_self
|
|
||||||
o1 = 5.5
|
|
||||||
o1.instance_eval { @iv = o1 }
|
|
||||||
marshal_equal(o1) {|o| o.instance_eval { @iv }}
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_float_extend
|
|
||||||
o1 = 0.0/0.0
|
|
||||||
o1.extend(Mod1)
|
|
||||||
marshal_equal(o1) { |o|
|
|
||||||
(class << self; self; end).ancestors
|
|
||||||
}
|
|
||||||
o1.extend(Mod2)
|
|
||||||
marshal_equal(o1) { |o|
|
|
||||||
(class << self; self; end).ancestors
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
class MyRange < Range; def initialize(v, *args) super(*args); @v = v; end end
|
class MyRange < Range; def initialize(v, *args) super(*args); @v = v; end end
|
||||||
def test_range
|
def test_range
|
||||||
marshal_equal(1..2)
|
marshal_equal(1..2)
|
||||||
|
|
|
@ -187,12 +187,8 @@ class TestClass < Test::Unit::TestCase
|
||||||
|
|
||||||
def test_singleton_class
|
def test_singleton_class
|
||||||
assert_raise(TypeError) { 1.extend(Module.new) }
|
assert_raise(TypeError) { 1.extend(Module.new) }
|
||||||
if 1.0.equal? 1.0 # flonum?
|
assert_raise(TypeError) { 1.0.extend(Module.new) }
|
||||||
assert_raise(TypeError) { 1.0.extend(Module.new) }
|
assert_raise(TypeError) { (2.0**1000).extend(Module.new) }
|
||||||
else
|
|
||||||
assert_nothing_raised { 1.0.extend(Module.new) }
|
|
||||||
end
|
|
||||||
assert_nothing_raised { (2.0**1000).extend(Module.new) }
|
|
||||||
assert_raise(TypeError) { :foo.extend(Module.new) }
|
assert_raise(TypeError) { :foo.extend(Module.new) }
|
||||||
|
|
||||||
assert_in_out_err([], <<-INPUT, %w(:foo :foo true true), [])
|
assert_in_out_err([], <<-INPUT, %w(:foo :foo true true), [])
|
||||||
|
|
|
@ -107,10 +107,6 @@ class PPInspectTest < Test::Unit::TestCase
|
||||||
a.instance_eval { @a = nil }
|
a.instance_eval { @a = nil }
|
||||||
result = PP.pp(a, '')
|
result = PP.pp(a, '')
|
||||||
assert_equal("#{a.inspect}\n", result)
|
assert_equal("#{a.inspect}\n", result)
|
||||||
a = 1.0
|
|
||||||
a.instance_eval { @a = nil }
|
|
||||||
result = PP.pp(a, '')
|
|
||||||
assert_equal("#{a.inspect}\n", result)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_to_s_without_iv
|
def test_to_s_without_iv
|
||||||
|
|
2
vm.c
2
vm.c
|
@ -1872,7 +1872,7 @@ vm_define_method(rb_thread_t *th, VALUE obj, ID id, VALUE iseqval,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_singleton) {
|
if (is_singleton) {
|
||||||
if (FIXNUM_P(obj) || FLONUM_P(obj) || SYMBOL_P(obj)) {
|
if (FIXNUM_P(obj) || SYMBOL_P(obj) || CLASS_OF(obj) == rb_cFloat) {
|
||||||
rb_raise(rb_eTypeError,
|
rb_raise(rb_eTypeError,
|
||||||
"can't define singleton method \"%s\" for %s",
|
"can't define singleton method \"%s\" for %s",
|
||||||
rb_id2name(id), rb_obj_classname(obj));
|
rb_id2name(id), rb_obj_classname(obj));
|
||||||
|
|
Loading…
Add table
Reference in a new issue