Skip to content

Commit

Permalink
Merge pull request #40 from ludvigak/setpts_ref
Browse files Browse the repository at this point in the history
Keep references to input arrays in guru plan struct
  • Loading branch information
ludvigak authored Feb 17, 2022
2 parents f935efa + 4568f59 commit d7214b8
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/guru.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@ mutable struct finufft_plan{T}
nj :: BIGINT
nk :: BIGINT
plan_ptr :: finufft_plan_c
# Arrays used for keeping references to input data alive.
# These should not be modified directly, as it will have no
# effect.
_xj :: Array{T}
_yj :: Array{T}
_zj :: Array{T}
_s :: Array{T}
_t :: Array{T}
_u :: Array{T}
# Default constructor that does not require input arrays (also for backwards compat)
finufft_plan{T}(type, ntrans, dim, ms, mt, mu, nj, nk, plan_ptr) where T =
new(type, ntrans, dim, ms, mt, mu, nj, nk, plan_ptr, [], [], [], [], [], [])
end

"""
Expand Down Expand Up @@ -157,6 +169,17 @@ function finufft_setpts!(plan::finufft_plan{T},
plan.nj = M
plan.nk = N

# Store references to input arrays in plan struct.
# This is important, since Julia garbage collection
# will not know about the C library keeping references
# to the input arrays.
plan._xj = xj
plan._yj = yj
plan._zj = zj
plan._s = s
plan._t = t
plan._u = u

if T==Float64
ret = ccall( (:finufft_setpts, libfinufft),
Cint,
Expand Down Expand Up @@ -272,6 +295,13 @@ If one attempts to destroy an already-destroyed plan, 1 is returned
(see FINUFFT documentation for finufft_destroy).
"""
function finufft_destroy!(plan::finufft_plan{T}) where T <: finufftReal
# Remove references to input arrays
plan._xj = T[]
plan._yj = T[]
plan._zj = T[]
plan._s = T[]
plan._t = T[]
plan._u = T[]
if plan.plan_ptr!=C_NULL # this test should not be needed since
# ccall should handle C_NULL returning 1, but ...that failed one CI test
if T==Float64
Expand Down

0 comments on commit d7214b8

Please sign in to comment.