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/util.cc
CHANGED
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
|
|
27
27
|
#include <napi.h>
|
|
28
28
|
|
|
29
|
-
namespace
|
|
29
|
+
namespace K {
|
|
30
30
|
|
|
31
31
|
// Value does not matter, the tag system uses memory addresses
|
|
32
32
|
const napi_type_tag TypeInfoMarker = { 0x1cc449675b294374, 0xbb13a50e97dcb017 };
|
|
@@ -35,7 +35,7 @@ const napi_type_tag MagicUnionMarker = { 0x5eaf2245526a4c7d, 0x8c86c9ee2b96ffc8
|
|
|
35
35
|
|
|
36
36
|
Napi::Function MagicUnion::InitClass(Napi::Env env, const TypeInfo *type)
|
|
37
37
|
{
|
|
38
|
-
|
|
38
|
+
K_ASSERT(type->primitive == PrimitiveKind::Union);
|
|
39
39
|
|
|
40
40
|
// node-addon-api wants std::vector
|
|
41
41
|
std::vector<Napi::ClassPropertyDescriptor<MagicUnion>> properties;
|
|
@@ -96,7 +96,7 @@ Napi::Value MagicUnion::Getter(const Napi::CallbackInfo &info)
|
|
|
96
96
|
active_idx = idx;
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
-
|
|
99
|
+
K_ASSERT(!value.IsEmpty());
|
|
100
100
|
return value;
|
|
101
101
|
}
|
|
102
102
|
|
|
@@ -203,7 +203,7 @@ const TypeInfo *ResolveType(Napi::Value value, int *out_directions)
|
|
|
203
203
|
const TypeInfo *raw = external.Data();
|
|
204
204
|
|
|
205
205
|
const TypeInfo *type = AlignDown(raw, 4);
|
|
206
|
-
|
|
206
|
+
K_ASSERT(type);
|
|
207
207
|
|
|
208
208
|
if (out_directions) {
|
|
209
209
|
Size delta = (uint8_t *)raw - (uint8_t *)type;
|
|
@@ -343,7 +343,7 @@ const TypeInfo *ResolveType(Napi::Env env, Span<const char> str)
|
|
|
343
343
|
|
|
344
344
|
TypeInfo *copy = instance->types.AppendDefault();
|
|
345
345
|
|
|
346
|
-
memcpy((void *)copy, (const void *)type,
|
|
346
|
+
memcpy((void *)copy, (const void *)type, K_SIZE(*type));
|
|
347
347
|
copy->name = Fmt(&instance->str_alloc, "<anonymous_%1>", instance->types.count).ptr;
|
|
348
348
|
copy->members.allocator = GetNullAllocator();
|
|
349
349
|
|
|
@@ -373,12 +373,12 @@ const TypeInfo *ResolveType(Napi::Env env, Span<const char> str)
|
|
|
373
373
|
}
|
|
374
374
|
|
|
375
375
|
type = MakeArrayType(instance, type, len);
|
|
376
|
-
|
|
376
|
+
K_ASSERT(type);
|
|
377
377
|
} else {
|
|
378
|
-
|
|
378
|
+
K_ASSERT(!len);
|
|
379
379
|
|
|
380
380
|
type = MakePointerType(instance, type);
|
|
381
|
-
|
|
381
|
+
K_ASSERT(type);
|
|
382
382
|
}
|
|
383
383
|
}
|
|
384
384
|
|
|
@@ -392,7 +392,7 @@ const TypeInfo *ResolveType(Napi::Env env, Span<const char> str)
|
|
|
392
392
|
|
|
393
393
|
TypeInfo *MakePointerType(InstanceData *instance, const TypeInfo *ref, int count)
|
|
394
394
|
{
|
|
395
|
-
|
|
395
|
+
K_ASSERT(count >= 1);
|
|
396
396
|
|
|
397
397
|
for (int i = 0; i < count; i++) {
|
|
398
398
|
char name_buf[256];
|
|
@@ -408,14 +408,14 @@ TypeInfo *MakePointerType(InstanceData *instance, const TypeInfo *ref, int count
|
|
|
408
408
|
|
|
409
409
|
if (ref->primitive != PrimitiveKind::Prototype) {
|
|
410
410
|
type->primitive = PrimitiveKind::Pointer;
|
|
411
|
-
type->size =
|
|
412
|
-
type->align =
|
|
411
|
+
type->size = K_SIZE(void *);
|
|
412
|
+
type->align = K_SIZE(void *);
|
|
413
413
|
type->ref.type = ref;
|
|
414
414
|
type->hint = (ref->flags & (int)TypeFlag::HasTypedArray) ? ArrayHint::Typed : ArrayHint::Array;
|
|
415
415
|
} else {
|
|
416
416
|
type->primitive = PrimitiveKind::Callback;
|
|
417
|
-
type->size =
|
|
418
|
-
type->align =
|
|
417
|
+
type->size = K_SIZE(void *);
|
|
418
|
+
type->align = K_SIZE(void *);
|
|
419
419
|
type->ref.proto = ref->ref.proto;
|
|
420
420
|
}
|
|
421
421
|
|
|
@@ -431,8 +431,8 @@ TypeInfo *MakePointerType(InstanceData *instance, const TypeInfo *ref, int count
|
|
|
431
431
|
|
|
432
432
|
static TypeInfo *MakeArrayType(InstanceData *instance, const TypeInfo *ref, Size len, ArrayHint hint, bool insert)
|
|
433
433
|
{
|
|
434
|
-
|
|
435
|
-
|
|
434
|
+
K_ASSERT(len >= 0);
|
|
435
|
+
K_ASSERT(len <= instance->config.max_type_size / ref->size);
|
|
436
436
|
|
|
437
437
|
TypeInfo *type = instance->types.AppendDefault();
|
|
438
438
|
|
|
@@ -597,7 +597,7 @@ const char *GetValueType(const InstanceData *instance, Napi::Value value)
|
|
|
597
597
|
|
|
598
598
|
void SetValueTag(const InstanceData *instance, Napi::Value value, const void *marker)
|
|
599
599
|
{
|
|
600
|
-
static_assert(
|
|
600
|
+
static_assert(K_SIZE(TypeInfo) >= 16);
|
|
601
601
|
|
|
602
602
|
// We used to make a temporary tag on the stack with lower set to a constant value and
|
|
603
603
|
// upper to the pointer address, but this broke in Node 20.12 and Node 21.6 due to ExternalWrapper
|
|
@@ -611,7 +611,7 @@ void SetValueTag(const InstanceData *instance, Napi::Value value, const void *ma
|
|
|
611
611
|
const napi_type_tag *tag = (const napi_type_tag *)marker;
|
|
612
612
|
|
|
613
613
|
napi_status status = napi_type_tag_object(value.Env(), value, tag);
|
|
614
|
-
|
|
614
|
+
K_ASSERT(status == napi_ok);
|
|
615
615
|
}
|
|
616
616
|
|
|
617
617
|
bool CheckValueTag(const InstanceData *instance, Napi::Value value, const void *marker)
|
|
@@ -641,7 +641,7 @@ int GetTypedArrayType(const TypeInfo *type)
|
|
|
641
641
|
default: return -1;
|
|
642
642
|
}
|
|
643
643
|
|
|
644
|
-
|
|
644
|
+
K_UNREACHABLE();
|
|
645
645
|
}
|
|
646
646
|
|
|
647
647
|
Napi::String MakeStringFromUTF32(Napi::Env env, const char32_t *ptr, Size len)
|
|
@@ -766,10 +766,10 @@ static uint32_t DecodeDynamicLength(const uint8_t *origin, const RecordMember &b
|
|
|
766
766
|
case PrimitiveKind::Array:
|
|
767
767
|
case PrimitiveKind::Float32:
|
|
768
768
|
case PrimitiveKind::Float64:
|
|
769
|
-
case PrimitiveKind::Prototype: {
|
|
769
|
+
case PrimitiveKind::Prototype: { K_UNREACHABLE(); } break;
|
|
770
770
|
}
|
|
771
771
|
|
|
772
|
-
|
|
772
|
+
K_UNREACHABLE();
|
|
773
773
|
}
|
|
774
774
|
|
|
775
775
|
void DecodeObject(Napi::Object obj, const uint8_t *origin, const TypeInfo *type)
|
|
@@ -777,7 +777,7 @@ void DecodeObject(Napi::Object obj, const uint8_t *origin, const TypeInfo *type)
|
|
|
777
777
|
Napi::Env env = obj.Env();
|
|
778
778
|
InstanceData *instance = env.GetInstanceData<InstanceData>();
|
|
779
779
|
|
|
780
|
-
|
|
780
|
+
K_ASSERT(type->primitive == PrimitiveKind::Record);
|
|
781
781
|
|
|
782
782
|
for (Size i = 0; i < type->members.len; i++) {
|
|
783
783
|
const RecordMember &member = type->members[i];
|
|
@@ -785,7 +785,7 @@ void DecodeObject(Napi::Object obj, const uint8_t *origin, const TypeInfo *type)
|
|
|
785
785
|
const uint8_t *src = origin + member.offset;
|
|
786
786
|
|
|
787
787
|
switch (member.type->primitive) {
|
|
788
|
-
case PrimitiveKind::Void: {
|
|
788
|
+
case PrimitiveKind::Void: { K_UNREACHABLE(); } break;
|
|
789
789
|
|
|
790
790
|
case PrimitiveKind::Bool: {
|
|
791
791
|
bool b = *(bool *)src;
|
|
@@ -929,7 +929,7 @@ void DecodeObject(Napi::Object obj, const uint8_t *origin, const TypeInfo *type)
|
|
|
929
929
|
obj.Set(member.name, Napi::Number::New(env, d));
|
|
930
930
|
} break;
|
|
931
931
|
|
|
932
|
-
case PrimitiveKind::Prototype: {
|
|
932
|
+
case PrimitiveKind::Prototype: { K_UNREACHABLE(); } break;
|
|
933
933
|
}
|
|
934
934
|
}
|
|
935
935
|
}
|
|
@@ -964,7 +964,7 @@ Napi::Value DecodeArray(Napi::Env env, const uint8_t *origin, const TypeInfo *ty
|
|
|
964
964
|
}); \
|
|
965
965
|
} else { \
|
|
966
966
|
Napi::TypedArrayType array = Napi::TypedArrayType::New(env, len); \
|
|
967
|
-
Span<uint8_t> buffer = MakeSpan((uint8_t *)array.ArrayBuffer().Data(), (Size)len *
|
|
967
|
+
Span<uint8_t> buffer = MakeSpan((uint8_t *)array.ArrayBuffer().Data(), (Size)len * K_SIZE(CType)); \
|
|
968
968
|
\
|
|
969
969
|
DecodeBuffer(buffer, origin, type->ref.type); \
|
|
970
970
|
\
|
|
@@ -981,7 +981,7 @@ Napi::Value DecodeArray(Napi::Env env, const uint8_t *origin, const TypeInfo *ty
|
|
|
981
981
|
}); \
|
|
982
982
|
} else { \
|
|
983
983
|
Napi::TypedArrayType array = Napi::TypedArrayType::New(env, len); \
|
|
984
|
-
Span<uint8_t> buffer = MakeSpan((uint8_t *)array.ArrayBuffer().Data(), (Size)len *
|
|
984
|
+
Span<uint8_t> buffer = MakeSpan((uint8_t *)array.ArrayBuffer().Data(), (Size)len * K_SIZE(CType)); \
|
|
985
985
|
\
|
|
986
986
|
DecodeBuffer(buffer, origin, type->ref.type); \
|
|
987
987
|
\
|
|
@@ -990,7 +990,7 @@ Napi::Value DecodeArray(Napi::Env env, const uint8_t *origin, const TypeInfo *ty
|
|
|
990
990
|
} while (false)
|
|
991
991
|
|
|
992
992
|
switch (type->ref.type->primitive) {
|
|
993
|
-
case PrimitiveKind::Void: {
|
|
993
|
+
case PrimitiveKind::Void: { K_UNREACHABLE(); } break;
|
|
994
994
|
|
|
995
995
|
case PrimitiveKind::Bool: {
|
|
996
996
|
POP_ARRAY({
|
|
@@ -1111,19 +1111,19 @@ Napi::Value DecodeArray(Napi::Env env, const uint8_t *origin, const TypeInfo *ty
|
|
|
1111
1111
|
case PrimitiveKind::Float32: { POP_NUMBER_ARRAY(Float32Array, float); } break;
|
|
1112
1112
|
case PrimitiveKind::Float64: { POP_NUMBER_ARRAY(Float64Array, double); } break;
|
|
1113
1113
|
|
|
1114
|
-
case PrimitiveKind::Prototype: {
|
|
1114
|
+
case PrimitiveKind::Prototype: { K_UNREACHABLE(); } break;
|
|
1115
1115
|
}
|
|
1116
1116
|
|
|
1117
1117
|
#undef POP_NUMBER_ARRAY_SWAP
|
|
1118
1118
|
#undef POP_NUMBER_ARRAY
|
|
1119
1119
|
#undef POP_ARRAY
|
|
1120
1120
|
|
|
1121
|
-
|
|
1121
|
+
K_UNREACHABLE();
|
|
1122
1122
|
}
|
|
1123
1123
|
|
|
1124
1124
|
Napi::Value DecodeArray(Napi::Env env, const uint8_t *origin, const TypeInfo *type)
|
|
1125
1125
|
{
|
|
1126
|
-
|
|
1126
|
+
K_ASSERT(type->primitive == PrimitiveKind::Array);
|
|
1127
1127
|
|
|
1128
1128
|
uint32_t len = type->size / type->ref.type->size;
|
|
1129
1129
|
return DecodeArray(env, origin, type, len);
|
|
@@ -1134,7 +1134,7 @@ void DecodeNormalArray(Napi::Array array, const uint8_t *origin, const TypeInfo
|
|
|
1134
1134
|
Napi::Env env = array.Env();
|
|
1135
1135
|
InstanceData *instance = env.GetInstanceData<InstanceData>();
|
|
1136
1136
|
|
|
1137
|
-
|
|
1137
|
+
K_ASSERT(array.IsArray());
|
|
1138
1138
|
|
|
1139
1139
|
Size offset = 0;
|
|
1140
1140
|
uint32_t len = array.Length();
|
|
@@ -1168,7 +1168,7 @@ void DecodeNormalArray(Napi::Array array, const uint8_t *origin, const TypeInfo
|
|
|
1168
1168
|
} while (false)
|
|
1169
1169
|
|
|
1170
1170
|
switch (ref->primitive) {
|
|
1171
|
-
case PrimitiveKind::Void: {
|
|
1171
|
+
case PrimitiveKind::Void: { K_UNREACHABLE(); } break;
|
|
1172
1172
|
|
|
1173
1173
|
case PrimitiveKind::Bool: {
|
|
1174
1174
|
POP_ARRAY({
|
|
@@ -1275,7 +1275,7 @@ void DecodeNormalArray(Napi::Array array, const uint8_t *origin, const TypeInfo
|
|
|
1275
1275
|
case PrimitiveKind::Float32: { POP_NUMBER_ARRAY(float); } break;
|
|
1276
1276
|
case PrimitiveKind::Float64: { POP_NUMBER_ARRAY(double); } break;
|
|
1277
1277
|
|
|
1278
|
-
case PrimitiveKind::Prototype: {
|
|
1278
|
+
case PrimitiveKind::Prototype: { K_UNREACHABLE(); } break;
|
|
1279
1279
|
}
|
|
1280
1280
|
|
|
1281
1281
|
#undef POP_NUMBER_ARRAY_SWAP
|
|
@@ -1291,7 +1291,7 @@ void DecodeBuffer(Span<uint8_t> buffer, const uint8_t *origin, const TypeInfo *r
|
|
|
1291
1291
|
#define SWAP(CType) \
|
|
1292
1292
|
do { \
|
|
1293
1293
|
CType *data = (CType *)buffer.ptr; \
|
|
1294
|
-
Size len = buffer.len /
|
|
1294
|
+
Size len = buffer.len / K_SIZE(CType); \
|
|
1295
1295
|
\
|
|
1296
1296
|
for (Size i = 0; i < len; i++) { \
|
|
1297
1297
|
data[i] = ReverseBytes(data[i]); \
|
|
@@ -1361,17 +1361,17 @@ Napi::Value Decode(Napi::Env env, const uint8_t *ptr, const TypeInfo *type, cons
|
|
|
1361
1361
|
} break;
|
|
1362
1362
|
case PrimitiveKind::Int16:
|
|
1363
1363
|
case PrimitiveKind::UInt16: {
|
|
1364
|
-
Size count = NullTerminatedLength((const char16_t *)ptr,
|
|
1364
|
+
Size count = NullTerminatedLength((const char16_t *)ptr, K_SIZE_MAX);
|
|
1365
1365
|
type = MakeArrayType(instance, type, count);
|
|
1366
1366
|
} break;
|
|
1367
1367
|
case PrimitiveKind::Int32:
|
|
1368
1368
|
case PrimitiveKind::UInt32: {
|
|
1369
|
-
Size count = NullTerminatedLength((const char32_t *)ptr,
|
|
1369
|
+
Size count = NullTerminatedLength((const char32_t *)ptr, K_SIZE_MAX);
|
|
1370
1370
|
type = MakeArrayType(instance, type, count);
|
|
1371
1371
|
} break;
|
|
1372
1372
|
|
|
1373
1373
|
case PrimitiveKind::Pointer: {
|
|
1374
|
-
Size count = NullTerminatedLength((const void **)ptr,
|
|
1374
|
+
Size count = NullTerminatedLength((const void **)ptr, K_SIZE_MAX);
|
|
1375
1375
|
type = MakeArrayType(instance, type, count);
|
|
1376
1376
|
} break;
|
|
1377
1377
|
|
|
@@ -1470,14 +1470,14 @@ Napi::Value Decode(Napi::Env env, const uint8_t *ptr, const TypeInfo *type, cons
|
|
|
1470
1470
|
|
|
1471
1471
|
case PrimitiveKind::Prototype: {
|
|
1472
1472
|
const FunctionInfo *proto = type->ref.proto;
|
|
1473
|
-
|
|
1474
|
-
|
|
1473
|
+
K_ASSERT(!proto->variadic);
|
|
1474
|
+
K_ASSERT(!proto->lib);
|
|
1475
1475
|
|
|
1476
1476
|
FunctionInfo *func = new FunctionInfo();
|
|
1477
|
-
|
|
1477
|
+
K_DEFER { func->Unref(); };
|
|
1478
1478
|
|
|
1479
|
-
memcpy((void *)func, proto,
|
|
1480
|
-
memset((void *)&func->parameters, 0,
|
|
1479
|
+
memcpy((void *)func, proto, K_SIZE(*proto));
|
|
1480
|
+
memset((void *)&func->parameters, 0, K_SIZE(func->parameters));
|
|
1481
1481
|
func->parameters = proto->parameters;
|
|
1482
1482
|
|
|
1483
1483
|
func->name = "<anonymous>";
|
|
@@ -1575,7 +1575,7 @@ bool Encode(Napi::Env env, uint8_t *origin, Napi::Value value, const TypeInfo *t
|
|
|
1575
1575
|
} while (false)
|
|
1576
1576
|
|
|
1577
1577
|
switch (type->primitive) {
|
|
1578
|
-
case PrimitiveKind::Void: {
|
|
1578
|
+
case PrimitiveKind::Void: { K_UNREACHABLE(); } break;
|
|
1579
1579
|
|
|
1580
1580
|
case PrimitiveKind::Bool: {
|
|
1581
1581
|
if (!value.IsBoolean()) [[unlikely]] {
|
|
@@ -1688,7 +1688,7 @@ bool Encode(Napi::Env env, uint8_t *origin, Napi::Value value, const TypeInfo *t
|
|
|
1688
1688
|
*(void **)origin = ptr;
|
|
1689
1689
|
} break;
|
|
1690
1690
|
|
|
1691
|
-
case PrimitiveKind::Prototype: {
|
|
1691
|
+
case PrimitiveKind::Prototype: { K_UNREACHABLE(); } break;
|
|
1692
1692
|
}
|
|
1693
1693
|
|
|
1694
1694
|
#undef PUSH_INTEGER_SWAP
|
package/src/koffi/src/util.hh
CHANGED
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
|
|
27
27
|
#include <napi.h>
|
|
28
28
|
|
|
29
|
-
namespace
|
|
29
|
+
namespace K {
|
|
30
30
|
|
|
31
31
|
extern const napi_type_tag TypeInfoMarker;
|
|
32
32
|
extern const napi_type_tag CastMarker;
|
|
@@ -151,7 +151,7 @@ static inline Span<uint8_t> GetRawBuffer(Napi::Value value)
|
|
|
151
151
|
return MakeSpan((uint8_t *)buffer.Data(), (Size)buffer.ByteLength());
|
|
152
152
|
}
|
|
153
153
|
|
|
154
|
-
|
|
154
|
+
K_UNREACHABLE();
|
|
155
155
|
}
|
|
156
156
|
|
|
157
157
|
int GetTypedArrayType(const TypeInfo *type);
|
|
@@ -159,7 +159,7 @@ int GetTypedArrayType(const TypeInfo *type);
|
|
|
159
159
|
template <typename T>
|
|
160
160
|
T GetNumber(Napi::Value value)
|
|
161
161
|
{
|
|
162
|
-
|
|
162
|
+
K_ASSERT(value.IsNumber() || value.IsBigInt());
|
|
163
163
|
|
|
164
164
|
if (value.IsNumber()) [[likely]] {
|
|
165
165
|
return (T)value.As<Napi::Number>().DoubleValue();
|
|
@@ -170,7 +170,7 @@ T GetNumber(Napi::Value value)
|
|
|
170
170
|
return (T)bigint.Uint64Value(&lossless);
|
|
171
171
|
}
|
|
172
172
|
|
|
173
|
-
|
|
173
|
+
K_UNREACHABLE();
|
|
174
174
|
}
|
|
175
175
|
|
|
176
176
|
template <typename T>
|
|
@@ -237,7 +237,7 @@ static inline Napi::Array GetOwnPropertyNames(Napi::Object obj)
|
|
|
237
237
|
napi_status status = napi_get_all_property_names(env, obj, napi_key_own_only,
|
|
238
238
|
(napi_key_filter)(napi_key_enumerable | napi_key_skip_symbols),
|
|
239
239
|
napi_key_numbers_to_strings, &result);
|
|
240
|
-
|
|
240
|
+
K_ASSERT(status == napi_ok);
|
|
241
241
|
|
|
242
242
|
return Napi::Array(env, result);
|
|
243
243
|
}
|
package/src/koffi/src/win32.cc
CHANGED
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
#include <ntsecapi.h>
|
|
35
35
|
#include <processthreadsapi.h>
|
|
36
36
|
|
|
37
|
-
namespace
|
|
37
|
+
namespace K {
|
|
38
38
|
|
|
39
39
|
const HashMap<int, const char *> WindowsMachineNames = {
|
|
40
40
|
{ 0x184, "Alpha AXP, 32-bit" },
|
|
@@ -138,9 +138,9 @@ static int GetFileMachine(HANDLE h, bool check_dll)
|
|
|
138
138
|
PE_DOS_HEADER dos = {};
|
|
139
139
|
PE_NT_HEADERS nt = {};
|
|
140
140
|
|
|
141
|
-
if (!ReadAt(h, 0, &dos,
|
|
141
|
+
if (!ReadAt(h, 0, &dos, K_SIZE(dos)))
|
|
142
142
|
goto generic;
|
|
143
|
-
if (!ReadAt(h, dos.e_lfanew, &nt,
|
|
143
|
+
if (!ReadAt(h, dos.e_lfanew, &nt, K_SIZE(nt)))
|
|
144
144
|
goto generic;
|
|
145
145
|
|
|
146
146
|
if (dos.e_magic != 0x5A4D) // MZ
|
|
@@ -179,7 +179,7 @@ int GetSelfMachine()
|
|
|
179
179
|
LogError("Cannot open '%1': %2", filename, GetWin32ErrorString());
|
|
180
180
|
return -1;
|
|
181
181
|
}
|
|
182
|
-
|
|
182
|
+
K_DEFER { CloseHandle(h); };
|
|
183
183
|
|
|
184
184
|
return GetFileMachine(h, false);
|
|
185
185
|
}
|
|
@@ -193,7 +193,7 @@ int GetDllMachine(const wchar_t *filename)
|
|
|
193
193
|
LogError("Cannot open '%1': %2", filename, GetWin32ErrorString());
|
|
194
194
|
return -1;
|
|
195
195
|
}
|
|
196
|
-
|
|
196
|
+
K_DEFER { CloseHandle(h); };
|
|
197
197
|
|
|
198
198
|
return GetFileMachine(h, true);
|
|
199
199
|
}
|