feat: variadic function support + go vet clean (v0.5.2)#49
Merged
Conversation
Zero-value (0) means non-variadic, preserving full backward compatibility. Values >0 indicate the number of fixed parameters before '...' in the C prototype. On Apple ARM64, this boundary triggers register exhaustion.
Wraps PrepareCallInterface and sets FixedArgCount on the resulting CIF. Validates nfixedargs is non-negative and does not exceed total arg count. On Apple ARM64, the Execute() method reads FixedArgCount to exhaust register allocators at the fixed/variadic boundary per Apple AAPCS64.
…Darwin Apple's AAPCS64 extension requires that all variadic arguments go on the stack regardless of register availability. When FixedArgCount > 0 and GOOS == darwin, the Execute() method sets gprIdx=8 and fprIdx=8 before processing the first variadic argument, forcing subsequent arguments into stack slots. This matches Apple clang and libffi ffi_prep_cif_var() on Darwin ARM64. Non-variadic CIFs (FixedArgCount == 0) and non-Darwin ARM64 targets are completely unaffected — the branch is never entered.
Add sum_variadic and variadic_two_fixed to testdata/structtest.c. Add ffi/variadic_e2e_test.go with three test functions: - TestVariadic_SumIntegers (nfixedargs=1, result=60) - TestVariadic_TwoFixed (nfixedargs=2, result=600) - TestVariadic_ErrorValidation (validation edge cases) Extend struct_e2e_test.go build tag from amd64-only to (amd64 || arm64) so that requireStructLib/structTestLib are available to variadic tests on arm64 hosts. Move the four AMD64-specific XMM struct return tests to a new ffi/struct_return_e2e_amd64_test.go with amd64-only build tag.
Compiles testdata/structtest.c via gcc and exercises both sum_variadic and variadic_two_fixed through PrepareVariadicCallInterface. Exits 0 on PASS, 1 on FAIL, 0 with SKIP message if gcc is unavailable. Runs on linux/darwin/freebsd (amd64 and arm64). Primary use: Apple Silicon verification — confirms variadic args land on the stack on darwin/arm64 as required by Apple AAPCS64 extension.
…ECTURE, ROADMAP CHANGELOG: add Unreleased section with PrepareVariadicCallInterface, Apple ARM64 stack-force, cmd/variadic-test, and variadic e2e tests. README: replace 'Variadic not supported' limitation with Apple ARM64 note; add variadic feature row to table; add variadic example; update roadmap table. ARCHITECTURE: add Variadic Function Support section explaining platform differences, FixedArgCount field semantics, and Darwin ARM64 register flush. ROADMAP: mark variadic as in-progress in v0.6.0 milestone.
- dl_unix.go: use double-indirection for dlopen/dlsym uintptr→Pointer (go.dev/issue/58625) - syscall_linux_stub.s: remove unused uint64 return from syscallStub signature (returns via struct field)
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
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.
Summary
PrepareVariadicCallInterface(cif, convention, nfixedargs, returnType, argTypes)for C variadic functions (printf, XCreateIC, etc.). Apple ARM64: variadic args forced to stack per Apple ABI. Closes Support for variadic functions on darwin/arm64 (Apple Silicon) #47dl_unix.gounsafe.Pointer warnings (double-indirection per Go #58625),syscall_linux_stub.sreturn signature mismatchdocs/dev/references from CHANGELOGcmd/variadic-test— standalone binary for Apple Silicon verificationTest plan
go build ./...— all 6 platformsgo vet ./...— 0 warnings (WSL Linux)go fmt ./...— cleango test ./ffi ./types ./internal/...— all passCGO_ENABLED=1 go test -race— all pass (WSL Linux)[0.5.2] - 2026-05-25header included