objc: encode 64-bit integers as q and Q - #499
Merged
TotallyGamerJet merged 2 commits intoAug 20, 2026
Merged
Conversation
encodeType mapped Go's 64-bit integer kinds to the 32-bit @encode spellings: int to "l", and int64, uint and uint64 all to "L", which additionally gave int64 an unsigned spelling. On darwin, which is LP64 on every architecture Go supports, clang spells 64-bit integers "q" and "Q". Argument passing is unaffected because purego marshals from the Go types, but consumers that read the declared width back from the runtime metadata - NSInvocation, NSMethodSignature and forwardInvocation: based proxies, KVC autoboxing from ivar encodings - silently truncate values above 2^32. Check the encoding of each type against clang @encode itself so that the expected encodings cannot drift from the compiler, and assert how encodeFunc assembles a full method signature. Closes ebitengine#493 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
hajimehoshi
reviewed
Aug 20, 2026
hajimehoshi
reviewed
Aug 20, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes Objective-C type encoding on Darwin so that Go 64-bit integer kinds are encoded using clang’s 64-bit @encode spellings (q/Q) rather than the previous 32-bit encodings, preventing silent truncation in consumers that interpret runtime metadata (e.g., NSInvocation, NSMethodSignature, KVC).
Changes:
- Update
encodeTypemappings on Darwin soint/int64encode asqanduint/uint64encode asQ. - Add Darwin-only tests that validate
encodeTypeoutputs and assertencodeFuncsignature assembly. - Add a compiler-oracle test that compares expected encodings against clang’s
@encodeoutput to prevent drift.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
objc/objc_runtime_darwin.go |
Corrects Darwin integer type encodings to q/Q for 64-bit integers. |
objc/encoding_darwin_test.go |
Adds encode-type oracle tests (via clang @encode) and signature-assembly tests for encodeFunc. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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.
What issue is this addressing?
Closes #493
What type of issue is this addressing?
bug
What this PR does | solves
encodeType mapped Go's 64-bit integer kinds to the 32-bit @encode spellings: int to "l", and int64, uint and uint64 all to "L", which additionally gave int64 an unsigned spelling. On darwin, which is LP64 on every architecture Go supports, clang spells 64-bit integers "q" and "Q".
Argument passing is unaffected because purego marshals from the Go types, but consumers that read the declared width back from the runtime metadata - NSInvocation, NSMethodSignature and forwardInvocation: based proxies, KVC autoboxing from ivar encodings - silently truncate values above 2^32.
Check the encoding of each type against clang @encode itself so that the expected encodings cannot drift from the compiler, and assert how encodeFunc assembles a full method signature.