purego: support struct arguments in callbacks#437
Open
hajimehoshi wants to merge 1 commit intoebitengine:mainfrom
Open
purego: support struct arguments in callbacks#437hajimehoshi wants to merge 1 commit intoebitengine:mainfrom
hajimehoshi wants to merge 1 commit intoebitengine:mainfrom
Conversation
Add getCallbackStruct implementations for amd64 and arm64 to decode struct arguments from the callback frame. Update callbackWrap to call getCallbackStruct instead of treating all struct arguments as CDecl. The struct argument tests are restructured to run each test case with both RegisterLibFunc (calling C) and GoCallbackFunc (Go callback via NewCallback), ensuring round-trip correctness through the callback path. Updates ebitengine#225
6b1f636 to
e69dd79
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR extends purego’s callback (Go function exported as a C-callable pointer via NewCallback) support to correctly handle struct arguments on amd64 and arm64 Unix platforms, and expands the test suite to validate struct argument round-trips.
Changes:
- Add ABI-aware decoding of struct callback arguments on amd64 (SysV) and arm64 (AAPCS64), with stub implementations on unsupported platforms.
- Expand
struct_test.goto run struct-argument tests through bothRegisterLibFuncandNewCallback-based callbacks, and add identity/round-trip struct tests. - Add new C identity functions in
testdata/structtest/struct_test.cto support round-trip validation from Go tests.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
testdata/structtest/struct_test.c |
Adds C identity functions used for struct argument round-trip tests. |
syscall_windows.go |
Adds stub callback frame helpers needed for cross-platform compilation. |
syscall_unix.go |
Enables struct callback args and routes struct inputs through getCallbackStruct. |
struct_test.go |
Refactors tests to run via both lib calls and NewCallback, adding identity tests. |
struct_amd64.go |
Implements amd64 SysV struct decoding from callback frames. |
struct_arm64.go |
Implements arm64 struct decoding (HFA/non-HFA, regs/stack) from callback frames. |
struct_arm.go |
Adds stub getCallbackStruct (panics) for unsupported arch. |
struct_386.go |
Adds stub getCallbackStruct (panics) for unsupported arch. |
struct_loong64.go |
Adds stub getCallbackStruct (panics) for unsupported arch. |
struct_ppc64le.go |
Adds stub getCallbackStruct (panics) for unsupported arch. |
struct_riscv64.go |
Adds stub getCallbackStruct (panics) for unsupported arch. |
struct_s390x.go |
Adds stub getCallbackStruct (panics) for unsupported arch. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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?
Updates #225
What type of issue is this addressing?
feature
What this PR does | solves
Add getCallbackStruct implementations for amd64 and arm64 to decode struct arguments from the callback frame. Update callbackWrap to call getCallbackStruct instead of treating all struct arguments as CDecl.
The struct argument tests are restructured to run each test case with both RegisterLibFunc (calling C) and GoCallbackFunc (Go callback via NewCallback), ensuring round-trip correctness through the callback path.
(This change is also mostly developed by Claude Code)