Skip to content

objc: encode 64-bit integers as q and Q - #499

Merged
TotallyGamerJet merged 2 commits into
ebitengine:mainfrom
TotallyGamerJet:objc-encode-64-bit-integers
Aug 20, 2026
Merged

objc: encode 64-bit integers as q and Q#499
TotallyGamerJet merged 2 commits into
ebitengine:mainfrom
TotallyGamerJet:objc-encode-64-bit-integers

Conversation

@TotallyGamerJet

Copy link
Copy Markdown
Collaborator

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.

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
hajimehoshi requested a lite review from Copilot August 20, 2026 15:56
Comment thread objc/encoding_darwin_test.go Outdated
Comment thread objc/objc_runtime_darwin.go

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 encodeType mappings on Darwin so int/int64 encode as q and uint/uint64 encode as Q.
  • Add Darwin-only tests that validate encodeType outputs and assert encodeFunc signature assembly.
  • Add a compiler-oracle test that compares expected encodings against clang’s @encode output 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.

@hajimehoshi hajimehoshi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@TotallyGamerJet
TotallyGamerJet merged commit f2f4202 into ebitengine:main Aug 20, 2026
25 checks passed
@TotallyGamerJet
TotallyGamerJet deleted the objc-encode-64-bit-integers branch August 20, 2026 17:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

objc: encodeType emits 32-bit encodings for 64-bit integer types

3 participants