Repository navigation
Marshal: a class path that is not ASCII carries its encoding, as 4.0 dumps it - #893
Merged
Merged
Conversation
…dumps it Three more of the 27 examples that went red on the move to Ruby 4.0 (#799), again one cause. `core/marshal/dump_spec.rb` goes 191 → 194, fail 18 → 15. ## The reference marshal.c at v4.0.9 brackets the class path with the same encoding machinery a String goes through: VALUE encname = w_encivar(path, arg); /* emits 'I' when path is non-ASCII */ w_byte(TYPE_CLASS, arg); w_bytes(RSTRING_PTR(path), RSTRING_LEN(path), arg); w_encname(encname, arg); /* 1 ivar: :E => true */ `w_encivar` returns nil when the path is ASCII-only, which is what keeps every ordinary class name dumping exactly as before: static VALUE w_encivar(VALUE str, struct dump_arg *arg) { VALUE encname = encoding_name(str, arg); if (NIL_P(encname) || is_ascii_string(str)) return Qnil; w_byte(TYPE_IVAR, arg); return encname; } `encoding_name` maps UTF-8 to Qtrue, so the trailer is the short `:E => true` form and never the long `:encoding => "..."` one — a constant name in rbgo is a Go string and therefore UTF-8, and there is no way to name a constant in another encoding. ## Measured, not read rubydiff against MRI 4.0.7 on this host: AGREE, byte for byte, on all eleven probes. The three dumps the specs assert: "\x04\bIc,MarshalSpec::Multibyte\xE3\x81\x81...Class\x06:\x06ET" "\x04\bIm-MarshalSpec::Multibyte\xE3\x81\x91...Module\x06:\x06ET" "\x04\bIc+MarshalSpec::Multibyte\xE3\x81\x81...Time\x06:\x06ET" ## The controls matter more than the three rows * An ASCII name must still dump unwrapped — `Marshal.dump(String)` is `"\x04\bc\vString"`. A wrapper emitted unconditionally would pass all three spec rows and break every existing dump. * The reader had never been handed an 'I' in front of a 'c'. All three round-trip to the identical object, which the specs do NOT assert — their second line has no `.should`. * Object links still resolve to the start of the wrapped form: `Marshal.dump([K, K])` ends `@\x06`, and loading it gives `[true, true]` on `.equal?`. specdelta, provenanced, over core/marshal: control 442, treatment 445, **+3, 1 file moved, 0 regressed**, with `load_spec.rb` unchanged at 230. Coverage: writeClassRef and classPathEncIvar at 100.0%. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
tannevaled
added a commit
that referenced
this pull request
Nov 5, 2026
tannevaled
added a commit
that referenced
this pull request
Nov 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Three more of the 27 examples that went red on the move to Ruby 4.0 (#799),
again one cause.
core/marshal/dump_spec.rbgoes 191 → 194, fail 18 → 15.The reference
marshal.catv4.0.9brackets a class path with the same encoding machinerya String goes through:
w_encivarreturns nil for an ASCII-only path — that single line is what keepsevery ordinary class name dumping exactly as before.
encoding_namemaps UTF-8to
Qtrue, so the trailer is the short:E => trueform and never the long:encoding => "…"one: a constant name here is a Go string, hence UTF-8, andthere is no way to name a constant in another encoding.
Measured, not read
rubydiffagainst MRI 4.0.7 on this host: AGREE, byte for byte, on alleleven probes. The three the specs assert:
⛔ The controls matter more than the three rows
Marshal.dump(String)is still"\x04\bc\vString"'I'in front of a'c'— and the specs do not assert this: their second line has no.shouldMarshal.dump([K, K])still ends@\x06, loading to[true, true]on.equal?'c'inside itspecdelta, provenanced, overcore/marshal:Coverage:
writeClassRefandclassPathEncIvarat 100.0%.Independent of #892 — different file, different cause, same issue.
🤖 Generated with Claude Code