Permalink
Browse files

Fix segv when primitive value

Fix #3352
  • Loading branch information...
ksss committed Dec 24, 2016
1 parent 000a311 commit 5c1c002ac2983fef8ef3254e2d2f3e016918c3cd
Showing with 18 additions and 3 deletions.
  1. +16 −2 src/kernel.c
  2. +2 −1 test/t/kernel.rb
View
@@ -453,9 +453,23 @@ mrb_obj_extend_m(mrb_state *mrb, mrb_value self)
static mrb_value
mrb_obj_freeze(mrb_state *mrb, mrb_value self)
{
struct RBasic *b = mrb_basic_ptr(self);
struct RBasic *b;
switch (mrb_type(self)) {
case MRB_TT_FALSE:
case MRB_TT_TRUE:
case MRB_TT_FIXNUM:
case MRB_TT_SYMBOL:
case MRB_TT_FLOAT:
return self;
default:
break;
}
MRB_SET_FROZEN_FLAG(b);
b = mrb_basic_ptr(self);
if (!MRB_FROZEN_P(b)) {
MRB_SET_FROZEN_FLAG(b);
}
return self;
}
View
@@ -260,6 +260,8 @@ def test_method; end
assert('Kernel#freeze') do
obj = Object.new
assert_equal obj, obj.freeze
assert_equal 0, 0.freeze
assert_equal :a, :a.freeze
end
assert('Kernel#global_variables', '15.3.1.3.14') do
@@ -620,4 +622,3 @@ def recurse(count, stop)
assert_equal 6, recurse(0, 5)
end

0 comments on commit 5c1c002

Please sign in to comment.