handle allocations for problematic structs to avoid sharing pointers-to-pointers with C (from Go) #82
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.
For additional background, read this thread.
Why does this PR exist?
When running software that consumed filecoin-ffi, setting
GODEBUG=cgocheck=2
option produced the following error:The cause of this error is that c-for-go generated code which mapped a slice of Go structs to a dynamic array of their C equivalents, but when those Go structs had fields which were
string
or[]byte
, a pointer to the original Go slice would be shared with C (instead of copying the nested value into the C heap). I suspect that this was by-design.What's in this PR?
To appease the gods, I have written custom allocating methods for the two structs which cause the reported issue. I have also rewritten the
fil_verify_hash
function to accept a flattened byte array, which prevents the double-pointer error.