From 632374f8d4c2276803609aa38ff46ef3075f6da8 Mon Sep 17 00:00:00 2001 From: "Jan Wedekind (Dr)" Date: Tue, 15 Oct 2024 22:27:53 +0100 Subject: [PATCH] Bugfix for const expressions --- src/clj/coffi/ffi.clj | 2 +- test/c/ffi_test.c | 2 ++ test/clj/coffi/ffi_test.clj | 3 +++ 3 files changed, 6 insertions(+), 1 deletion(-) 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..0b6193b 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 (ffi/const "c" ::mem/int) 42)) + (t/deftest can-call-primitive-fns (t/is (= 5 ((ffi/cfn "add_numbers" [::mem/int ::mem/int] ::mem/int) 2 3))))