From 582ff8909b037a2db248de6d9b97676832653b05 Mon Sep 17 00:00:00 2001 From: dzaima Date: Sun, 21 Aug 2022 07:49:09 +0300 Subject: [PATCH] =?UTF-8?q?@=20=E2=80=A2FFI=20=F0=9D=95=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ffi.c | 9 ++++++--- test/ffi/shared.expected | 1 + test/ffi/sharedTest.c | 1 + test/ffi/test.bqn | 5 +++++ test/ffi/test.expected | 4 ++++ 5 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/ffi.c b/src/ffi.c index 11bd0bbc..0a93b643 100644 --- a/src/ffi.c +++ b/src/ffi.c @@ -702,11 +702,14 @@ B ffiload_c2(B t, B w, B x) { #endif if (tRes.resSingle && mutCount!=1) thrF("FFI: Return was \"&\", but found %i mutated variables", mutCount); - w = path_rel(nfn_objU(t), w); - char* ws = toCStr(w); + char* ws = NULL; + if (w.u != m_c32(0).u) { + w = path_rel(nfn_objU(t), w); + ws = toCStr(w); + } void* dl = dlopen(ws, RTLD_NOW); - freeCStr(ws); + if (ws) freeCStr(ws); dec(w); if (dl==NULL) thrF("Failed to load: %S", dlerror()); diff --git a/test/ffi/shared.expected b/test/ffi/shared.expected index b8626c4c..4a3b60e3 100644 --- a/test/ffi/shared.expected +++ b/test/ffi/shared.expected @@ -1 +1,2 @@ 4 +'!' diff --git a/test/ffi/sharedTest.c b/test/ffi/sharedTest.c index 443cd1ad..2aed7fff 100644 --- a/test/ffi/sharedTest.c +++ b/test/ffi/sharedTest.c @@ -6,4 +6,5 @@ int main() { bqn_init(); double res = bqn_toF64(bqn_evalCStr("2+2")); printf("%g\n", res); + bqn_free(bqn_evalCStr("f←@ •FFI \"a\"‿\"bqn_makeChar\"‿\">u64\" ⋄ •Show F 33")); } diff --git a/test/ffi/test.bqn b/test/ffi/test.bqn index 8b7d1cf5..821eab9a 100644 --- a/test/ffi/test.bqn +++ b/test/ffi/test.bqn @@ -72,6 +72,11 @@ f ↩ "lib.so" •FFI ⟨"u64:i8","pick_u64",">*u64:i8",">𝕨i32"⟩ ⋄ •Sho f ↩ "lib.so" •FFI ⟨"u64:i8","pick_u64",">*u64:i8",">𝕨i32"⟩ ⋄ •Show @+3 F "000000001234560011122100abacabad"-@ f ↩ "lib.so" •FFI ⟨"u64", "pick_u64",">*u64:i8",">𝕨i32"⟩ ⋄ •Show 1 F "000000001234560011122100"-'0' +Section "# self-ffi" +•term.Flush@ +f ↩ @ •FFI ⟨"i32", "putchar", ">i32"⟩ ⋄ F¨ 10∾˜"text"-@ +•term.Flush@ +f ↩ @ •FFI ⟨"a", "bqn_makeChar", ">u64"⟩ ⋄ •Show F 120169 # erroring: diff --git a/test/ffi/test.expected b/test/ffi/test.expected index 29b6edda..e3efe185 100644 --- a/test/ffi/test.expected +++ b/test/ffi/test.expected @@ -87,3 +87,7 @@ ff7fdfefefdf7bb4 ff7fdfefefdf7bb4 fefffdfff7ffbffb bffff7fffdfffeff "11122100" "abacabad" 6618611909121 + +# self-ffi +text +'𝕩'