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

ruby-changes:25289

From: ko1 <ko1@a...>
Date: Sat, 27 Oct 2012 11:11:50 +0900 (JST)
Subject: [ruby-changes:25289] ko1:r37341 (trunk): * numeric.c (rb_float_new_in_heap), include/ruby/ruby.h:

ko1	2012-10-27 11:10:53 +0900 (Sat, 27 Oct 2012)

  New Revision: 37341

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=37341

  Log:
    * 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@r...>.
    * 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.

  Modified files:
    trunk/ChangeLog
    trunk/class.c
    trunk/include/ruby/ruby.h
    trunk/numeric.c
    trunk/test/ruby/marshaltestlib.rb
    trunk/test/ruby/test_class.rb
    trunk/test/test_pp.rb
    trunk/vm.c

Index: include/ruby/ruby.h
===================================================================
--- include/ruby/ruby.h	(revision 37340)
+++ include/ruby/ruby.h	(revision 37341)
@@ -1133,7 +1133,7 @@
                         (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
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 37340)
+++ ChangeLog	(revision 37341)
@@ -1,3 +1,21 @@
+Sat Oct 27 11:01:10 2012  Koichi Sasada  <ko1@a...>
+
+	* 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@r...>.
+
+	* 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@t...>
 
 	* object.c (rb_mod_const_get): make sure the constant name is
Index: class.c
===================================================================
--- class.c	(revision 37340)
+++ class.c	(revision 37341)
@@ -1322,6 +1322,10 @@
 	    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) {
Index: numeric.c
===================================================================
--- numeric.c	(revision 37340)
+++ numeric.c	(revision 37341)
@@ -620,6 +620,7 @@
     NEWOBJ_OF(flt, struct RFloat, rb_cFloat, T_FLOAT);
 
     flt->float_value = d;
+    OBJ_FREEZE(flt);
     return (VALUE)flt;
 }
 
Index: vm.c
===================================================================
--- vm.c	(revision 37340)
+++ vm.c	(revision 37341)
@@ -1872,7 +1872,7 @@
     }
 
     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));
Index: test/ruby/marshaltestlib.rb
===================================================================
--- test/ruby/marshaltestlib.rb	(revision 37340)
+++ test/ruby/marshaltestlib.rb	(revision 37341)
@@ -207,30 +207,6 @@
     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)
Index: test/ruby/test_class.rb
===================================================================
--- test/ruby/test_class.rb	(revision 37340)
+++ test/ruby/test_class.rb	(revision 37341)
@@ -187,12 +187,8 @@
 
   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), [])
Index: test/test_pp.rb
===================================================================
--- test/test_pp.rb	(revision 37340)
+++ test/test_pp.rb	(revision 37341)
@@ -107,10 +107,6 @@
     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

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

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