summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2016-12-03 12:01:43 +0900
committerGitHub <[email protected]>2016-12-03 12:01:43 +0900
commit9776150263d58b2b4948580201fc630eb5626bdc (patch)
tree61e765c2198f512e7e5318c88224c0f828cfd025
parentd89cfca02c2f632cef443442339136b89ff15017 (diff)
parent9c61e1cd87aca3646fe39a6d53223efdcb11e250 (diff)
downloadmruby-9776150263d58b2b4948580201fc630eb5626bdc.tar.gz
mruby-9776150263d58b2b4948580201fc630eb5626bdc.zip
Merge pull request #3317 from bouk/missing-to-s
Use mrb_ptr instead of mrb_cptr in Kernel#to_s
-rw-r--r--src/object.c2
-rw-r--r--test/t/kernel.rb15
2 files changed, 16 insertions, 1 deletions
diff --git a/src/object.c b/src/object.c
index f76ee68a2..eb2c23e63 100644
--- a/src/object.c
+++ b/src/object.c
@@ -444,7 +444,7 @@ mrb_any_to_s(mrb_state *mrb, mrb_value obj)
mrb_str_cat_lit(mrb, str, "#<");
mrb_str_cat_cstr(mrb, str, cname);
mrb_str_cat_lit(mrb, str, ":");
- mrb_str_concat(mrb, str, mrb_ptr_to_str(mrb, mrb_cptr(obj)));
+ mrb_str_concat(mrb, str, mrb_ptr_to_str(mrb, mrb_ptr(obj)));
mrb_str_cat_lit(mrb, str, ">");
return str;
diff --git a/test/t/kernel.rb b/test/t/kernel.rb
index d240e59dc..e59bd6a10 100644
--- a/test/t/kernel.rb
+++ b/test/t/kernel.rb
@@ -520,6 +520,21 @@ assert('Kernel#to_s', '15.3.1.3.46') do
assert_equal to_s.class, String
end
+assert('Kernel#to_s on primitives') do
+ begin
+ Fixnum.alias_method :to_s_, :to_s
+ Fixnum.remove_method :to_s
+
+ assert_nothing_raised do
+ # segfaults if mrb_cptr is used
+ 1.to_s
+ end
+ ensure
+ Fixnum.alias_method :to_s, :to_s_
+ Fixnum.remove_method :to_s_
+ end
+end
+
assert('Kernel.local_variables', '15.3.1.2.7') do
a, b = 0, 1
a += b