Skip to content

purego: support struct arguments in callbacks#437

Open
hajimehoshi wants to merge 1 commit intoebitengine:mainfrom
hajimehoshi:issue-225-structs4
Open

purego: support struct arguments in callbacks#437
hajimehoshi wants to merge 1 commit intoebitengine:mainfrom
hajimehoshi:issue-225-structs4

Conversation

@hajimehoshi
Copy link
Member

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)

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
Copilot AI review requested due to automatic review settings March 10, 2026 04:33
Copy link
Contributor

Copilot AI left a comment

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 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.go to run struct-argument tests through both RegisterLibFunc and NewCallback-based callbacks, and add identity/round-trip struct tests.
  • Add new C identity functions in testdata/structtest/struct_test.c to 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.

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.

2 participants