Skip to content

feat(ffi): add proposal root retrieval #910

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Jun 2, 2025
Prev Previous commit
Next Next commit
Unused function
  • Loading branch information
alarso16 committed May 29, 2025
commit a59bc25c54f2b105d7d5553e473fede005f8a62a
32 changes: 0 additions & 32 deletions ffi/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,38 +95,6 @@ func extractErrorThenFree(v *C.struct_Value) error {
return errBadValue
}

// extractUintThenFree converts the cgo `Value` payload to either:
// 1. a nonzero uint32 and nil error, indicating a valid int
// 2. a zero uint32 and a non-nil error, indicating an error occurred.
// This should only be called when the `Value` is expected to only contain an error or an ID.
// Otherwise, an error is returned.
func extractUintThenFree(v *C.struct_Value) (uint32, error) {
// Pin the returned value to prevent it from being garbage collected.
defer runtime.KeepAlive(v)

if v == nil {
return 0, errNilBuffer
}

// Normal case, length is non-zero and data is nil.
if v.len != 0 && v.data == nil {
return uint32(v.len), nil
}

// If the value is an error string, it should be freed and an error
// returned.
if v.len == 0 && v.data != nil {
errStr := C.GoString((*C.char)(unsafe.Pointer(v.data)))
C.fwd_free_value(v)
return 0, fmt.Errorf("firewood error: %s", errStr)
}

// The value is formatted incorrectly.
// We should still attempt to free the value.
C.fwd_free_value(v)
return 0, errBadValue
}

// extractBytesThenFree converts the cgo `Value` payload to either:
// 1. a non-nil byte slice and nil error, indicating a valid byte slice
// 2. a nil byte slice and nil error, indicating an empty byte slice
Expand Down