Skip to content

Commit 29a960c

Browse files
committed
Use fptr in destructor, add __init__
1 parent e947aa8 commit 29a960c

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

src/FFTW.jl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ mutable struct FakeLazyLibrary{T}
3636
on_load_callback::T
3737
@atomic h::Ptr{Cvoid}
3838
end
39-
import Libdl: LazyLibrary, dlopen
39+
import Libdl: LazyLibrary, dlopen, dlsym
4040
function dlopen(lib::FakeLazyLibrary{T}) where T
4141
h = @atomic :monotonic lib.h
4242
h != C_NULL && return h
@@ -60,7 +60,13 @@ end
6060
const libfftw3 = FakeLazyLibrary(:libfftw3_no_init, fftw_init_check, C_NULL)
6161
const libfftw3f = FakeLazyLibrary(:libfftw3f_no_init, fftw_init_check, C_NULL)
6262

63-
else
63+
if VERSION >= v"1.12.0"
64+
function __init__()
65+
dlopen(libfftw3) # Ensure that dlopen(::FakeLazyLibrary) is built by JuliaC
66+
end
67+
end
68+
69+
else # !(VERSION >= v"1.11.0")
6470
@static if fftw_provider == "fftw"
6571
import FFTW_jll: libfftw3_path as libfftw3_no_init,
6672
libfftw3f_path as libfftw3f_no_init,

src/fft.jl

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -322,20 +322,18 @@ unsafe_convert(::Type{PlanPtr}, p::FFTWPlan) = p.plan
322322

323323
struct FFTWPlanDestructor
324324
ptr::PlanPtr
325-
use_32bit_lib::Bool
325+
fptr::Ptr{Cvoid}
326326
end
327327

328-
FFTWPlanDestructor(plan::FFTWPlan{<:fftwSingle}) = FFTWPlanDestructor(plan.plan, true)
329-
FFTWPlanDestructor(plan::FFTWPlan{<:fftwDouble}) = FFTWPlanDestructor(plan.plan, false)
328+
FFTWPlanDestructor(plan::FFTWPlan{<:fftwSingle}) =
329+
FFTWPlanDestructor(plan.plan, dlsym(dlopen(libfftw3f), :fftwf_destroy_plan))
330+
FFTWPlanDestructor(plan::FFTWPlan{<:fftwDouble}) =
331+
FFTWPlanDestructor(plan.plan, dlsym(dlopen(libfftw3), :fftw_destroy_plan))
330332

331333
# these functions should only be called while the fftwlock is held
332334
unsafe_destroy_plan(plan::FFTWPlan) = unsafe_destroy_plan(FFTWPlanDestructor(plan))
333335
function unsafe_destroy_plan(destructor::FFTWPlanDestructor)
334-
if destructor.use_32bit_lib
335-
ccall((:fftwf_destroy_plan,libfftw3f), Cvoid, (PlanPtr,), destructor.ptr)
336-
else
337-
ccall((:fftw_destroy_plan,libfftw3), Cvoid, (PlanPtr,), destructor.ptr)
338-
end
336+
ccall(destructor.fptr, Cvoid, (PlanPtr, ), destructor.ptr)
339337
end
340338

341339
const deferred_destroy_lock = ReentrantLock() # lock protecting the deferred_destroy_plans list

0 commit comments

Comments
 (0)