@@ -320,14 +320,26 @@ unsafe_convert(::Type{PlanPtr}, p::FFTWPlan) = p.plan
320320# pushing the plan to be destroyed to the deferred_destroy_plans (which itself is protected by a lock).
321321# This is accomplished by the maybe_destroy_plan function, which is used as the plan finalizer.
322322
323+ struct FFTWPlanDestructor
324+ ptr:: PlanPtr
325+ use_32bit_lib:: Bool
326+ end
327+
328+ FFTWPlanDestructor (plan:: FFTWPlan{<:fftwSingle} ) = FFTWPlanDestructor (plan. plan, true )
329+ FFTWPlanDestructor (plan:: FFTWPlan{<:fftwDouble} ) = FFTWPlanDestructor (plan. plan, false )
330+
323331# these functions should only be called while the fftwlock is held
324- unsafe_destroy_plan (@nospecialize (plan:: FFTWPlan{<:fftwDouble} )) =
325- ccall ((:fftw_destroy_plan ,libfftw3), Cvoid, (PlanPtr,), plan)
326- unsafe_destroy_plan (@nospecialize (plan:: FFTWPlan{<:fftwSingle} )) =
327- ccall ((:fftwf_destroy_plan ,libfftw3f), Cvoid, (PlanPtr,), plan)
332+ unsafe_destroy_plan (plan:: FFTWPlan ) = unsafe_destroy_plan (FFTWPlanDestructor (plan))
333+ 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
339+ end
328340
329341const deferred_destroy_lock = ReentrantLock () # lock protecting the deferred_destroy_plans list
330- const deferred_destroy_plans = FFTWPlan []
342+ const deferred_destroy_plans = FFTWPlanDestructor []
331343
332344function destroy_deferred ()
333345 lock (deferred_destroy_lock)
@@ -375,7 +387,7 @@ function maybe_destroy_plan(plan::FFTWPlan)
375387 unlock (fftwlock)
376388 end
377389 else
378- push! (deferred_destroy_plans, plan)
390+ push! (deferred_destroy_plans, FFTWPlanDestructor ( plan) )
379391 end
380392 finally
381393 unlock (deferred_destroy_lock)
@@ -495,11 +507,11 @@ function assert_applicable(p::FFTWPlan{T,K,inplace}, X::StridedArray{T}, Y::Stri
495507 elseif alignment_of (Y) != p. oalign && p. flags & UNALIGNED == 0
496508 throw (ArgumentError (" FFTW plan applied to output with wrong memory alignment" ))
497509 elseif inplace != (pointer (X) == pointer (Y))
498- throw (ArgumentError (string ( " FFTW " ,
510+ throw (ArgumentError (join ([ " FFTW " ,
499511 inplace ? " in-place" : " out-of-place" ,
500512 " plan applied to " ,
501513 inplace ? " out-of-place" : " in-place" ,
502- " data" )))
514+ " data" ] )))
503515 end
504516end
505517
0 commit comments