Write a byte escape in upper case hex, as CRuby does - #7145
Conversation
`String#inspect` and `String#dump` write a byte that spells no character as `\xNN`, and mruby spells the two digits in lower case where CRuby spells them in upper case: ```ruby 171.chr.inspect #=> "\"\\xAB\"" in CRuby, "\"\\xab\"" in mruby "る".dump #=> "\"\\xE3\\x82\\x8B\"" in CRuby, lower case here ``` Move the expectations that pinned the lower case spelling, and give `String#inspect` a case of a single byte above ASCII, which it had none of. `mrb_vformat`'s `%!l` and the debugger's `p` print through the same escape, so their expectations move with it.
`str_escape()` spelled the two digits of a `\xNN` escape out of `mrb_digitmap`, which is lower case because `Integer#to_s` reads a number through it and CRuby spells that in lower case. CRuby spells the escape itself in upper case, so the two cannot share one table. Give the escape a table of its own. `mrb_ptr_to_str()` stays on `mrb_digitmap`, since CRuby writes the address in `#<Object:0x...>` in lower case as well. `String#inspect`, `String#dump`, `Symbol#inspect` of a name that has to be quoted, and the `%!` conversions of `mrb_vformat()` all print through `str_escape()`, so they change together.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (6)
📝 WalkthroughWalkthroughString escape generation now uses uppercase hexadecimal digits for ChangesString escape formatting
Estimated code review effort: 1 (Trivial) | ~5 minutes Merge Risk: ⚪ Minimal · up to This PR changes byte escapes from lowercase to uppercase hexadecimal to match CRuby and updates the affected tests; no actionable merge-blocking risk remains after normal checks and review. Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
String#inspectandString#dumpwrite a byte that spells no character as\xNN, and mruby spells the two digits in lower case where CRuby spells them in upper case:str_escape()takes the two digits frommrb_digitmap, the tableInteger#to_sreads a number through. Lower case is right for that table, since CRuby spells a number in lower case as well, so the escape gets a table of its own rather than the shared one moving under both readers.What moves with it
Everything that prints through
str_escape():String#inspect,String#dump,Symbol#inspectof a name that has to be quoted, and the%!conversions ofmrb_vformat(), which is what the debugger'spprints through.What stays
mrb_ptr_to_str()keepsmrb_digitmap, since CRuby writes the address in#<Object:0x...>in lower case too.%Xin mruby-sprintf upper cases its own output throughtoupper()and never reads the table.Tests
The first commit moves every expectation that pinned the lower case spelling, and gives
String#inspecta case of a single byte above ASCII, which it had none of. It fails without the second.Five places held such an expectation: core
String#inspectandmrb_vformat, mruby-string-ext'sString#dumpand itsinspectof a byte-read string, mruby-encoding'sInteger#chrabove ASCII, and mruby-bin-debugger's bintest forp.Verification
At the tip, the full suite is green on
ci/gcc-clangin full, which isfull-debug,bintest,cxx_abiand the default gembox build, and on the plainhostbuild. 0 failures, 0 crashes. The bintest run is included, since the debugger'spprints through this escape.Summary by CodeRabbit
\xAB, for non-printable and binary characters.