From cf7d07570f50ef9c16007019afcff11ba6500d70 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@ruby-lang.org> Date: Fri, 22 Jul 2022 09:54:57 +0900 Subject: [PATCH] Dump non-ASCII char as unsigned Non-ASCII code may be negative on platforms plain char is signed. --- ext/objspace/objspace_dump.c | 2 +- test/objspace/test_objspace.rb | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/ext/objspace/objspace_dump.c b/ext/objspace/objspace_dump.c index e4f1216a9a..24a2b0b245 100644 --- a/ext/objspace/objspace_dump.c +++ b/ext/objspace/objspace_dump.c @@ -142,7 +142,7 @@ dump_append_sizet(struct dump_config *dc, const size_t number) } static void -dump_append_c(struct dump_config *dc, char c) +dump_append_c(struct dump_config *dc, unsigned char c) { if (c <= 0x1f) { const unsigned int width = (sizeof(c) * CHAR_BIT / 4) + 5; diff --git a/test/objspace/test_objspace.rb b/test/objspace/test_objspace.rb index 1392447e4f..3b90319858 100644 --- a/test/objspace/test_objspace.rb +++ b/test/objspace/test_objspace.rb @@ -725,4 +725,19 @@ class TestObjSpace < Test::Unit::TestCase assert_equal '42', out[2] end end + + def test_utf8_method_names + name = "utf8_❨╯°□°❩╯︵┻━┻" + obj = ObjectSpace.trace_object_allocations do + __send__(name) + end + dump = ObjectSpace.dump(obj) + assert_equal name, JSON.parse(dump)["method"], dump + end + + private + + def utf8_❨╯°□°❩╯︵┻━┻ + "1#{2}" + end end