summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2019-05-23 19:54:45 +0900
committerGitHub <[email protected]>2019-05-23 19:54:45 +0900
commit43a26aa95862690fa8f1341fe947faa876739b17 (patch)
treeb291e8179877550f44703894900db36b30f3e27a
parent5f4eb87735c8c084fdb6b98df1eed0663e18b9d2 (diff)
parent48903850e9041e74c526fef5e63857007d2cac38 (diff)
downloadmruby-43a26aa95862690fa8f1341fe947faa876739b17.tar.gz
mruby-43a26aa95862690fa8f1341fe947faa876739b17.zip
Merge pull request #4463 from shuujii/freeze-Rational-and-Complex-objects
Freeze `Rational` and `Complex` objects
-rw-r--r--mrbgems/mruby-complex/src/complex.c1
-rw-r--r--mrbgems/mruby-complex/test/complex.rb8
-rw-r--r--mrbgems/mruby-rational/src/rational.c1
-rw-r--r--mrbgems/mruby-rational/test/rational.rb6
4 files changed, 15 insertions, 1 deletions
diff --git a/mrbgems/mruby-complex/src/complex.c b/mrbgems/mruby-complex/src/complex.c
index c6fb7a829..1b030c317 100644
--- a/mrbgems/mruby-complex/src/complex.c
+++ b/mrbgems/mruby-complex/src/complex.c
@@ -24,6 +24,7 @@ complex_new(mrb_state *mrb, mrb_float real, mrb_float imaginary)
struct mrb_complex *p = complex_ptr(mrb, comp);
p->real = real;
p->imaginary = imaginary;
+ MRB_SET_FROZEN_FLAG(s);
return comp;
}
diff --git a/mrbgems/mruby-complex/test/complex.rb b/mrbgems/mruby-complex/test/complex.rb
index e7fcc7322..6996eb214 100644
--- a/mrbgems/mruby-complex/test/complex.rb
+++ b/mrbgems/mruby-complex/test/complex.rb
@@ -1,5 +1,5 @@
def assert_complex(real, exp)
- assert_float real.real, exp.real
+ assert_float real.real, exp.real
assert_float real.imaginary, exp.imaginary
end
@@ -126,3 +126,9 @@ assert 'Complex::to_i' do
Complex(1, 2).to_i
end
end
+
+assert 'Complex#frozen?' do
+ assert_predicate(1i, :frozen?)
+ assert_predicate(Complex(2,3), :frozen?)
+ assert_predicate(4+5i, :frozen?)
+end
diff --git a/mrbgems/mruby-rational/src/rational.c b/mrbgems/mruby-rational/src/rational.c
index 2a3f6df09..fa061c0b8 100644
--- a/mrbgems/mruby-rational/src/rational.c
+++ b/mrbgems/mruby-rational/src/rational.c
@@ -37,6 +37,7 @@ rational_new(mrb_state *mrb, mrb_int numerator, mrb_int denominator)
struct mrb_rational *p = rational_ptr(rat);
p->numerator = numerator;
p->denominator = denominator;
+ MRB_SET_FROZEN_FLAG(s);
return rat;
}
diff --git a/mrbgems/mruby-rational/test/rational.rb b/mrbgems/mruby-rational/test/rational.rb
index 914f8505e..1ed3b3a07 100644
--- a/mrbgems/mruby-rational/test/rational.rb
+++ b/mrbgems/mruby-rational/test/rational.rb
@@ -278,3 +278,9 @@ assert 'Rational#negative?' do
assert_not_predicate(Rational(2,3), :negative?)
assert_not_predicate(Rational(0), :negative?)
end
+
+assert 'Rational#frozen?' do
+ assert_predicate(1r, :frozen?)
+ assert_predicate(Rational(2,3), :frozen?)
+ assert_predicate(4/5r, :frozen?)
+end