SunnySuite / Sunny.jl

Spin dynamics and generalization to SU(N) coherent states
Other
86 stars 19 forks source link

Avoid all use of `deepcopy` #66

Closed kbarros closed 1 year ago

kbarros commented 1 year ago

Julia developers Gabriel Baraldi and Jameson Nash pointed out that the use of deepcopy can be memory unsafe, especially when used in combination with C datastructures. It appears this was the source of intermittent segfault behavior observed when calling FFTW. (Perhaps the problem was deep-copying an FFTW plan, or perhaps it was some other memory corruption.)

This PR replaces all calls to deepcopy with custom clone functions that perform ordinary copy operations on mutable arrays. Hopefully resolves https://github.com/SunnySuite/Sunny.jl/issues/65, originally reported in https://github.com/JuliaLang/julia/issues/48722 .