koffi 2.14.1 → 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 +19 -0
- 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 +1 -1
- package/doc/pages/misc.md +16 -11
- package/doc/pages.ini +4 -0
- package/doc/static/highlight.js +2 -14
- package/doc/static/koffi.css +3 -15
- package/doc/static/print.css +2 -14
- package/index.d.ts +29 -24
- package/index.js +8 -8
- package/indirect.js +8 -8
- package/{src/core → lib/native}/base/base.cc +1058 -630
- package/{src/core → lib/native}/base/base.hh +334 -165
- package/{src/core → lib/native}/base/crc.inc +2 -20
- 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 +2 -20
- package/{src/core → lib/native}/base/unicode_gen.py +4 -41
- package/package.json +1 -1
- 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 +2 -20
- 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 +7 -25
- package/src/koffi/src/abi_arm32_asm.S +2 -20
- package/src/koffi/src/abi_arm64.cc +7 -25
- 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 +7 -25
- package/src/koffi/src/abi_riscv64_asm.S +2 -20
- package/src/koffi/src/abi_x64_sysv.cc +7 -25
- package/src/koffi/src/abi_x64_sysv_asm.S +2 -20
- package/src/koffi/src/abi_x64_win.cc +12 -30
- package/src/koffi/src/abi_x64_win_asm.asm +2 -20
- package/src/koffi/src/abi_x86.cc +7 -25
- 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 +25 -45
- package/src/koffi/src/call.hh +3 -21
- package/src/koffi/src/errno.inc +2 -20
- package/src/koffi/src/ffi.cc +62 -62
- package/src/koffi/src/ffi.hh +14 -29
- package/src/koffi/src/init.js +2 -20
- package/src/koffi/src/parser.cc +13 -27
- package/src/koffi/src/parser.hh +3 -21
- 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 +0 -21
- package/src/koffi/src/util.cc +44 -59
- package/src/koffi/src/util.hh +6 -24
- 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 +2 -20
- package/src/koffi/src/win32.hh +3 -21
- 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/init.js
CHANGED
|
@@ -1,23 +1,5 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
3
|
-
// Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
4
|
-
// this software and associated documentation files (the “Software”), to deal in
|
|
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.
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
// SPDX-FileCopyrightText: 2025 Niels Martignène <niels.martignene@protonmail.com>
|
|
21
3
|
|
|
22
4
|
const fs = require('fs');
|
|
23
5
|
const path = require('path');
|
package/src/koffi/src/parser.cc
CHANGED
|
@@ -1,25 +1,7 @@
|
|
|
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 "parser.hh"
|
|
25
7
|
|
|
@@ -164,12 +146,16 @@ const TypeInfo *PrototypeParser::ParseType(int *out_directions)
|
|
|
164
146
|
}
|
|
165
147
|
offset--;
|
|
166
148
|
|
|
167
|
-
if (out_directions
|
|
168
|
-
|
|
149
|
+
if (out_directions) {
|
|
150
|
+
if (offset > start) {
|
|
151
|
+
int directions = ResolveDirections(tokens[start]);
|
|
169
152
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
153
|
+
if (directions) {
|
|
154
|
+
*out_directions = directions;
|
|
155
|
+
start++;
|
|
156
|
+
} else {
|
|
157
|
+
*out_directions = 1;
|
|
158
|
+
}
|
|
173
159
|
} else {
|
|
174
160
|
*out_directions = 1;
|
|
175
161
|
}
|
package/src/koffi/src/parser.hh
CHANGED
|
@@ -1,27 +1,9 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
3
|
-
// Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
4
|
-
// this software and associated documentation files (the “Software”), to deal in
|
|
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.
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
// SPDX-FileCopyrightText: 2025 Niels Martignène <niels.martignene@protonmail.com>
|
|
21
3
|
|
|
22
4
|
#pragma once
|
|
23
5
|
|
|
24
|
-
#include "
|
|
6
|
+
#include "lib/native/base/base.hh"
|
|
25
7
|
#include "util.hh"
|
|
26
8
|
|
|
27
9
|
#include <napi.h>
|
|
@@ -1,24 +1,3 @@
|
|
|
1
|
-
; Copyright (C) 2025 Niels Martignène <niels.martignene@protonmail.com>
|
|
2
|
-
;
|
|
3
|
-
; Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
4
|
-
; this software and associated documentation files (the “Software”), to deal in
|
|
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
1
|
EXPORT Trampoline0
|
|
23
2
|
EXPORT Trampoline1
|
|
24
3
|
EXPORT Trampoline2
|
|
@@ -1,24 +1,3 @@
|
|
|
1
|
-
# Copyright (C) 2025 Niels Martignène <niels.martignene@protonmail.com>
|
|
2
|
-
#
|
|
3
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
4
|
-
# this software and associated documentation files (the “Software”), to deal in
|
|
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
1
|
.global SYMBOL(Trampoline0)
|
|
23
2
|
.global SYMBOL(Trampoline1)
|
|
24
3
|
.global SYMBOL(Trampoline2)
|
|
@@ -1,24 +1,3 @@
|
|
|
1
|
-
; Copyright (C) 2025 Niels Martignène <niels.martignene@protonmail.com>
|
|
2
|
-
;
|
|
3
|
-
; Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
4
|
-
; this software and associated documentation files (the “Software”), to deal in
|
|
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
1
|
public Trampoline0
|
|
23
2
|
public Trampoline1
|
|
24
3
|
public Trampoline2
|
|
@@ -1,24 +1,3 @@
|
|
|
1
|
-
; Copyright (C) 2025 Niels Martignène <niels.martignene@protonmail.com>
|
|
2
|
-
;
|
|
3
|
-
; Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
4
|
-
; this software and associated documentation files (the “Software”), to deal in
|
|
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
1
|
public Trampoline0
|
|
23
2
|
public Trampoline1
|
|
24
3
|
public Trampoline2
|
|
@@ -1,24 +1,3 @@
|
|
|
1
|
-
// Copyright (C) 2025 Niels Martignène <niels.martignene@protonmail.com>
|
|
2
|
-
//
|
|
3
|
-
// Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
4
|
-
// this software and associated documentation files (the “Software”), to deal in
|
|
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
1
|
extern "C" int Trampoline0; extern "C" int TrampolineX0;
|
|
23
2
|
extern "C" int Trampoline1; extern "C" int TrampolineX1;
|
|
24
3
|
extern "C" int Trampoline2; extern "C" int TrampolineX2;
|
package/src/koffi/src/util.cc
CHANGED
|
@@ -1,25 +1,7 @@
|
|
|
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 "call.hh"
|
|
24
6
|
#include "ffi.hh"
|
|
25
7
|
#include "util.hh"
|
|
@@ -38,7 +20,7 @@ Napi::Function MagicUnion::InitClass(Napi::Env env, const TypeInfo *type)
|
|
|
38
20
|
K_ASSERT(type->primitive == PrimitiveKind::Union);
|
|
39
21
|
|
|
40
22
|
// node-addon-api wants std::vector
|
|
41
|
-
std::vector<Napi::ClassPropertyDescriptor<MagicUnion>> properties;
|
|
23
|
+
std::vector<Napi::ClassPropertyDescriptor<MagicUnion>> properties;
|
|
42
24
|
properties.reserve(type->members.len);
|
|
43
25
|
|
|
44
26
|
for (Size i = 0; i < type->members.len; i++) {
|
|
@@ -187,7 +169,7 @@ const TypeInfo *ResolveType(Napi::Value value, int *out_directions)
|
|
|
187
169
|
|
|
188
170
|
// Cache for quick future access
|
|
189
171
|
bool inserted;
|
|
190
|
-
auto bucket = instance->types_map.
|
|
172
|
+
auto bucket = instance->types_map.InsertOrGetDefault(remain.ptr, &inserted);
|
|
191
173
|
|
|
192
174
|
if (inserted) {
|
|
193
175
|
bucket->key = DuplicateString(remain, &instance->str_alloc).ptr;
|
|
@@ -198,7 +180,7 @@ const TypeInfo *ResolveType(Napi::Value value, int *out_directions)
|
|
|
198
180
|
}
|
|
199
181
|
|
|
200
182
|
return type;
|
|
201
|
-
} else if (CheckValueTag(
|
|
183
|
+
} else if (CheckValueTag(value, &TypeInfoMarker)) {
|
|
202
184
|
Napi::External<TypeInfo> external = value.As<Napi::External<TypeInfo>>();
|
|
203
185
|
const TypeInfo *raw = external.Data();
|
|
204
186
|
|
|
@@ -399,7 +381,7 @@ TypeInfo *MakePointerType(InstanceData *instance, const TypeInfo *ref, int count
|
|
|
399
381
|
Fmt(name_buf, "%1%2*", ref->name, EndsWith(ref->name, "*") ? "" : " ");
|
|
400
382
|
|
|
401
383
|
bool inserted;
|
|
402
|
-
auto bucket = instance->types_map.
|
|
384
|
+
auto bucket = instance->types_map.InsertOrGetDefault(name_buf, &inserted);
|
|
403
385
|
|
|
404
386
|
if (inserted) {
|
|
405
387
|
TypeInfo *type = instance->types.AppendDefault();
|
|
@@ -446,7 +428,7 @@ static TypeInfo *MakeArrayType(InstanceData *instance, const TypeInfo *ref, Size
|
|
|
446
428
|
|
|
447
429
|
if (insert) {
|
|
448
430
|
bool inserted;
|
|
449
|
-
type = (TypeInfo *)*instance->types_map.
|
|
431
|
+
type = (TypeInfo *)*instance->types_map.InsertOrGet(type->name, type, &inserted);
|
|
450
432
|
instance->types.RemoveLast(!inserted);
|
|
451
433
|
}
|
|
452
434
|
|
|
@@ -473,10 +455,10 @@ TypeInfo *MakeArrayType(InstanceData *instance, const TypeInfo *ref, Size len, A
|
|
|
473
455
|
return MakeArrayType(instance, ref, len, hint, false);
|
|
474
456
|
}
|
|
475
457
|
|
|
476
|
-
Napi::External<TypeInfo> WrapType(Napi::Env env,
|
|
458
|
+
Napi::External<TypeInfo> WrapType(Napi::Env env, const TypeInfo *type)
|
|
477
459
|
{
|
|
478
460
|
Napi::External<TypeInfo> external = Napi::External<TypeInfo>::New(env, (TypeInfo *)type);
|
|
479
|
-
SetValueTag(
|
|
461
|
+
SetValueTag(external, &TypeInfoMarker);
|
|
480
462
|
|
|
481
463
|
return external;
|
|
482
464
|
}
|
|
@@ -540,17 +522,17 @@ bool CanStoreType(const TypeInfo *type)
|
|
|
540
522
|
|
|
541
523
|
const char *GetValueType(const InstanceData *instance, Napi::Value value)
|
|
542
524
|
{
|
|
543
|
-
if (CheckValueTag(
|
|
525
|
+
if (CheckValueTag(value, &CastMarker)) {
|
|
544
526
|
Napi::External<ValueCast> external = value.As<Napi::External<ValueCast>>();
|
|
545
527
|
ValueCast *cast = external.Data();
|
|
546
528
|
|
|
547
529
|
return cast->type->name;
|
|
548
530
|
}
|
|
549
531
|
|
|
550
|
-
if (CheckValueTag(
|
|
532
|
+
if (CheckValueTag(value, &TypeInfoMarker))
|
|
551
533
|
return "Type";
|
|
552
534
|
for (const TypeInfo &type: instance->types) {
|
|
553
|
-
if (type.ref.marker && CheckValueTag(
|
|
535
|
+
if (type.ref.marker && CheckValueTag(value, type.ref.marker))
|
|
554
536
|
return type.name;
|
|
555
537
|
}
|
|
556
538
|
|
|
@@ -595,7 +577,7 @@ const char *GetValueType(const InstanceData *instance, Napi::Value value)
|
|
|
595
577
|
return "Unknown";
|
|
596
578
|
}
|
|
597
579
|
|
|
598
|
-
void SetValueTag(
|
|
580
|
+
void SetValueTag(Napi::Value value, const void *marker)
|
|
599
581
|
{
|
|
600
582
|
static_assert(K_SIZE(TypeInfo) >= 16);
|
|
601
583
|
|
|
@@ -614,7 +596,7 @@ void SetValueTag(const InstanceData *instance, Napi::Value value, const void *ma
|
|
|
614
596
|
K_ASSERT(status == napi_ok);
|
|
615
597
|
}
|
|
616
598
|
|
|
617
|
-
bool CheckValueTag(
|
|
599
|
+
bool CheckValueTag(Napi::Value value, const void *marker)
|
|
618
600
|
{
|
|
619
601
|
bool match = false;
|
|
620
602
|
|
|
@@ -646,25 +628,27 @@ int GetTypedArrayType(const TypeInfo *type)
|
|
|
646
628
|
|
|
647
629
|
Napi::String MakeStringFromUTF32(Napi::Env env, const char32_t *ptr, Size len)
|
|
648
630
|
{
|
|
631
|
+
static const char16_t ReplacementChar = 0xFFFD;
|
|
632
|
+
|
|
649
633
|
HeapArray<char16_t> buf;
|
|
650
634
|
buf.Reserve(len * 2);
|
|
651
635
|
|
|
652
636
|
for (Size i = 0; i < len; i++) {
|
|
653
637
|
char32_t uc = ptr[i];
|
|
654
638
|
|
|
655
|
-
if (uc
|
|
639
|
+
if (uc <= 0xFFFF) {
|
|
656
640
|
if (uc < 0xD800 || uc > 0xDFFF) {
|
|
657
641
|
buf.Append((char16_t)uc);
|
|
658
642
|
} else {
|
|
659
|
-
buf.Append(
|
|
643
|
+
buf.Append(ReplacementChar);
|
|
660
644
|
}
|
|
661
|
-
} else if (uc
|
|
645
|
+
} else if (uc <= 0x10FFFF) {
|
|
662
646
|
uc -= 0x0010000UL;
|
|
663
647
|
|
|
664
648
|
buf.Append((char16_t)((uc >> 10) + 0xD800));
|
|
665
649
|
buf.Append((char16_t)((uc & 0x3FFul) + 0xDC00));
|
|
666
650
|
} else {
|
|
667
|
-
buf.Append(
|
|
651
|
+
buf.Append(ReplacementChar);
|
|
668
652
|
}
|
|
669
653
|
}
|
|
670
654
|
|
|
@@ -676,10 +660,8 @@ Napi::Object DecodeObject(Napi::Env env, const uint8_t *origin, const TypeInfo *
|
|
|
676
660
|
{
|
|
677
661
|
// We can't decode unions because we don't know which member is valid
|
|
678
662
|
if (type->primitive == PrimitiveKind::Union) {
|
|
679
|
-
InstanceData *instance = env.GetInstanceData<InstanceData>();
|
|
680
|
-
|
|
681
663
|
Napi::Object wrapper = type->construct.New({}).As<Napi::Object>();
|
|
682
|
-
SetValueTag(
|
|
664
|
+
SetValueTag(wrapper, &MagicUnionMarker);
|
|
683
665
|
|
|
684
666
|
MagicUnion *u = MagicUnion::Unwrap(wrapper);
|
|
685
667
|
u->SetRaw(origin);
|
|
@@ -775,7 +757,6 @@ static uint32_t DecodeDynamicLength(const uint8_t *origin, const RecordMember &b
|
|
|
775
757
|
void DecodeObject(Napi::Object obj, const uint8_t *origin, const TypeInfo *type)
|
|
776
758
|
{
|
|
777
759
|
Napi::Env env = obj.Env();
|
|
778
|
-
InstanceData *instance = env.GetInstanceData<InstanceData>();
|
|
779
760
|
|
|
780
761
|
K_ASSERT(type->primitive == PrimitiveKind::Record);
|
|
781
762
|
|
|
@@ -887,7 +868,7 @@ void DecodeObject(Napi::Object obj, const uint8_t *origin, const TypeInfo *type)
|
|
|
887
868
|
obj.Set(member.name, value);
|
|
888
869
|
} else if (ptr2) {
|
|
889
870
|
Napi::External<void> external = Napi::External<void>::New(env, ptr2);
|
|
890
|
-
SetValueTag(
|
|
871
|
+
SetValueTag(external, member.type->ref.marker);
|
|
891
872
|
|
|
892
873
|
obj.Set(member.name, external);
|
|
893
874
|
} else {
|
|
@@ -936,7 +917,6 @@ void DecodeObject(Napi::Object obj, const uint8_t *origin, const TypeInfo *type)
|
|
|
936
917
|
|
|
937
918
|
Napi::Value DecodeArray(Napi::Env env, const uint8_t *origin, const TypeInfo *type, uint32_t len)
|
|
938
919
|
{
|
|
939
|
-
InstanceData *instance = env.GetInstanceData<InstanceData>();
|
|
940
920
|
Size offset = 0;
|
|
941
921
|
|
|
942
922
|
#define POP_ARRAY(SetCode) \
|
|
@@ -1087,7 +1067,7 @@ Napi::Value DecodeArray(Napi::Env env, const uint8_t *origin, const TypeInfo *ty
|
|
|
1087
1067
|
|
|
1088
1068
|
if (ptr2) {
|
|
1089
1069
|
Napi::External<void> external = Napi::External<void>::New(env, ptr2);
|
|
1090
|
-
SetValueTag(
|
|
1070
|
+
SetValueTag(external, type->ref.type->ref.marker);
|
|
1091
1071
|
|
|
1092
1072
|
array.Set(i, external);
|
|
1093
1073
|
} else {
|
|
@@ -1132,7 +1112,6 @@ Napi::Value DecodeArray(Napi::Env env, const uint8_t *origin, const TypeInfo *ty
|
|
|
1132
1112
|
void DecodeNormalArray(Napi::Array array, const uint8_t *origin, const TypeInfo *ref)
|
|
1133
1113
|
{
|
|
1134
1114
|
Napi::Env env = array.Env();
|
|
1135
|
-
InstanceData *instance = env.GetInstanceData<InstanceData>();
|
|
1136
1115
|
|
|
1137
1116
|
K_ASSERT(array.IsArray());
|
|
1138
1117
|
|
|
@@ -1247,7 +1226,7 @@ void DecodeNormalArray(Napi::Array array, const uint8_t *origin, const TypeInfo
|
|
|
1247
1226
|
|
|
1248
1227
|
if (ptr2) {
|
|
1249
1228
|
Napi::External<void> external = Napi::External<void>::New(env, ptr2);
|
|
1250
|
-
SetValueTag(
|
|
1229
|
+
SetValueTag(external, ref->ref.marker);
|
|
1251
1230
|
|
|
1252
1231
|
array.Set(i, external);
|
|
1253
1232
|
} else {
|
|
@@ -1322,6 +1301,10 @@ Napi::Value Decode(Napi::Value value, Size offset, const TypeInfo *type, const S
|
|
|
1322
1301
|
} else if (IsRawBuffer(value)) {
|
|
1323
1302
|
Span<uint8_t> buffer = GetRawBuffer(value);
|
|
1324
1303
|
|
|
1304
|
+
if (offset < 0) [[unlikely]] {
|
|
1305
|
+
ThrowError<Napi::Error>(env, "Offset must be >= 0");
|
|
1306
|
+
return env.Null();
|
|
1307
|
+
}
|
|
1325
1308
|
if (buffer.len - offset < type->size) [[unlikely]] {
|
|
1326
1309
|
ThrowError<Napi::Error>(env, "Expected buffer with size superior or equal to type %1 (%2 bytes)",
|
|
1327
1310
|
type->name, type->size + offset);
|
|
@@ -1354,12 +1337,12 @@ Napi::Value Decode(Napi::Env env, const uint8_t *ptr, const TypeInfo *type, cons
|
|
|
1354
1337
|
type = MakeArrayType(instance, type, *len);
|
|
1355
1338
|
} else {
|
|
1356
1339
|
switch (type->primitive) {
|
|
1357
|
-
case PrimitiveKind::Int8:
|
|
1340
|
+
case PrimitiveKind::Int8:
|
|
1358
1341
|
case PrimitiveKind::UInt8: {
|
|
1359
1342
|
Size count = strlen((const char *)ptr);
|
|
1360
1343
|
type = MakeArrayType(instance, type, count);
|
|
1361
1344
|
} break;
|
|
1362
|
-
case PrimitiveKind::Int16:
|
|
1345
|
+
case PrimitiveKind::Int16:
|
|
1363
1346
|
case PrimitiveKind::UInt16: {
|
|
1364
1347
|
Size count = NullTerminatedLength((const char16_t *)ptr, K_SIZE_MAX);
|
|
1365
1348
|
type = MakeArrayType(instance, type, count);
|
|
@@ -1513,6 +1496,10 @@ bool Encode(Napi::Value ref, Size offset, Napi::Value value, const TypeInfo *typ
|
|
|
1513
1496
|
} else if (IsRawBuffer(ref)) {
|
|
1514
1497
|
Span<uint8_t> buffer = GetRawBuffer(ref);
|
|
1515
1498
|
|
|
1499
|
+
if (offset < 0) [[unlikely]] {
|
|
1500
|
+
ThrowError<Napi::Error>(env, "Offset must be >= 0");
|
|
1501
|
+
return env.Null();
|
|
1502
|
+
}
|
|
1516
1503
|
if (buffer.len - offset < type->size) [[unlikely]] {
|
|
1517
1504
|
ThrowError<Napi::Error>(env, "Expected buffer with size superior or equal to type %1 (%2 bytes)",
|
|
1518
1505
|
type->name, type->size + offset);
|
|
@@ -1521,7 +1508,7 @@ bool Encode(Napi::Value ref, Size offset, Napi::Value value, const TypeInfo *typ
|
|
|
1521
1508
|
|
|
1522
1509
|
ptr = (uint8_t *)buffer.ptr;
|
|
1523
1510
|
} else {
|
|
1524
|
-
ThrowError<Napi::TypeError>(env, "Unexpected %1 value for reference, expected external or TypedArray", GetValueType(instance,
|
|
1511
|
+
ThrowError<Napi::TypeError>(env, "Unexpected %1 value for reference, expected external or TypedArray", GetValueType(instance, ref));
|
|
1525
1512
|
return env.Null();
|
|
1526
1513
|
}
|
|
1527
1514
|
|
|
@@ -1676,7 +1663,7 @@ bool Encode(Napi::Env env, uint8_t *origin, Napi::Value value, const TypeInfo *t
|
|
|
1676
1663
|
if (value.IsFunction()) {
|
|
1677
1664
|
ThrowError<Napi::Error>(env, "Cannot encode non-registered callback");
|
|
1678
1665
|
return false;
|
|
1679
|
-
} else if (CheckValueTag(
|
|
1666
|
+
} else if (CheckValueTag(value, type->ref.marker)) {
|
|
1680
1667
|
ptr = value.As<Napi::External<void>>().Data();
|
|
1681
1668
|
} else if (IsNullOrUndefined(value)) {
|
|
1682
1669
|
ptr = nullptr;
|
|
@@ -1715,8 +1702,6 @@ bool Encode(Napi::Env env, uint8_t *origin, Napi::Value value, const TypeInfo *t
|
|
|
1715
1702
|
|
|
1716
1703
|
Napi::Function WrapFunction(Napi::Env env, const FunctionInfo *func)
|
|
1717
1704
|
{
|
|
1718
|
-
InstanceData *instance = env.GetInstanceData<InstanceData>();
|
|
1719
|
-
|
|
1720
1705
|
Napi::Function wrapper;
|
|
1721
1706
|
if (func->variadic) {
|
|
1722
1707
|
Napi::Function::Callback call = TranslateVariadicCall;
|
|
@@ -1742,11 +1727,11 @@ Napi::Function WrapFunction(Napi::Env env, const FunctionInfo *func)
|
|
|
1742
1727
|
|
|
1743
1728
|
meta.Set("name", Napi::String::New(env, func->name));
|
|
1744
1729
|
meta.Set("arguments", arguments);
|
|
1745
|
-
meta.Set("result", WrapType(env,
|
|
1730
|
+
meta.Set("result", WrapType(env, func->ret.type));
|
|
1746
1731
|
|
|
1747
1732
|
for (Size i = 0; i < func->parameters.len; i++) {
|
|
1748
1733
|
const ParameterInfo ¶m = func->parameters[i];
|
|
1749
|
-
arguments.Set((uint32_t)i, WrapType(env,
|
|
1734
|
+
arguments.Set((uint32_t)i, WrapType(env, param.type));
|
|
1750
1735
|
}
|
|
1751
1736
|
|
|
1752
1737
|
wrapper.Set("info", meta);
|
|
@@ -1811,11 +1796,11 @@ void DumpMemory(const char *type, Span<const uint8_t> bytes)
|
|
|
1811
1796
|
PrintLn(StdErr, "%1 at 0x%2 (%3):", type, bytes.ptr, FmtMemSize(bytes.len));
|
|
1812
1797
|
|
|
1813
1798
|
for (const uint8_t *ptr = bytes.begin(); ptr < bytes.end();) {
|
|
1814
|
-
Print(StdErr, " [0x%1 %2 %3] ",
|
|
1815
|
-
|
|
1816
|
-
|
|
1799
|
+
Print(StdErr, " [0x%1 %2 %3] ", FmtInt((uintptr_t)ptr, 16),
|
|
1800
|
+
FmtInt((ptr - bytes.begin()) / sizeof(void *), 4, ' '),
|
|
1801
|
+
FmtInt(ptr - bytes.begin(), 4, ' '));
|
|
1817
1802
|
for (int i = 0; ptr < bytes.end() && i < (int)sizeof(void *); i++, ptr++) {
|
|
1818
|
-
Print(StdErr, " %1", FmtHex(*ptr
|
|
1803
|
+
Print(StdErr, " %1", FmtHex(*ptr, 2));
|
|
1819
1804
|
}
|
|
1820
1805
|
PrintLn(StdErr);
|
|
1821
1806
|
}
|
package/src/koffi/src/util.hh
CHANGED
|
@@ -1,27 +1,9 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
3
|
-
// Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
4
|
-
// this software and associated documentation files (the “Software”), to deal in
|
|
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.
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
// SPDX-FileCopyrightText: 2025 Niels Martignène <niels.martignene@protonmail.com>
|
|
21
3
|
|
|
22
4
|
#pragma once
|
|
23
5
|
|
|
24
|
-
#include "
|
|
6
|
+
#include "lib/native/base/base.hh"
|
|
25
7
|
#include "ffi.hh"
|
|
26
8
|
|
|
27
9
|
#include <napi.h>
|
|
@@ -94,7 +76,7 @@ TypeInfo *MakePointerType(InstanceData *instance, const TypeInfo *ref, int count
|
|
|
94
76
|
TypeInfo *MakeArrayType(InstanceData *instance, const TypeInfo *ref, Size len);
|
|
95
77
|
TypeInfo *MakeArrayType(InstanceData *instance, const TypeInfo *ref, Size len, ArrayHint hint);
|
|
96
78
|
|
|
97
|
-
Napi::External<TypeInfo> WrapType(Napi::Env env,
|
|
79
|
+
Napi::External<TypeInfo> WrapType(Napi::Env env, const TypeInfo *type);
|
|
98
80
|
|
|
99
81
|
bool CanPassType(const TypeInfo *type, int directions);
|
|
100
82
|
bool CanReturnType(const TypeInfo *type);
|
|
@@ -103,8 +85,8 @@ bool CanStoreType(const TypeInfo *type);
|
|
|
103
85
|
// Can be slow, only use for error messages
|
|
104
86
|
const char *GetValueType(const InstanceData *instance, Napi::Value value);
|
|
105
87
|
|
|
106
|
-
void SetValueTag(
|
|
107
|
-
bool CheckValueTag(
|
|
88
|
+
void SetValueTag(Napi::Value value, const void *marker);
|
|
89
|
+
bool CheckValueTag(Napi::Value value, const void *marker);
|
|
108
90
|
|
|
109
91
|
static inline bool IsNullOrUndefined(Napi::Value value)
|
|
110
92
|
{
|