extendr-impl: Return the right reference #726
Open
+394
−29
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.
Following the polishing of
ExternalPtr
is this PR on returning the right reference.First, we remove the ability to take
&T
and makeExternalPtr<T>
. This is a flawed construct: Making anExternalPtr
is not just wrapping a pointer, it is also signing a pointer up for destruction. Converting a&T
toExternalPtr<T>
may cause spurious double-free events.The Rules of ExternalPtr are simple:
ExternalPtr
.&ExternalPtr<T>
you can create&T
, and similarly for&mut ExternalPtr<T>
and&mut T
.So, should there be no references used or returned? A reference that comes from a true
ExternalPtr<T>
may be used. We embed this logic on the wrapping function, rather than do any C-crimes.If a reference corresponds to any of the
ExternalPtr<T>
in the argument list, then that is returned.Fixes #725