koffi 2.16.1 → 3.0.0-alpha.2
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 +2 -2
- package/README.md +8 -8
- 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_ia32/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_ia32/koffi.node +0 -0
- package/build/koffi/win32_x64/koffi.node +0 -0
- package/doc/benchmarks.md +33 -33
- package/doc/benchmarks.xlsx +0 -0
- package/doc/contribute.md +37 -25
- package/doc/index.md +8 -8
- package/doc/variables.md +1 -1
- package/index.d.ts +11 -9
- package/index.js +1 -634
- package/indirect.js +1 -533
- package/lib/native/base/base.cc +63 -85
- package/lib/native/base/base.hh +178 -151
- package/package.json +3 -4
- package/src/build.js +1178 -0
- package/src/koffi/CMakeLists.txt +97 -34
- package/src/koffi/index.js +359 -0
- package/src/koffi/indirect.js +216 -0
- package/src/koffi/src/{abi_arm32.cc → abi/arm32.cc} +279 -275
- package/src/koffi/src/{abi_arm32_asm.S → abi/arm32_asm.S} +2 -5
- package/src/koffi/src/abi/arm64.cc +1511 -0
- package/src/koffi/src/{abi_arm64_asm.S → abi/arm64_asm.S} +44 -23
- package/src/koffi/src/{abi_arm64_asm.asm → abi/arm64_asm.asm} +32 -25
- package/src/koffi/src/{abi_loong64_asm.S → abi/loong64_asm.S} +1 -5
- package/src/koffi/src/{abi_riscv64.cc → abi/riscv64.cc} +279 -273
- package/src/koffi/src/{abi_riscv64_asm.S → abi/riscv64_asm.S} +1 -4
- package/src/koffi/src/abi/x64sysv.cc +1456 -0
- package/src/koffi/src/{abi_x64_sysv_asm.S → abi/x64sysv_asm.S} +30 -33
- package/src/koffi/src/abi/x64win.cc +1121 -0
- package/src/koffi/src/{abi_x64_win_asm.S → abi/x64win_asm.S} +8 -12
- package/src/koffi/src/{abi_x64_win_asm.asm → abi/x64win_asm.asm} +11 -14
- package/src/koffi/src/abi/x86.cc +1233 -0
- package/src/koffi/src/{abi_x86_asm.S → abi/x86_asm.S} +49 -25
- package/src/koffi/src/{abi_x86_asm.asm → abi/x86_asm.asm} +11 -14
- package/src/koffi/src/call.cc +458 -598
- package/src/koffi/src/call.hh +61 -82
- package/src/koffi/src/ffi.cc +595 -309
- package/src/koffi/src/ffi.hh +103 -89
- package/src/koffi/src/parser.cc +0 -4
- package/src/koffi/src/primitives.inc +39 -0
- package/src/koffi/{tools/write_trampolines.js → src/trampolines.js} +1 -1
- package/src/koffi/src/util.cc +503 -446
- package/src/koffi/src/util.hh +269 -57
- package/src/koffi/src/uv.cc +2 -2
- package/src/koffi/src/uv.def +3 -0
- package/src/koffi/src/win32.hh +30 -1
- package/vendor/node-addon-api/napi-inl.h +4 -0
- package/vendor/node-addon-api/napi.h +1 -0
- package/build/koffi/linux_armhf/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/win32_arm64/koffi.exp +0 -0
- package/build/koffi/win32_arm64/koffi.lib +0 -0
- package/build/koffi/win32_arm64/koffi.node +0 -0
- package/doc/platforms.md +0 -36
- package/src/cnoke/LICENSE.txt +0 -22
- package/src/cnoke/README.md +0 -99
- package/src/cnoke/assets/FindCNoke.cmake +0 -127
- package/src/cnoke/assets/toolchains.json +0 -126
- package/src/cnoke/assets/win_delay_hook.c +0 -36
- package/src/cnoke/cnoke.js +0 -170
- package/src/cnoke/package.json +0 -24
- package/src/cnoke/src/builder.js +0 -511
- package/src/cnoke/src/index.js +0 -10
- package/src/cnoke/src/tools.js +0 -407
- package/src/koffi/src/abi_arm64.cc +0 -1295
- package/src/koffi/src/abi_x64_sysv.cc +0 -939
- package/src/koffi/src/abi_x64_win.cc +0 -715
- package/src/koffi/src/abi_x86.cc +0 -860
- package/src/koffi/src/init.js +0 -105
- /package/src/koffi/src/{abi_loong64.cc → abi/loong64.cc} +0 -0
package/lib/native/base/base.hh
CHANGED
|
@@ -140,7 +140,7 @@ static_assert(sizeof(double) == 8, "This code base is not designed to support si
|
|
|
140
140
|
#define K_STRINGIFY(a) K_STRINGIFY_(a)
|
|
141
141
|
#define K_CONCAT_(a, b) a ## b
|
|
142
142
|
#define K_CONCAT(a, b) K_CONCAT_(a, b)
|
|
143
|
-
#define K_UNIQUE_NAME(prefix) K_CONCAT(prefix,
|
|
143
|
+
#define K_UNIQUE_NAME(prefix) K_CONCAT(prefix, __COUNTER__)
|
|
144
144
|
#define K_FORCE_EXPAND(x) x
|
|
145
145
|
#define K_IGNORE (void)!
|
|
146
146
|
|
|
@@ -564,19 +564,33 @@ class DeferGuard {
|
|
|
564
564
|
K_DELETE_COPY(DeferGuard)
|
|
565
565
|
|
|
566
566
|
Fun f;
|
|
567
|
-
bool enabled;
|
|
568
567
|
|
|
569
568
|
public:
|
|
570
569
|
DeferGuard() = delete;
|
|
571
|
-
DeferGuard(Fun f_
|
|
572
|
-
~DeferGuard()
|
|
570
|
+
DeferGuard(Fun f_) : f(std::move(f_)) {}
|
|
571
|
+
~DeferGuard() { f(); }
|
|
572
|
+
|
|
573
|
+
DeferGuard(DeferGuard &&other) : f(std::move(other.f)) {}
|
|
574
|
+
};
|
|
575
|
+
|
|
576
|
+
template <typename Fun>
|
|
577
|
+
class NamedDeferGuard {
|
|
578
|
+
K_DELETE_COPY(NamedDeferGuard)
|
|
579
|
+
|
|
580
|
+
Fun f;
|
|
581
|
+
bool enabled;
|
|
582
|
+
|
|
583
|
+
public:
|
|
584
|
+
NamedDeferGuard() = delete;
|
|
585
|
+
NamedDeferGuard(Fun f_, bool enable = true) : f(std::move(f_)), enabled(enable) {}
|
|
586
|
+
~NamedDeferGuard()
|
|
573
587
|
{
|
|
574
588
|
if (enabled) {
|
|
575
589
|
f();
|
|
576
590
|
}
|
|
577
591
|
}
|
|
578
592
|
|
|
579
|
-
|
|
593
|
+
NamedDeferGuard(NamedDeferGuard &&other)
|
|
580
594
|
: f(std::move(other.f)), enabled(other.enabled)
|
|
581
595
|
{
|
|
582
596
|
other.enabled = false;
|
|
@@ -593,6 +607,12 @@ DeferGuard<Fun> operator+(DeferGuardHelper, Fun &&f)
|
|
|
593
607
|
{
|
|
594
608
|
return DeferGuard<Fun>(std::forward<Fun>(f));
|
|
595
609
|
}
|
|
610
|
+
struct NamedDeferGuardHelper {};
|
|
611
|
+
template <typename Fun>
|
|
612
|
+
NamedDeferGuard<Fun> operator+(NamedDeferGuardHelper, Fun &&f)
|
|
613
|
+
{
|
|
614
|
+
return NamedDeferGuard<Fun>(std::forward<Fun>(f));
|
|
615
|
+
}
|
|
596
616
|
|
|
597
617
|
// Write 'DEFER { code };' to do something at the end of the current scope, you
|
|
598
618
|
// can use DEFER_N(Name) if you need to disable the guard for some reason, and
|
|
@@ -600,11 +620,11 @@ DeferGuard<Fun> operator+(DeferGuardHelper, Fun &&f)
|
|
|
600
620
|
#define K_DEFER \
|
|
601
621
|
auto K_UNIQUE_NAME(defer) = K::DeferGuardHelper() + [&]()
|
|
602
622
|
#define K_DEFER_N(Name) \
|
|
603
|
-
auto Name = K::
|
|
623
|
+
auto Name = K::NamedDeferGuardHelper() + [&]()
|
|
604
624
|
#define K_DEFER_C(...) \
|
|
605
625
|
auto K_UNIQUE_NAME(defer) = K::DeferGuardHelper() + [&, __VA_ARGS__]()
|
|
606
626
|
#define K_DEFER_NC(Name, ...) \
|
|
607
|
-
auto Name = K::
|
|
627
|
+
auto Name = K::NamedDeferGuardHelper() + [&, __VA_ARGS__]()
|
|
608
628
|
|
|
609
629
|
template <typename T>
|
|
610
630
|
class NoDestroy {
|
|
@@ -1069,11 +1089,6 @@ static constexpr inline Strider<T> MakeStrider(T (&arr)[N])
|
|
|
1069
1089
|
return Strider<T>(arr, K_SIZE(T));
|
|
1070
1090
|
}
|
|
1071
1091
|
|
|
1072
|
-
enum class AllocFlag {
|
|
1073
|
-
Zero = 1,
|
|
1074
|
-
Resizable = 2
|
|
1075
|
-
};
|
|
1076
|
-
|
|
1077
1092
|
class Allocator {
|
|
1078
1093
|
K_DELETE_COPY(Allocator)
|
|
1079
1094
|
|
|
@@ -1081,120 +1096,40 @@ public:
|
|
|
1081
1096
|
Allocator() = default;
|
|
1082
1097
|
virtual ~Allocator() = default;
|
|
1083
1098
|
|
|
1084
|
-
virtual void *Allocate(Size size
|
|
1085
|
-
virtual void *Resize(void *ptr, Size old_size, Size new_size
|
|
1099
|
+
virtual void *Allocate(Size size) = 0;
|
|
1100
|
+
virtual void *Resize(void *ptr, Size old_size, Size new_size) = 0;
|
|
1086
1101
|
virtual void Release(const void *ptr, Size size) = 0;
|
|
1087
1102
|
};
|
|
1088
1103
|
|
|
1089
|
-
Allocator
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
if (!alloc) {
|
|
1097
|
-
alloc = GetDefaultAllocator();
|
|
1098
|
-
}
|
|
1099
|
-
|
|
1100
|
-
void *ptr = alloc->Allocate(size, flags);
|
|
1101
|
-
return ptr;
|
|
1102
|
-
}
|
|
1103
|
-
|
|
1104
|
-
template <typename T>
|
|
1105
|
-
T *AllocateOne(Allocator *alloc, unsigned int flags = 0)
|
|
1106
|
-
{
|
|
1107
|
-
if (!alloc) {
|
|
1108
|
-
alloc = GetDefaultAllocator();
|
|
1109
|
-
}
|
|
1110
|
-
|
|
1111
|
-
Size size = K_SIZE(T);
|
|
1112
|
-
|
|
1113
|
-
T *ptr = (T *)alloc->Allocate(size, flags);
|
|
1114
|
-
return ptr;
|
|
1115
|
-
}
|
|
1116
|
-
|
|
1117
|
-
template <typename T>
|
|
1118
|
-
Span<T> AllocateSpan(Allocator *alloc, Size len, unsigned int flags = 0)
|
|
1119
|
-
{
|
|
1120
|
-
K_ASSERT(len >= 0);
|
|
1121
|
-
|
|
1122
|
-
if (!alloc) {
|
|
1123
|
-
alloc = GetDefaultAllocator();
|
|
1124
|
-
}
|
|
1125
|
-
|
|
1126
|
-
Size size = len * K_SIZE(T);
|
|
1127
|
-
|
|
1128
|
-
T *ptr = (T *)alloc->Allocate(size, flags);
|
|
1129
|
-
return MakeSpan(ptr, len);
|
|
1130
|
-
}
|
|
1131
|
-
|
|
1132
|
-
static inline void *ResizeRaw(Allocator *alloc, void *ptr, Size old_size, Size new_size,
|
|
1133
|
-
unsigned int flags = 0)
|
|
1134
|
-
{
|
|
1135
|
-
K_ASSERT(new_size >= 0);
|
|
1136
|
-
|
|
1137
|
-
if (!alloc) {
|
|
1138
|
-
alloc = GetDefaultAllocator();
|
|
1139
|
-
}
|
|
1140
|
-
|
|
1141
|
-
ptr = alloc->Resize(ptr, old_size, new_size, flags);
|
|
1142
|
-
return ptr;
|
|
1143
|
-
}
|
|
1144
|
-
|
|
1145
|
-
template <typename T>
|
|
1146
|
-
Span<T> ResizeSpan(Allocator *alloc, Span<T> mem, Size new_len,
|
|
1147
|
-
unsigned int flags = 0)
|
|
1148
|
-
{
|
|
1149
|
-
K_ASSERT(new_len >= 0);
|
|
1150
|
-
|
|
1151
|
-
if (!alloc) {
|
|
1152
|
-
alloc = GetDefaultAllocator();
|
|
1153
|
-
}
|
|
1154
|
-
|
|
1155
|
-
Size old_size = mem.len * K_SIZE(T);
|
|
1156
|
-
Size new_size = new_len * K_SIZE(T);
|
|
1157
|
-
|
|
1158
|
-
mem.ptr = (T *)alloc->Resize(mem.ptr, old_size, new_size, flags);
|
|
1159
|
-
return MakeSpan(mem.ptr, new_len);
|
|
1160
|
-
}
|
|
1161
|
-
|
|
1162
|
-
static inline void ReleaseRaw(Allocator *alloc, const void *ptr, Size size)
|
|
1163
|
-
{
|
|
1164
|
-
if (!alloc) {
|
|
1165
|
-
alloc = GetDefaultAllocator();
|
|
1166
|
-
}
|
|
1167
|
-
|
|
1168
|
-
alloc->Release(ptr, size);
|
|
1169
|
-
}
|
|
1170
|
-
|
|
1171
|
-
template<typename T>
|
|
1172
|
-
void ReleaseOne(Allocator *alloc, T *ptr)
|
|
1173
|
-
{
|
|
1174
|
-
if (!alloc) {
|
|
1175
|
-
alloc = GetDefaultAllocator();
|
|
1176
|
-
}
|
|
1177
|
-
|
|
1178
|
-
alloc->Release((void *)ptr, K_SIZE(T));
|
|
1179
|
-
}
|
|
1104
|
+
class MallocAllocator final: public Allocator {
|
|
1105
|
+
public:
|
|
1106
|
+
void *Allocate(Size size) override;
|
|
1107
|
+
void *Resize(void *ptr, Size old_size, Size new_size) override;
|
|
1108
|
+
void Release(const void *ptr, Size) override;
|
|
1109
|
+
};
|
|
1180
1110
|
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
{
|
|
1184
|
-
|
|
1185
|
-
alloc = GetDefaultAllocator();
|
|
1186
|
-
}
|
|
1111
|
+
class NullAllocator: public Allocator {
|
|
1112
|
+
public:
|
|
1113
|
+
void *Allocate(Size) override { K_UNREACHABLE(); }
|
|
1114
|
+
void *Resize(void *, Size, Size) override { K_UNREACHABLE(); }
|
|
1187
1115
|
|
|
1188
|
-
|
|
1116
|
+
// This is the only useful method, switch to the null allocator (call GetNullAllocator())
|
|
1117
|
+
// when you want to keep container memory around when it is destroyed. This can be used
|
|
1118
|
+
// to leak HeapArray memory without resetting it, for example.
|
|
1119
|
+
void Release(const void *, Size) override {}
|
|
1120
|
+
};
|
|
1189
1121
|
|
|
1190
|
-
|
|
1191
|
-
|
|
1122
|
+
K_DEFAULT_ALLOCATOR *GetDefaultAllocator();
|
|
1123
|
+
Allocator *GetNullAllocator();
|
|
1192
1124
|
|
|
1193
1125
|
class LinkedAllocator final: public Allocator {
|
|
1194
1126
|
struct Bucket {
|
|
1127
|
+
#if defined(K_DEBUG)
|
|
1128
|
+
Size size;
|
|
1129
|
+
#endif
|
|
1195
1130
|
Bucket *prev;
|
|
1196
1131
|
Bucket *next;
|
|
1197
|
-
uint8_t data[];
|
|
1132
|
+
alignas(16) uint8_t data[];
|
|
1198
1133
|
};
|
|
1199
1134
|
|
|
1200
1135
|
Allocator *allocator;
|
|
@@ -1202,7 +1137,7 @@ class LinkedAllocator final: public Allocator {
|
|
|
1202
1137
|
Bucket *list = nullptr;
|
|
1203
1138
|
|
|
1204
1139
|
public:
|
|
1205
|
-
LinkedAllocator(Allocator *alloc = nullptr) : allocator(alloc) {}
|
|
1140
|
+
LinkedAllocator(Allocator *alloc = nullptr) : allocator(alloc ? alloc : GetDefaultAllocator()) {}
|
|
1206
1141
|
~LinkedAllocator() override { ReleaseAll(); }
|
|
1207
1142
|
|
|
1208
1143
|
LinkedAllocator(LinkedAllocator &&other) { *this = std::move(other); }
|
|
@@ -1211,8 +1146,8 @@ public:
|
|
|
1211
1146
|
void ReleaseAll();
|
|
1212
1147
|
void ReleaseAllExcept(void *ptr);
|
|
1213
1148
|
|
|
1214
|
-
void *Allocate(Size size
|
|
1215
|
-
void *Resize(void *ptr, Size old_size, Size new_size
|
|
1149
|
+
void *Allocate(Size size) override;
|
|
1150
|
+
void *Resize(void *ptr, Size old_size, Size new_size) override;
|
|
1216
1151
|
void Release(const void *ptr, Size size) override;
|
|
1217
1152
|
|
|
1218
1153
|
bool IsUsed() const { return list; }
|
|
@@ -1223,7 +1158,7 @@ private:
|
|
|
1223
1158
|
static Bucket *PointerToBucket(void *ptr);
|
|
1224
1159
|
};
|
|
1225
1160
|
|
|
1226
|
-
class BlockAllocator: public Allocator {
|
|
1161
|
+
class BlockAllocator final: public Allocator {
|
|
1227
1162
|
struct Bucket {
|
|
1228
1163
|
Size used;
|
|
1229
1164
|
uint8_t data[];
|
|
@@ -1236,11 +1171,13 @@ class BlockAllocator: public Allocator {
|
|
|
1236
1171
|
uint8_t *last_alloc = nullptr;
|
|
1237
1172
|
|
|
1238
1173
|
public:
|
|
1239
|
-
BlockAllocator(Size block_size = K_BLOCK_ALLOCATOR_DEFAULT_SIZE)
|
|
1240
|
-
: block_size(block_size)
|
|
1174
|
+
BlockAllocator(Allocator *alloc, Size block_size = K_BLOCK_ALLOCATOR_DEFAULT_SIZE)
|
|
1175
|
+
: allocator(alloc), block_size(block_size)
|
|
1241
1176
|
{
|
|
1242
1177
|
K_ASSERT(block_size > 0);
|
|
1243
1178
|
}
|
|
1179
|
+
BlockAllocator(Size block_size = K_BLOCK_ALLOCATOR_DEFAULT_SIZE)
|
|
1180
|
+
: BlockAllocator(nullptr, block_size) {}
|
|
1244
1181
|
|
|
1245
1182
|
BlockAllocator(BlockAllocator &&other) { *this = std::move(other); }
|
|
1246
1183
|
BlockAllocator& operator=(BlockAllocator &&other);
|
|
@@ -1248,8 +1185,8 @@ public:
|
|
|
1248
1185
|
void Reset();
|
|
1249
1186
|
void ReleaseAll();
|
|
1250
1187
|
|
|
1251
|
-
void *Allocate(Size size
|
|
1252
|
-
void *Resize(void *ptr, Size old_size, Size new_size
|
|
1188
|
+
void *Allocate(Size size) override;
|
|
1189
|
+
void *Resize(void *ptr, Size old_size, Size new_size) override;
|
|
1253
1190
|
void Release(const void *ptr, Size size) override;
|
|
1254
1191
|
|
|
1255
1192
|
bool IsUsed() const { return allocator.IsUsed(); }
|
|
@@ -1261,6 +1198,92 @@ private:
|
|
|
1261
1198
|
bool AllocateSeparately(Size aligned_size) const { return aligned_size > block_size / 2; }
|
|
1262
1199
|
};
|
|
1263
1200
|
|
|
1201
|
+
static inline void *AllocateRaw(Allocator *alloc, Size size)
|
|
1202
|
+
{
|
|
1203
|
+
K_ASSERT(size >= 0);
|
|
1204
|
+
|
|
1205
|
+
alloc = alloc ? alloc : GetDefaultAllocator();
|
|
1206
|
+
|
|
1207
|
+
void *ptr = alloc->Allocate(size);
|
|
1208
|
+
|
|
1209
|
+
return ptr;
|
|
1210
|
+
}
|
|
1211
|
+
|
|
1212
|
+
template <typename T>
|
|
1213
|
+
T *AllocateOne(Allocator *alloc)
|
|
1214
|
+
{
|
|
1215
|
+
alloc = alloc ? alloc : GetDefaultAllocator();
|
|
1216
|
+
|
|
1217
|
+
Size size = K_SIZE(T);
|
|
1218
|
+
T *ptr = (T *)alloc->Allocate(size);
|
|
1219
|
+
|
|
1220
|
+
return ptr;
|
|
1221
|
+
}
|
|
1222
|
+
|
|
1223
|
+
template <typename T>
|
|
1224
|
+
Span<T> AllocateSpan(Allocator *alloc, Size len)
|
|
1225
|
+
{
|
|
1226
|
+
K_ASSERT(len >= 0);
|
|
1227
|
+
K_ASSERT(len <= K_SIZE_MAX / K_SIZE(T));
|
|
1228
|
+
|
|
1229
|
+
alloc = alloc ? alloc : GetDefaultAllocator();
|
|
1230
|
+
|
|
1231
|
+
Size size = len * K_SIZE(T);
|
|
1232
|
+
T *ptr = (T *)alloc->Allocate(size);
|
|
1233
|
+
|
|
1234
|
+
return MakeSpan(ptr, len);
|
|
1235
|
+
}
|
|
1236
|
+
|
|
1237
|
+
static inline void *ResizeRaw(Allocator *alloc, void *ptr, Size old_size, Size new_size)
|
|
1238
|
+
{
|
|
1239
|
+
K_ASSERT(new_size >= 0);
|
|
1240
|
+
|
|
1241
|
+
alloc = alloc ? alloc : GetDefaultAllocator();
|
|
1242
|
+
|
|
1243
|
+
ptr = alloc->Resize(ptr, old_size, new_size);
|
|
1244
|
+
|
|
1245
|
+
return ptr;
|
|
1246
|
+
}
|
|
1247
|
+
|
|
1248
|
+
template <typename T>
|
|
1249
|
+
Span<T> ResizeSpan(Allocator *alloc, Span<T> mem, Size new_len)
|
|
1250
|
+
{
|
|
1251
|
+
K_ASSERT(new_len >= 0);
|
|
1252
|
+
K_ASSERT(new_len <= K_SIZE_MAX / K_SIZE(T));
|
|
1253
|
+
|
|
1254
|
+
alloc = alloc ? alloc : GetDefaultAllocator();
|
|
1255
|
+
|
|
1256
|
+
Size old_size = mem.len * K_SIZE(T);
|
|
1257
|
+
Size new_size = new_len * K_SIZE(T);
|
|
1258
|
+
|
|
1259
|
+
mem.ptr = (T *)alloc->Resize(mem.ptr, old_size, new_size);
|
|
1260
|
+
|
|
1261
|
+
return MakeSpan(mem.ptr, new_len);
|
|
1262
|
+
}
|
|
1263
|
+
|
|
1264
|
+
static inline void ReleaseRaw(Allocator *alloc, const void *ptr, Size size)
|
|
1265
|
+
{
|
|
1266
|
+
alloc = alloc ? alloc : GetDefaultAllocator();
|
|
1267
|
+
alloc->Release(ptr, size);
|
|
1268
|
+
}
|
|
1269
|
+
|
|
1270
|
+
template<typename T>
|
|
1271
|
+
void ReleaseOne(Allocator *alloc, T *ptr)
|
|
1272
|
+
{
|
|
1273
|
+
alloc = alloc ? alloc : GetDefaultAllocator();
|
|
1274
|
+
alloc->Release((void *)ptr, K_SIZE(T));
|
|
1275
|
+
}
|
|
1276
|
+
|
|
1277
|
+
template<typename T>
|
|
1278
|
+
void ReleaseSpan(Allocator *alloc, Span<T> mem)
|
|
1279
|
+
{
|
|
1280
|
+
alloc = alloc ? alloc : GetDefaultAllocator();
|
|
1281
|
+
|
|
1282
|
+
Size size = mem.len * K_SIZE(T);
|
|
1283
|
+
|
|
1284
|
+
alloc->Release((void *)mem.ptr, size);
|
|
1285
|
+
}
|
|
1286
|
+
|
|
1264
1287
|
void *AllocateSafe(Size len);
|
|
1265
1288
|
void ReleaseSafe(void *ptr, Size len);
|
|
1266
1289
|
void ZeroSafe(void *ptr, Size len);
|
|
@@ -2987,14 +3010,16 @@ private:
|
|
|
2987
3010
|
Size old_capacity = capacity;
|
|
2988
3011
|
|
|
2989
3012
|
if (new_capacity) {
|
|
2990
|
-
|
|
2991
|
-
|
|
2992
|
-
|
|
3013
|
+
Size used_size = (new_capacity + (K_SIZE(size_t) * 8) - 1) / K_SIZE(size_t);
|
|
3014
|
+
|
|
3015
|
+
used = (size_t *)AllocateRaw(allocator, used_size);
|
|
2993
3016
|
data = (ValueType *)AllocateRaw(allocator, new_capacity * K_SIZE(ValueType));
|
|
3017
|
+
capacity = new_capacity;
|
|
3018
|
+
|
|
2994
3019
|
for (Size i = 0; i < new_capacity; i++) {
|
|
2995
3020
|
new (&data[i]) ValueType();
|
|
2996
3021
|
}
|
|
2997
|
-
|
|
3022
|
+
MemSet(used, 0, used_size);
|
|
2998
3023
|
|
|
2999
3024
|
for (Size i = 0; i < old_capacity; i++) {
|
|
3000
3025
|
if (!IsEmpty(old_used, i)) {
|
|
@@ -4721,34 +4746,34 @@ public:
|
|
|
4721
4746
|
virtual void Run() = 0;
|
|
4722
4747
|
};
|
|
4723
4748
|
|
|
4724
|
-
#define K_INIT_(
|
|
4725
|
-
class
|
|
4749
|
+
#define K_INIT_(Cls, Name) \
|
|
4750
|
+
class Cls: public InitHelper { \
|
|
4726
4751
|
public: \
|
|
4727
|
-
|
|
4752
|
+
Cls(): InitHelper(Name) {} \
|
|
4728
4753
|
void Run() override; \
|
|
4729
4754
|
}; \
|
|
4730
|
-
static
|
|
4731
|
-
void
|
|
4732
|
-
#define K_INIT(Name) K_INIT_(
|
|
4755
|
+
static Cls K_UNIQUE_NAME(init); \
|
|
4756
|
+
void Cls::Run()
|
|
4757
|
+
#define K_INIT(Name) K_INIT_(InitHelper ## Name, K_STRINGIFY(Name))
|
|
4733
4758
|
|
|
4734
|
-
#define K_FINALIZE_(
|
|
4735
|
-
class
|
|
4759
|
+
#define K_FINALIZE_(Cls, Name) \
|
|
4760
|
+
class Cls: public FinalizeHelper { \
|
|
4736
4761
|
public: \
|
|
4737
|
-
|
|
4762
|
+
Cls(): FinalizeHelper(Name) {} \
|
|
4738
4763
|
void Run() override; \
|
|
4739
4764
|
}; \
|
|
4740
|
-
static
|
|
4741
|
-
void
|
|
4742
|
-
#define K_FINALIZE(Name) K_FINALIZE_(
|
|
4765
|
+
static Cls K_UNIQUE_NAME(finalize); \
|
|
4766
|
+
void Cls::Run()
|
|
4767
|
+
#define K_FINALIZE(Name) K_FINALIZE_(FinalizeHelper ## Name, K_STRINGIFY(Name))
|
|
4743
4768
|
|
|
4744
|
-
#define K_EXIT_(
|
|
4745
|
-
class
|
|
4769
|
+
#define K_EXIT_(Cls) \
|
|
4770
|
+
class Cls { \
|
|
4746
4771
|
public: \
|
|
4747
|
-
~
|
|
4772
|
+
~Cls(); \
|
|
4748
4773
|
}; \
|
|
4749
|
-
static
|
|
4750
|
-
|
|
4751
|
-
#define K_EXIT(Name) K_EXIT_(
|
|
4774
|
+
static Cls K_UNIQUE_NAME(exit); \
|
|
4775
|
+
Cls::~Cls()
|
|
4776
|
+
#define K_EXIT(Name) K_EXIT_(ExitHelper ## Name)
|
|
4752
4777
|
|
|
4753
4778
|
void InitApp();
|
|
4754
4779
|
void ExitApp();
|
|
@@ -5207,13 +5232,14 @@ public:
|
|
|
5207
5232
|
StreamDecompressorHelper(CompressionType type, CreateDecompressorFunc *func);
|
|
5208
5233
|
};
|
|
5209
5234
|
|
|
5210
|
-
#define
|
|
5211
|
-
static StreamDecoder *
|
|
5235
|
+
#define K_REGISTER_DECOMPRESSOR_(Func, Type, Cls) \
|
|
5236
|
+
static StreamDecoder *Func(StreamReader *reader, CompressionType type) \
|
|
5212
5237
|
{ \
|
|
5213
5238
|
StreamDecoder *decompressor = new Cls(reader, type); \
|
|
5214
5239
|
return decompressor; \
|
|
5215
5240
|
} \
|
|
5216
|
-
static StreamDecompressorHelper K_UNIQUE_NAME(
|
|
5241
|
+
static StreamDecompressorHelper K_UNIQUE_NAME(decompressor_helper)((Type), Func)
|
|
5242
|
+
#define K_REGISTER_DECOMPRESSOR(Type, Cls) K_REGISTER_DECOMPRESSOR_(K_UNIQUE_NAME(CreateDecompressor), (Type), (Cls))
|
|
5217
5243
|
|
|
5218
5244
|
class LineReader {
|
|
5219
5245
|
K_DELETE_COPY(LineReader)
|
|
@@ -5419,13 +5445,14 @@ public:
|
|
|
5419
5445
|
StreamCompressorHelper(CompressionType type, CreateCompressorFunc *func);
|
|
5420
5446
|
};
|
|
5421
5447
|
|
|
5422
|
-
#define
|
|
5423
|
-
static StreamEncoder *
|
|
5448
|
+
#define K_REGISTER_COMPRESSOR_(Func, Type, Cls) \
|
|
5449
|
+
static StreamEncoder *Func(StreamWriter *writer, CompressionType type, CompressionSpeed speed) \
|
|
5424
5450
|
{ \
|
|
5425
5451
|
StreamEncoder *compressor = new Cls(writer, type, speed); \
|
|
5426
5452
|
return compressor; \
|
|
5427
5453
|
} \
|
|
5428
|
-
static StreamCompressorHelper K_UNIQUE_NAME(
|
|
5454
|
+
static StreamCompressorHelper K_UNIQUE_NAME(compressor_helper)((Type), Func)
|
|
5455
|
+
#define K_REGISTER_COMPRESSOR(Type, Cls) K_REGISTER_COMPRESSOR_(K_UNIQUE_NAME(CreateCompressor), (Type), (Cls))
|
|
5429
5456
|
|
|
5430
5457
|
bool SpliceStream(StreamReader *reader, int64_t max_len, StreamWriter *writer, Span<uint8_t> buf,
|
|
5431
5458
|
FunctionRef<void(int64_t, int64_t)> progress = [](int64_t, int64_t) {});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "koffi",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0-alpha.2",
|
|
4
4
|
"description": "Fast and simple C FFI (foreign function interface) for Node.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"foreign",
|
|
@@ -24,15 +24,14 @@
|
|
|
24
24
|
"main": "./index.js",
|
|
25
25
|
"types": "./index.d.ts",
|
|
26
26
|
"scripts": {
|
|
27
|
-
"install": "node src/
|
|
27
|
+
"install": "node src/build.js -P . -D src/koffi --prebuild --release"
|
|
28
28
|
},
|
|
29
29
|
"license": "MIT",
|
|
30
30
|
"cnoke": {
|
|
31
31
|
"api": "../../vendor/node-api-headers",
|
|
32
32
|
"output": "build/koffi/{{ toolchain }}",
|
|
33
33
|
"node": 16,
|
|
34
|
-
"napi": 8
|
|
35
|
-
"require": "./index.js"
|
|
34
|
+
"napi": 8
|
|
36
35
|
},
|
|
37
36
|
"funding": "https://liberapay.com/Koromix"
|
|
38
37
|
}
|