Fix downgrade freed borrow outputs#118
Merged
Merged
Conversation
Keep locally owned return values boxed when their callers consume or free the result, while preserving raw ABI boundaries for configured C-exposed functions. Tighten local callee summaries so borrow-only wrappers no longer force owning callers back to raw pointers, but freeing or escaping callees still do.
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
This PR improves the pointer rewriter’s handling of freshly owned local return values.
When a local helper returns a newly owned allocation and the caller later frees or consumes it, the rewriter can now preserve that value as
Box/Option<Box>instead of downgrading the flow back to raw pointers. C-exposed functions remain raw at the exported ABI boundary.Against the latest
origin/master(99cd730), the branch reduces pointer-stage unsafe findings by 11 occurrences.Change Summary
Box/Option<Box>when the caller consumes or frees the allocation.ptr = make(); free(ptr)->buf = make(); drop(buf.take())extern "C" -> Option<Box<[T]>>->extern "C" -> *mut TUnsafe reductions by kind
freemallocas_refThe corpus reductions come from
cJSON_libandcharinbuf_lib, where temporary returned buffers now remain boxed and are cleaned up with Rust ownership instead ofmalloc/free.rdg_genstdout_libchanges in the opposite direction forFIO_createFilename_fromOutDir: it is listed inc_exposed_fns, so the exportedextern "C"function must return*mut i8. The previousOption<Box<[i8]>>return passed vectors by platform-specific ABI accident, but Rust still warns that it is not FFI-safe. The ideal future shape is a boxedFIO_createFilename_fromOutDir_internal(...) -> Option<Box<[i8]>>plus a raw C wrapper; this PR keeps the exported ABI correct, even though that internal-wrapper split is still future work.