allocate at least minimum size, rename functions

This commit is contained in:
dzaima 2022-05-11 22:56:09 +03:00
parent 09755e5e2c
commit d186294e28
3 changed files with 8 additions and 6 deletions

View File

@ -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") \

View File

@ -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");

View File

@ -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