diff --git a/src/clj/coffi/ffi.clj b/src/clj/coffi/ffi.clj index d6e72fd..6c174af 100644 --- a/src/clj/coffi/ffi.clj +++ b/src/clj/coffi/ffi.clj @@ -606,7 +606,7 @@ (defn const "Gets the value of a constant stored in `symbol-or-addr`." [symbol-or-addr type] - (mem/deserialize (.address (ensure-symbol symbol-or-addr)) [::mem/pointer type])) + (mem/deserialize (ensure-symbol symbol-or-addr) [::mem/pointer type])) (s/def ::defconst-args (s/cat :var-name simple-symbol? diff --git a/test/c/ffi_test.c b/test/c/ffi_test.c index 21095cf..aca0368 100644 --- a/test/c/ffi_test.c +++ b/test/c/ffi_test.c @@ -1,6 +1,8 @@ #include #include +const int c = 42; + int add_numbers(int a, int b) { return a + b; } diff --git a/test/clj/coffi/ffi_test.clj b/test/clj/coffi/ffi_test.clj index cc44347..adda64c 100644 --- a/test/clj/coffi/ffi_test.clj +++ b/test/clj/coffi/ffi_test.clj @@ -10,6 +10,9 @@ (t/deftest can-load-symbols (t/is (not (nil? (ffi/find-symbol "add_numbers"))))) +(t/deftest can-fetch-constant + (t/is (= 42 (ffi/const "c" ::mem/int)))) + (t/deftest can-call-primitive-fns (t/is (= 5 ((ffi/cfn "add_numbers" [::mem/int ::mem/int] ::mem/int) 2 3))))