From d186294e283cd3baca9f97c6331fc77014b88b53 Mon Sep 17 00:00:00 2001 From: dzaima Date: Wed, 11 May 2022 22:56:09 +0300 Subject: [PATCH] allocate at least minimum size, rename functions --- src/builtins.h | 2 +- src/builtins/sysfn.c | 2 +- src/ffi.c | 10 ++++++---- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/builtins.h b/src/builtins.h index 3b88e255..8d5d380c 100644 --- a/src/builtins.h +++ b/src/builtins.h @@ -12,7 +12,7 @@ /* sysfn.c*/M(repr,"•Repr") M(fmt,"•Fmt") A(asrt,"!") A(casrt,"!") M(out,"•Out") M(show,"•Show") A(bqn,"•BQN") A(sh,"•SH") M(fromUtf8,"•FromUTF8") M(currentError,"•CurrentError") \ /* sysfn.c*/D(cmp,"•Cmp") A(hash,"•Hash") M(unixTime,"•UnixTime") M(monoTime,"•MonoTime") M(delay,"•Delay") M(makeRand,"•MakeRand") M(reBQN,"•ReBQN") M(exit,"•Exit") M(getLine,"•GetLine") \ /* sysfn.c*/M(fName,"•file.Name") \ -/* ffi.c*/D(loadffi,"•LoadFFI") \ +/* ffi.c*/D(ffiload,"•FFI") \ /* sysfn.c*/M(tRawMode,"•term.RawMode") M(tFlush,"•term.Flush") M(tCharB,"•term.CharB") M(tCharN,"•term.CharN") M(tOutRaw,"•term.OutRaw") M(tErrRaw,"•term.ErrRaw") \ /* inverse.c*/M(setInvReg, "(SetInvReg)") M(setInvSwap, "(SetInvSwap)") M(nativeInvReg, "(NativeInvReg)") M(nativeInvSwap, "(NativeInvSwap)") \ /*internal.c*/M(itype,"•internal.Type") M(elType,"•internal.ElType") M(refc,"•internal.Refc") M(isPure,"•internal.IsPure") A(info,"•internal.Info") M(heapDump,"•internal.HeapDump") \ diff --git a/src/builtins/sysfn.c b/src/builtins/sysfn.c index b04a8a4d..1586c2ec 100644 --- a/src/builtins/sysfn.c +++ b/src/builtins/sysfn.c @@ -1142,7 +1142,7 @@ B sys_c1(B t, B x) { else if (eqStr(c, U"import")) cr = m_nfn(importDesc, inc(REQ_PATH)); else if (eqStr(c, U"currenterror")) cr = inc(bi_currentError); #if FFI - else if (eqStr(c, U"loadffi")) cr = inc(bi_loadffi); + else if (eqStr(c, U"loadffi")) cr = inc(bi_ffiload); #endif else if (eqStr(c, U"state")) { if (q_N(comp_currArgs)) thrM("No arguments present for •state"); diff --git a/src/ffi.c b/src/ffi.c index 4bc3d13c..bdeb232b 100644 --- a/src/ffi.c +++ b/src/ffi.c @@ -563,8 +563,7 @@ B libffiFn_c1(B t, B x) { return libffiFn_c2(t, bi_N, x); } - -B loadffi_c2(B t, B w, B x) { +B ffiload_c2(B t, B w, B x) { usz xia = a(x)->ia; if (xia<2) thrM("FFI: Function specification must have at least two items"); usz argn = xia-2; @@ -580,6 +579,7 @@ B loadffi_c2(B t, B w, B x) { char* ws = toCStr(w); void* dl = dlopen(ws, RTLD_NOW); + freeCStr(ws); dec(w); if (dl==NULL) thrF("Failed to load: %S", dlerror()); @@ -593,7 +593,9 @@ B loadffi_c2(B t, B w, B x) { #if FFI==1 return m_ffiFn(foreignFnDesc, bi_N, directFn_c1, directFn_c2, sym, sym); #else - TAlloc* argsRaw = ARBOBJ(argn*sizeof(ffi_type*)); + u64 sz = argn*sizeof(ffi_type*); + if (sz<16) sz = 16; + TAlloc* argsRaw = ARBOBJ(sz); ffi_type** argsRawArr = (ffi_type**)argsRaw->data; for (usz i = 0; i < argn; i++) argsRawArr[i] = &args[i+1].t; // for (usz i = 0; i < argn; i++) { @@ -637,5 +639,5 @@ void ffi_init() { #else void ffi_init() { } -B loadffi_c2(B t, B w, B x) { thrM("CBQN was compiled without FFI"); } +B ffiload_c2(B t, B w, B x) { thrM("CBQN was compiled without FFI"); } #endif