koffi 2.14.1 → 2.15.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/build/koffi/darwin_arm64/koffi.node +0 -0
  3. package/build/koffi/darwin_x64/koffi.node +0 -0
  4. package/build/koffi/freebsd_arm64/koffi.node +0 -0
  5. package/build/koffi/freebsd_ia32/koffi.node +0 -0
  6. package/build/koffi/freebsd_x64/koffi.node +0 -0
  7. package/build/koffi/linux_arm64/koffi.node +0 -0
  8. package/build/koffi/linux_armhf/koffi.node +0 -0
  9. package/build/koffi/linux_ia32/koffi.node +0 -0
  10. package/build/koffi/linux_loong64/koffi.node +0 -0
  11. package/build/koffi/linux_riscv64d/koffi.node +0 -0
  12. package/build/koffi/linux_x64/koffi.node +0 -0
  13. package/build/koffi/musl_arm64/koffi.node +0 -0
  14. package/build/koffi/musl_x64/koffi.node +0 -0
  15. package/build/koffi/openbsd_ia32/koffi.node +0 -0
  16. package/build/koffi/openbsd_x64/koffi.node +0 -0
  17. package/build/koffi/win32_arm64/koffi.node +0 -0
  18. package/build/koffi/win32_ia32/koffi.node +0 -0
  19. package/build/koffi/win32_x64/koffi.node +0 -0
  20. package/doc/assets.ini +2 -1
  21. package/doc/build.sh +9 -0
  22. package/doc/pages/404.md +17 -0
  23. package/doc/pages/index.md +5 -3
  24. package/doc/pages/misc.md +18 -11
  25. package/doc/pages.ini +4 -0
  26. package/doc/static/highlight.js +2 -14
  27. package/doc/static/koffi.css +3 -15
  28. package/doc/static/print.css +2 -14
  29. package/doc/templates/code.html +1 -2
  30. package/doc/templates/page.html +1 -2
  31. package/index.d.ts +29 -24
  32. package/index.js +9 -9
  33. package/indirect.js +9 -9
  34. package/{src/core → lib/native}/base/base.cc +1137 -674
  35. package/{src/core → lib/native}/base/base.hh +362 -195
  36. package/{src/core → lib/native}/base/crc.inc +2 -20
  37. package/lib/native/base/crc_gen.py +72 -0
  38. package/{src/core → lib/native}/base/mimetypes.inc +2 -20
  39. package/{src/core → lib/native}/base/mimetypes_gen.py +2 -21
  40. package/lib/native/base/tower.cc +821 -0
  41. package/lib/native/base/tower.hh +81 -0
  42. package/{src/core → lib/native}/base/unicode.inc +2 -20
  43. package/{src/core → lib/native}/base/unicode_gen.py +4 -41
  44. package/package.json +2 -2
  45. package/src/cnoke/assets/FindCNoke.cmake +24 -30
  46. package/src/cnoke/assets/win_delay_hook.c +6 -20
  47. package/src/cnoke/cnoke.js +2 -21
  48. package/src/cnoke/src/builder.js +51 -66
  49. package/src/cnoke/src/index.js +2 -20
  50. package/src/cnoke/src/tools.js +2 -20
  51. package/src/koffi/CMakeLists.txt +30 -23
  52. package/src/koffi/cmake/raylib.cmake +5 -22
  53. package/src/koffi/cmake/sqlite3.cmake +2 -20
  54. package/src/koffi/src/abi_arm32.cc +7 -25
  55. package/src/koffi/src/abi_arm32_asm.S +2 -20
  56. package/src/koffi/src/abi_arm64.cc +7 -25
  57. package/src/koffi/src/abi_arm64_asm.S +2 -20
  58. package/src/koffi/src/abi_arm64_asm.asm +2 -20
  59. package/src/koffi/src/abi_loong64.cc +2 -20
  60. package/src/koffi/src/abi_loong64_asm.S +2 -20
  61. package/src/koffi/src/abi_riscv64.cc +7 -25
  62. package/src/koffi/src/abi_riscv64_asm.S +2 -20
  63. package/src/koffi/src/abi_x64_sysv.cc +7 -25
  64. package/src/koffi/src/abi_x64_sysv_asm.S +2 -20
  65. package/src/koffi/src/abi_x64_win.cc +12 -30
  66. package/src/koffi/src/abi_x64_win_asm.S +162 -0
  67. package/src/koffi/src/abi_x64_win_asm.asm +2 -20
  68. package/src/koffi/src/abi_x86.cc +7 -25
  69. package/src/koffi/src/abi_x86_asm.S +2 -20
  70. package/src/koffi/src/abi_x86_asm.asm +2 -20
  71. package/src/koffi/src/call.cc +25 -45
  72. package/src/koffi/src/call.hh +3 -21
  73. package/src/koffi/src/errno.inc +2 -20
  74. package/src/koffi/src/ffi.cc +64 -63
  75. package/src/koffi/src/ffi.hh +15 -30
  76. package/src/koffi/src/init.js +2 -20
  77. package/src/koffi/src/parser.cc +13 -27
  78. package/src/koffi/src/parser.hh +3 -21
  79. package/src/koffi/src/trampolines/armasm.inc +0 -21
  80. package/src/koffi/src/trampolines/gnu.inc +0 -21
  81. package/src/koffi/src/trampolines/masm32.inc +0 -21
  82. package/src/koffi/src/trampolines/masm64.inc +0 -21
  83. package/src/koffi/src/trampolines/prototypes.inc +0 -21
  84. package/src/koffi/src/util.cc +50 -64
  85. package/src/koffi/src/util.hh +8 -25
  86. package/src/koffi/src/uv.cc +193 -0
  87. package/src/koffi/src/uv.def +10 -0
  88. package/src/koffi/src/uv.hh +40 -0
  89. package/src/koffi/src/win32.cc +2 -20
  90. package/src/koffi/src/win32.hh +3 -21
  91. package/vendor/node-api-headers/CHANGELOG.md +22 -0
  92. package/vendor/node-api-headers/README.md +6 -17
  93. package/vendor/node-api-headers/include/js_native_api.h +3 -13
  94. package/vendor/node-api-headers/include/js_native_api_types.h +15 -0
  95. package/vendor/node-api-headers/include/node_api.h +0 -4
  96. package/vendor/node-api-headers/include/node_api_types.h +6 -0
  97. package/vendor/node-api-headers/include/uv/aix.h +32 -0
  98. package/vendor/node-api-headers/include/uv/bsd.h +34 -0
  99. package/vendor/node-api-headers/include/uv/darwin.h +61 -0
  100. package/vendor/node-api-headers/include/uv/errno.h +483 -0
  101. package/vendor/node-api-headers/include/uv/linux.h +34 -0
  102. package/vendor/node-api-headers/include/uv/os390.h +33 -0
  103. package/vendor/node-api-headers/include/uv/posix.h +31 -0
  104. package/vendor/node-api-headers/include/uv/sunos.h +44 -0
  105. package/vendor/node-api-headers/include/uv/threadpool.h +37 -0
  106. package/vendor/node-api-headers/include/uv/tree.h +521 -0
  107. package/vendor/node-api-headers/include/uv/unix.h +512 -0
  108. package/vendor/node-api-headers/include/uv/version.h +43 -0
  109. package/vendor/node-api-headers/include/uv/win.h +698 -0
  110. package/vendor/node-api-headers/include/uv.h +1990 -0
  111. package/vendor/node-api-headers/package.json +1 -1
  112. package/vendor/node-api-headers/scripts/update-headers.js +6 -0
  113. package/src/core/base/crc_gen.py +0 -109
@@ -0,0 +1,162 @@
1
+ # SPDX-License-Identifier: MIT
2
+ # SPDX-FileCopyrightText: 2025 Niels Martignène <niels.martignene@protonmail.com>
3
+
4
+ #define SYMBOL(Symbol) Symbol
5
+
6
+ # Forward
7
+ # ----------------------------
8
+
9
+ .global ForwardCallG
10
+ .global ForwardCallF
11
+ .global ForwardCallD
12
+ .global ForwardCallXG
13
+ .global ForwardCallXF
14
+ .global ForwardCallXD
15
+
16
+ # Copy function pointer to RAX, in order to save it through argument forwarding.
17
+ # Also make a copy of the SP to CallData::old_sp because the callback system might need it.
18
+ # Save RSP in RBX (non-volatile), and use carefully assembled stack provided by caller.
19
+ .macro prologue
20
+ endbr64
21
+ movq %rcx, %rax
22
+ push %rbp
23
+ movq %rsp, %rbp
24
+ movq %rsp, (%r8)
25
+ movq %rdx, %rsp
26
+ .endm
27
+
28
+ # Call native function.
29
+ # Once done, restore normal stack pointer and return.
30
+ # The return value is passed untouched through RAX or XMM0.
31
+ .macro epilogue
32
+ call *%rax
33
+ movq %rbp, %rsp
34
+ pop %rbp
35
+ ret
36
+ .endm
37
+
38
+ # Prepare integer argument registers from array passed by caller.
39
+ .macro forward_gpr
40
+ movq 24(%rdx), %r9
41
+ movq 16(%rdx), %r8
42
+ movq 0(%rdx), %rcx
43
+ movq 8(%rdx), %rdx
44
+ .endm
45
+
46
+ # Prepare XMM argument registers from array passed by caller.
47
+ .macro forward_xmm
48
+ movsd 24(%rdx), %xmm3
49
+ movsd 16(%rdx), %xmm2
50
+ movsd 8(%rdx), %xmm1
51
+ movsd 0(%rdx), %xmm0
52
+ .endm
53
+
54
+ ForwardCallG:
55
+ prologue
56
+ forward_gpr
57
+ epilogue
58
+
59
+ ForwardCallF:
60
+ prologue
61
+ forward_gpr
62
+ epilogue
63
+
64
+ ForwardCallD:
65
+ prologue
66
+ forward_gpr
67
+ epilogue
68
+
69
+ ForwardCallXG:
70
+ prologue
71
+ forward_xmm
72
+ forward_gpr
73
+ epilogue
74
+
75
+ ForwardCallXF:
76
+ prologue
77
+ forward_xmm
78
+ forward_gpr
79
+ epilogue
80
+
81
+ ForwardCallXD:
82
+ prologue
83
+ forward_xmm
84
+ forward_gpr
85
+ epilogue
86
+
87
+ # Callbacks
88
+ # ----------------------------
89
+
90
+ .global RelayCallback
91
+ .global CallSwitchStack
92
+
93
+ # First, make a copy of the GPR argument registers (rcx, rdx, r8, r9).
94
+ # Then call the C function RelayCallback with the following arguments:
95
+ # static trampoline ID, a pointer to the saved GPR array, a pointer to the stack
96
+ # arguments of this call, and a pointer to a struct that will contain the result registers.
97
+ # After the call, simply load these registers from the output struct.
98
+ .macro trampoline id
99
+ endbr64
100
+ subq $120, %rsp
101
+ movq %rcx, 32(%rsp)
102
+ movq %rdx, 40(%rsp)
103
+ movq %r8, 48(%rsp)
104
+ movq %r9, 56(%rsp)
105
+ movq $\id, %rcx
106
+ leaq 32(%rsp), %rdx
107
+ leaq 160(%rsp), %r8
108
+ leaq 96(%rsp), %r9
109
+ call RelayCallback
110
+ movq 96(%rsp), %rax
111
+ addq $120, %rsp
112
+ ret
113
+ .endm
114
+
115
+ # Same thing, but also forward the XMM argument registers and load the XMM result registers.
116
+ .macro trampoline_vec id
117
+ endbr64
118
+ subq $120, %rsp
119
+ movq %rcx, 32(%rsp)
120
+ movq %rdx, 40(%rsp)
121
+ movq %r8, 48(%rsp)
122
+ movq %r9, 56(%rsp)
123
+ movsd %xmm0, 64(%rsp)
124
+ movsd %xmm1, 72(%rsp)
125
+ movsd %xmm2, 80(%rsp)
126
+ movsd %xmm3, 88(%rsp)
127
+ movq $\id, %rcx
128
+ leaq 32(%rsp), %rdx
129
+ leaq 160(%rsp), %r8
130
+ leaq 96(%rsp), %r9
131
+ call RelayCallback
132
+ movq 96(%rsp), %rax
133
+ movsd 104(%rsp), %xmm0
134
+ addq $120, %rsp
135
+ ret
136
+ .endm
137
+
138
+ # When a callback is relayed, Koffi will call into Node.js and V8 to execute Javascript.
139
+ # The problem is that we're still running on the separate Koffi stack, and V8 will
140
+ # probably misdetect this as a "stack overflow". We have to restore the old
141
+ # stack pointer, call Node.js/V8 and go back to ours.
142
+ # The first three parameters (rcx, rdx, r8) are passed through untouched.
143
+ CallSwitchStack:
144
+ endbr64
145
+ push %rbp
146
+ movq %rsp, %rbp
147
+ movq 56(%rsp), %rax
148
+ movq %rsp, %r10
149
+ movq 48(%rsp), %r11
150
+ subq 0(%r11), %r10
151
+ andq $-16, %r10
152
+ movq %r10, 8(%r11)
153
+ leaq -32(%r9), %rsp
154
+ call *%rax
155
+ movq %rbp, %rsp
156
+ pop %rbp
157
+ ret
158
+
159
+ # Trampolines
160
+ # ----------------------------
161
+
162
+ #include "trampolines/gnu.inc"
@@ -1,23 +1,5 @@
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.
1
+ ; SPDX-License-Identifier: MIT
2
+ ; SPDX-FileCopyrightText: 2025 Niels Martignène <niels.martignene@protonmail.com>
21
3
 
22
4
  ; Forward
23
5
  ; ----------------------------
@@ -1,27 +1,9 @@
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.
1
+ // SPDX-License-Identifier: MIT
2
+ // SPDX-FileCopyrightText: 2025 Niels Martignène <niels.martignene@protonmail.com>
21
3
 
22
4
  #if defined(__i386__) || defined(_M_IX86)
23
5
 
24
- #include "src/core/base/base.hh"
6
+ #include "lib/native/base/base.hh"
25
7
  #include "ffi.hh"
26
8
  #include "call.hh"
27
9
  #include "util.hh"
@@ -438,7 +420,7 @@ Napi::Value CallData::Complete(const FunctionInfo *func)
438
420
  case PrimitiveKind::Callback: {
439
421
  if (result.ptr) {
440
422
  Napi::External<void> external = Napi::External<void>::New(env, result.ptr);
441
- SetValueTag(instance, external, func->ret.type->ref.marker);
423
+ SetValueTag(external, func->ret.type->ref.marker);
442
424
 
443
425
  return external;
444
426
  } else {
@@ -660,7 +642,7 @@ void CallData::Relay(Size idx, uint8_t *, uint8_t *caller_sp, bool switch_stack,
660
642
 
661
643
  if (ptr2) {
662
644
  Napi::External<void> external = Napi::External<void>::New(env, ptr2);
663
- SetValueTag(instance, external, param.type->ref.marker);
645
+ SetValueTag(external, param.type->ref.marker);
664
646
 
665
647
  arguments.Append(external);
666
648
  } else {
@@ -810,7 +792,7 @@ void CallData::Relay(Size idx, uint8_t *, uint8_t *caller_sp, bool switch_stack,
810
792
  case PrimitiveKind::Pointer: {
811
793
  uint8_t *ptr;
812
794
 
813
- if (CheckValueTag(instance, value, type->ref.marker)) {
795
+ if (CheckValueTag(value, type->ref.marker)) {
814
796
  ptr = value.As<Napi::External<uint8_t>>().Data();
815
797
  } else if (IsObject(value) && (type->ref.type->primitive == PrimitiveKind::Record ||
816
798
  type->ref.type->primitive == PrimitiveKind::Union)) {
@@ -874,7 +856,7 @@ void CallData::Relay(Size idx, uint8_t *, uint8_t *caller_sp, bool switch_stack,
874
856
  ptr = ReserveTrampoline(type->ref.proto, func2);
875
857
  if (!ptr) [[unlikely]]
876
858
  return;
877
- } else if (CheckValueTag(instance, value, type->ref.marker)) {
859
+ } else if (CheckValueTag(value, type->ref.marker)) {
878
860
  ptr = value.As<Napi::External<void>>().Data();
879
861
  } else if (IsNullOrUndefined(value)) {
880
862
  ptr = nullptr;
@@ -1,23 +1,5 @@
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.
1
+ # SPDX-License-Identifier: MIT
2
+ # SPDX-FileCopyrightText: 2025 Niels Martignène <niels.martignene@protonmail.com>
21
3
 
22
4
  #define SYMBOL(Symbol) Symbol
23
5
 
@@ -1,23 +1,5 @@
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.
1
+ ; SPDX-License-Identifier: MIT
2
+ ; SPDX-FileCopyrightText: 2025 Niels Martignène <niels.martignene@protonmail.com>
21
3
 
22
4
  ; Forward
23
5
  ; ----------------------------
@@ -1,25 +1,7 @@
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
- #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"
@@ -88,15 +70,7 @@ void CallData::Dispose()
88
70
  }
89
71
  }
90
72
 
91
- instance->temporaries -= mem->temporary;
92
-
93
- if (!--mem->depth) {
94
- mem->busy = false;
95
-
96
- if (mem->temporary) {
97
- delete mem;
98
- }
99
- }
73
+ ReleaseMemory(instance, mem);
100
74
 
101
75
  instance = nullptr;
102
76
  }
@@ -264,6 +238,8 @@ Size CallData::PushString16Value(Napi::Value value, const char16_t **out_str16)
264
238
 
265
239
  Size CallData::PushString32Value(Napi::Value value, const char32_t **out_str32)
266
240
  {
241
+ static const char32_t ReplacementChar = 0x0000FFFD;
242
+
267
243
  Span<char32_t> buf;
268
244
 
269
245
  Span<const char16_t> buf16;
@@ -287,15 +263,19 @@ Size CallData::PushString32Value(Napi::Value value, const char32_t **out_str32)
287
263
  char32_t uc = buf16[i];
288
264
 
289
265
  if (uc >= 0xD800 && uc <= 0xDBFF) {
290
- char16_t uc2 = buf16.ptr[++i];
266
+ if (++i < buf16.len) {
267
+ char16_t uc2 = buf16.ptr[i];
291
268
 
292
- if (uc2 >= 0xDC00 && uc2 <= 0xDFFF) {
293
- uc = ((uc - 0xD800) << 10) + (uc2 - 0xDC00) + 0x10000u;
269
+ if (uc2 >= 0xDC00 && uc2 <= 0xDFFF) [[likely]] {
270
+ uc = ((uc - 0xD800) << 10) + (uc2 - 0xDC00) + 0x10000u;
271
+ } else {
272
+ uc = ReplacementChar;
273
+ }
294
274
  } else {
295
- uc = '?';
275
+ uc = ReplacementChar;
296
276
  }
297
- } else if (uc >= 0xDC00 && uc <= 0xDFFF) {
298
- uc = '?';
277
+ } else if (uc >= 0xDC00 && uc <= 0xDFFF) [[unlikely]] {
278
+ uc = ReplacementChar;
299
279
  }
300
280
 
301
281
  buf[j++] = uc;
@@ -316,7 +296,7 @@ bool CallData::PushObject(Napi::Object obj, const TypeInfo *type, uint8_t *origi
316
296
  if (type->primitive == PrimitiveKind::Record) {
317
297
  members = type->members;
318
298
  } else if (type->primitive == PrimitiveKind::Union) {
319
- if (CheckValueTag(instance, obj, &MagicUnionMarker)) {
299
+ if (CheckValueTag(obj, &MagicUnionMarker)) {
320
300
  MagicUnion *u = MagicUnion::Unwrap(obj);
321
301
  const uint8_t *raw = u->GetRaw();
322
302
 
@@ -909,7 +889,7 @@ bool CallData::PushStringArray(Napi::Value obj, const TypeInfo *type, uint8_t *o
909
889
 
910
890
  bool CallData::PushPointer(Napi::Value value, const TypeInfo *type, int directions, void **out_ptr)
911
891
  {
912
- if (CheckValueTag(instance, value, &CastMarker)) {
892
+ if (CheckValueTag(value, &CastMarker)) {
913
893
  Napi::External<ValueCast> external = value.As<Napi::External<ValueCast>>();
914
894
  ValueCast *cast = external.Data();
915
895
 
@@ -932,8 +912,8 @@ bool CallData::PushPointer(Napi::Value value, const TypeInfo *type, int directio
932
912
  type->primitive == PrimitiveKind::String16 ||
933
913
  type->primitive == PrimitiveKind::String32);
934
914
 
935
- if (!CheckValueTag(instance, value, type->ref.marker) &&
936
- !CheckValueTag(instance, value, instance->void_type) &&
915
+ if (!CheckValueTag(value, type->ref.marker) &&
916
+ !CheckValueTag(value, instance->void_type) &&
937
917
  ref != instance->void_type) [[unlikely]]
938
918
  goto unexpected;
939
919
 
@@ -1000,7 +980,7 @@ bool CallData::PushPointer(Napi::Value value, const TypeInfo *type, int directio
1000
980
  ptr = AllocHeap(ref->size, 16);
1001
981
 
1002
982
  if (ref->primitive == PrimitiveKind::Union &&
1003
- (directions & 2) && !CheckValueTag(instance, obj, &MagicUnionMarker)) [[unlikely]] {
983
+ (directions & 2) && !CheckValueTag(obj, &MagicUnionMarker)) [[unlikely]] {
1004
984
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected union value", GetValueType(instance, obj));
1005
985
  return false;
1006
986
  }
@@ -1108,9 +1088,9 @@ bool CallData::PushCallback(Napi::Value value, const TypeInfo *type, void **out_
1108
1088
  return false;
1109
1089
 
1110
1090
  *out_ptr = ptr;
1111
- } else if (CheckValueTag(instance, value, type->ref.marker)) {
1091
+ } else if (CheckValueTag(value, type->ref.marker)) {
1112
1092
  *out_ptr = value.As<Napi::External<void>>().Data();
1113
- } else if (CheckValueTag(instance, value, &CastMarker)) {
1093
+ } else if (CheckValueTag(value, &CastMarker)) {
1114
1094
  Napi::External<ValueCast> external = value.As<Napi::External<ValueCast>>();
1115
1095
  ValueCast *cast = external.Data();
1116
1096
 
@@ -1324,7 +1304,7 @@ void CallData::PopOutArguments()
1324
1304
  case OutArgument::Kind::Object: {
1325
1305
  Napi::Object obj = value.As<Napi::Object>();
1326
1306
 
1327
- if (CheckValueTag(instance, value, &MagicUnionMarker)) {
1307
+ if (CheckValueTag(value, &MagicUnionMarker)) {
1328
1308
  MagicUnion *u = MagicUnion::Unwrap(obj);
1329
1309
  u->SetRaw(out.ptr);
1330
1310
  } else {
@@ -1,27 +1,9 @@
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.
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 "src/core/base/base.hh"
6
+ #include "lib/native/base/base.hh"
25
7
  #include "ffi.hh"
26
8
  #include "util.hh"
27
9
 
@@ -1,23 +1,5 @@
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.
1
+ // SPDX-License-Identifier: MIT
2
+ // SPDX-FileCopyrightText: 2025 Niels Martignène <niels.martignene@protonmail.com>
21
3
 
22
4
  #include <errno.h>
23
5