statsig-go: Fix C — JNI-style callback FFI for raw_feature_gate#11
Closed
nsaini-figma wants to merge 1 commit into
Closed
statsig-go: Fix C — JNI-style callback FFI for raw_feature_gate#11nsaini-figma wants to merge 1 commit into
nsaini-figma wants to merge 1 commit into
Conversation
Adds statsig_get_raw_feature_gate_cb, a callback-style variant that mirrors how JNI/pyo3/napi already cross the FFI boundary in this codebase. The Go side passes a purego.NewCallback that receives the JSON bytes via a borrowed *const u8 + length while the Rust-side FeatureGateRaw is still alive — no heap transfer, no *mut u64 inout, no free_string round-trip. Scope-limited to GetFeatureGateWithOptions for prototype review. Other _raw_ returners would be ported in follow-up work. JNI parallel: statsig-ffi/src/jni/statsig_jni.rs:838.
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
Prototype of the structural fix for the labmate SIGSEGV in the
Rust→Go FFI string return path. Companion minimal-fix prototype
(Fix A+B — NUL-scan + ptr guard) lives on branch
nsaini/fix-a-nul-scan. Both prototypes are draft for side-by-sidereview.
What changed
#[no_mangle] pub extern "C" fn statsig_get_raw_feature_gate_cbin
statsig-ffi/src/statsig_c.rs. Builds the JSON string insidethe closure body of
use_raw_feature_gate_with_optionsand passesit to the Go callback by borrowed slice. The existing
statsig_get_raw_feature_gateextern is left untouched.statsig-go/statsig_ffi.go: registers the new callback symbol viapurego.
statsig-go/statsig.goGetFeatureGateWithOptions: rewrittento use the callback path. Other gate/experiment/config functions
are unchanged — they still use the heap-transfer model. Follow-up
work would port them once Fix C is validated.
statsig-cpp/include/libstatsig_ffi.h,statsig-ffi/include/statsig_ffi.h,statsig-dotnet/src/Statsig/StatsigFFI.g.cs: auto-regenerated bycargo buildto reflect the new extern. No hand edits — includedto keep the checked-in bindings in sync with the Rust ABI.
Why this shape
Mirrors the JNI binding (
statsig-ffi/src/jni/statsig_jni.rs:838-861)and pyo3/napi: the Rust side builds the host-language object inside
the closure while the borrow is alive. No
*mut c_charever crossesthe FFI boundary, no
*mut u64inout writeback, nofree_stringround-trip — i.e. every failure surface identified for the original
crash is eliminated for this code path.
Failure modes covered
lenfrom purego trampoline → not usedptrfrom purego trampoline → buffer is Rust-owned, only crossesthe boundary for the callback's lifetime
Test plan
cargo check -p statsig_fficleancargo build --release -p statsig_ffi --target x86_64-unknown-linux-gnucleannm -D libstatsig_ffi.so | grep statsig_get_raw_feature_gate_cbconfirms symbol exportedgo vet ./statsig-go/...cleango build ./statsig-go/...cleanRefs
~/nsaini/state/explorations/labmate-statsig-ffi-crash.md~/nsaini/state/explorations/labmate-statsig-ffi-fix.md(Fix C section)nsaini/fix-a-nul-scan