aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog17
-rw-r--r--bignum.c2
-rw-r--r--class.c4
-rw-r--r--include/ruby/ruby.h2
-rw-r--r--test/ruby/marshaltestlib.rb16
-rw-r--r--test/ruby/test_bignum.rb4
-rw-r--r--test/ruby/test_eval.rb2
-rw-r--r--test/ruby/test_fixnum.rb4
-rw-r--r--test/ruby/test_object.rb4
9 files changed, 33 insertions, 22 deletions
diff --git a/ChangeLog b/ChangeLog
index 9730603f84..9d99b50acb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,20 @@
+Sun Oct 28 08:23:16 2012 Koichi Sasada <ko1@atdot.net>
+
+ * bignum.c (bignew_1): Bignum instances are frozen.
+ Feature #3222
+
+ * include/ruby/ruby.h: Fixnum instances are also frozen.
+
+ * class.c (singleton_class_of): check Bignum before
+ singleton cheking.
+
+ * test/ruby/test_bignum.rb: add a test.
+
+ * test/ruby/test_fixnum.rb: ditto.
+
+ * test/ruby/marshaltestlib.rb, test/ruby/test_eval.rb,
+ test/ruby/test_object.rb: catch up above changes.
+
Sun Oct 28 04:38:06 2012 Koichi Sasada <ko1@atdot.net>
* vm.c (vm_define_method): remove type and frozen checking.
diff --git a/bignum.c b/bignum.c
index 685f9b80c1..d30f89eff4 100644
--- a/bignum.c
+++ b/bignum.c
@@ -176,7 +176,7 @@ bignew_1(VALUE klass, long len, int sign)
RBIGNUM(big)->as.heap.digits = ALLOC_N(BDIGIT, len);
RBIGNUM(big)->as.heap.len = len;
}
-
+ OBJ_FREEZE(big);
return (VALUE)big;
}
diff --git a/class.c b/class.c
index c5f0390853..e083bf633d 100644
--- a/class.c
+++ b/class.c
@@ -1323,8 +1323,10 @@ singleton_class_of(VALUE obj)
return klass;
}
else {
- if (BUILTIN_TYPE(obj) == T_FLOAT)
+ enum ruby_value_type type = BUILTIN_TYPE(obj);
+ if (type == T_FLOAT || type == T_BIGNUM) {
rb_raise(rb_eTypeError, "can't define singleton");
+ }
}
if (FL_TEST(RBASIC(obj)->klass, FL_SINGLETON) &&
diff --git a/include/ruby/ruby.h b/include/ruby/ruby.h
index 34f2c69152..3e513cc63d 100644
--- a/include/ruby/ruby.h
+++ b/include/ruby/ruby.h
@@ -1133,7 +1133,7 @@ struct RBignum {
(FL_TAINT | FL_UNTRUSTED); \
} while (0)
-#define OBJ_FROZEN(x) (!!(FL_ABLE(x)?(RBASIC(x)->flags&(FL_FREEZE)):FLONUM_P(x)))
+#define OBJ_FROZEN(x) (!!(FL_ABLE(x)?(RBASIC(x)->flags&(FL_FREEZE)):(FIXNUM_P(x)||FLONUM_P(x))))
#define OBJ_FREEZE(x) FL_SET((x), FL_FREEZE)
#if SIZEOF_INT < SIZEOF_LONG
diff --git a/test/ruby/marshaltestlib.rb b/test/ruby/marshaltestlib.rb
index d9d06325fe..56ea8892df 100644
--- a/test/ruby/marshaltestlib.rb
+++ b/test/ruby/marshaltestlib.rb
@@ -178,22 +178,6 @@ module MarshalTestLib
marshal_equal(0x3fff_ffff)
end
- def test_fixnum_ivar
- o1 = 1
- o1.instance_eval { @iv = 2 }
- marshal_equal(o1) {|o| o.instance_eval { @iv }}
- ensure
- 1.instance_eval { remove_instance_variable("@iv") }
- end
-
- def test_fixnum_ivar_self
- o1 = 1
- o1.instance_eval { @iv = 1 }
- marshal_equal(o1) {|o| o.instance_eval { @iv }}
- ensure
- 1.instance_eval { remove_instance_variable("@iv") }
- end
-
def test_float
marshal_equal(-1.0)
marshal_equal(0.0)
diff --git a/test/ruby/test_bignum.rb b/test/ruby/test_bignum.rb
index a9193b9452..0b34acb7b8 100644
--- a/test/ruby/test_bignum.rb
+++ b/test/ruby/test_bignum.rb
@@ -510,4 +510,8 @@ class TestBignum < Test::Unit::TestCase
# this test assumes 32bit/64bit platform
assert_raise(TypeError) { a = 1 << 64; def a.foo; end }
end
+
+ def test_frozen
+ assert_equal(true, (2**100).frozen?)
+ end
end
diff --git a/test/ruby/test_eval.rb b/test/ruby/test_eval.rb
index e1de99c847..e7da66e149 100644
--- a/test/ruby/test_eval.rb
+++ b/test/ruby/test_eval.rb
@@ -128,7 +128,7 @@ class TestEval < Test::Unit::TestCase
end
def forall_TYPE
- objects = [Object.new, [], nil, true, false, 77, :sym] # TODO: check
+ objects = [Object.new, [], nil, true, false, :sym] # TODO: check
objects.each do |obj|
obj.instance_variable_set :@ivar, 12
yield obj
diff --git a/test/ruby/test_fixnum.rb b/test/ruby/test_fixnum.rb
index a031923b02..4567da0a60 100644
--- a/test/ruby/test_fixnum.rb
+++ b/test/ruby/test_fixnum.rb
@@ -275,4 +275,8 @@ class TestFixnum < Test::Unit::TestCase
def test_singleton_method
assert_raise(TypeError) { a = 1; def a.foo; end }
end
+
+ def test_frozen
+ assert_equal(true, 1.frozen?)
+ end
end
diff --git a/test/ruby/test_object.rb b/test/ruby/test_object.rb
index 151825e5e4..4e958a7f7b 100644
--- a/test/ruby/test_object.rb
+++ b/test/ruby/test_object.rb
@@ -62,10 +62,10 @@ class TestObject < Test::Unit::TestCase
end
def test_freeze_immediate
- assert_equal(false, 1.frozen?)
+ assert_equal(true, 1.frozen?)
1.freeze
assert_equal(true, 1.frozen?)
- assert_equal(false, 2.frozen?)
+ assert_equal(true, 2.frozen?)
end
def test_nil_to_f