koffi 2.12.0 → 2.12.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (188) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/LICENSE.txt +2 -2
  3. package/README.md +8 -8
  4. package/build/koffi/darwin_arm64/koffi.node +0 -0
  5. package/build/koffi/darwin_x64/koffi.node +0 -0
  6. package/build/koffi/freebsd_arm64/koffi.node +0 -0
  7. package/build/koffi/freebsd_ia32/koffi.node +0 -0
  8. package/build/koffi/freebsd_x64/koffi.node +0 -0
  9. package/build/koffi/linux_arm64/koffi.node +0 -0
  10. package/build/koffi/linux_armhf/koffi.node +0 -0
  11. package/build/koffi/linux_ia32/koffi.node +0 -0
  12. package/build/koffi/linux_loong64/koffi.node +0 -0
  13. package/build/koffi/linux_riscv64d/koffi.node +0 -0
  14. package/build/koffi/linux_x64/koffi.node +0 -0
  15. package/build/koffi/musl_arm64/koffi.node +0 -0
  16. package/build/koffi/musl_x64/koffi.node +0 -0
  17. package/build/koffi/openbsd_ia32/koffi.node +0 -0
  18. package/build/koffi/openbsd_x64/koffi.node +0 -0
  19. package/build/koffi/win32_arm64/koffi.exp +0 -0
  20. package/build/koffi/win32_arm64/koffi.node +0 -0
  21. package/build/koffi/win32_ia32/koffi.exp +0 -0
  22. package/build/koffi/win32_ia32/koffi.node +0 -0
  23. package/build/koffi/win32_x64/koffi.exp +0 -0
  24. package/build/koffi/win32_x64/koffi.node +0 -0
  25. package/doc/assets.ini +3 -3
  26. package/doc/develop.sh +4 -3
  27. package/doc/pages/platforms.md +1 -1
  28. package/doc/static/highlight.js +1 -1
  29. package/doc/static/koffi.css +3 -2
  30. package/doc/static/print.css +1 -1
  31. package/doc/templates/code.html +5 -5
  32. package/doc/templates/page.html +4 -4
  33. package/index.d.ts +2 -2
  34. package/index.js +25 -25
  35. package/indirect.js +25 -5
  36. package/package.json +2 -2
  37. package/src/cnoke/LICENSE.txt +2 -2
  38. package/src/cnoke/README.md +2 -0
  39. package/src/cnoke/assets/FindCNoke.cmake +12 -2
  40. package/src/cnoke/assets/win_delay_hook.c +4 -4
  41. package/src/cnoke/cnoke.js +4 -2
  42. package/src/cnoke/package.json +1 -1
  43. package/src/cnoke/src/builder.js +11 -14
  44. package/src/cnoke/src/index.js +2 -2
  45. package/src/cnoke/src/tools.js +34 -2
  46. package/src/core/{libcc/libcc.cc → base/base.cc} +3092 -1674
  47. package/src/core/{libcc/libcc.hh → base/base.hh} +3059 -2432
  48. package/src/core/{libcc → base}/mimetypes.inc +42 -4
  49. package/src/core/{libcc → base}/mimetypes_gen.py +3 -3
  50. package/src/core/unicode/generate.py +124 -0
  51. package/src/core/unicode/xid.cc +52 -0
  52. package/src/core/unicode/xid.hh +29 -0
  53. package/src/core/unicode/xid.inc +465 -0
  54. package/src/koffi/CMakeLists.txt +8 -5
  55. package/src/koffi/cmake/raylib.cmake +6 -2
  56. package/src/koffi/cmake/{sqlite.cmake → sqlite3.cmake} +3 -3
  57. package/src/koffi/examples/electron-forge/forge.config.js +23 -3
  58. package/src/koffi/examples/electron-forge/package.json +18 -16
  59. package/src/koffi/src/abi_arm32.cc +8 -21
  60. package/src/koffi/src/abi_arm32_asm.S +2 -2
  61. package/src/koffi/src/abi_arm64.cc +46 -59
  62. package/src/koffi/src/abi_arm64_asm.S +4 -4
  63. package/src/koffi/src/abi_arm64_asm.asm +2 -2
  64. package/src/koffi/src/abi_loong64_asm.S +2 -2
  65. package/src/koffi/src/abi_riscv64.cc +6 -19
  66. package/src/koffi/src/abi_riscv64_asm.S +2 -2
  67. package/src/koffi/src/abi_x64_sysv.cc +4 -17
  68. package/src/koffi/src/abi_x64_sysv_asm.S +5 -5
  69. package/src/koffi/src/abi_x64_win.cc +4 -17
  70. package/src/koffi/src/abi_x64_win_asm.asm +2 -2
  71. package/src/koffi/src/abi_x86.cc +9 -22
  72. package/src/koffi/src/abi_x86_asm.S +2 -2
  73. package/src/koffi/src/abi_x86_asm.asm +2 -2
  74. package/src/koffi/src/call.cc +49 -42
  75. package/src/koffi/src/call.hh +9 -8
  76. package/src/koffi/src/errno.inc +152 -152
  77. package/src/koffi/src/ffi.cc +45 -39
  78. package/src/koffi/src/ffi.hh +6 -6
  79. package/src/koffi/src/init.js +1 -1
  80. package/src/koffi/src/parser.cc +6 -5
  81. package/src/koffi/src/parser.hh +3 -3
  82. package/src/koffi/src/trampolines/armasm.inc +2 -2
  83. package/src/koffi/src/trampolines/gnu.inc +2 -2
  84. package/src/koffi/src/trampolines/masm32.inc +2 -2
  85. package/src/koffi/src/trampolines/masm64.inc +2 -2
  86. package/src/koffi/src/trampolines/prototypes.inc +2 -2
  87. package/src/koffi/src/util.cc +9 -9
  88. package/src/koffi/src/util.hh +3 -3
  89. package/src/koffi/src/win32.cc +5 -5
  90. package/src/koffi/src/win32.hh +9 -9
  91. package/vendor/node-addon-api/CHANGELOG.md +97 -2
  92. package/vendor/node-addon-api/CONTRIBUTING.md +117 -7
  93. package/vendor/node-addon-api/README.md +25 -249
  94. package/vendor/node-addon-api/common.gypi +1 -0
  95. package/vendor/node-addon-api/doc/README.md +145 -0
  96. package/vendor/node-addon-api/doc/array_buffer.md +15 -15
  97. package/vendor/node-addon-api/doc/basic_env.md +200 -0
  98. package/vendor/node-addon-api/doc/buffer.md +24 -26
  99. package/vendor/node-addon-api/doc/cmake-js.md +19 -0
  100. package/vendor/node-addon-api/doc/{creating_a_release.md → contributing/creating_a_release.md} +16 -4
  101. package/vendor/node-addon-api/doc/env.md +11 -131
  102. package/vendor/node-addon-api/doc/error_handling.md +12 -0
  103. package/vendor/node-addon-api/doc/external.md +13 -4
  104. package/vendor/node-addon-api/doc/finalization.md +153 -0
  105. package/vendor/node-addon-api/doc/memory_management.md +1 -1
  106. package/vendor/node-addon-api/doc/object_wrap.md +19 -3
  107. package/vendor/node-addon-api/doc/promises.md +51 -0
  108. package/vendor/node-addon-api/doc/setup.md +29 -6
  109. package/vendor/node-addon-api/doc/value.md +13 -0
  110. package/vendor/node-addon-api/doc/version_management.md +2 -2
  111. package/vendor/node-addon-api/eslint.config.js +5 -0
  112. package/vendor/node-addon-api/index.js +2 -0
  113. package/vendor/node-addon-api/napi-inl.h +592 -166
  114. package/vendor/node-addon-api/napi.h +167 -59
  115. package/vendor/node-addon-api/node_addon_api.gyp +10 -0
  116. package/vendor/node-addon-api/noexcept.gypi +1 -1
  117. package/vendor/node-addon-api/package.json +10 -13
  118. package/vendor/node-addon-api/release-please-config.json +15 -0
  119. package/vendor/node-addon-api/test/addon_build/tpl/binding.gyp +2 -1
  120. package/vendor/node-addon-api/test/array_buffer.js +1 -1
  121. package/vendor/node-addon-api/test/async_context.js +2 -2
  122. package/vendor/node-addon-api/test/async_progress_queue_worker.js +3 -3
  123. package/vendor/node-addon-api/test/async_progress_worker.js +3 -3
  124. package/vendor/node-addon-api/test/async_worker.cc +15 -13
  125. package/vendor/node-addon-api/test/async_worker.js +5 -5
  126. package/vendor/node-addon-api/test/basic_types/value.cc +6 -0
  127. package/vendor/node-addon-api/test/basic_types/value.js +17 -0
  128. package/vendor/node-addon-api/test/binding.cc +8 -0
  129. package/vendor/node-addon-api/test/binding.gyp +23 -1
  130. package/vendor/node-addon-api/test/buffer.js +1 -2
  131. package/vendor/node-addon-api/test/common/index.js +1 -1
  132. package/vendor/node-addon-api/test/except_all.cc +22 -0
  133. package/vendor/node-addon-api/test/except_all.js +14 -0
  134. package/vendor/node-addon-api/test/exports.js +19 -0
  135. package/vendor/node-addon-api/test/finalizer_order.cc +152 -0
  136. package/vendor/node-addon-api/test/finalizer_order.js +98 -0
  137. package/vendor/node-addon-api/test/function.js +2 -2
  138. package/vendor/node-addon-api/test/function_reference.js +2 -2
  139. package/vendor/node-addon-api/test/globalObject/global_object_delete_property.cc +4 -4
  140. package/vendor/node-addon-api/test/globalObject/global_object_get_property.cc +4 -4
  141. package/vendor/node-addon-api/test/globalObject/global_object_has_own_property.cc +3 -3
  142. package/vendor/node-addon-api/test/globalObject/global_object_set_property.cc +5 -5
  143. package/vendor/node-addon-api/test/name.cc +10 -8
  144. package/vendor/node-addon-api/test/object/delete_property.cc +5 -5
  145. package/vendor/node-addon-api/test/object/get_property.cc +5 -5
  146. package/vendor/node-addon-api/test/object/has_own_property.cc +4 -4
  147. package/vendor/node-addon-api/test/object/has_property.cc +5 -5
  148. package/vendor/node-addon-api/test/object/object.cc +1 -1
  149. package/vendor/node-addon-api/test/object/set_property.cc +5 -5
  150. package/vendor/node-addon-api/test/object/subscript_operator.cc +3 -3
  151. package/vendor/node-addon-api/test/object_reference.cc +18 -18
  152. package/vendor/node-addon-api/test/promise.cc +75 -0
  153. package/vendor/node-addon-api/test/promise.js +23 -0
  154. package/vendor/node-addon-api/test/require_basic_finalizers/index.js +38 -0
  155. package/vendor/node-addon-api/test/require_basic_finalizers/tpl/addon.cc +12 -0
  156. package/vendor/node-addon-api/test/require_basic_finalizers/tpl/binding.gyp +48 -0
  157. package/vendor/node-addon-api/test/require_basic_finalizers/tpl/index.js +3 -0
  158. package/vendor/node-addon-api/test/require_basic_finalizers/tpl/package.json +11 -0
  159. package/vendor/node-addon-api/test/run_script.cc +1 -1
  160. package/vendor/node-addon-api/test/type_taggable.cc +1 -1
  161. package/vendor/node-addon-api/test/type_taggable.js +3 -4
  162. package/vendor/node-addon-api/test/typedarray.cc +28 -24
  163. package/vendor/node-addon-api/tools/conversion.js +1 -1
  164. package/vendor/node-api-headers/CHANGELOG.md +29 -0
  165. package/vendor/node-api-headers/CREATING_A_RELEASE.md +12 -2
  166. package/vendor/node-api-headers/def/js_native_api.def +6 -1
  167. package/vendor/node-api-headers/def/node_api.def +7 -1
  168. package/vendor/node-api-headers/include/js_native_api.h +56 -24
  169. package/vendor/node-api-headers/include/js_native_api_types.h +27 -0
  170. package/vendor/node-api-headers/include/node_api.h +38 -29
  171. package/vendor/node-api-headers/lib/parse-utils.js +92 -0
  172. package/vendor/node-api-headers/package.json +7 -7
  173. package/vendor/node-api-headers/release-please-config.json +12 -0
  174. package/vendor/node-api-headers/scripts/update-headers.js +63 -12
  175. package/vendor/node-api-headers/scripts/write-symbols.js +1 -1
  176. package/vendor/node-api-headers/symbols.js +17 -1
  177. package/vendor/node-api-headers/test/parse-utils.js +21 -0
  178. package/doc/flat/flat.css +0 -27
  179. package/doc/flat/normal.css +0 -429
  180. package/doc/flat/print.css +0 -29
  181. package/doc/flat/reset.css +0 -41
  182. package/doc/flat/small.css +0 -104
  183. package/doc/flat/static.js +0 -161
  184. package/src/core/libcc/brotli.cc +0 -186
  185. package/src/core/libcc/lz4.cc +0 -197
  186. package/src/core/libcc/miniz.cc +0 -353
  187. package/vendor/node-addon-api/tools/eslint-format.js +0 -79
  188. /package/vendor/node-api-headers/{scripts → lib}/clang-utils.js +0 -0
@@ -1,7 +1,7 @@
1
- // Copyright 2023 Niels Martignène <niels.martignene@protonmail.com>
1
+ // Copyright (C) 2025 Niels Martignène <niels.martignene@protonmail.com>
2
2
  //
3
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
4
+ // this software and associated documentation files (the “Software”), to deal in
5
5
  // the Software without restriction, including without limitation the rights to use,
6
6
  // copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
7
7
  // Software, and to permit persons to whom the Software is furnished to do so,
@@ -21,7 +21,7 @@
21
21
 
22
22
  #if defined(__x86_64__) && !defined(_WIN32)
23
23
 
24
- #include "src/core/libcc/libcc.hh"
24
+ #include "src/core/base/base.hh"
25
25
  #include "ffi.hh"
26
26
  #include "call.hh"
27
27
  #include "util.hh"
@@ -403,21 +403,8 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
403
403
  } break;
404
404
  case PrimitiveKind::Callback: {
405
405
  void *ptr;
406
-
407
- if (value.IsFunction()) {
408
- Napi::Function func = value.As<Napi::Function>();
409
-
410
- ptr = ReserveTrampoline(param.type->ref.proto, func);
411
- if (!ptr) [[unlikely]]
412
- return false;
413
- } else if (CheckValueTag(instance, value, param.type->ref.marker)) {
414
- ptr = value.As<Napi::External<void>>().Data();
415
- } else if (IsNullOrUndefined(value)) {
416
- ptr = nullptr;
417
- } else {
418
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected %2", GetValueType(instance, value), param.type->name);
406
+ if (!PushCallback(value, param.type, &ptr)) [[unlikely]]
419
407
  return false;
420
- }
421
408
 
422
409
  *(void **)((param.gpr_count ? gpr_ptr : args_ptr)++) = ptr;
423
410
  } break;
@@ -1,7 +1,7 @@
1
- # Copyright 2023 Niels Martignène <niels.martignene@protonmail.com>
1
+ # Copyright (C) 2025 Niels Martignène <niels.martignene@protonmail.com>
2
2
  #
3
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
4
+ # this software and associated documentation files (the “Software”), to deal in
5
5
  # the Software without restriction, including without limitation the rights to use,
6
6
  # copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
7
7
  # Software, and to permit persons to whom the Software is furnished to do so,
@@ -19,7 +19,7 @@
19
19
  # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20
20
  # OTHER DEALINGS IN THE SOFTWARE.
21
21
 
22
- #ifdef __APPLE__
22
+ #if defined(__APPLE__)
23
23
  #define SYMBOL(Symbol) _ ## Symbol
24
24
  #else
25
25
  #define SYMBOL(Symbol) Symbol
@@ -187,7 +187,7 @@ SYMBOL(ForwardCallXDD):
187
187
  movq %rsp, %rsi
188
188
  leaq 160(%rsp), %rdx
189
189
  leaq 112(%rsp), %rcx
190
- #ifdef __linux__
190
+ #if defined(__linux__)
191
191
  call *RelayCallback@GOTPCREL(%rip)
192
192
  #else
193
193
  call SYMBOL(RelayCallback)
@@ -225,7 +225,7 @@ SYMBOL(ForwardCallXDD):
225
225
  movq %rsp, %rsi
226
226
  leaq 160(%rsp), %rdx
227
227
  leaq 112(%rsp), %rcx
228
- #ifdef __linux__
228
+ #if defined(__linux__)
229
229
  call *RelayCallback@GOTPCREL(%rip)
230
230
  #else
231
231
  call SYMBOL(RelayCallback)
@@ -1,7 +1,7 @@
1
- // Copyright 2023 Niels Martignène <niels.martignene@protonmail.com>
1
+ // Copyright (C) 2025 Niels Martignène <niels.martignene@protonmail.com>
2
2
  //
3
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
4
+ // this software and associated documentation files (the “Software”), to deal in
5
5
  // the Software without restriction, including without limitation the rights to use,
6
6
  // copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
7
7
  // Software, and to permit persons to whom the Software is furnished to do so,
@@ -21,7 +21,7 @@
21
21
 
22
22
  #if defined(_WIN32) && (defined(__x86_64__) || defined(_M_AMD64))
23
23
 
24
- #include "src/core/libcc/libcc.hh"
24
+ #include "src/core/base/base.hh"
25
25
  #include "ffi.hh"
26
26
  #include "call.hh"
27
27
  #include "util.hh"
@@ -200,21 +200,8 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
200
200
  } break;
201
201
  case PrimitiveKind::Callback: {
202
202
  void *ptr;
203
-
204
- if (value.IsFunction()) {
205
- Napi::Function func = value.As<Napi::Function>();
206
-
207
- ptr = ReserveTrampoline(param.type->ref.proto, func);
208
- if (!ptr) [[unlikely]]
209
- return false;
210
- } else if (CheckValueTag(instance, value, param.type->ref.marker)) {
211
- ptr = value.As<Napi::External<void>>().Data();
212
- } else if (IsNullOrUndefined(value)) {
213
- ptr = nullptr;
214
- } else {
215
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected %2", GetValueType(instance, value), param.type->name);
203
+ if (!PushCallback(value, param.type, &ptr)) [[unlikely]]
216
204
  return false;
217
- }
218
205
 
219
206
  *(void **)(args_ptr++) = ptr;
220
207
  } break;
@@ -1,7 +1,7 @@
1
- ; Copyright 2023 Niels Martignène <niels.martignene@protonmail.com>
1
+ ; Copyright (C) 2025 Niels Martignène <niels.martignene@protonmail.com>
2
2
  ;
3
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
4
+ ; this software and associated documentation files (the “Software”), to deal in
5
5
  ; the Software without restriction, including without limitation the rights to use,
6
6
  ; copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
7
7
  ; Software, and to permit persons to whom the Software is furnished to do so,
@@ -1,7 +1,7 @@
1
- // Copyright 2023 Niels Martignène <niels.martignene@protonmail.com>
1
+ // Copyright (C) 2025 Niels Martignène <niels.martignene@protonmail.com>
2
2
  //
3
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
4
+ // this software and associated documentation files (the “Software”), to deal in
5
5
  // the Software without restriction, including without limitation the rights to use,
6
6
  // copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
7
7
  // Software, and to permit persons to whom the Software is furnished to do so,
@@ -21,11 +21,11 @@
21
21
 
22
22
  #if defined(__i386__) || defined(_M_IX86)
23
23
 
24
- #include "src/core/libcc/libcc.hh"
24
+ #include "src/core/base/base.hh"
25
25
  #include "ffi.hh"
26
26
  #include "call.hh"
27
27
  #include "util.hh"
28
- #ifdef _WIN32
28
+ #if defined(_WIN32)
29
29
  #include "win32.hh"
30
30
  #endif
31
31
 
@@ -89,7 +89,7 @@ bool AnalyseFunction(Napi::Env env, InstanceData *instance, FunctionInfo *func)
89
89
  #endif
90
90
  #endif
91
91
  }
92
- #ifndef _WIN32
92
+ #if !defined(_WIN32)
93
93
  if (fast && !func->ret.trivial) {
94
94
  func->ret.fast = 1;
95
95
  fast--;
@@ -294,21 +294,8 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
294
294
  } break;
295
295
  case PrimitiveKind::Callback: {
296
296
  void *ptr;
297
-
298
- if (value.IsFunction()) {
299
- Napi::Function func = value.As<Napi::Function>();
300
-
301
- ptr = ReserveTrampoline(param.type->ref.proto, func);
302
- if (!ptr) [[unlikely]]
303
- return false;
304
- } else if (CheckValueTag(instance, value, param.type->ref.marker)) {
305
- ptr = value.As<Napi::External<void>>().Data();
306
- } else if (IsNullOrUndefined(value)) {
307
- ptr = nullptr;
308
- } else {
309
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected %2", GetValueType(instance, value), param.type->name);
297
+ if (!PushCallback(value, param.type, &ptr)) [[unlikely]]
310
298
  return false;
311
- }
312
299
 
313
300
  *(void **)((param.fast ? fast_ptr : args_ptr)++) = ptr;
314
301
  } break;
@@ -329,7 +316,7 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
329
316
 
330
317
  void CallData::Execute(const FunctionInfo *func, void *native)
331
318
  {
332
- #ifdef _WIN32
319
+ #if defined(_WIN32)
333
320
  TEB *teb = GetTEB();
334
321
 
335
322
  // Restore previous stack limits at the end
@@ -481,7 +468,7 @@ void CallData::Relay(Size idx, uint8_t *, uint8_t *caller_sp, bool switch_stack,
481
468
  if (env.IsExceptionPending()) [[unlikely]]
482
469
  return;
483
470
 
484
- #ifdef _WIN32
471
+ #if defined(_WIN32)
485
472
  TEB *teb = GetTEB();
486
473
 
487
474
  // Restore previous stack limits at the end
@@ -512,7 +499,7 @@ void CallData::Relay(Size idx, uint8_t *, uint8_t *caller_sp, bool switch_stack,
512
499
  if (proto->convention == CallConvention::Stdcall) {
513
500
  out_reg->ret_pop = (int)proto->args_size;
514
501
  } else {
515
- #ifdef _WIN32
502
+ #if defined(_WIN32)
516
503
  out_reg->ret_pop = 0;
517
504
  #else
518
505
  out_reg->ret_pop = return_ptr ? 4 : 0;
@@ -1,7 +1,7 @@
1
- # Copyright 2023 Niels Martignène <niels.martignene@protonmail.com>
1
+ # Copyright (C) 2025 Niels Martignène <niels.martignene@protonmail.com>
2
2
  #
3
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
4
+ # this software and associated documentation files (the “Software”), to deal in
5
5
  # the Software without restriction, including without limitation the rights to use,
6
6
  # copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
7
7
  # Software, and to permit persons to whom the Software is furnished to do so,
@@ -1,7 +1,7 @@
1
- ; Copyright 2023 Niels Martignène <niels.martignene@protonmail.com>
1
+ ; Copyright (C) 2025 Niels Martignène <niels.martignene@protonmail.com>
2
2
  ;
3
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
4
+ ; this software and associated documentation files (the “Software”), to deal in
5
5
  ; the Software without restriction, including without limitation the rights to use,
6
6
  ; copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
7
7
  ; Software, and to permit persons to whom the Software is furnished to do so,
@@ -1,7 +1,7 @@
1
- // Copyright 2023 Niels Martignène <niels.martignene@protonmail.com>
1
+ // Copyright (C) 2025 Niels Martignène <niels.martignene@protonmail.com>
2
2
  //
3
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
4
+ // this software and associated documentation files (the “Software”), to deal in
5
5
  // the Software without restriction, including without limitation the rights to use,
6
6
  // copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
7
7
  // Software, and to permit persons to whom the Software is furnished to do so,
@@ -19,7 +19,7 @@
19
19
  // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20
20
  // OTHER DEALINGS IN THE SOFTWARE.
21
21
 
22
- #include "src/core/libcc/libcc.hh"
22
+ #include "src/core/base/base.hh"
23
23
  #include "call.hh"
24
24
  #include "ffi.hh"
25
25
  #include "util.hh"
@@ -743,22 +743,8 @@ bool CallData::PushObject(Napi::Object obj, const TypeInfo *type, uint8_t *origi
743
743
  } break;
744
744
  case PrimitiveKind::Callback: {
745
745
  void *ptr;
746
-
747
- if (value.IsFunction()) {
748
- Napi::Function func = value.As<Napi::Function>();
749
-
750
- ptr = ReserveTrampoline(member.type->ref.proto, func);
751
- if (!ptr) [[unlikely]]
752
- return false;
753
- } else if (CheckValueTag(instance, value, member.type->ref.marker)) {
754
- Napi::External<void> external = value.As<Napi::External<void>>();
755
- ptr = external.Data();
756
- } else if (IsNullOrUndefined(value)) {
757
- ptr = nullptr;
758
- } else {
759
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected %2", GetValueType(instance, value), member.type->name);
746
+ if (!PushCallback(value, member.type, &ptr))
760
747
  return false;
761
- }
762
748
 
763
749
  *(void **)dest = ptr;
764
750
  } break;
@@ -991,22 +977,8 @@ bool CallData::PushNormalArray(Napi::Array array, Size len, const TypeInfo *type
991
977
  uint8_t *dest = origin + offset;
992
978
 
993
979
  void *ptr;
994
-
995
- if (value.IsFunction()) {
996
- Napi::Function func = value.As<Napi::Function>();
997
-
998
- ptr = ReserveTrampoline(ref->ref.proto, func);
999
- if (!ptr) [[unlikely]]
1000
- return false;
1001
- } else if (CheckValueTag(instance, value, ref->ref.marker)) {
1002
- Napi::External<void> external = value.As<Napi::External<void>>();
1003
- ptr = external.Data();
1004
- } else if (IsNullOrUndefined(value)) {
1005
- ptr = nullptr;
1006
- } else {
1007
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected %2", GetValueType(instance, value), ref->name);
980
+ if (!PushCallback(value, ref, &ptr))
1008
981
  return false;
1009
- }
1010
982
 
1011
983
  *(void **)dest = ptr;
1012
984
 
@@ -1027,8 +999,8 @@ void CallData::PushBuffer(Span<const uint8_t> buffer, Size size, const TypeInfo
1027
999
  buffer.len = std::min(buffer.len, size);
1028
1000
 
1029
1001
  // Go fast brrrrrrr :)
1030
- memcpy_safe(origin, buffer.ptr, (size_t)buffer.len);
1031
- memset_safe(origin + buffer.len, 0, (size_t)(size - buffer.len));
1002
+ MemCpy(origin, buffer.ptr, (size_t)buffer.len);
1003
+ MemSet(origin + buffer.len, 0, (size_t)(size - buffer.len));
1032
1004
 
1033
1005
  #define SWAP(CType) \
1034
1006
  do { \
@@ -1080,7 +1052,7 @@ bool CallData::PushStringArray(Napi::Value obj, const TypeInfo *type, uint8_t *o
1080
1052
  } break;
1081
1053
  }
1082
1054
 
1083
- memset_safe(origin + encoded, 0, type->size - encoded);
1055
+ MemSet(origin + encoded, 0, type->size - encoded);
1084
1056
 
1085
1057
  return true;
1086
1058
  }
@@ -1155,7 +1127,7 @@ bool CallData::PushPointer(Napi::Value value, const TypeInfo *type, int directio
1155
1127
  if (!PushNormalArray(array, len, type, ptr))
1156
1128
  return false;
1157
1129
  } else {
1158
- memset_safe(ptr, 0, size);
1130
+ MemSet(ptr, 0, size);
1159
1131
  }
1160
1132
 
1161
1133
  out_kind = OutArgument::Kind::Array;
@@ -1185,7 +1157,7 @@ bool CallData::PushPointer(Napi::Value value, const TypeInfo *type, int directio
1185
1157
  if (!PushObject(obj, type->ref.type, ptr))
1186
1158
  return false;
1187
1159
  } else {
1188
- memset_safe(ptr, 0, type->size);
1160
+ MemSet(ptr, 0, type->size);
1189
1161
  }
1190
1162
 
1191
1163
  out_kind = OutArgument::Kind::Object;
@@ -1274,6 +1246,41 @@ unexpected:
1274
1246
  return false;
1275
1247
  }
1276
1248
 
1249
+ bool CallData::PushCallback(Napi::Value value, const TypeInfo *type, void **out_ptr)
1250
+ {
1251
+ if (value.IsFunction()) {
1252
+ Napi::Function func = value.As<Napi::Function>();
1253
+
1254
+ void *ptr = ReserveTrampoline(type->ref.proto, func);
1255
+ if (!ptr) [[unlikely]]
1256
+ return false;
1257
+
1258
+ *out_ptr = ptr;
1259
+ } else if (CheckValueTag(instance, value, type->ref.marker)) {
1260
+ *out_ptr = value.As<Napi::External<void>>().Data();
1261
+ } else if (CheckValueTag(instance, value, &CastMarker)) {
1262
+ Napi::External<ValueCast> external = value.As<Napi::External<ValueCast>>();
1263
+ ValueCast *cast = external.Data();
1264
+
1265
+ value = cast->ref.Value();
1266
+
1267
+ if (!value.IsExternal() || cast->type != type)
1268
+ goto unexpected;
1269
+
1270
+ *out_ptr = value.As<Napi::External<void>>().Data();
1271
+ } else if (IsNullOrUndefined(value)) {
1272
+ *out_ptr = nullptr;
1273
+ } else {
1274
+ goto unexpected;
1275
+ }
1276
+
1277
+ return true;
1278
+
1279
+ unexpected:
1280
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected %2", GetValueType(instance, value), type->name);
1281
+ return false;
1282
+ }
1283
+
1277
1284
  Size CallData::PushIndirectString(Napi::Array array, const TypeInfo *ref, uint8_t **out_ptr)
1278
1285
  {
1279
1286
  if (array.Length() != 1)
@@ -1334,16 +1341,16 @@ void *CallData::ReserveTrampoline(const FunctionInfo *proto, Napi::Function func
1334
1341
 
1335
1342
  void CallData::DumpForward(const FunctionInfo *func) const
1336
1343
  {
1337
- PrintLn(stderr, "%!..+---- %1 (%2) ----%!0", func->name, CallConventionNames[(int)func->convention]);
1344
+ PrintLn(StdErr, "%!..+---- %1 (%2) ----%!0", func->name, CallConventionNames[(int)func->convention]);
1338
1345
 
1339
1346
  if (func->parameters.len) {
1340
- PrintLn(stderr, "Parameters:");
1347
+ PrintLn(StdErr, "Parameters:");
1341
1348
  for (Size i = 0; i < func->parameters.len; i++) {
1342
1349
  const ParameterInfo &param = func->parameters[i];
1343
- PrintLn(stderr, " %1 = %2 (%3)", i, param.type->name, FmtMemSize(param.type->size));
1350
+ PrintLn(StdErr, " %1 = %2 (%3)", i, param.type->name, FmtMemSize(param.type->size));
1344
1351
  }
1345
1352
  }
1346
- PrintLn(stderr, "Return: %1 (%2)", func->ret.type->name, FmtMemSize(func->ret.type->size));
1353
+ PrintLn(StdErr, "Return: %1 (%2)", func->ret.type->name, FmtMemSize(func->ret.type->size));
1347
1354
 
1348
1355
  Span<const uint8_t> stack = MakeSpan(mem->stack.end(), old_stack_mem.end() - mem->stack.end());
1349
1356
  Span<const uint8_t> heap = MakeSpan(old_heap_mem.ptr, mem->heap.ptr - old_heap_mem.ptr);
@@ -1,7 +1,7 @@
1
- // Copyright 2023 Niels Martignène <niels.martignene@protonmail.com>
1
+ // Copyright (C) 2025 Niels Martignène <niels.martignene@protonmail.com>
2
2
  //
3
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
4
+ // this software and associated documentation files (the “Software”), to deal in
5
5
  // the Software without restriction, including without limitation the rights to use,
6
6
  // copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
7
7
  // Software, and to permit persons to whom the Software is furnished to do so,
@@ -21,7 +21,7 @@
21
21
 
22
22
  #pragma once
23
23
 
24
- #include "src/core/libcc/libcc.hh"
24
+ #include "src/core/base/base.hh"
25
25
  #include "ffi.hh"
26
26
  #include "util.hh"
27
27
 
@@ -92,8 +92,8 @@ public:
92
92
 
93
93
  void Dispose();
94
94
 
95
- #ifdef UNITY_BUILD
96
- #ifdef _MSC_VER
95
+ #if defined(UNITY_BUILD)
96
+ #if defined(_MSC_VER)
97
97
  #define INLINE_IF_UNITY __forceinline
98
98
  #else
99
99
  #define INLINE_IF_UNITY __attribute__((always_inline)) inline
@@ -125,6 +125,7 @@ public:
125
125
  void PushBuffer(Span<const uint8_t> buffer, Size size, const TypeInfo *type, uint8_t *origin);
126
126
  bool PushStringArray(Napi::Value value, const TypeInfo *type, uint8_t *origin);
127
127
  bool PushPointer(Napi::Value value, const TypeInfo *type, int directions, void **out_ptr);
128
+ bool PushCallback(Napi::Value value, const TypeInfo *type, void **out_ptr);
128
129
  Size PushIndirectString(Napi::Array array, const TypeInfo *ref, uint8_t **out_ptr);
129
130
 
130
131
  void *ReserveTrampoline(const FunctionInfo *proto, Napi::Function func);
@@ -152,7 +153,7 @@ inline bool CallData::AllocStack(Size size, Size align, T **out_ptr)
152
153
  return false;
153
154
  }
154
155
 
155
- #ifdef RG_DEBUG
156
+ #if defined(RG_DEBUG)
156
157
  memset(ptr, 0, delta);
157
158
  #endif
158
159
 
@@ -169,7 +170,7 @@ inline T *CallData::AllocHeap(Size size, Size align)
169
170
  Size delta = size + (ptr - mem->heap.ptr);
170
171
 
171
172
  if (size < 4096 && delta <= mem->heap.len) [[likely]] {
172
- #ifdef RG_DEBUG
173
+ #if defined(RG_DEBUG)
173
174
  memset(mem->heap.ptr, 0, (size_t)delta);
174
175
  #endif
175
176
 
@@ -178,7 +179,7 @@ inline T *CallData::AllocHeap(Size size, Size align)
178
179
 
179
180
  return ptr;
180
181
  } else {
181
- #ifdef RG_DEBUG
182
+ #if defined(RG_DEBUG)
182
183
  int flags = (int)AllocFlag::Zero;
183
184
  #else
184
185
  int flags = 0;