[OM] Use custom CAPI wrappers for Object. #5275
Merged
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.
This adds custom CAPI wrap and unwrap functionality for Object to better align with the std::shared_ptr functionality. Object now enables the shared_from_this functionality, which allows the unwrap function to more seamlessly create shared pointers to the Object with the appropriate reference count. Similarly, the wrap functionality is updated to always allocate new shared pointers, to ensure reference counts are incremented appropriately. This was done at the instantiate API previously, but is now handled generically whenever an Object is wrapped.
These changes are required to avoid double frees of Objects in general. A test case has been added that demonstrated the faulty behavior, which now succeeds.