Skip to content
Browse files

* 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
  • Loading branch information...
1 parent 909bc58 commit 180c744b3b4043b2491031a4af9c8cbe4c0ae2ab @ko1 ko1 committed Oct 27, 2012
Showing with 27 additions and 36 deletions.
  1. +18 −0 ChangeLog
  2. +4 −0 class.c
  3. +1 −1 include/ruby/ruby.h
  4. +1 −0 numeric.c
  5. +0 −24 test/ruby/marshaltestlib.rb
  6. +2 −6 test/ruby/test_class.rb
  7. +0 −4 test/test_pp.rb
  8. +1 −1 vm.c
View
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>
* object.c (rb_mod_const_get): make sure the constant name is
View
4 class.c
@@ -1322,6 +1322,10 @@ singleton_class_of(VALUE obj)
rb_bug("unknown immediate %p", (void *)obj);
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) &&
rb_ivar_get(RBASIC(obj)->klass, id_attached) == obj) {
View
2 include/ruby/ruby.h
@@ -1133,7 +1133,7 @@ struct RBignum {
(FL_TAINT | FL_UNTRUSTED); \
} 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)
#if SIZEOF_INT < SIZEOF_LONG
View
1 numeric.c
@@ -620,6 +620,7 @@ rb_float_new_in_heap(double d)
NEWOBJ_OF(flt, struct RFloat, rb_cFloat, T_FLOAT);
flt->float_value = d;
+ OBJ_FREEZE(flt);
return (VALUE)flt;
}
View
24 test/ruby/marshaltestlib.rb
@@ -207,30 +207,6 @@ def test_float_inf_nan
marshal_equal(NegativeZero) {|o| 1.0/o}
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
def test_range
marshal_equal(1..2)
View
8 test/ruby/test_class.rb
@@ -187,12 +187,8 @@ def test_initialize_copy
def test_singleton_class
assert_raise(TypeError) { 1.extend(Module.new) }
- if 1.0.equal? 1.0 # flonum?
- assert_raise(TypeError) { 1.0.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) { 1.0.extend(Module.new) }
+ assert_raise(TypeError) { (2.0**1000).extend(Module.new) }
assert_raise(TypeError) { :foo.extend(Module.new) }
assert_in_out_err([], <<-INPUT, %w(:foo :foo true true), [])
View
4 test/test_pp.rb
@@ -107,10 +107,6 @@ def a.to_s() "aaa" end
a.instance_eval { @a = nil }
result = PP.pp(a, '')
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
def test_to_s_without_iv
View
2 vm.c
@@ -1872,7 +1872,7 @@ vm_define_method(rb_thread_t *th, VALUE obj, ID id, VALUE iseqval,
}
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,
"can't define singleton method \"%s\" for %s",
rb_id2name(id), rb_obj_classname(obj));

0 comments on commit 180c744

Please sign in to comment.
Something went wrong with that request. Please try again.