Fix ffi/defbind for non-lazy bindings.

Add testing to bind to symbols in current binary.
This commit is contained in:
Calvin Rose 2022-06-18 10:14:42 -05:00
parent a1aab4008f
commit d803561582
2 changed files with 12 additions and 1 deletions

View File

@ -3670,7 +3670,7 @@
(defn make-sig []
(ffi/signature :default ret-type ;computed-type-args))
(defn make-ptr []
(assert (ffi/lookup (llib) raw-symbol) "failed to find symbol"))
(assert (ffi/lookup (if lazy (llib) lib) raw-symbol) "failed to find symbol"))
(if lazy
~(defn ,name ,;meta [,;formal-args]
(,ffi/call (,(delay (make-ptr))) (,(delay (make-sig))) ,;formal-args))

View File

@ -28,5 +28,16 @@
(assert (= (thunk) 1) "delay 3")
(assert (= counter 1) "delay 4")
# FFI check
(compwhen (dyn 'ffi/native)
(ffi/context))
(compwhen (dyn 'ffi/native)
(ffi/defbind memcpy :ptr [dest :ptr src :ptr n :size]))
(compwhen (dyn 'ffi/native)
(def buffer1 @"aaaa")
(def buffer2 @"bbbb")
(memcpy buffer1 buffer2 4)
(assert (= (string buffer1) "bbbb") "ffi 1 - memcpy"))
(end-suite)