koffi 2.14.0 → 2.14.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -1
- package/README.md +1 -1
- package/build/koffi/darwin_arm64/koffi.node +0 -0
- package/build/koffi/darwin_x64/koffi.node +0 -0
- package/build/koffi/freebsd_arm64/koffi.node +0 -0
- package/build/koffi/freebsd_ia32/koffi.node +0 -0
- package/build/koffi/freebsd_x64/koffi.node +0 -0
- package/build/koffi/linux_arm64/koffi.node +0 -0
- package/build/koffi/linux_armhf/koffi.node +0 -0
- package/build/koffi/linux_ia32/koffi.node +0 -0
- package/build/koffi/linux_loong64/koffi.node +0 -0
- package/build/koffi/linux_riscv64d/koffi.node +0 -0
- package/build/koffi/linux_x64/koffi.node +0 -0
- package/build/koffi/musl_arm64/koffi.node +0 -0
- package/build/koffi/musl_x64/koffi.node +0 -0
- package/build/koffi/openbsd_ia32/koffi.node +0 -0
- package/build/koffi/openbsd_x64/koffi.node +0 -0
- package/build/koffi/win32_arm64/koffi.node +0 -0
- package/build/koffi/win32_ia32/koffi.node +0 -0
- package/build/koffi/win32_x64/koffi.node +0 -0
- package/doc/pages/index.md +43 -4
- package/doc/pages/platforms.md +8 -19
- package/doc/pages.ini +0 -7
- package/doc/static/perf_windows.png +0 -0
- package/index.js +3 -2
- package/indirect.js +3 -2
- package/package.json +3 -2
- package/src/cnoke/src/builder.js +1 -2
- package/src/core/base/base.cc +791 -555
- package/src/core/base/base.hh +577 -450
- package/src/core/base/crc.inc +1 -1
- package/src/core/base/crc_gen.py +1 -1
- package/src/core/base/unicode.inc +1 -1
- package/src/core/base/unicode_gen.py +1 -1
- package/src/koffi/src/abi_arm32.cc +24 -24
- package/src/koffi/src/abi_arm64.cc +29 -29
- package/src/koffi/src/abi_riscv64.cc +27 -27
- package/src/koffi/src/abi_x64_sysv.cc +29 -29
- package/src/koffi/src/abi_x64_win.cc +20 -20
- package/src/koffi/src/abi_x86.cc +26 -26
- package/src/koffi/src/call.cc +82 -236
- package/src/koffi/src/call.hh +6 -6
- package/src/koffi/src/ffi.cc +60 -60
- package/src/koffi/src/ffi.hh +9 -9
- package/src/koffi/src/parser.cc +2 -2
- package/src/koffi/src/parser.hh +1 -1
- package/src/koffi/src/trampolines/prototypes.inc +1 -1
- package/src/koffi/src/util.cc +43 -43
- package/src/koffi/src/util.hh +5 -5
- package/src/koffi/src/win32.cc +5 -5
- package/src/koffi/src/win32.hh +1 -1
package/src/koffi/src/ffi.cc
CHANGED
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
|
|
51
51
|
#include <napi.h>
|
|
52
52
|
|
|
53
|
-
namespace
|
|
53
|
+
namespace K {
|
|
54
54
|
|
|
55
55
|
SharedData shared;
|
|
56
56
|
|
|
@@ -147,7 +147,7 @@ static Napi::Value GetSetConfig(const Napi::CallbackInfo &info)
|
|
|
147
147
|
if (!ChangeMemorySize(key.c_str(), value, &new_config.async_heap_size))
|
|
148
148
|
return env.Null();
|
|
149
149
|
} else if (key == "resident_async_pools") {
|
|
150
|
-
if (!ChangeAsyncLimit(key.c_str(), value,
|
|
150
|
+
if (!ChangeAsyncLimit(key.c_str(), value, K_LEN(instance->memories.data) - 1, &new_config.resident_async_pools))
|
|
151
151
|
return env.Null();
|
|
152
152
|
} else if (key == "max_async_calls") {
|
|
153
153
|
if (!ChangeAsyncLimit(key.c_str(), value, MaxAsyncCalls, &max_async_calls))
|
|
@@ -259,7 +259,7 @@ static Napi::Value CreateStructType(const Napi::CallbackInfo &info, bool pad)
|
|
|
259
259
|
Napi::Object obj = info[skip].As<Napi::Object>();
|
|
260
260
|
Napi::Array keys = GetOwnPropertyNames(obj);
|
|
261
261
|
|
|
262
|
-
|
|
262
|
+
K_DEFER_NC(err_guard, count = instance->types.count) {
|
|
263
263
|
Size start = count + !skip;
|
|
264
264
|
|
|
265
265
|
for (Size i = start; i < instance->types.count; i++) {
|
|
@@ -454,7 +454,7 @@ static Napi::Value CreateUnionType(const Napi::CallbackInfo &info)
|
|
|
454
454
|
Napi::Object obj = info[skip].As<Napi::Object>();
|
|
455
455
|
Napi::Array keys = GetOwnPropertyNames(obj);
|
|
456
456
|
|
|
457
|
-
|
|
457
|
+
K_DEFER_NC(err_guard, count = instance->types.count) {
|
|
458
458
|
Size start = count + !skip;
|
|
459
459
|
|
|
460
460
|
for (Size i = start; i < instance->types.count; i++) {
|
|
@@ -629,7 +629,7 @@ static Napi::Value CreateOpaqueType(const Napi::CallbackInfo &info)
|
|
|
629
629
|
Napi::String name = info[0].As<Napi::String>();
|
|
630
630
|
|
|
631
631
|
TypeInfo *type = instance->types.AppendDefault();
|
|
632
|
-
|
|
632
|
+
K_DEFER_N(err_guard) { instance->types.RemoveLast(1); };
|
|
633
633
|
|
|
634
634
|
type->name = named ? DuplicateString(name.Utf8Value().c_str(), &instance->str_alloc).ptr
|
|
635
635
|
: Fmt(&instance->str_alloc, "<anonymous_%1>", instance->types.count).ptr;
|
|
@@ -690,13 +690,13 @@ static Napi::Value CreatePointerType(const Napi::CallbackInfo &info)
|
|
|
690
690
|
}
|
|
691
691
|
|
|
692
692
|
TypeInfo *type = MakePointerType(instance, ref, count);
|
|
693
|
-
|
|
693
|
+
K_ASSERT(type);
|
|
694
694
|
|
|
695
695
|
if (named || !countedby.IsEmpty()) {
|
|
696
696
|
TypeInfo *copy = instance->types.AppendDefault();
|
|
697
|
-
|
|
697
|
+
K_DEFER_N(err_guard) { instance->types.RemoveLast(1); };
|
|
698
698
|
|
|
699
|
-
memcpy((void *)copy, type,
|
|
699
|
+
memcpy((void *)copy, type, K_SIZE(*type));
|
|
700
700
|
copy->name = named ? DuplicateString(name.c_str(), &instance->str_alloc).ptr : copy->name;
|
|
701
701
|
|
|
702
702
|
if (!countedby.IsEmpty()) {
|
|
@@ -717,7 +717,7 @@ static Napi::Value CreatePointerType(const Napi::CallbackInfo &info)
|
|
|
717
717
|
|
|
718
718
|
static Napi::Value EncodePointerDirection(const Napi::CallbackInfo &info, int directions)
|
|
719
719
|
{
|
|
720
|
-
|
|
720
|
+
K_ASSERT(directions >= 1 && directions <= 3);
|
|
721
721
|
|
|
722
722
|
Napi::Env env = info.Env();
|
|
723
723
|
InstanceData *instance = env.GetInstanceData<InstanceData>();
|
|
@@ -817,7 +817,7 @@ static Napi::Value CreateDisposableType(const Napi::CallbackInfo &info)
|
|
|
817
817
|
external
|
|
818
818
|
};
|
|
819
819
|
|
|
820
|
-
ref.Call(self,
|
|
820
|
+
ref.Call(self, K_LEN(args), args);
|
|
821
821
|
instance->stats.disposed++;
|
|
822
822
|
};
|
|
823
823
|
dispose_func = func;
|
|
@@ -831,9 +831,9 @@ static Napi::Value CreateDisposableType(const Napi::CallbackInfo &info)
|
|
|
831
831
|
}
|
|
832
832
|
|
|
833
833
|
TypeInfo *type = instance->types.AppendDefault();
|
|
834
|
-
|
|
834
|
+
K_DEFER_N(err_guard) { instance->types.RemoveLast(1); };
|
|
835
835
|
|
|
836
|
-
memcpy((void *)type, (const void *)src,
|
|
836
|
+
memcpy((void *)type, (const void *)src, K_SIZE(*src));
|
|
837
837
|
type->members.allocator = GetNullAllocator();
|
|
838
838
|
|
|
839
839
|
type->name = named ? DuplicateString(name.Utf8Value().c_str(), &instance->str_alloc).ptr
|
|
@@ -1052,7 +1052,7 @@ static Napi::Value CreateArrayType(const Napi::CallbackInfo &info)
|
|
|
1052
1052
|
|
|
1053
1053
|
static bool ParseClassicFunction(const Napi::CallbackInfo &info, bool concrete, FunctionInfo *out_func)
|
|
1054
1054
|
{
|
|
1055
|
-
|
|
1055
|
+
K_ASSERT(info.Length() >= 2);
|
|
1056
1056
|
|
|
1057
1057
|
Napi::Env env = info.Env();
|
|
1058
1058
|
InstanceData *instance = env.GetInstanceData<InstanceData>();
|
|
@@ -1158,7 +1158,7 @@ static Napi::Value CreateFunctionType(const Napi::CallbackInfo &info)
|
|
|
1158
1158
|
InstanceData *instance = env.GetInstanceData<InstanceData>();
|
|
1159
1159
|
|
|
1160
1160
|
FunctionInfo *func = instance->callbacks.AppendDefault();
|
|
1161
|
-
|
|
1161
|
+
K_DEFER_N(err_guard) { instance->callbacks.RemoveLast(1); };
|
|
1162
1162
|
|
|
1163
1163
|
if (info.Length() >= 2) {
|
|
1164
1164
|
if (!ParseClassicFunction(info, false, func))
|
|
@@ -1205,7 +1205,7 @@ static Napi::Value CreateFunctionType(const Napi::CallbackInfo &info)
|
|
|
1205
1205
|
|
|
1206
1206
|
type->primitive = PrimitiveKind::Prototype;
|
|
1207
1207
|
type->align = alignof(void *);
|
|
1208
|
-
type->size =
|
|
1208
|
+
type->size = K_SIZE(void *);
|
|
1209
1209
|
type->ref.proto = func;
|
|
1210
1210
|
|
|
1211
1211
|
instance->types_map.Set(type->name, type);
|
|
@@ -1428,7 +1428,7 @@ static InstanceMemory *AllocateMemory(InstanceData *instance, Size stack_size, S
|
|
|
1428
1428
|
return nullptr;
|
|
1429
1429
|
|
|
1430
1430
|
InstanceMemory *mem = new InstanceMemory();
|
|
1431
|
-
|
|
1431
|
+
K_DEFER_N(mem_guard) { delete mem; };
|
|
1432
1432
|
|
|
1433
1433
|
stack_size = AlignLen(stack_size, Kibibytes(64));
|
|
1434
1434
|
|
|
@@ -1437,12 +1437,12 @@ static InstanceMemory *AllocateMemory(InstanceData *instance, Size stack_size, S
|
|
|
1437
1437
|
mem->stack.len = stack_size;
|
|
1438
1438
|
mem->stack.ptr = (uint8_t *)VirtualAlloc(nullptr, mem->stack.len, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
|
|
1439
1439
|
|
|
1440
|
-
|
|
1440
|
+
K_CRITICAL(mem->stack.ptr, "Failed to allocate %1 of memory", mem->stack.len);
|
|
1441
1441
|
#else
|
|
1442
1442
|
mem->stack.len = stack_size;
|
|
1443
1443
|
mem->stack.ptr = (uint8_t *)mmap(nullptr, mem->stack.len, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON | MAP_STACK, -1, 0);
|
|
1444
1444
|
|
|
1445
|
-
|
|
1445
|
+
K_CRITICAL(mem->stack.ptr, "Failed to allocate %1 of memory", mem->stack.len);
|
|
1446
1446
|
#endif
|
|
1447
1447
|
|
|
1448
1448
|
#if defined(__OpenBSD__)
|
|
@@ -1459,7 +1459,7 @@ static InstanceMemory *AllocateMemory(InstanceData *instance, Size stack_size, S
|
|
|
1459
1459
|
#else
|
|
1460
1460
|
mem->heap.ptr = (uint8_t *)mmap(nullptr, mem->heap.len, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0);
|
|
1461
1461
|
#endif
|
|
1462
|
-
|
|
1462
|
+
K_CRITICAL(mem->heap.ptr, "Failed to allocate %1 of memory", mem->heap.len);
|
|
1463
1463
|
|
|
1464
1464
|
if (temporary) {
|
|
1465
1465
|
instance->temporaries++;
|
|
@@ -1498,7 +1498,7 @@ static Napi::Value TranslateNormalCall(const FunctionInfo *func, void *native,
|
|
|
1498
1498
|
|
|
1499
1499
|
// Execute call
|
|
1500
1500
|
{
|
|
1501
|
-
|
|
1501
|
+
K_DEFER_C(prev_call = exec_call) { exec_call = prev_call; };
|
|
1502
1502
|
exec_call = &call;
|
|
1503
1503
|
|
|
1504
1504
|
call.Execute(func, native);
|
|
@@ -1520,11 +1520,11 @@ static Napi::Value TranslateVariadicCall(const FunctionInfo *func, void *native,
|
|
|
1520
1520
|
InstanceData *instance = env.GetInstanceData<InstanceData>();
|
|
1521
1521
|
|
|
1522
1522
|
FunctionInfo copy;
|
|
1523
|
-
memcpy((void *)©, func,
|
|
1523
|
+
memcpy((void *)©, func, K_SIZE(*func));
|
|
1524
1524
|
copy.lib = nullptr;
|
|
1525
1525
|
|
|
1526
1526
|
// This makes variadic calls non-reentrant
|
|
1527
|
-
|
|
1527
|
+
K_DEFER_C(len = copy.parameters.len) {
|
|
1528
1528
|
copy.parameters.RemoveFrom(len);
|
|
1529
1529
|
copy.parameters.Leak();
|
|
1530
1530
|
};
|
|
@@ -1579,7 +1579,7 @@ static Napi::Value TranslateVariadicCall(const FunctionInfo *func, void *native,
|
|
|
1579
1579
|
|
|
1580
1580
|
// Execute call
|
|
1581
1581
|
{
|
|
1582
|
-
|
|
1582
|
+
K_DEFER_C(prev_call = exec_call) { exec_call = prev_call; };
|
|
1583
1583
|
exec_call = &call;
|
|
1584
1584
|
|
|
1585
1585
|
call.Execute(©, native);
|
|
@@ -1629,7 +1629,7 @@ public:
|
|
|
1629
1629
|
void AsyncCall::Execute()
|
|
1630
1630
|
{
|
|
1631
1631
|
if (prepared) {
|
|
1632
|
-
|
|
1632
|
+
K_DEFER_C(prev_call = exec_call) { exec_call = prev_call; };
|
|
1633
1633
|
exec_call = &call;
|
|
1634
1634
|
|
|
1635
1635
|
call.Execute(func, native);
|
|
@@ -1638,7 +1638,7 @@ void AsyncCall::Execute()
|
|
|
1638
1638
|
|
|
1639
1639
|
void AsyncCall::OnOK()
|
|
1640
1640
|
{
|
|
1641
|
-
|
|
1641
|
+
K_ASSERT(prepared);
|
|
1642
1642
|
|
|
1643
1643
|
Napi::FunctionReference &callback = Callback();
|
|
1644
1644
|
|
|
@@ -1648,13 +1648,13 @@ void AsyncCall::OnOK()
|
|
|
1648
1648
|
call.Complete(func)
|
|
1649
1649
|
};
|
|
1650
1650
|
|
|
1651
|
-
callback.Call(self,
|
|
1651
|
+
callback.Call(self, K_LEN(args), args);
|
|
1652
1652
|
}
|
|
1653
1653
|
|
|
1654
1654
|
static Napi::Value TranslateAsyncCall(const FunctionInfo *func, void *native,
|
|
1655
1655
|
const Napi::CallbackInfo &info)
|
|
1656
1656
|
{
|
|
1657
|
-
|
|
1657
|
+
K_ASSERT(!func->variadic);
|
|
1658
1658
|
|
|
1659
1659
|
Napi::Env env = info.Env();
|
|
1660
1660
|
InstanceData *instance = env.GetInstanceData<InstanceData>();
|
|
@@ -1712,7 +1712,7 @@ extern "C" void RelayCallback(Size idx, uint8_t *own_sp, uint8_t *caller_sp, Bac
|
|
|
1712
1712
|
}
|
|
1713
1713
|
|
|
1714
1714
|
// Avoid triggering the "use callback beyond FFI" check
|
|
1715
|
-
|
|
1715
|
+
K_DEFER_C(generation = trampoline->generation) { trampoline->generation = generation; };
|
|
1716
1716
|
trampoline->generation = -1;
|
|
1717
1717
|
|
|
1718
1718
|
// We set dispose_call to true so that the main thread will dispose of CallData itself
|
|
@@ -1728,7 +1728,7 @@ static Napi::Value FindLibraryFunction(const Napi::CallbackInfo &info)
|
|
|
1728
1728
|
LibraryHolder *lib = (LibraryHolder *)info.Data();
|
|
1729
1729
|
|
|
1730
1730
|
FunctionInfo *func = new FunctionInfo();
|
|
1731
|
-
|
|
1731
|
+
K_DEFER { func->Unref(); };
|
|
1732
1732
|
|
|
1733
1733
|
func->lib = lib->Ref();
|
|
1734
1734
|
|
|
@@ -1876,7 +1876,7 @@ static Napi::Value LoadSharedLibrary(const Napi::CallbackInfo &info)
|
|
|
1876
1876
|
|
|
1877
1877
|
if (!instance->memories.len) {
|
|
1878
1878
|
AllocateMemory(instance, instance->config.sync_stack_size, instance->config.sync_heap_size);
|
|
1879
|
-
|
|
1879
|
+
K_ASSERT(instance->memories.len);
|
|
1880
1880
|
}
|
|
1881
1881
|
|
|
1882
1882
|
// Load shared library
|
|
@@ -1890,7 +1890,7 @@ static Napi::Value LoadSharedLibrary(const Napi::CallbackInfo &info)
|
|
|
1890
1890
|
return env.Null();
|
|
1891
1891
|
} else {
|
|
1892
1892
|
module = GetModuleHandle(nullptr);
|
|
1893
|
-
|
|
1893
|
+
K_ASSERT(module);
|
|
1894
1894
|
}
|
|
1895
1895
|
#else
|
|
1896
1896
|
if (info[0].IsString()) {
|
|
@@ -1917,7 +1917,7 @@ static Napi::Value LoadSharedLibrary(const Napi::CallbackInfo &info)
|
|
|
1917
1917
|
#endif
|
|
1918
1918
|
|
|
1919
1919
|
LibraryHolder *lib = new LibraryHolder(module);
|
|
1920
|
-
|
|
1920
|
+
K_DEFER { lib->Unref(); };
|
|
1921
1921
|
|
|
1922
1922
|
Napi::Object obj = Napi::Object::New(env);
|
|
1923
1923
|
|
|
@@ -2040,7 +2040,7 @@ static Napi::Value UnregisterCallback(const Napi::CallbackInfo &info)
|
|
|
2040
2040
|
std::lock_guard<std::mutex> lock(shared.mutex);
|
|
2041
2041
|
|
|
2042
2042
|
TrampolineInfo *trampoline = &shared.trampolines[idx];
|
|
2043
|
-
|
|
2043
|
+
K_ASSERT(!trampoline->func.IsEmpty());
|
|
2044
2044
|
|
|
2045
2045
|
trampoline->func.Reset();
|
|
2046
2046
|
trampoline->recv.Reset();
|
|
@@ -2354,8 +2354,8 @@ bool InitAsyncBroker(Napi::Env env, InstanceData *instance)
|
|
|
2354
2354
|
static void RegisterPrimitiveType(Napi::Env env, Napi::Object map, std::initializer_list<const char *> names,
|
|
2355
2355
|
PrimitiveKind primitive, int32_t size, int16_t align, const char *ref = nullptr)
|
|
2356
2356
|
{
|
|
2357
|
-
|
|
2358
|
-
|
|
2357
|
+
K_ASSERT(names.size() > 0);
|
|
2358
|
+
K_ASSERT(align <= size);
|
|
2359
2359
|
|
|
2360
2360
|
InstanceData *instance = env.GetInstanceData<InstanceData>();
|
|
2361
2361
|
|
|
@@ -2379,7 +2379,7 @@ static void RegisterPrimitiveType(Napi::Env env, Napi::Object map, std::initiali
|
|
|
2379
2379
|
|
|
2380
2380
|
if (ref) {
|
|
2381
2381
|
const TypeInfo *marker = instance->types_map.FindValue(ref, nullptr);
|
|
2382
|
-
|
|
2382
|
+
K_ASSERT(marker);
|
|
2383
2383
|
|
|
2384
2384
|
type->ref.marker = marker;
|
|
2385
2385
|
}
|
|
@@ -2389,7 +2389,7 @@ static void RegisterPrimitiveType(Napi::Env env, Napi::Object map, std::initiali
|
|
|
2389
2389
|
for (const char *name: names) {
|
|
2390
2390
|
bool inserted;
|
|
2391
2391
|
instance->types_map.TrySet(name, type, &inserted);
|
|
2392
|
-
|
|
2392
|
+
K_ASSERT(inserted);
|
|
2393
2393
|
|
|
2394
2394
|
if (!EndsWith(name, "*")) {
|
|
2395
2395
|
map.Set(name, wrapper);
|
|
@@ -2406,12 +2406,12 @@ static inline PrimitiveKind GetSignPrimitive(Size len, bool sign)
|
|
|
2406
2406
|
case 8: return sign ? PrimitiveKind::Int64 : PrimitiveKind::UInt64;
|
|
2407
2407
|
}
|
|
2408
2408
|
|
|
2409
|
-
|
|
2409
|
+
K_UNREACHABLE();
|
|
2410
2410
|
}
|
|
2411
2411
|
|
|
2412
2412
|
static inline PrimitiveKind GetLittleEndianPrimitive(PrimitiveKind kind)
|
|
2413
2413
|
{
|
|
2414
|
-
#if defined(
|
|
2414
|
+
#if defined(K_BIG_ENDIAN)
|
|
2415
2415
|
return (PrimitiveKind)((int)kind + 1);
|
|
2416
2416
|
#else
|
|
2417
2417
|
return kind;
|
|
@@ -2420,7 +2420,7 @@ static inline PrimitiveKind GetLittleEndianPrimitive(PrimitiveKind kind)
|
|
|
2420
2420
|
|
|
2421
2421
|
static inline PrimitiveKind GetBigEndianPrimitive(PrimitiveKind kind)
|
|
2422
2422
|
{
|
|
2423
|
-
#if defined(
|
|
2423
|
+
#if defined(K_BIG_ENDIAN)
|
|
2424
2424
|
return kind;
|
|
2425
2425
|
#else
|
|
2426
2426
|
return (PrimitiveKind)((int)kind + 1);
|
|
@@ -2430,7 +2430,7 @@ static inline PrimitiveKind GetBigEndianPrimitive(PrimitiveKind kind)
|
|
|
2430
2430
|
static InstanceData *CreateInstance()
|
|
2431
2431
|
{
|
|
2432
2432
|
InstanceData *instance = new InstanceData();
|
|
2433
|
-
|
|
2433
|
+
K_DEFER_N(err_guard) { delete instance; };
|
|
2434
2434
|
|
|
2435
2435
|
instance->main_thread_id = std::this_thread::get_id();
|
|
2436
2436
|
|
|
@@ -2450,7 +2450,7 @@ static InstanceData *CreateInstance()
|
|
|
2450
2450
|
static Napi::Object InitModule(Napi::Env env, Napi::Object exports)
|
|
2451
2451
|
{
|
|
2452
2452
|
InstanceData *instance = CreateInstance();
|
|
2453
|
-
|
|
2453
|
+
K_CRITICAL(instance, "Failed to initialize Koffi");
|
|
2454
2454
|
|
|
2455
2455
|
env.SetInstanceData(instance);
|
|
2456
2456
|
|
|
@@ -2525,16 +2525,16 @@ static Napi::Object InitModule(Napi::Env env, Napi::Object exports)
|
|
|
2525
2525
|
exports.Set("types", types);
|
|
2526
2526
|
|
|
2527
2527
|
RegisterPrimitiveType(env, types, {"void"}, PrimitiveKind::Void, 0, 0);
|
|
2528
|
-
RegisterPrimitiveType(env, types, {"bool"}, PrimitiveKind::Bool,
|
|
2528
|
+
RegisterPrimitiveType(env, types, {"bool"}, PrimitiveKind::Bool, K_SIZE(bool), alignof(bool));
|
|
2529
2529
|
RegisterPrimitiveType(env, types, {"int8_t", "int8"}, PrimitiveKind::Int8, 1, 1);
|
|
2530
2530
|
RegisterPrimitiveType(env, types, {"uint8_t", "uint8"}, PrimitiveKind::UInt8, 1, 1);
|
|
2531
2531
|
RegisterPrimitiveType(env, types, {"char"}, PrimitiveKind::Int8, 1, 1);
|
|
2532
2532
|
RegisterPrimitiveType(env, types, {"unsigned char", "uchar"}, PrimitiveKind::UInt8, 1, 1);
|
|
2533
2533
|
RegisterPrimitiveType(env, types, {"char16_t", "char16"}, PrimitiveKind::Int16, 2, 2);
|
|
2534
2534
|
RegisterPrimitiveType(env, types, {"char32_t", "char32"}, PrimitiveKind::Int32, 4, 4);
|
|
2535
|
-
if (
|
|
2535
|
+
if (K_SIZE(wchar_t) == 2) {
|
|
2536
2536
|
RegisterPrimitiveType(env, types, {"wchar_t", "wchar"}, PrimitiveKind::Int16, 2, 2);
|
|
2537
|
-
} else if (
|
|
2537
|
+
} else if (K_SIZE(wchar_t) == 4) {
|
|
2538
2538
|
RegisterPrimitiveType(env, types, {"wchar_t", "wchar"}, PrimitiveKind::Int32, 4, 4);
|
|
2539
2539
|
}
|
|
2540
2540
|
RegisterPrimitiveType(env, types, {"int16_t", "int16"}, PrimitiveKind::Int16, 2, 2);
|
|
@@ -2559,22 +2559,22 @@ static Napi::Object InitModule(Napi::Env env, Napi::Object exports)
|
|
|
2559
2559
|
RegisterPrimitiveType(env, types, {"uint64_t", "uint64"}, PrimitiveKind::UInt64, 8, alignof(int64_t));
|
|
2560
2560
|
RegisterPrimitiveType(env, types, {"uint64_le_t", "uint64_le"}, GetLittleEndianPrimitive(PrimitiveKind::UInt64), 8, alignof(int64_t));
|
|
2561
2561
|
RegisterPrimitiveType(env, types, {"uint64_be_t", "uint64_be"}, GetBigEndianPrimitive(PrimitiveKind::UInt64), 8, alignof(int64_t));
|
|
2562
|
-
RegisterPrimitiveType(env, types, {"intptr_t", "intptr"}, GetSignPrimitive(
|
|
2563
|
-
RegisterPrimitiveType(env, types, {"uintptr_t", "uintptr"}, GetSignPrimitive(
|
|
2564
|
-
RegisterPrimitiveType(env, types, {"size_t"}, GetSignPrimitive(
|
|
2565
|
-
RegisterPrimitiveType(env, types, {"long"}, GetSignPrimitive(
|
|
2566
|
-
RegisterPrimitiveType(env, types, {"unsigned long", "ulong"}, GetSignPrimitive(
|
|
2567
|
-
RegisterPrimitiveType(env, types, {"long long", "longlong"}, PrimitiveKind::Int64,
|
|
2568
|
-
RegisterPrimitiveType(env, types, {"unsigned long long", "ulonglong"}, PrimitiveKind::UInt64,
|
|
2562
|
+
RegisterPrimitiveType(env, types, {"intptr_t", "intptr"}, GetSignPrimitive(K_SIZE(intptr_t), true), K_SIZE(intptr_t), alignof(intptr_t));
|
|
2563
|
+
RegisterPrimitiveType(env, types, {"uintptr_t", "uintptr"}, GetSignPrimitive(K_SIZE(intptr_t), false), K_SIZE(intptr_t), alignof(intptr_t));
|
|
2564
|
+
RegisterPrimitiveType(env, types, {"size_t"}, GetSignPrimitive(K_SIZE(size_t), false), K_SIZE(size_t), alignof(size_t));
|
|
2565
|
+
RegisterPrimitiveType(env, types, {"long"}, GetSignPrimitive(K_SIZE(long), true), K_SIZE(long), alignof(long));
|
|
2566
|
+
RegisterPrimitiveType(env, types, {"unsigned long", "ulong"}, GetSignPrimitive(K_SIZE(long), false), K_SIZE(long), alignof(long));
|
|
2567
|
+
RegisterPrimitiveType(env, types, {"long long", "longlong"}, PrimitiveKind::Int64, K_SIZE(int64_t), alignof(int64_t));
|
|
2568
|
+
RegisterPrimitiveType(env, types, {"unsigned long long", "ulonglong"}, PrimitiveKind::UInt64, K_SIZE(uint64_t), alignof(uint64_t));
|
|
2569
2569
|
RegisterPrimitiveType(env, types, {"float", "float32"}, PrimitiveKind::Float32, 4, alignof(float));
|
|
2570
2570
|
RegisterPrimitiveType(env, types, {"double", "float64"}, PrimitiveKind::Float64, 8, alignof(double));
|
|
2571
|
-
RegisterPrimitiveType(env, types, {"char *", "str", "string"}, PrimitiveKind::String,
|
|
2572
|
-
RegisterPrimitiveType(env, types, {"char16_t *", "char16 *", "str16", "string16"}, PrimitiveKind::String16,
|
|
2573
|
-
RegisterPrimitiveType(env, types, {"char32_t *", "char32 *", "str32", "string32"}, PrimitiveKind::String32,
|
|
2574
|
-
if (
|
|
2575
|
-
RegisterPrimitiveType(env, types, {"wchar_t *", "wchar *"}, PrimitiveKind::String16,
|
|
2576
|
-
} else if (
|
|
2577
|
-
RegisterPrimitiveType(env, types, {"wchar_t *", "wchar *"}, PrimitiveKind::String32,
|
|
2571
|
+
RegisterPrimitiveType(env, types, {"char *", "str", "string"}, PrimitiveKind::String, K_SIZE(void *), alignof(void *), "char");
|
|
2572
|
+
RegisterPrimitiveType(env, types, {"char16_t *", "char16 *", "str16", "string16"}, PrimitiveKind::String16, K_SIZE(void *), alignof(void *), "char16_t");
|
|
2573
|
+
RegisterPrimitiveType(env, types, {"char32_t *", "char32 *", "str32", "string32"}, PrimitiveKind::String32, K_SIZE(void *), alignof(void *), "char32_t");
|
|
2574
|
+
if (K_SIZE(wchar_t) == 2) {
|
|
2575
|
+
RegisterPrimitiveType(env, types, {"wchar_t *", "wchar *"}, PrimitiveKind::String16, K_SIZE(void *), alignof(void *), "wchar_t");
|
|
2576
|
+
} else if (K_SIZE(wchar_t) == 4) {
|
|
2577
|
+
RegisterPrimitiveType(env, types, {"wchar_t *", "wchar *"}, PrimitiveKind::String32, K_SIZE(void *), alignof(void *), "wchar_t");
|
|
2578
2578
|
}
|
|
2579
2579
|
|
|
2580
2580
|
instance->void_type = instance->types_map.FindValue("void", nullptr);
|
|
@@ -2601,7 +2601,7 @@ static Napi::Object InitModule(Napi::Env env, Napi::Object exports)
|
|
|
2601
2601
|
node.Set("env", external);
|
|
2602
2602
|
}
|
|
2603
2603
|
|
|
2604
|
-
exports.Set("version", Napi::String::New(env,
|
|
2604
|
+
exports.Set("version", Napi::String::New(env, K_STRINGIFY(VERSION)));
|
|
2605
2605
|
|
|
2606
2606
|
return exports;
|
|
2607
2607
|
}
|
package/src/koffi/src/ffi.hh
CHANGED
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
|
|
26
26
|
#include <napi.h>
|
|
27
27
|
|
|
28
|
-
namespace
|
|
28
|
+
namespace K {
|
|
29
29
|
|
|
30
30
|
static const Size DefaultSyncStackSize = Mebibytes(1);
|
|
31
31
|
static const Size DefaultSyncHeapSize = Mebibytes(2);
|
|
@@ -47,17 +47,17 @@ enum class PrimitiveKind {
|
|
|
47
47
|
Int8,
|
|
48
48
|
UInt8,
|
|
49
49
|
Int16,
|
|
50
|
-
Int16S,
|
|
50
|
+
Int16S, // Keep behind Int16
|
|
51
51
|
UInt16,
|
|
52
|
-
UInt16S,
|
|
52
|
+
UInt16S, // Keep behind UInt16
|
|
53
53
|
Int32,
|
|
54
|
-
Int32S,
|
|
54
|
+
Int32S, // Keep behind Int32
|
|
55
55
|
UInt32,
|
|
56
|
-
UInt32S,
|
|
56
|
+
UInt32S, // Keep behind UInt32
|
|
57
57
|
Int64,
|
|
58
|
-
Int64S,
|
|
58
|
+
Int64S, // Keep behind Int64
|
|
59
59
|
UInt64,
|
|
60
|
-
UInt64S,
|
|
60
|
+
UInt64S, // Keep behind UInt64
|
|
61
61
|
String,
|
|
62
62
|
String16,
|
|
63
63
|
String32,
|
|
@@ -152,7 +152,7 @@ struct TypeInfo {
|
|
|
152
152
|
mutable Napi::FunctionReference construct; // Union only
|
|
153
153
|
mutable Napi::ObjectReference defn;
|
|
154
154
|
|
|
155
|
-
|
|
155
|
+
K_HASHTABLE_HANDLER(TypeInfo, name);
|
|
156
156
|
};
|
|
157
157
|
|
|
158
158
|
struct RecordMember {
|
|
@@ -329,7 +329,7 @@ struct InstanceData {
|
|
|
329
329
|
int64_t disposed = 0;
|
|
330
330
|
} stats;
|
|
331
331
|
};
|
|
332
|
-
static_assert(DefaultResidentAsyncPools <=
|
|
332
|
+
static_assert(DefaultResidentAsyncPools <= K_LEN(InstanceData::memories.data) - 1);
|
|
333
333
|
static_assert(DefaultMaxAsyncCalls >= DefaultResidentAsyncPools);
|
|
334
334
|
static_assert(MaxAsyncCalls >= DefaultMaxAsyncCalls);
|
|
335
335
|
|
package/src/koffi/src/parser.cc
CHANGED
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
|
|
26
26
|
#include <napi.h>
|
|
27
27
|
|
|
28
|
-
namespace
|
|
28
|
+
namespace K {
|
|
29
29
|
|
|
30
30
|
bool PrototypeParser::Parse(const char *str, bool concrete, FunctionInfo *out_func)
|
|
31
31
|
{
|
|
@@ -221,7 +221,7 @@ bool PrototypeParser::Match(const char *expect)
|
|
|
221
221
|
|
|
222
222
|
bool PrototypeParser::IsIdentifier(Span<const char> tok) const
|
|
223
223
|
{
|
|
224
|
-
|
|
224
|
+
K_ASSERT(tok.len);
|
|
225
225
|
return IsAsciiAlpha(tok[0]) || tok[0] == '_';
|
|
226
226
|
}
|
|
227
227
|
|
package/src/koffi/src/parser.hh
CHANGED
|
@@ -16406,4 +16406,4 @@ static void *const Trampolines[][2] = {
|
|
|
16406
16406
|
{ &Trampoline8190, &TrampolineX8190 },
|
|
16407
16407
|
{ &Trampoline8191, &TrampolineX8191 }
|
|
16408
16408
|
};
|
|
16409
|
-
static_assert(
|
|
16409
|
+
static_assert(K_LEN(Trampolines) == MaxTrampolines);
|