Conversation
There was a problem hiding this comment.
Pull request overview
This PR addresses a lifetime bug in the Zig port where string return values from metacall could be freed before the caller uses them by introducing a manual-deinit wrapper for string returns, plus updates to Zig build/test portability.
Changes:
- Introduces a
Value(T)wrapper and routes string return types through it to avoid prematuremetacall_value_destroy. - Updates the integrated Zig test to use repo-relative loader paths and adds stress/edge-case coverage for string returns.
- Adds a
build.zigfor the Zig port and adjusts.gitignorefor Zig cache directories.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| source/ports/zig_port/src/root.zig | Adds Value(T) wrapper and changes metacall return type behavior for strings. |
| source/ports/zig_port/src/tests/integrated.zig | Uses relative test paths and adds stress/empty-string checks for string returns. |
| source/ports/zig_port/build.zig | Adds Zig build/test steps for the port (currently mis-wired as noted in comments). |
| source/ports/zig_port/.gitignore | Updates Zig cache ignore entry to .zig-cache. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Do you think it's ready to merge then? I would like to add CI even if it's after this PR. |
Yes ofcourse of you want them merge it or add ci for zig |
I prefer if you add it. |
|
@tarun1sisodia can you add zig to the ci? I will leave it as draft meanwhile, check out tools/metacall-environment.sh |



Description
This PR fixes a critical bug in the MetaCall Zig port where string return types were being freed before they could be used by the caller. It introduces a
Value(T)wrapper pattern that provides manual control over resource deinitialization (RAII-like), ensuring memory safety for multi-language calls.Key Changes:
Value(T)struct withget()anddeinit()methods. Updatedmetacallto return this wrapper for strings while maintaining direct returns for primitive types.build.zigandintegrated.zigwith repo-relative paths (../../../buildandsrc/tests/*)..Arrayvs.array) to support Zig 0.16.0-dev.Type of change
Checklist:
zig build test --summary all).zig fmtand followed style guidelines.