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
@@ -10,28 +10,30 @@
10
10
  "publish": "electron-forge publish",
11
11
  "lint": "echo \"No linting configured\""
12
12
  },
13
+ "devDependencies": {
14
+ "@electron-forge/cli": "^7.6.1",
15
+ "@electron-forge/maker-deb": "^7.6.1",
16
+ "@electron-forge/maker-rpm": "^7.6.1",
17
+ "@electron-forge/maker-squirrel": "^7.6.1",
18
+ "@electron-forge/maker-zip": "^7.6.1",
19
+ "@electron-forge/plugin-auto-unpack-natives": "^7.6.1",
20
+ "@electron-forge/plugin-fuses": "^7.6.1",
21
+ "@electron-forge/plugin-webpack": "^7.6.1",
22
+ "@electron/fuses": "^1.8.0",
23
+ "@vercel/webpack-asset-relocator-loader": "^1.7.3",
24
+ "css-loader": "^6.11.0",
25
+ "electron": "34.2.0",
26
+ "node-loader": "^2.1.0",
27
+ "style-loader": "^3.3.4"
28
+ },
13
29
  "keywords": [],
14
30
  "author": {
15
31
  "name": "Niels Martignène",
16
32
  "email": "niels.martignene@protonmail.com"
17
33
  },
18
34
  "license": "MIT",
19
- "devDependencies": {
20
- "@electron-forge/cli": "^6.2.1",
21
- "@electron-forge/maker-deb": "^6.2.1",
22
- "@electron-forge/maker-rpm": "^6.2.1",
23
- "@electron-forge/maker-squirrel": "^6.2.1",
24
- "@electron-forge/maker-zip": "^6.2.1",
25
- "@electron-forge/plugin-auto-unpack-natives": "^6.2.1",
26
- "@electron-forge/plugin-webpack": "^6.2.1",
27
- "@vercel/webpack-asset-relocator-loader": "^1.7.3",
28
- "css-loader": "^6.8.1",
29
- "electron": "25.3.2",
30
- "node-loader": "^2.0.0",
31
- "style-loader": "^3.3.3"
32
- },
33
35
  "dependencies": {
34
- "electron-squirrel-startup": "^1.0.0",
35
- "koffi": "^2.5.18"
36
+ "electron-squirrel-startup": "^1.0.1",
37
+ "koffi": "^2.10.1"
36
38
  }
37
39
  }
@@ -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(__arm__) || (defined(__M_ARM) && !defined(_M_ARM64))
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"
@@ -64,7 +64,7 @@ extern "C" napi_value CallSwitchStack(Napi::Function *func, size_t argc, napi_va
64
64
 
65
65
  static int IsHFA(const TypeInfo *type)
66
66
  {
67
- #ifdef __ARM_PCS_VFP
67
+ #if defined(__ARM_PCS_VFP)
68
68
  bool float32 = false;
69
69
  bool float64 = false;
70
70
  int count = 0;
@@ -179,7 +179,7 @@ bool AnalyseFunction(Napi::Env, InstanceData *, FunctionInfo *func)
179
179
  case PrimitiveKind::Array: { RG_UNREACHABLE(); } break;
180
180
  case PrimitiveKind::Float32:
181
181
  case PrimitiveKind::Float64: {
182
- #ifdef __ARM_PCS_VFP
182
+ #if defined(__ARM_PCS_VFP)
183
183
  bool vfp = !param.variadic;
184
184
  #else
185
185
  bool vfp = false;
@@ -431,21 +431,8 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
431
431
  } break;
432
432
  case PrimitiveKind::Callback: {
433
433
  void *ptr;
434
-
435
- if (value.IsFunction()) {
436
- Napi::Function func = value.As<Napi::Function>();
437
-
438
- ptr = ReserveTrampoline(param.type->ref.proto, func);
439
- if (!ptr) [[unlikely]]
440
- return false;
441
- } else if (CheckValueTag(instance, value, param.type->ref.marker)) {
442
- ptr = value.As<Napi::External<void>>().Data();
443
- } else if (IsNullOrUndefined(value)) {
444
- ptr = nullptr;
445
- } else {
446
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected %2", GetValueType(instance, value), param.type->name);
434
+ if (!PushCallback(value, param.type, &ptr)) [[unlikely]]
447
435
  return false;
448
- }
449
436
 
450
437
  *(void **)((param.gpr_count ? gpr_ptr : args_ptr)++) = ptr;
451
438
  } break;
@@ -995,7 +982,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool switch_
995
982
  }
996
983
 
997
984
  float f = GetNumber<float>(value);
998
- #ifdef __ARM_PCS_VFP
985
+ #if defined(__ARM_PCS_VFP)
999
986
  memcpy(&out_reg->d0, &f, 4);
1000
987
  #else
1001
988
  memcpy(&out_reg->r0, &f, 4);
@@ -1008,7 +995,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool switch_
1008
995
  }
1009
996
 
1010
997
  double d = GetNumber<double>(value);
1011
- #ifdef __ARM_PCS_VFP
998
+ #if defined(__ARM_PCS_VFP)
1012
999
  out_reg->d0 = d;
1013
1000
  #else
1014
1001
  memcpy(&out_reg->r0, &d, 8);
@@ -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(__aarch64__) || defined(_M_ARM64)
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
 
@@ -135,7 +135,7 @@ bool AnalyseFunction(Napi::Env, InstanceData *, FunctionInfo *func)
135
135
 
136
136
  int gpr_avail = 8;
137
137
  int vec_avail = 8;
138
- #ifdef _M_ARM64EC
138
+ #if defined(_M_ARM64EC)
139
139
  if (func->variadic) {
140
140
  gpr_avail = 4;
141
141
  }
@@ -165,7 +165,7 @@ bool AnalyseFunction(Napi::Env, InstanceData *, FunctionInfo *func)
165
165
  case PrimitiveKind::String32:
166
166
  case PrimitiveKind::Pointer:
167
167
  case PrimitiveKind::Callback: {
168
- #ifdef __APPLE__
168
+ #if defined(__APPLE__)
169
169
  if (param.variadic)
170
170
  break;
171
171
  #endif
@@ -179,7 +179,7 @@ bool AnalyseFunction(Napi::Env, InstanceData *, FunctionInfo *func)
179
179
  case PrimitiveKind::Union: {
180
180
  HfaInfo hfa = IsHFA(param.type);
181
181
 
182
- #ifdef _M_ARM64EC
182
+ #if defined(_M_ARM64EC)
183
183
  if (func->variadic) {
184
184
  if (IsRegularSize(param.type->size, 8) && gpr_avail) {
185
185
  param.gpr_count = 1;
@@ -283,7 +283,7 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
283
283
  gpr_ptr[8] = (uint64_t)return_ptr;
284
284
  }
285
285
 
286
- #ifdef _M_ARM64EC
286
+ #if defined(_M_ARM64EC)
287
287
  if (func->variadic) {
288
288
  gpr_ptr[4] = (uint64_t)args_ptr;
289
289
  gpr_ptr[5] = 0;
@@ -295,7 +295,7 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
295
295
  }
296
296
  #endif
297
297
 
298
- #ifdef __APPLE__
298
+ #if defined(__APPLE__)
299
299
  #define PUSH_INTEGER(CType) \
300
300
  do { \
301
301
  if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] { \
@@ -371,7 +371,7 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
371
371
 
372
372
  bool b = value.As<Napi::Boolean>();
373
373
 
374
- #ifdef __APPLE__
374
+ #if defined(__APPLE__)
375
375
  if (param.gpr_count) [[likely]] {
376
376
  *(gpr_ptr++) = (uint64_t)b;
377
377
  } else {
@@ -401,7 +401,7 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
401
401
  if (!PushString(value, param.directions, &str)) [[unlikely]]
402
402
  return false;
403
403
 
404
- #ifdef __APPLE__
404
+ #if defined(__APPLE__)
405
405
  args_ptr = param.gpr_count ? args_ptr : AlignUp(args_ptr, 8);
406
406
  #endif
407
407
  *(const char **)((param.gpr_count ? gpr_ptr : args_ptr)++) = str;
@@ -411,7 +411,7 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
411
411
  if (!PushString16(value, param.directions, &str16)) [[unlikely]]
412
412
  return false;
413
413
 
414
- #ifdef __APPLE__
414
+ #if defined(__APPLE__)
415
415
  args_ptr = param.gpr_count ? args_ptr : AlignUp(args_ptr, 8);
416
416
  #endif
417
417
  *(const char16_t **)((param.gpr_count ? gpr_ptr : args_ptr)++) = str16;
@@ -431,7 +431,7 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
431
431
  if (!PushPointer(value, param.type, param.directions, &ptr)) [[unlikely]]
432
432
  return false;
433
433
 
434
- #ifdef __APPLE__
434
+ #if defined(__APPLE__)
435
435
  args_ptr = param.gpr_count ? args_ptr : AlignUp(args_ptr, 8);
436
436
  #endif
437
437
  *(void **)((param.gpr_count ? gpr_ptr : args_ptr)++) = ptr;
@@ -461,7 +461,7 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
461
461
  return false;
462
462
  gpr_ptr += param.gpr_count;
463
463
  } else if (param.type->size) {
464
- #ifdef __APPLE__
464
+ #if defined(__APPLE__)
465
465
  args_ptr = AlignUp(args_ptr, 8);
466
466
  #endif
467
467
  if (!PushObject(obj, param.type, (uint8_t *)args_ptr))
@@ -477,7 +477,7 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
477
477
 
478
478
  *(uint8_t **)(gpr_ptr++) = ptr;
479
479
  } else {
480
- #ifdef __APPLE__
480
+ #if defined(__APPLE__)
481
481
  args_ptr = AlignUp(args_ptr, 8);
482
482
  #endif
483
483
  *(uint8_t **)(args_ptr++) = ptr;
@@ -499,13 +499,13 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
499
499
  if (param.vec_count) [[likely]] {
500
500
  memset((uint8_t *)vec_ptr + 4, 0, 4);
501
501
  *(float *)(vec_ptr++) = f;
502
- #ifdef _WIN32
502
+ #if defined(_WIN32)
503
503
  } else if (param.gpr_count) {
504
504
  memset((uint8_t *)gpr_ptr + 4, 0, 4);
505
505
  *(float *)(gpr_ptr++) = f;
506
506
  #endif
507
507
  } else {
508
- #ifdef __APPLE__
508
+ #if defined(__APPLE__)
509
509
  args_ptr = AlignUp(args_ptr, 4);
510
510
  *(float *)args_ptr = f;
511
511
  args_ptr = (uint64_t *)((uint8_t *)args_ptr + 4);
@@ -525,12 +525,12 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
525
525
 
526
526
  if (param.vec_count) [[likely]] {
527
527
  *(double *)(vec_ptr++) = d;
528
- #ifdef _WIN32
528
+ #if defined(_WIN32)
529
529
  } else if (param.gpr_count) {
530
530
  *(double *)(gpr_ptr++) = d;
531
531
  #endif
532
532
  } else {
533
- #ifdef __APPLE__
533
+ #if defined(__APPLE__)
534
534
  args_ptr = AlignUp(args_ptr, 8);
535
535
  #endif
536
536
  *(double *)(args_ptr++) = d;
@@ -538,23 +538,10 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
538
538
  } break;
539
539
  case PrimitiveKind::Callback: {
540
540
  void *ptr;
541
-
542
- if (value.IsFunction()) {
543
- Napi::Function func = value.As<Napi::Function>();
544
-
545
- ptr = ReserveTrampoline(param.type->ref.proto, func);
546
- if (!ptr) [[unlikely]]
547
- return false;
548
- } else if (CheckValueTag(instance, value, param.type->ref.marker)) {
549
- ptr = value.As<Napi::External<void>>().Data();
550
- } else if (IsNullOrUndefined(value)) {
551
- ptr = nullptr;
552
- } else {
553
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected %2", GetValueType(instance, value), param.type->name);
541
+ if (!PushCallback(value, param.type, &ptr)) [[unlikely]]
554
542
  return false;
555
- }
556
543
 
557
- #ifdef __APPLE__
544
+ #if defined(__APPLE__)
558
545
  args_ptr = param.gpr_count ? args_ptr : AlignUp(args_ptr, 8);
559
546
  #endif
560
547
  *(void **)((param.gpr_count ? gpr_ptr : args_ptr)++) = ptr;
@@ -574,7 +561,7 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
574
561
 
575
562
  void CallData::Execute(const FunctionInfo *func, void *native)
576
563
  {
577
- #ifdef _WIN32
564
+ #if defined(_WIN32)
578
565
  TEB *teb = GetTEB();
579
566
 
580
567
  // Restore previous stack limits at the end
@@ -727,7 +714,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool switch_
727
714
  if (env.IsExceptionPending()) [[unlikely]]
728
715
  return;
729
716
 
730
- #ifdef _WIN32
717
+ #if defined(_WIN32)
731
718
  TEB *teb = GetTEB();
732
719
 
733
720
  // Restore previous stack limits at the end
@@ -776,7 +763,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool switch_
776
763
  case PrimitiveKind::Void: { RG_UNREACHABLE(); } break;
777
764
 
778
765
  case PrimitiveKind::Bool: {
779
- #ifdef __APPLE__
766
+ #if defined(__APPLE__)
780
767
  bool b;
781
768
  if (param.gpr_count) {
782
769
  b = *(bool *)(gpr_ptr++);
@@ -792,7 +779,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool switch_
792
779
  arguments.Append(arg);
793
780
  } break;
794
781
  case PrimitiveKind::Int8: {
795
- #ifdef __APPLE__
782
+ #if defined(__APPLE__)
796
783
  double d;
797
784
  if (param.gpr_count) {
798
785
  d = (double)*(int8_t *)(gpr_ptr++);
@@ -808,7 +795,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool switch_
808
795
  arguments.Append(arg);
809
796
  } break;
810
797
  case PrimitiveKind::UInt8: {
811
- #ifdef __APPLE__
798
+ #if defined(__APPLE__)
812
799
  double d;
813
800
  if (param.gpr_count) {
814
801
  d = (double)*(uint8_t *)(gpr_ptr++);
@@ -824,7 +811,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool switch_
824
811
  arguments.Append(arg);
825
812
  } break;
826
813
  case PrimitiveKind::Int16: {
827
- #ifdef __APPLE__
814
+ #if defined(__APPLE__)
828
815
  double d;
829
816
  if (param.gpr_count) {
830
817
  d = (double)*(int16_t *)(gpr_ptr++);
@@ -841,7 +828,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool switch_
841
828
  arguments.Append(arg);
842
829
  } break;
843
830
  case PrimitiveKind::Int16S: {
844
- #ifdef __APPLE__
831
+ #if defined(__APPLE__)
845
832
  double d;
846
833
  if (param.gpr_count) {
847
834
  int16_t v = *(int16_t *)(gpr_ptr++);
@@ -863,7 +850,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool switch_
863
850
  arguments.Append(arg);
864
851
  } break;
865
852
  case PrimitiveKind::UInt16: {
866
- #ifdef __APPLE__
853
+ #if defined(__APPLE__)
867
854
  double d;
868
855
  if (param.gpr_count) {
869
856
  d = (double)*(uint16_t *)(gpr_ptr++);
@@ -880,7 +867,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool switch_
880
867
  arguments.Append(arg);
881
868
  } break;
882
869
  case PrimitiveKind::UInt16S: {
883
- #ifdef __APPLE__
870
+ #if defined(__APPLE__)
884
871
  double d;
885
872
  if (param.gpr_count) {
886
873
  uint16_t v = *(uint16_t *)(gpr_ptr++);
@@ -902,7 +889,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool switch_
902
889
  arguments.Append(arg);
903
890
  } break;
904
891
  case PrimitiveKind::Int32: {
905
- #ifdef __APPLE__
892
+ #if defined(__APPLE__)
906
893
  double d;
907
894
  if (param.gpr_count) {
908
895
  d = (double)*(int32_t *)(gpr_ptr++);
@@ -919,7 +906,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool switch_
919
906
  arguments.Append(arg);
920
907
  } break;
921
908
  case PrimitiveKind::Int32S: {
922
- #ifdef __APPLE__
909
+ #if defined(__APPLE__)
923
910
  double d;
924
911
  if (param.gpr_count) {
925
912
  int32_t v = *(int32_t *)(gpr_ptr++);
@@ -941,7 +928,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool switch_
941
928
  arguments.Append(arg);
942
929
  } break;
943
930
  case PrimitiveKind::UInt32: {
944
- #ifdef __APPLE__
931
+ #if defined(__APPLE__)
945
932
  double d;
946
933
  if (param.gpr_count) {
947
934
  d = (double)*(uint32_t *)(gpr_ptr++);
@@ -958,7 +945,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool switch_
958
945
  arguments.Append(arg);
959
946
  } break;
960
947
  case PrimitiveKind::UInt32S: {
961
- #ifdef __APPLE__
948
+ #if defined(__APPLE__)
962
949
  double d;
963
950
  if (param.gpr_count) {
964
951
  uint32_t v = *(uint32_t *)(gpr_ptr++);
@@ -980,7 +967,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool switch_
980
967
  arguments.Append(arg);
981
968
  } break;
982
969
  case PrimitiveKind::Int64: {
983
- #ifdef __APPLE__
970
+ #if defined(__APPLE__)
984
971
  args_ptr = AlignUp(args_ptr, 8);
985
972
  #endif
986
973
 
@@ -990,7 +977,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool switch_
990
977
  arguments.Append(arg);
991
978
  } break;
992
979
  case PrimitiveKind::Int64S: {
993
- #ifdef __APPLE__
980
+ #if defined(__APPLE__)
994
981
  args_ptr = AlignUp(args_ptr, 8);
995
982
  #endif
996
983
 
@@ -1000,7 +987,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool switch_
1000
987
  arguments.Append(arg);
1001
988
  } break;
1002
989
  case PrimitiveKind::UInt64: {
1003
- #ifdef __APPLE__
990
+ #if defined(__APPLE__)
1004
991
  args_ptr = AlignUp(args_ptr, 8);
1005
992
  #endif
1006
993
 
@@ -1010,7 +997,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool switch_
1010
997
  arguments.Append(arg);
1011
998
  } break;
1012
999
  case PrimitiveKind::UInt64S: {
1013
- #ifdef __APPLE__
1000
+ #if defined(__APPLE__)
1014
1001
  args_ptr = AlignUp(args_ptr, 8);
1015
1002
  #endif
1016
1003
 
@@ -1020,7 +1007,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool switch_
1020
1007
  arguments.Append(arg);
1021
1008
  } break;
1022
1009
  case PrimitiveKind::String: {
1023
- #ifdef __APPLE__
1010
+ #if defined(__APPLE__)
1024
1011
  args_ptr = AlignUp(args_ptr, 8);
1025
1012
  #endif
1026
1013
 
@@ -1034,7 +1021,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool switch_
1034
1021
  }
1035
1022
  } break;
1036
1023
  case PrimitiveKind::String16: {
1037
- #ifdef __APPLE__
1024
+ #if defined(__APPLE__)
1038
1025
  args_ptr = AlignUp(args_ptr, 8);
1039
1026
  #endif
1040
1027
 
@@ -1059,7 +1046,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool switch_
1059
1046
  } break;
1060
1047
  case PrimitiveKind::Pointer:
1061
1048
  case PrimitiveKind::Callback: {
1062
- #ifdef __APPLE__
1049
+ #if defined(__APPLE__)
1063
1050
  args_ptr = AlignUp(args_ptr, 8);
1064
1051
  #endif
1065
1052
 
@@ -1106,7 +1093,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool switch_
1106
1093
  args_ptr += (param.type->size + 7) / 8;
1107
1094
  }
1108
1095
  } else {
1109
- #ifdef __APPLE__
1096
+ #if defined(__APPLE__)
1110
1097
  args_ptr = AlignUp(args_ptr, 8);
1111
1098
  #endif
1112
1099
 
@@ -1121,12 +1108,12 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool switch_
1121
1108
  float f;
1122
1109
  if (param.vec_count) [[likely]] {
1123
1110
  f = *(float *)(vec_ptr++);
1124
- #ifdef _WIN32
1111
+ #if defined(_WIN32)
1125
1112
  } else if (param.gpr_count) {
1126
1113
  f = *(float *)(gpr_ptr++);
1127
1114
  #endif
1128
1115
  } else {
1129
- #ifdef __APPLE__
1116
+ #if defined(__APPLE__)
1130
1117
  args_ptr = AlignUp(args_ptr, 4);
1131
1118
  f = *(float *)args_ptr;
1132
1119
  args_ptr = (uint64_t *)((uint8_t *)args_ptr + 4);
@@ -1142,12 +1129,12 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool switch_
1142
1129
  double d;
1143
1130
  if (param.vec_count) [[likely]] {
1144
1131
  d = *(double *)(vec_ptr++);
1145
- #ifdef _WIN32
1132
+ #if defined(_WIN32)
1146
1133
  } else if (param.gpr_count) {
1147
1134
  d = *(double *)(gpr_ptr++);
1148
1135
  #endif
1149
1136
  } else {
1150
- #ifdef __APPLE__
1137
+ #if defined(__APPLE__)
1151
1138
  args_ptr = AlignUp(args_ptr, 8);
1152
1139
  #endif
1153
1140
 
@@ -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
@@ -28,7 +28,7 @@
28
28
  # Forward
29
29
  # ----------------------------
30
30
 
31
- #ifdef __APPLE__
31
+ #if defined(__APPLE__)
32
32
  # Fix "arm64 function not 4-byte aligned" linker warnings
33
33
  .p2align 2
34
34
  #endif
@@ -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,
@@ -21,7 +21,7 @@
21
21
 
22
22
  #if __riscv_xlen == 64 || defined(__loongarch64)
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"
@@ -305,7 +305,7 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
305
305
  } else {
306
306
  RG_ASSERT(param.type->align <= 8);
307
307
 
308
- memcpy_safe(args_ptr, regs, param.type->size);
308
+ MemCpy(args_ptr, regs, param.type->size);
309
309
  args_ptr += (param.type->size + 7) / 8;
310
310
  }
311
311
  } else {
@@ -362,21 +362,8 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
362
362
  } break;
363
363
  case PrimitiveKind::Callback: {
364
364
  void *ptr;
365
-
366
- if (value.IsFunction()) {
367
- Napi::Function func = value.As<Napi::Function>();
368
-
369
- ptr = ReserveTrampoline(param.type->ref.proto, func);
370
- if (!ptr) [[unlikely]]
371
- return false;
372
- } else if (CheckValueTag(instance, value, param.type->ref.marker)) {
373
- ptr = value.As<Napi::External<void>>().Data();
374
- } else if (IsNullOrUndefined(value)) {
375
- ptr = nullptr;
376
- } else {
377
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected %2", GetValueType(instance, value), param.type->name);
365
+ if (!PushCallback(value, param.type, &ptr)) [[unlikely]]
378
366
  return false;
379
- }
380
367
 
381
368
  *(void **)((param.gpr_count ? gpr_ptr : args_ptr)++) = ptr;
382
369
  } break;
@@ -703,7 +690,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool switch_
703
690
  } else {
704
691
  RG_ASSERT(param.type->align <= 8);
705
692
 
706
- memcpy_safe(regs, args_ptr, param.type->size);
693
+ MemCpy(regs, args_ptr, param.type->size);
707
694
  args_ptr += (param.type->size + 7) / 8;
708
695
  }
709
696
 
@@ -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,