On linux, I was able to reliably cause a segfault when using dt-ffi/define-library-interface. The crash seems to be caused by the calling a native function after its corresponding com.sun.jna.NatilveLibrary instance has been garbage collected.
The following will crash:
(dt-ffi/define-library-interface
{:answer {:rettype :int32}}
:libraries ["answer"])
(defn -main [& args]
(println (answer))
(while true
(System/gc)
(println (answer))
(Thread/sleep 1000)))
Workaround: Holding a reference to the NativeLibrary instance prevents the crash:
;; hang on to lib instance
(def libanswer (com.sun.jna.NativeLibrary/getInstance "answer"))
(dt-ffi/define-library-interface
{:answer {:rettype :int32}}
:libraries ["answer"])
(defn -main [& args]
(println (answer))
(while true
(System/gc)
(println (answer))
(Thread/sleep 1000)))
Instructions and code: https://github.com/phronmophobic/dtype-ffi-linux-repro/
On linux, I was able to reliably cause a segfault when using
dt-ffi/define-library-interface. The crash seems to be caused by the calling a native function after its correspondingcom.sun.jna.NatilveLibraryinstance has been garbage collected.The following will crash:
Workaround: Holding a reference to the NativeLibrary instance prevents the crash:
Instructions and code: https://github.com/phronmophobic/dtype-ffi-linux-repro/