Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

* 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.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37348 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information...
commit f3e5f2cd758f5013685d997ffd9efdcceccd449f 1 parent 5dc9855
@ko1 ko1 authored
View
17 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.
View
2  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;
}
View
4 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) &&
View
2  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
View
16 test/ruby/marshaltestlib.rb
@@ -178,22 +178,6 @@ def test_fixnum
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)
View
4 test/ruby/test_bignum.rb
@@ -510,4 +510,8 @@ def test_singleton_method
# 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
View
2  test/ruby/test_eval.rb
@@ -128,7 +128,7 @@ def test_module_eval_block_basic
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
View
4 test/ruby/test_fixnum.rb
@@ -275,4 +275,8 @@ def test_xor_with_nonintegral_numeric
def test_singleton_method
assert_raise(TypeError) { a = 1; def a.foo; end }
end
+
+ def test_frozen
+ assert_equal(true, 1.frozen?)
+ end
end
View
4 test/ruby/test_object.rb
@@ -62,10 +62,10 @@ def test_freeze_under_safe_4
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
Please sign in to comment.
Something went wrong with that request. Please try again.