koffi 2.14.0 → 2.15.0
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 +26 -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/assets.ini +2 -1
- package/doc/build.sh +9 -0
- package/doc/pages/404.md +17 -0
- package/doc/pages/index.md +43 -4
- package/doc/pages/misc.md +16 -11
- package/doc/pages/platforms.md +8 -19
- package/doc/pages.ini +4 -7
- package/doc/static/highlight.js +2 -14
- package/doc/static/koffi.css +3 -15
- package/doc/static/perf_windows.png +0 -0
- package/doc/static/print.css +2 -14
- package/index.d.ts +29 -24
- package/index.js +10 -9
- package/indirect.js +10 -9
- package/{src/core → lib/native}/base/base.cc +1753 -1089
- package/{src/core → lib/native}/base/base.hh +868 -572
- package/{src/core → lib/native}/base/crc.inc +3 -21
- package/lib/native/base/crc_gen.py +72 -0
- package/{src/core → lib/native}/base/mimetypes.inc +2 -20
- package/{src/core → lib/native}/base/mimetypes_gen.py +2 -21
- package/lib/native/base/tower.cc +821 -0
- package/lib/native/base/tower.hh +81 -0
- package/{src/core → lib/native}/base/unicode.inc +3 -21
- package/{src/core → lib/native}/base/unicode_gen.py +5 -42
- package/package.json +3 -2
- package/src/cnoke/assets/FindCNoke.cmake +8 -20
- package/src/cnoke/assets/win_delay_hook.c +2 -20
- package/src/cnoke/cnoke.js +2 -21
- package/src/cnoke/src/builder.js +3 -22
- package/src/cnoke/src/index.js +2 -20
- package/src/cnoke/src/tools.js +2 -20
- package/src/koffi/CMakeLists.txt +19 -22
- package/src/koffi/cmake/raylib.cmake +5 -22
- package/src/koffi/cmake/sqlite3.cmake +2 -20
- package/src/koffi/src/abi_arm32.cc +31 -49
- package/src/koffi/src/abi_arm32_asm.S +2 -20
- package/src/koffi/src/abi_arm64.cc +36 -54
- package/src/koffi/src/abi_arm64_asm.S +2 -20
- package/src/koffi/src/abi_arm64_asm.asm +2 -20
- package/src/koffi/src/abi_loong64.cc +2 -20
- package/src/koffi/src/abi_loong64_asm.S +2 -20
- package/src/koffi/src/abi_riscv64.cc +34 -52
- package/src/koffi/src/abi_riscv64_asm.S +2 -20
- package/src/koffi/src/abi_x64_sysv.cc +36 -54
- package/src/koffi/src/abi_x64_sysv_asm.S +2 -20
- package/src/koffi/src/abi_x64_win.cc +32 -50
- package/src/koffi/src/abi_x64_win_asm.asm +2 -20
- package/src/koffi/src/abi_x86.cc +33 -51
- package/src/koffi/src/abi_x86_asm.S +2 -20
- package/src/koffi/src/abi_x86_asm.asm +2 -20
- package/src/koffi/src/call.cc +107 -281
- package/src/koffi/src/call.hh +9 -27
- package/src/koffi/src/errno.inc +2 -20
- package/src/koffi/src/ffi.cc +121 -121
- package/src/koffi/src/ffi.hh +23 -38
- package/src/koffi/src/init.js +2 -20
- package/src/koffi/src/parser.cc +15 -29
- package/src/koffi/src/parser.hh +4 -22
- package/src/koffi/src/trampolines/armasm.inc +0 -21
- package/src/koffi/src/trampolines/gnu.inc +0 -21
- package/src/koffi/src/trampolines/masm32.inc +0 -21
- package/src/koffi/src/trampolines/masm64.inc +0 -21
- package/src/koffi/src/trampolines/prototypes.inc +1 -22
- package/src/koffi/src/util.cc +87 -102
- package/src/koffi/src/util.hh +11 -29
- package/src/koffi/src/uv.cc +193 -0
- package/src/koffi/src/uv.def +10 -0
- package/src/koffi/src/uv.hh +40 -0
- package/src/koffi/src/win32.cc +7 -25
- package/src/koffi/src/win32.hh +4 -22
- package/vendor/node-api-headers/include/uv/aix.h +32 -0
- package/vendor/node-api-headers/include/uv/bsd.h +34 -0
- package/vendor/node-api-headers/include/uv/darwin.h +61 -0
- package/vendor/node-api-headers/include/uv/errno.h +483 -0
- package/vendor/node-api-headers/include/uv/linux.h +34 -0
- package/vendor/node-api-headers/include/uv/os390.h +33 -0
- package/vendor/node-api-headers/include/uv/posix.h +31 -0
- package/vendor/node-api-headers/include/uv/sunos.h +44 -0
- package/vendor/node-api-headers/include/uv/threadpool.h +37 -0
- package/vendor/node-api-headers/include/uv/tree.h +521 -0
- package/vendor/node-api-headers/include/uv/unix.h +512 -0
- package/vendor/node-api-headers/include/uv/version.h +43 -0
- package/vendor/node-api-headers/include/uv/win.h +698 -0
- package/vendor/node-api-headers/include/uv.h +1990 -0
- package/src/core/base/crc_gen.py +0 -109
package/src/koffi/src/ffi.cc
CHANGED
|
@@ -1,29 +1,12 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
// the Software without restriction, including without limitation the rights to use,
|
|
6
|
-
// copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
|
|
7
|
-
// Software, and to permit persons to whom the Software is furnished to do so,
|
|
8
|
-
// subject to the following conditions:
|
|
9
|
-
//
|
|
10
|
-
// The above copyright notice and this permission notice shall be included in all
|
|
11
|
-
// copies or substantial portions of the Software.
|
|
12
|
-
//
|
|
13
|
-
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
|
|
14
|
-
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
15
|
-
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
16
|
-
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
17
|
-
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
18
|
-
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
19
|
-
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
20
|
-
// OTHER DEALINGS IN THE SOFTWARE.
|
|
21
|
-
|
|
22
|
-
#include "src/core/base/base.hh"
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
// SPDX-FileCopyrightText: 2025 Niels Martignène <niels.martignene@protonmail.com>
|
|
3
|
+
|
|
4
|
+
#include "lib/native/base/base.hh"
|
|
23
5
|
#include "ffi.hh"
|
|
24
6
|
#include "call.hh"
|
|
25
7
|
#include "parser.hh"
|
|
26
8
|
#include "util.hh"
|
|
9
|
+
#include "uv.hh"
|
|
27
10
|
#if defined(_WIN32)
|
|
28
11
|
#include "win32.hh"
|
|
29
12
|
#endif
|
|
@@ -50,7 +33,7 @@
|
|
|
50
33
|
|
|
51
34
|
#include <napi.h>
|
|
52
35
|
|
|
53
|
-
namespace
|
|
36
|
+
namespace K {
|
|
54
37
|
|
|
55
38
|
SharedData shared;
|
|
56
39
|
|
|
@@ -147,7 +130,7 @@ static Napi::Value GetSetConfig(const Napi::CallbackInfo &info)
|
|
|
147
130
|
if (!ChangeMemorySize(key.c_str(), value, &new_config.async_heap_size))
|
|
148
131
|
return env.Null();
|
|
149
132
|
} else if (key == "resident_async_pools") {
|
|
150
|
-
if (!ChangeAsyncLimit(key.c_str(), value,
|
|
133
|
+
if (!ChangeAsyncLimit(key.c_str(), value, K_LEN(instance->memories.data) - 1, &new_config.resident_async_pools))
|
|
151
134
|
return env.Null();
|
|
152
135
|
} else if (key == "max_async_calls") {
|
|
153
136
|
if (!ChangeAsyncLimit(key.c_str(), value, MaxAsyncCalls, &max_async_calls))
|
|
@@ -222,7 +205,7 @@ static bool MapType(Napi::Env env, InstanceData *instance, const TypeInfo *type,
|
|
|
222
205
|
}
|
|
223
206
|
|
|
224
207
|
bool inserted;
|
|
225
|
-
instance->types_map.
|
|
208
|
+
instance->types_map.InsertOrGet(name, type, &inserted);
|
|
226
209
|
|
|
227
210
|
if (!inserted) {
|
|
228
211
|
ThrowError<Napi::Error>(env, "Duplicate type name '%1'", name);
|
|
@@ -244,7 +227,7 @@ static Napi::Value CreateStructType(const Napi::CallbackInfo &info, bool pad)
|
|
|
244
227
|
|
|
245
228
|
bool skip = (info.Length() > 1);
|
|
246
229
|
bool named = skip && !IsNullOrUndefined(info[0]);
|
|
247
|
-
bool redefine = named && CheckValueTag(
|
|
230
|
+
bool redefine = named && CheckValueTag(info[0], &TypeInfoMarker);
|
|
248
231
|
|
|
249
232
|
if (named && !info[0].IsString() && !redefine) {
|
|
250
233
|
ThrowError<Napi::TypeError>(env, "Unexpected %1 value for name, expected string", GetValueType(instance, info[0]));
|
|
@@ -259,7 +242,7 @@ static Napi::Value CreateStructType(const Napi::CallbackInfo &info, bool pad)
|
|
|
259
242
|
Napi::Object obj = info[skip].As<Napi::Object>();
|
|
260
243
|
Napi::Array keys = GetOwnPropertyNames(obj);
|
|
261
244
|
|
|
262
|
-
|
|
245
|
+
K_DEFER_NC(err_guard, count = instance->types.count) {
|
|
263
246
|
Size start = count + !skip;
|
|
264
247
|
|
|
265
248
|
for (Size i = start; i < instance->types.count; i++) {
|
|
@@ -364,7 +347,7 @@ static Napi::Value CreateStructType(const Napi::CallbackInfo &info, bool pad)
|
|
|
364
347
|
}
|
|
365
348
|
|
|
366
349
|
bool inserted;
|
|
367
|
-
members.
|
|
350
|
+
members.InsertOrGet(member.name, &inserted);
|
|
368
351
|
|
|
369
352
|
if (!inserted) {
|
|
370
353
|
ThrowError<Napi::Error>(env, "Duplicate member '%1' in struct '%2'", member.name, type->name);
|
|
@@ -414,7 +397,7 @@ static Napi::Value CreateStructType(const Napi::CallbackInfo &info, bool pad)
|
|
|
414
397
|
type = replace;
|
|
415
398
|
}
|
|
416
399
|
|
|
417
|
-
return WrapType(env,
|
|
400
|
+
return WrapType(env, type);
|
|
418
401
|
}
|
|
419
402
|
|
|
420
403
|
static Napi::Value CreatePaddedStructType(const Napi::CallbackInfo &info)
|
|
@@ -439,7 +422,7 @@ static Napi::Value CreateUnionType(const Napi::CallbackInfo &info)
|
|
|
439
422
|
|
|
440
423
|
bool skip = (info.Length() > 1);
|
|
441
424
|
bool named = skip && !IsNullOrUndefined(info[0]);
|
|
442
|
-
bool redefine = named && CheckValueTag(
|
|
425
|
+
bool redefine = named && CheckValueTag(info[0], &TypeInfoMarker);
|
|
443
426
|
|
|
444
427
|
if (named && !info[0].IsString() && !redefine) {
|
|
445
428
|
ThrowError<Napi::TypeError>(env, "Unexpected %1 value for name, expected string", GetValueType(instance, info[0]));
|
|
@@ -454,7 +437,7 @@ static Napi::Value CreateUnionType(const Napi::CallbackInfo &info)
|
|
|
454
437
|
Napi::Object obj = info[skip].As<Napi::Object>();
|
|
455
438
|
Napi::Array keys = GetOwnPropertyNames(obj);
|
|
456
439
|
|
|
457
|
-
|
|
440
|
+
K_DEFER_NC(err_guard, count = instance->types.count) {
|
|
458
441
|
Size start = count + !skip;
|
|
459
442
|
|
|
460
443
|
for (Size i = start; i < instance->types.count; i++) {
|
|
@@ -554,7 +537,7 @@ static Napi::Value CreateUnionType(const Napi::CallbackInfo &info)
|
|
|
554
537
|
}
|
|
555
538
|
|
|
556
539
|
bool inserted;
|
|
557
|
-
members.
|
|
540
|
+
members.InsertOrGet(member.name, &inserted);
|
|
558
541
|
|
|
559
542
|
if (!inserted) {
|
|
560
543
|
ThrowError<Napi::Error>(env, "Duplicate member '%1' in union '%2'", member.name, type->name);
|
|
@@ -583,13 +566,12 @@ static Napi::Value CreateUnionType(const Napi::CallbackInfo &info)
|
|
|
583
566
|
type = replace;
|
|
584
567
|
}
|
|
585
568
|
|
|
586
|
-
return WrapType(env,
|
|
569
|
+
return WrapType(env, type);
|
|
587
570
|
}
|
|
588
571
|
|
|
589
572
|
Napi::Value InstantiateUnion(const Napi::CallbackInfo &info)
|
|
590
573
|
{
|
|
591
574
|
Napi::Env env = info.Env();
|
|
592
|
-
InstanceData *instance = env.GetInstanceData<InstanceData>();
|
|
593
575
|
|
|
594
576
|
if (!info.IsConstructCall()) {
|
|
595
577
|
ThrowError<Napi::TypeError>(env, "This function is a constructor and must be called with new");
|
|
@@ -609,7 +591,7 @@ Napi::Value InstantiateUnion(const Napi::CallbackInfo &info)
|
|
|
609
591
|
}
|
|
610
592
|
|
|
611
593
|
Napi::Object wrapper = type->construct.New({}).As<Napi::Object>();
|
|
612
|
-
SetValueTag(
|
|
594
|
+
SetValueTag(wrapper, &MagicUnionMarker);
|
|
613
595
|
|
|
614
596
|
return wrapper;
|
|
615
597
|
}
|
|
@@ -626,10 +608,10 @@ static Napi::Value CreateOpaqueType(const Napi::CallbackInfo &info)
|
|
|
626
608
|
return env.Null();
|
|
627
609
|
}
|
|
628
610
|
|
|
629
|
-
Napi::String name = info[0].As<Napi::String>();
|
|
611
|
+
Napi::String name = info[0].As<Napi::String>();
|
|
630
612
|
|
|
631
613
|
TypeInfo *type = instance->types.AppendDefault();
|
|
632
|
-
|
|
614
|
+
K_DEFER_N(err_guard) { instance->types.RemoveLast(1); };
|
|
633
615
|
|
|
634
616
|
type->name = named ? DuplicateString(name.Utf8Value().c_str(), &instance->str_alloc).ptr
|
|
635
617
|
: Fmt(&instance->str_alloc, "<anonymous_%1>", instance->types.count).ptr;
|
|
@@ -643,7 +625,7 @@ static Napi::Value CreateOpaqueType(const Napi::CallbackInfo &info)
|
|
|
643
625
|
return env.Null();
|
|
644
626
|
err_guard.Disable();
|
|
645
627
|
|
|
646
|
-
return WrapType(env,
|
|
628
|
+
return WrapType(env, type);
|
|
647
629
|
}
|
|
648
630
|
|
|
649
631
|
static Napi::Value CreatePointerType(const Napi::CallbackInfo &info)
|
|
@@ -690,13 +672,13 @@ static Napi::Value CreatePointerType(const Napi::CallbackInfo &info)
|
|
|
690
672
|
}
|
|
691
673
|
|
|
692
674
|
TypeInfo *type = MakePointerType(instance, ref, count);
|
|
693
|
-
|
|
675
|
+
K_ASSERT(type);
|
|
694
676
|
|
|
695
677
|
if (named || !countedby.IsEmpty()) {
|
|
696
678
|
TypeInfo *copy = instance->types.AppendDefault();
|
|
697
|
-
|
|
679
|
+
K_DEFER_N(err_guard) { instance->types.RemoveLast(1); };
|
|
698
680
|
|
|
699
|
-
memcpy((void *)copy, type,
|
|
681
|
+
memcpy((void *)copy, type, K_SIZE(*type));
|
|
700
682
|
copy->name = named ? DuplicateString(name.c_str(), &instance->str_alloc).ptr : copy->name;
|
|
701
683
|
|
|
702
684
|
if (!countedby.IsEmpty()) {
|
|
@@ -712,15 +694,14 @@ static Napi::Value CreatePointerType(const Napi::CallbackInfo &info)
|
|
|
712
694
|
type = copy;
|
|
713
695
|
}
|
|
714
696
|
|
|
715
|
-
return WrapType(env,
|
|
697
|
+
return WrapType(env, type);
|
|
716
698
|
}
|
|
717
699
|
|
|
718
700
|
static Napi::Value EncodePointerDirection(const Napi::CallbackInfo &info, int directions)
|
|
719
701
|
{
|
|
720
|
-
|
|
702
|
+
K_ASSERT(directions >= 1 && directions <= 3);
|
|
721
703
|
|
|
722
704
|
Napi::Env env = info.Env();
|
|
723
|
-
InstanceData *instance = env.GetInstanceData<InstanceData>();
|
|
724
705
|
|
|
725
706
|
if (info.Length() < 1) {
|
|
726
707
|
ThrowError<Napi::TypeError>(env, "Expected 1 argument, got %1", info.Length());
|
|
@@ -742,7 +723,7 @@ static Napi::Value EncodePointerDirection(const Napi::CallbackInfo &info, int di
|
|
|
742
723
|
// Embed direction in unused pointer bits
|
|
743
724
|
const TypeInfo *marked = (const TypeInfo *)((uint8_t *)type + directions - 1);
|
|
744
725
|
|
|
745
|
-
return WrapType(env,
|
|
726
|
+
return WrapType(env, marked);
|
|
746
727
|
}
|
|
747
728
|
|
|
748
729
|
static Napi::Value MarkIn(const Napi::CallbackInfo &info)
|
|
@@ -810,14 +791,14 @@ static Napi::Value CreateDisposableType(const Napi::CallbackInfo &info)
|
|
|
810
791
|
const Napi::FunctionReference &ref = type->dispose_ref;
|
|
811
792
|
|
|
812
793
|
Napi::External<void> external = Napi::External<void>::New(env, (void *)ptr);
|
|
813
|
-
SetValueTag(
|
|
794
|
+
SetValueTag(external, type->ref.marker);
|
|
814
795
|
|
|
815
796
|
Napi::Value self = env.Null();
|
|
816
797
|
napi_value args[] = {
|
|
817
798
|
external
|
|
818
799
|
};
|
|
819
800
|
|
|
820
|
-
ref.Call(self,
|
|
801
|
+
ref.Call(self, K_LEN(args), args);
|
|
821
802
|
instance->stats.disposed++;
|
|
822
803
|
};
|
|
823
804
|
dispose_func = func;
|
|
@@ -831,9 +812,9 @@ static Napi::Value CreateDisposableType(const Napi::CallbackInfo &info)
|
|
|
831
812
|
}
|
|
832
813
|
|
|
833
814
|
TypeInfo *type = instance->types.AppendDefault();
|
|
834
|
-
|
|
815
|
+
K_DEFER_N(err_guard) { instance->types.RemoveLast(1); };
|
|
835
816
|
|
|
836
|
-
memcpy((void *)type, (const void *)src,
|
|
817
|
+
memcpy((void *)type, (const void *)src, K_SIZE(*src));
|
|
837
818
|
type->members.allocator = GetNullAllocator();
|
|
838
819
|
|
|
839
820
|
type->name = named ? DuplicateString(name.Utf8Value().c_str(), &instance->str_alloc).ptr
|
|
@@ -845,7 +826,7 @@ static Napi::Value CreateDisposableType(const Napi::CallbackInfo &info)
|
|
|
845
826
|
// If the insert succeeds, we cannot fail anymore
|
|
846
827
|
if (named) {
|
|
847
828
|
bool inserted;
|
|
848
|
-
instance->types_map.
|
|
829
|
+
instance->types_map.InsertOrGet(type->name, type, &inserted);
|
|
849
830
|
|
|
850
831
|
if (!inserted) {
|
|
851
832
|
ThrowError<Napi::Error>(env, "Duplicate type name '%1'", type->name);
|
|
@@ -854,7 +835,7 @@ static Napi::Value CreateDisposableType(const Napi::CallbackInfo &info)
|
|
|
854
835
|
}
|
|
855
836
|
err_guard.Disable();
|
|
856
837
|
|
|
857
|
-
return WrapType(env,
|
|
838
|
+
return WrapType(env, type);
|
|
858
839
|
}
|
|
859
840
|
|
|
860
841
|
static inline bool GetExternalPointer(Napi::Env env, Napi::Value value, void **out_ptr)
|
|
@@ -864,9 +845,9 @@ static inline bool GetExternalPointer(Napi::Env env, Napi::Value value, void **o
|
|
|
864
845
|
if (IsNullOrUndefined(value)) {
|
|
865
846
|
*out_ptr = 0;
|
|
866
847
|
return true;
|
|
867
|
-
} else if (value.IsExternal() && !CheckValueTag(
|
|
868
|
-
!CheckValueTag(
|
|
869
|
-
!CheckValueTag(
|
|
848
|
+
} else if (value.IsExternal() && !CheckValueTag(value, &TypeInfoMarker) &&
|
|
849
|
+
!CheckValueTag(value, &CastMarker) &&
|
|
850
|
+
!CheckValueTag(value, &MagicUnionMarker)) {
|
|
870
851
|
Napi::External<void> external = value.As<Napi::External<void>>();
|
|
871
852
|
void *ptr = external.Data();
|
|
872
853
|
|
|
@@ -922,7 +903,7 @@ static Napi::Value CallAlloc(const Napi::CallbackInfo &info)
|
|
|
922
903
|
}
|
|
923
904
|
|
|
924
905
|
Napi::External<void> external = Napi::External<void>::New(env, ptr);
|
|
925
|
-
SetValueTag(
|
|
906
|
+
SetValueTag(external, type);
|
|
926
907
|
|
|
927
908
|
return external;
|
|
928
909
|
}
|
|
@@ -1047,12 +1028,12 @@ static Napi::Value CreateArrayType(const Napi::CallbackInfo &info)
|
|
|
1047
1028
|
type->countedby = DuplicateString(str.Utf8Value().c_str(), &instance->str_alloc).ptr;
|
|
1048
1029
|
}
|
|
1049
1030
|
|
|
1050
|
-
return WrapType(env,
|
|
1031
|
+
return WrapType(env, type);
|
|
1051
1032
|
}
|
|
1052
1033
|
|
|
1053
1034
|
static bool ParseClassicFunction(const Napi::CallbackInfo &info, bool concrete, FunctionInfo *out_func)
|
|
1054
1035
|
{
|
|
1055
|
-
|
|
1036
|
+
K_ASSERT(info.Length() >= 2);
|
|
1056
1037
|
|
|
1057
1038
|
Napi::Env env = info.Env();
|
|
1058
1039
|
InstanceData *instance = env.GetInstanceData<InstanceData>();
|
|
@@ -1158,7 +1139,7 @@ static Napi::Value CreateFunctionType(const Napi::CallbackInfo &info)
|
|
|
1158
1139
|
InstanceData *instance = env.GetInstanceData<InstanceData>();
|
|
1159
1140
|
|
|
1160
1141
|
FunctionInfo *func = instance->callbacks.AppendDefault();
|
|
1161
|
-
|
|
1142
|
+
K_DEFER_N(err_guard) { instance->callbacks.RemoveLast(1); };
|
|
1162
1143
|
|
|
1163
1144
|
if (info.Length() >= 2) {
|
|
1164
1145
|
if (!ParseClassicFunction(info, false, func))
|
|
@@ -1205,12 +1186,12 @@ static Napi::Value CreateFunctionType(const Napi::CallbackInfo &info)
|
|
|
1205
1186
|
|
|
1206
1187
|
type->primitive = PrimitiveKind::Prototype;
|
|
1207
1188
|
type->align = alignof(void *);
|
|
1208
|
-
type->size =
|
|
1189
|
+
type->size = K_SIZE(void *);
|
|
1209
1190
|
type->ref.proto = func;
|
|
1210
1191
|
|
|
1211
1192
|
instance->types_map.Set(type->name, type);
|
|
1212
1193
|
|
|
1213
|
-
return WrapType(env,
|
|
1194
|
+
return WrapType(env, type);
|
|
1214
1195
|
}
|
|
1215
1196
|
|
|
1216
1197
|
static Napi::Value CreateTypeAlias(const Napi::CallbackInfo &info)
|
|
@@ -1238,7 +1219,7 @@ static Napi::Value CreateTypeAlias(const Napi::CallbackInfo &info)
|
|
|
1238
1219
|
if (!MapType(env, instance, type, alias))
|
|
1239
1220
|
return env.Null();
|
|
1240
1221
|
|
|
1241
|
-
return WrapType(env,
|
|
1222
|
+
return WrapType(env, type);
|
|
1242
1223
|
}
|
|
1243
1224
|
|
|
1244
1225
|
static Napi::Value GetTypeSize(const Napi::CallbackInfo &info)
|
|
@@ -1310,7 +1291,6 @@ static Napi::Value GetMemberOffset(const Napi::CallbackInfo &info)
|
|
|
1310
1291
|
static Napi::Value GetResolvedType(const Napi::CallbackInfo &info)
|
|
1311
1292
|
{
|
|
1312
1293
|
Napi::Env env = info.Env();
|
|
1313
|
-
InstanceData *instance = env.GetInstanceData<InstanceData>();
|
|
1314
1294
|
|
|
1315
1295
|
if (info.Length() < 1) {
|
|
1316
1296
|
ThrowError<Napi::TypeError>(env, "Expected 1 argument, got %1", info.Length());
|
|
@@ -1321,13 +1301,12 @@ static Napi::Value GetResolvedType(const Napi::CallbackInfo &info)
|
|
|
1321
1301
|
if (!type)
|
|
1322
1302
|
return env.Null();
|
|
1323
1303
|
|
|
1324
|
-
return WrapType(env,
|
|
1304
|
+
return WrapType(env, type);
|
|
1325
1305
|
}
|
|
1326
1306
|
|
|
1327
1307
|
static Napi::Value GetTypeDefinition(const Napi::CallbackInfo &info)
|
|
1328
1308
|
{
|
|
1329
1309
|
Napi::Env env = info.Env();
|
|
1330
|
-
InstanceData *instance = env.GetInstanceData<InstanceData>();
|
|
1331
1310
|
|
|
1332
1311
|
if (info.Length() < 1) {
|
|
1333
1312
|
ThrowError<Napi::TypeError>(env, "Expected 1 argument, got %1", info.Length());
|
|
@@ -1378,7 +1357,7 @@ static Napi::Value GetTypeDefinition(const Napi::CallbackInfo &info)
|
|
|
1378
1357
|
defn.Set("hint", ArrayHintNames[(int)type->hint]);
|
|
1379
1358
|
} [[fallthrough]];
|
|
1380
1359
|
case PrimitiveKind::Pointer: {
|
|
1381
|
-
Napi::Value value = WrapType(env,
|
|
1360
|
+
Napi::Value value = WrapType(env, type->ref.type);
|
|
1382
1361
|
defn.Set("ref", value);
|
|
1383
1362
|
} break;
|
|
1384
1363
|
case PrimitiveKind::Record:
|
|
@@ -1389,7 +1368,7 @@ static Napi::Value GetTypeDefinition(const Napi::CallbackInfo &info)
|
|
|
1389
1368
|
Napi::Object obj = Napi::Object::New(env);
|
|
1390
1369
|
|
|
1391
1370
|
obj.Set("name", member.name);
|
|
1392
|
-
obj.Set("type", WrapType(env,
|
|
1371
|
+
obj.Set("type", WrapType(env, member.type));
|
|
1393
1372
|
obj.Set("offset", member.offset);
|
|
1394
1373
|
if (member.countedby >= 0) {
|
|
1395
1374
|
obj.Set("countedBy", type->members[member.countedby].name);
|
|
@@ -1409,9 +1388,9 @@ static Napi::Value GetTypeDefinition(const Napi::CallbackInfo &info)
|
|
|
1409
1388
|
return type->defn.Value();
|
|
1410
1389
|
}
|
|
1411
1390
|
|
|
1412
|
-
|
|
1391
|
+
InstanceMemory *AllocateMemory(InstanceData *instance, Size stack_size, Size heap_size)
|
|
1413
1392
|
{
|
|
1414
|
-
std::lock_guard<std::mutex> lock(instance->
|
|
1393
|
+
std::lock_guard<std::mutex> lock(instance->mem_mutex);
|
|
1415
1394
|
|
|
1416
1395
|
for (Size i = 1; i < instance->memories.len; i++) {
|
|
1417
1396
|
InstanceMemory *mem = instance->memories[i];
|
|
@@ -1424,11 +1403,11 @@ static InstanceMemory *AllocateMemory(InstanceData *instance, Size stack_size, S
|
|
|
1424
1403
|
|
|
1425
1404
|
bool temporary = (instance->memories.len > instance->config.resident_async_pools);
|
|
1426
1405
|
|
|
1427
|
-
if (temporary && instance->temporaries
|
|
1406
|
+
if (temporary && instance->temporaries > instance->config.max_temporaries)
|
|
1428
1407
|
return nullptr;
|
|
1429
1408
|
|
|
1430
1409
|
InstanceMemory *mem = new InstanceMemory();
|
|
1431
|
-
|
|
1410
|
+
K_DEFER_N(mem_guard) { delete mem; };
|
|
1432
1411
|
|
|
1433
1412
|
stack_size = AlignLen(stack_size, Kibibytes(64));
|
|
1434
1413
|
|
|
@@ -1437,12 +1416,12 @@ static InstanceMemory *AllocateMemory(InstanceData *instance, Size stack_size, S
|
|
|
1437
1416
|
mem->stack.len = stack_size;
|
|
1438
1417
|
mem->stack.ptr = (uint8_t *)VirtualAlloc(nullptr, mem->stack.len, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
|
|
1439
1418
|
|
|
1440
|
-
|
|
1419
|
+
K_CRITICAL(mem->stack.ptr, "Failed to allocate %1 of memory", mem->stack.len);
|
|
1441
1420
|
#else
|
|
1442
1421
|
mem->stack.len = stack_size;
|
|
1443
1422
|
mem->stack.ptr = (uint8_t *)mmap(nullptr, mem->stack.len, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON | MAP_STACK, -1, 0);
|
|
1444
1423
|
|
|
1445
|
-
|
|
1424
|
+
K_CRITICAL(mem->stack.ptr, "Failed to allocate %1 of memory", mem->stack.len);
|
|
1446
1425
|
#endif
|
|
1447
1426
|
|
|
1448
1427
|
#if defined(__OpenBSD__)
|
|
@@ -1459,7 +1438,7 @@ static InstanceMemory *AllocateMemory(InstanceData *instance, Size stack_size, S
|
|
|
1459
1438
|
#else
|
|
1460
1439
|
mem->heap.ptr = (uint8_t *)mmap(nullptr, mem->heap.len, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0);
|
|
1461
1440
|
#endif
|
|
1462
|
-
|
|
1441
|
+
K_CRITICAL(mem->heap.ptr, "Failed to allocate %1 of memory", mem->heap.len);
|
|
1463
1442
|
|
|
1464
1443
|
if (temporary) {
|
|
1465
1444
|
instance->temporaries++;
|
|
@@ -1475,6 +1454,25 @@ static InstanceMemory *AllocateMemory(InstanceData *instance, Size stack_size, S
|
|
|
1475
1454
|
return mem;
|
|
1476
1455
|
}
|
|
1477
1456
|
|
|
1457
|
+
void ReleaseMemory(InstanceData *instance, InstanceMemory *mem)
|
|
1458
|
+
{
|
|
1459
|
+
if (--mem->depth)
|
|
1460
|
+
return;
|
|
1461
|
+
|
|
1462
|
+
// The first InstanceMemory is used for sync calls, no need to manage the async stuff
|
|
1463
|
+
if (mem == instance->memories[0])
|
|
1464
|
+
return;
|
|
1465
|
+
|
|
1466
|
+
std::lock_guard<std::mutex> lock(instance->mem_mutex);
|
|
1467
|
+
|
|
1468
|
+
if (mem->temporary) {
|
|
1469
|
+
instance->temporaries--;
|
|
1470
|
+
delete mem;
|
|
1471
|
+
} else {
|
|
1472
|
+
mem->busy = false;
|
|
1473
|
+
}
|
|
1474
|
+
}
|
|
1475
|
+
|
|
1478
1476
|
static Napi::Value TranslateNormalCall(const FunctionInfo *func, void *native,
|
|
1479
1477
|
const Napi::CallbackInfo &info)
|
|
1480
1478
|
{
|
|
@@ -1498,7 +1496,7 @@ static Napi::Value TranslateNormalCall(const FunctionInfo *func, void *native,
|
|
|
1498
1496
|
|
|
1499
1497
|
// Execute call
|
|
1500
1498
|
{
|
|
1501
|
-
|
|
1499
|
+
K_DEFER_C(prev_call = exec_call) { exec_call = prev_call; };
|
|
1502
1500
|
exec_call = &call;
|
|
1503
1501
|
|
|
1504
1502
|
call.Execute(func, native);
|
|
@@ -1520,11 +1518,11 @@ static Napi::Value TranslateVariadicCall(const FunctionInfo *func, void *native,
|
|
|
1520
1518
|
InstanceData *instance = env.GetInstanceData<InstanceData>();
|
|
1521
1519
|
|
|
1522
1520
|
FunctionInfo copy;
|
|
1523
|
-
memcpy((void *)©, func,
|
|
1521
|
+
memcpy((void *)©, func, K_SIZE(*func));
|
|
1524
1522
|
copy.lib = nullptr;
|
|
1525
1523
|
|
|
1526
1524
|
// This makes variadic calls non-reentrant
|
|
1527
|
-
|
|
1525
|
+
K_DEFER_C(len = copy.parameters.len) {
|
|
1528
1526
|
copy.parameters.RemoveFrom(len);
|
|
1529
1527
|
copy.parameters.Leak();
|
|
1530
1528
|
};
|
|
@@ -1579,7 +1577,7 @@ static Napi::Value TranslateVariadicCall(const FunctionInfo *func, void *native,
|
|
|
1579
1577
|
|
|
1580
1578
|
// Execute call
|
|
1581
1579
|
{
|
|
1582
|
-
|
|
1580
|
+
K_DEFER_C(prev_call = exec_call) { exec_call = prev_call; };
|
|
1583
1581
|
exec_call = &call;
|
|
1584
1582
|
|
|
1585
1583
|
call.Execute(©, native);
|
|
@@ -1629,7 +1627,7 @@ public:
|
|
|
1629
1627
|
void AsyncCall::Execute()
|
|
1630
1628
|
{
|
|
1631
1629
|
if (prepared) {
|
|
1632
|
-
|
|
1630
|
+
K_DEFER_C(prev_call = exec_call) { exec_call = prev_call; };
|
|
1633
1631
|
exec_call = &call;
|
|
1634
1632
|
|
|
1635
1633
|
call.Execute(func, native);
|
|
@@ -1638,7 +1636,7 @@ void AsyncCall::Execute()
|
|
|
1638
1636
|
|
|
1639
1637
|
void AsyncCall::OnOK()
|
|
1640
1638
|
{
|
|
1641
|
-
|
|
1639
|
+
K_ASSERT(prepared);
|
|
1642
1640
|
|
|
1643
1641
|
Napi::FunctionReference &callback = Callback();
|
|
1644
1642
|
|
|
@@ -1648,13 +1646,13 @@ void AsyncCall::OnOK()
|
|
|
1648
1646
|
call.Complete(func)
|
|
1649
1647
|
};
|
|
1650
1648
|
|
|
1651
|
-
callback.Call(self,
|
|
1649
|
+
callback.Call(self, K_LEN(args), args);
|
|
1652
1650
|
}
|
|
1653
1651
|
|
|
1654
1652
|
static Napi::Value TranslateAsyncCall(const FunctionInfo *func, void *native,
|
|
1655
1653
|
const Napi::CallbackInfo &info)
|
|
1656
1654
|
{
|
|
1657
|
-
|
|
1655
|
+
K_ASSERT(!func->variadic);
|
|
1658
1656
|
|
|
1659
1657
|
Napi::Env env = info.Env();
|
|
1660
1658
|
InstanceData *instance = env.GetInstanceData<InstanceData>();
|
|
@@ -1712,7 +1710,7 @@ extern "C" void RelayCallback(Size idx, uint8_t *own_sp, uint8_t *caller_sp, Bac
|
|
|
1712
1710
|
}
|
|
1713
1711
|
|
|
1714
1712
|
// Avoid triggering the "use callback beyond FFI" check
|
|
1715
|
-
|
|
1713
|
+
K_DEFER_C(generation = trampoline->generation) { trampoline->generation = generation; };
|
|
1716
1714
|
trampoline->generation = -1;
|
|
1717
1715
|
|
|
1718
1716
|
// We set dispose_call to true so that the main thread will dispose of CallData itself
|
|
@@ -1728,7 +1726,7 @@ static Napi::Value FindLibraryFunction(const Napi::CallbackInfo &info)
|
|
|
1728
1726
|
LibraryHolder *lib = (LibraryHolder *)info.Data();
|
|
1729
1727
|
|
|
1730
1728
|
FunctionInfo *func = new FunctionInfo();
|
|
1731
|
-
|
|
1729
|
+
K_DEFER { func->Unref(); };
|
|
1732
1730
|
|
|
1733
1731
|
func->lib = lib->Ref();
|
|
1734
1732
|
|
|
@@ -1825,7 +1823,7 @@ static Napi::Value FindSymbol(const Napi::CallbackInfo &info)
|
|
|
1825
1823
|
}
|
|
1826
1824
|
|
|
1827
1825
|
Napi::External<void> external = Napi::External<void>::New(env, ptr);
|
|
1828
|
-
SetValueTag(
|
|
1826
|
+
SetValueTag(external, &type);
|
|
1829
1827
|
|
|
1830
1828
|
return external;
|
|
1831
1829
|
}
|
|
@@ -1876,7 +1874,7 @@ static Napi::Value LoadSharedLibrary(const Napi::CallbackInfo &info)
|
|
|
1876
1874
|
|
|
1877
1875
|
if (!instance->memories.len) {
|
|
1878
1876
|
AllocateMemory(instance, instance->config.sync_stack_size, instance->config.sync_heap_size);
|
|
1879
|
-
|
|
1877
|
+
K_ASSERT(instance->memories.len == 1);
|
|
1880
1878
|
}
|
|
1881
1879
|
|
|
1882
1880
|
// Load shared library
|
|
@@ -1890,7 +1888,7 @@ static Napi::Value LoadSharedLibrary(const Napi::CallbackInfo &info)
|
|
|
1890
1888
|
return env.Null();
|
|
1891
1889
|
} else {
|
|
1892
1890
|
module = GetModuleHandle(nullptr);
|
|
1893
|
-
|
|
1891
|
+
K_ASSERT(module);
|
|
1894
1892
|
}
|
|
1895
1893
|
#else
|
|
1896
1894
|
if (info[0].IsString()) {
|
|
@@ -1917,7 +1915,7 @@ static Napi::Value LoadSharedLibrary(const Napi::CallbackInfo &info)
|
|
|
1917
1915
|
#endif
|
|
1918
1916
|
|
|
1919
1917
|
LibraryHolder *lib = new LibraryHolder(module);
|
|
1920
|
-
|
|
1918
|
+
K_DEFER { lib->Unref(); };
|
|
1921
1919
|
|
|
1922
1920
|
Napi::Object obj = Napi::Object::New(env);
|
|
1923
1921
|
|
|
@@ -1997,7 +1995,7 @@ static Napi::Value RegisterCallback(const Napi::CallbackInfo &info)
|
|
|
1997
1995
|
void *ptr = GetTrampoline(idx, type->ref.proto);
|
|
1998
1996
|
|
|
1999
1997
|
Napi::External<void> external = Napi::External<void>::New(env, ptr);
|
|
2000
|
-
SetValueTag(
|
|
1998
|
+
SetValueTag(external, type->ref.marker);
|
|
2001
1999
|
|
|
2002
2000
|
// Cache index for fast unregistration
|
|
2003
2001
|
instance->trampolines_map.Set(ptr, idx);
|
|
@@ -2040,7 +2038,7 @@ static Napi::Value UnregisterCallback(const Napi::CallbackInfo &info)
|
|
|
2040
2038
|
std::lock_guard<std::mutex> lock(shared.mutex);
|
|
2041
2039
|
|
|
2042
2040
|
TrampolineInfo *trampoline = &shared.trampolines[idx];
|
|
2043
|
-
|
|
2041
|
+
K_ASSERT(!trampoline->func.IsEmpty());
|
|
2044
2042
|
|
|
2045
2043
|
trampoline->func.Reset();
|
|
2046
2044
|
trampoline->recv.Reset();
|
|
@@ -2054,7 +2052,6 @@ static Napi::Value UnregisterCallback(const Napi::CallbackInfo &info)
|
|
|
2054
2052
|
static Napi::Value CastValue(const Napi::CallbackInfo &info)
|
|
2055
2053
|
{
|
|
2056
2054
|
Napi::Env env = info.Env();
|
|
2057
|
-
InstanceData *instance = env.GetInstanceData<InstanceData>();
|
|
2058
2055
|
|
|
2059
2056
|
if (info.Length() < 2) [[unlikely]] {
|
|
2060
2057
|
ThrowError<Napi::TypeError>(env, "Expected 2 arguments, got %1", info.Length());
|
|
@@ -2081,7 +2078,7 @@ static Napi::Value CastValue(const Napi::CallbackInfo &info)
|
|
|
2081
2078
|
cast->type = type;
|
|
2082
2079
|
|
|
2083
2080
|
Napi::External<ValueCast> external = Napi::External<ValueCast>::New(env, cast, [](Napi::Env, ValueCast *cast) { delete cast; });
|
|
2084
|
-
SetValueTag(
|
|
2081
|
+
SetValueTag(external, &CastMarker);
|
|
2085
2082
|
|
|
2086
2083
|
return external;
|
|
2087
2084
|
}
|
|
@@ -2354,8 +2351,8 @@ bool InitAsyncBroker(Napi::Env env, InstanceData *instance)
|
|
|
2354
2351
|
static void RegisterPrimitiveType(Napi::Env env, Napi::Object map, std::initializer_list<const char *> names,
|
|
2355
2352
|
PrimitiveKind primitive, int32_t size, int16_t align, const char *ref = nullptr)
|
|
2356
2353
|
{
|
|
2357
|
-
|
|
2358
|
-
|
|
2354
|
+
K_ASSERT(names.size() > 0);
|
|
2355
|
+
K_ASSERT(align <= size);
|
|
2359
2356
|
|
|
2360
2357
|
InstanceData *instance = env.GetInstanceData<InstanceData>();
|
|
2361
2358
|
|
|
@@ -2379,17 +2376,17 @@ static void RegisterPrimitiveType(Napi::Env env, Napi::Object map, std::initiali
|
|
|
2379
2376
|
|
|
2380
2377
|
if (ref) {
|
|
2381
2378
|
const TypeInfo *marker = instance->types_map.FindValue(ref, nullptr);
|
|
2382
|
-
|
|
2379
|
+
K_ASSERT(marker);
|
|
2383
2380
|
|
|
2384
2381
|
type->ref.marker = marker;
|
|
2385
2382
|
}
|
|
2386
2383
|
|
|
2387
|
-
Napi::Value wrapper = WrapType(env,
|
|
2384
|
+
Napi::Value wrapper = WrapType(env, type);
|
|
2388
2385
|
|
|
2389
2386
|
for (const char *name: names) {
|
|
2390
2387
|
bool inserted;
|
|
2391
|
-
instance->types_map.
|
|
2392
|
-
|
|
2388
|
+
instance->types_map.InsertOrGet(name, type, &inserted);
|
|
2389
|
+
K_ASSERT(inserted);
|
|
2393
2390
|
|
|
2394
2391
|
if (!EndsWith(name, "*")) {
|
|
2395
2392
|
map.Set(name, wrapper);
|
|
@@ -2406,12 +2403,12 @@ static inline PrimitiveKind GetSignPrimitive(Size len, bool sign)
|
|
|
2406
2403
|
case 8: return sign ? PrimitiveKind::Int64 : PrimitiveKind::UInt64;
|
|
2407
2404
|
}
|
|
2408
2405
|
|
|
2409
|
-
|
|
2406
|
+
K_UNREACHABLE();
|
|
2410
2407
|
}
|
|
2411
2408
|
|
|
2412
2409
|
static inline PrimitiveKind GetLittleEndianPrimitive(PrimitiveKind kind)
|
|
2413
2410
|
{
|
|
2414
|
-
#if defined(
|
|
2411
|
+
#if defined(K_BIG_ENDIAN)
|
|
2415
2412
|
return (PrimitiveKind)((int)kind + 1);
|
|
2416
2413
|
#else
|
|
2417
2414
|
return kind;
|
|
@@ -2420,7 +2417,7 @@ static inline PrimitiveKind GetLittleEndianPrimitive(PrimitiveKind kind)
|
|
|
2420
2417
|
|
|
2421
2418
|
static inline PrimitiveKind GetBigEndianPrimitive(PrimitiveKind kind)
|
|
2422
2419
|
{
|
|
2423
|
-
#if defined(
|
|
2420
|
+
#if defined(K_BIG_ENDIAN)
|
|
2424
2421
|
return kind;
|
|
2425
2422
|
#else
|
|
2426
2423
|
return (PrimitiveKind)((int)kind + 1);
|
|
@@ -2430,7 +2427,7 @@ static inline PrimitiveKind GetBigEndianPrimitive(PrimitiveKind kind)
|
|
|
2430
2427
|
static InstanceData *CreateInstance()
|
|
2431
2428
|
{
|
|
2432
2429
|
InstanceData *instance = new InstanceData();
|
|
2433
|
-
|
|
2430
|
+
K_DEFER_N(err_guard) { delete instance; };
|
|
2434
2431
|
|
|
2435
2432
|
instance->main_thread_id = std::this_thread::get_id();
|
|
2436
2433
|
|
|
@@ -2450,7 +2447,7 @@ static InstanceData *CreateInstance()
|
|
|
2450
2447
|
static Napi::Object InitModule(Napi::Env env, Napi::Object exports)
|
|
2451
2448
|
{
|
|
2452
2449
|
InstanceData *instance = CreateInstance();
|
|
2453
|
-
|
|
2450
|
+
K_CRITICAL(instance, "Failed to initialize Koffi");
|
|
2454
2451
|
|
|
2455
2452
|
env.SetInstanceData(instance);
|
|
2456
2453
|
|
|
@@ -2525,16 +2522,16 @@ static Napi::Object InitModule(Napi::Env env, Napi::Object exports)
|
|
|
2525
2522
|
exports.Set("types", types);
|
|
2526
2523
|
|
|
2527
2524
|
RegisterPrimitiveType(env, types, {"void"}, PrimitiveKind::Void, 0, 0);
|
|
2528
|
-
RegisterPrimitiveType(env, types, {"bool"}, PrimitiveKind::Bool,
|
|
2525
|
+
RegisterPrimitiveType(env, types, {"bool"}, PrimitiveKind::Bool, K_SIZE(bool), alignof(bool));
|
|
2529
2526
|
RegisterPrimitiveType(env, types, {"int8_t", "int8"}, PrimitiveKind::Int8, 1, 1);
|
|
2530
2527
|
RegisterPrimitiveType(env, types, {"uint8_t", "uint8"}, PrimitiveKind::UInt8, 1, 1);
|
|
2531
2528
|
RegisterPrimitiveType(env, types, {"char"}, PrimitiveKind::Int8, 1, 1);
|
|
2532
2529
|
RegisterPrimitiveType(env, types, {"unsigned char", "uchar"}, PrimitiveKind::UInt8, 1, 1);
|
|
2533
2530
|
RegisterPrimitiveType(env, types, {"char16_t", "char16"}, PrimitiveKind::Int16, 2, 2);
|
|
2534
2531
|
RegisterPrimitiveType(env, types, {"char32_t", "char32"}, PrimitiveKind::Int32, 4, 4);
|
|
2535
|
-
if (
|
|
2532
|
+
if (K_SIZE(wchar_t) == 2) {
|
|
2536
2533
|
RegisterPrimitiveType(env, types, {"wchar_t", "wchar"}, PrimitiveKind::Int16, 2, 2);
|
|
2537
|
-
} else if (
|
|
2534
|
+
} else if (K_SIZE(wchar_t) == 4) {
|
|
2538
2535
|
RegisterPrimitiveType(env, types, {"wchar_t", "wchar"}, PrimitiveKind::Int32, 4, 4);
|
|
2539
2536
|
}
|
|
2540
2537
|
RegisterPrimitiveType(env, types, {"int16_t", "int16"}, PrimitiveKind::Int16, 2, 2);
|
|
@@ -2559,22 +2556,22 @@ static Napi::Object InitModule(Napi::Env env, Napi::Object exports)
|
|
|
2559
2556
|
RegisterPrimitiveType(env, types, {"uint64_t", "uint64"}, PrimitiveKind::UInt64, 8, alignof(int64_t));
|
|
2560
2557
|
RegisterPrimitiveType(env, types, {"uint64_le_t", "uint64_le"}, GetLittleEndianPrimitive(PrimitiveKind::UInt64), 8, alignof(int64_t));
|
|
2561
2558
|
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,
|
|
2559
|
+
RegisterPrimitiveType(env, types, {"intptr_t", "intptr"}, GetSignPrimitive(K_SIZE(intptr_t), true), K_SIZE(intptr_t), alignof(intptr_t));
|
|
2560
|
+
RegisterPrimitiveType(env, types, {"uintptr_t", "uintptr"}, GetSignPrimitive(K_SIZE(intptr_t), false), K_SIZE(intptr_t), alignof(intptr_t));
|
|
2561
|
+
RegisterPrimitiveType(env, types, {"size_t"}, GetSignPrimitive(K_SIZE(size_t), false), K_SIZE(size_t), alignof(size_t));
|
|
2562
|
+
RegisterPrimitiveType(env, types, {"long"}, GetSignPrimitive(K_SIZE(long), true), K_SIZE(long), alignof(long));
|
|
2563
|
+
RegisterPrimitiveType(env, types, {"unsigned long", "ulong"}, GetSignPrimitive(K_SIZE(long), false), K_SIZE(long), alignof(long));
|
|
2564
|
+
RegisterPrimitiveType(env, types, {"long long", "longlong"}, PrimitiveKind::Int64, K_SIZE(int64_t), alignof(int64_t));
|
|
2565
|
+
RegisterPrimitiveType(env, types, {"unsigned long long", "ulonglong"}, PrimitiveKind::UInt64, K_SIZE(uint64_t), alignof(uint64_t));
|
|
2569
2566
|
RegisterPrimitiveType(env, types, {"float", "float32"}, PrimitiveKind::Float32, 4, alignof(float));
|
|
2570
2567
|
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,
|
|
2568
|
+
RegisterPrimitiveType(env, types, {"char *", "str", "string"}, PrimitiveKind::String, K_SIZE(void *), alignof(void *), "char");
|
|
2569
|
+
RegisterPrimitiveType(env, types, {"char16_t *", "char16 *", "str16", "string16"}, PrimitiveKind::String16, K_SIZE(void *), alignof(void *), "char16_t");
|
|
2570
|
+
RegisterPrimitiveType(env, types, {"char32_t *", "char32 *", "str32", "string32"}, PrimitiveKind::String32, K_SIZE(void *), alignof(void *), "char32_t");
|
|
2571
|
+
if (K_SIZE(wchar_t) == 2) {
|
|
2572
|
+
RegisterPrimitiveType(env, types, {"wchar_t *", "wchar *"}, PrimitiveKind::String16, K_SIZE(void *), alignof(void *), "wchar_t");
|
|
2573
|
+
} else if (K_SIZE(wchar_t) == 4) {
|
|
2574
|
+
RegisterPrimitiveType(env, types, {"wchar_t *", "wchar *"}, PrimitiveKind::String32, K_SIZE(void *), alignof(void *), "wchar_t");
|
|
2578
2575
|
}
|
|
2579
2576
|
|
|
2580
2577
|
instance->void_type = instance->types_map.FindValue("void", nullptr);
|
|
@@ -2596,12 +2593,15 @@ static Napi::Object InitModule(Napi::Env env, Napi::Object exports)
|
|
|
2596
2593
|
exports.Set("node", node);
|
|
2597
2594
|
|
|
2598
2595
|
Napi::External<void> external = Napi::External<void>::New(env, (napi_env)env);
|
|
2599
|
-
SetValueTag(
|
|
2596
|
+
SetValueTag(external, instance->void_type);
|
|
2600
2597
|
|
|
2601
2598
|
node.Set("env", external);
|
|
2599
|
+
|
|
2600
|
+
node.Set("poll", Napi::Function::New(env, &Poll, "poll"));
|
|
2601
|
+
node.Set("PollHandle", PollHandle::Define(env));
|
|
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
|
}
|