Memory-safety and allocations fixes for Handle{T} #446
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.
Addresses #435 and also fixes a potential problem with memory safety:
Allocations in convert(Ptr{T}, Handle{T})
Fix is as suggested in Allocations in
convert(Ptr{T}, Handle{T})
#435(Handle is now a mutable struct with a ptr field)
Memory safety robustness fix
Remove convert and use paired Base.cconvert / Base.unsafe_convert to get the ptr field from
a Handle object h, so that the h is preserved from GC across the ccall
This fix is analogous to that for the NVector wrapper in PR Workaround for N_Vector segfaults #380
(NB: there is no actual problem at least when Sundials is used with the SciML interface,
as the Handle{CVODEMem} and similar objects are held by a persistent solver data structure, but this
change should reduce the risk of something going wrong in the future, or for eg test harnesses that don't use
the SciML interface)
Checklist
contributor guidelines, in particular the SciML Style Guide and
COLPRAC.
Additional context
Add any other context about the problem here.