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,
@@ -19,21 +19,22 @@
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
+ #include "src/core/unicode/xid.hh"
23
24
  #include "ffi.hh"
24
25
  #include "call.hh"
25
26
  #include "parser.hh"
26
27
  #include "util.hh"
27
- #ifdef _WIN32
28
+ #if defined(_WIN32)
28
29
  #include "win32.hh"
29
30
  #endif
30
31
  #include "errno.inc"
31
32
 
32
- #ifdef _WIN32
33
- #ifndef NOMINMAX
33
+ #if defined(_WIN32)
34
+ #if !defined(NOMINMAX)
34
35
  #define NOMINMAX
35
36
  #endif
36
- #ifndef WIN32_LEAN_AND_MEAN
37
+ #if !defined(WIN32_LEAN_AND_MEAN)
37
38
  #define WIN32_LEAN_AND_MEAN
38
39
  #endif
39
40
  #include <windows.h>
@@ -42,7 +43,7 @@
42
43
  #include <dlfcn.h>
43
44
  #include <unistd.h>
44
45
  #include <sys/mman.h>
45
- #ifndef MAP_STACK
46
+ #if !defined(MAP_STACK)
46
47
  #define MAP_STACK 0
47
48
  #endif
48
49
  #endif
@@ -54,7 +55,7 @@ namespace RG {
54
55
 
55
56
  SharedData shared;
56
57
 
57
- static RG_THREAD_LOCAL CallData *exec_call;
58
+ static thread_local CallData *exec_call;
58
59
 
59
60
  static bool ChangeSize(const char *name, Napi::Value value, Size min_size, Size max_size, Size *out_size)
60
61
  {
@@ -201,14 +202,13 @@ static inline bool CheckAlignment(int64_t align)
201
202
  return valid;
202
203
  }
203
204
 
204
- // Prevent simple mistakes but don't be too strict, the world is bigger than the US!
205
205
  static bool IsNameValid(const char *name)
206
206
  {
207
- if (!name[0] || IsAsciiWhite(name[0]) || IsAsciiDigit(name[0])) [[unlikely]]
207
+ if (!IsXidStart(name[0]))
208
208
  return false;
209
209
 
210
210
  for (Size i = 1; name[i]; i++) {
211
- if (IsAsciiWhite(name[i])) [[unlikely]]
211
+ if (!IsXidContinue(name[i])) [[unlikely]]
212
212
  return false;
213
213
  }
214
214
 
@@ -259,10 +259,10 @@ static Napi::Value CreateStructType(const Napi::CallbackInfo &info, bool pad)
259
259
  Napi::Object obj = info[named].As<Napi::Object>();
260
260
  Napi::Array keys = GetOwnPropertyNames(obj);
261
261
 
262
- RG_DEFER_NC(err_guard, len = instance->types.len) {
263
- Size start = len + !named;
262
+ RG_DEFER_NC(err_guard, count = instance->types.count) {
263
+ Size start = count + !named;
264
264
 
265
- for (Size i = start; i < instance->types.len; i++) {
265
+ for (Size i = start; i < instance->types.count; i++) {
266
266
  const TypeInfo *it = &instance->types[i];
267
267
  const TypeInfo **ptr = instance->types_map.Find(it->name);
268
268
 
@@ -271,7 +271,7 @@ static Napi::Value CreateStructType(const Napi::CallbackInfo &info, bool pad)
271
271
  }
272
272
  }
273
273
 
274
- instance->types.RemoveFrom(len);
274
+ instance->types.RemoveFrom(count);
275
275
  };
276
276
 
277
277
  TypeInfo *type = instance->types.AppendDefault();
@@ -294,7 +294,7 @@ static Napi::Value CreateStructType(const Napi::CallbackInfo &info, bool pad)
294
294
  if (!MapType(env, instance, type, type->name))
295
295
  return env.Null();
296
296
  } else {
297
- type->name = Fmt(&instance->str_alloc, "<anonymous_%1>", instance->types.len).ptr;
297
+ type->name = Fmt(&instance->str_alloc, "<anonymous_%1>", instance->types.count).ptr;
298
298
  }
299
299
 
300
300
  type->primitive = PrimitiveKind::Record;
@@ -353,6 +353,9 @@ static Napi::Value CreateStructType(const Napi::CallbackInfo &info, bool pad)
353
353
  return env.Null();
354
354
  }
355
355
 
356
+ if (TestStr(member.name, "_"))
357
+ continue;
358
+
356
359
  if (!IsNameValid(member.name)) {
357
360
  ThrowError<Napi::Error>(env, "Invalid member name '%1'", member.name);
358
361
  return env.Null();
@@ -423,10 +426,10 @@ static Napi::Value CreateUnionType(const Napi::CallbackInfo &info)
423
426
  Napi::Object obj = info[named].As<Napi::Object>();
424
427
  Napi::Array keys = GetOwnPropertyNames(obj);
425
428
 
426
- RG_DEFER_NC(err_guard, len = instance->types.len) {
427
- Size start = len + !named;
429
+ RG_DEFER_NC(err_guard, count = instance->types.count) {
430
+ Size start = count + !named;
428
431
 
429
- for (Size i = start; i < instance->types.len; i++) {
432
+ for (Size i = start; i < instance->types.count; i++) {
430
433
  const TypeInfo *it = &instance->types[i];
431
434
  const TypeInfo **ptr = instance->types_map.Find(it->name);
432
435
 
@@ -435,7 +438,7 @@ static Napi::Value CreateUnionType(const Napi::CallbackInfo &info)
435
438
  }
436
439
  }
437
440
 
438
- instance->types.RemoveFrom(len);
441
+ instance->types.RemoveFrom(count);
439
442
  };
440
443
 
441
444
  TypeInfo *type = instance->types.AppendDefault();
@@ -458,7 +461,7 @@ static Napi::Value CreateUnionType(const Napi::CallbackInfo &info)
458
461
  if (!MapType(env, instance, type, type->name))
459
462
  return env.Null();
460
463
  } else {
461
- type->name = Fmt(&instance->str_alloc, "<anonymous_%1>", instance->types.len).ptr;
464
+ type->name = Fmt(&instance->str_alloc, "<anonymous_%1>", instance->types.count).ptr;
462
465
  }
463
466
 
464
467
  type->primitive = PrimitiveKind::Union;
@@ -508,6 +511,9 @@ static Napi::Value CreateUnionType(const Napi::CallbackInfo &info)
508
511
  size = std::max(size, member.type->size);
509
512
  type->align = std::max(type->align, align);
510
513
 
514
+ if (TestStr(member.name, "_"))
515
+ continue;
516
+
511
517
  if (!IsNameValid(member.name)) {
512
518
  ThrowError<Napi::Error>(env, "Invalid member name '%1'", member.name);
513
519
  return env.Null();
@@ -592,7 +598,7 @@ static Napi::Value CreateOpaqueType(const Napi::CallbackInfo &info)
592
598
  RG_DEFER_N(err_guard) { instance->types.RemoveLast(1); };
593
599
 
594
600
  type->name = named ? DuplicateString(name.Utf8Value().c_str(), &instance->str_alloc).ptr
595
- : Fmt(&instance->str_alloc, "<anonymous_%1>", instance->types.len).ptr;
601
+ : Fmt(&instance->str_alloc, "<anonymous_%1>", instance->types.count).ptr;
596
602
 
597
603
  type->primitive = PrimitiveKind::Void;
598
604
  type->size = 0;
@@ -788,7 +794,7 @@ static Napi::Value CreateDisposableType(const Napi::CallbackInfo &info)
788
794
  type->members.allocator = GetNullAllocator();
789
795
 
790
796
  type->name = named ? DuplicateString(name.Utf8Value().c_str(), &instance->str_alloc).ptr
791
- : Fmt(&instance->str_alloc, "<anonymous_%1>", instance->types.len).ptr;
797
+ : Fmt(&instance->str_alloc, "<anonymous_%1>", instance->types.count).ptr;
792
798
 
793
799
  type->dispose = dispose;
794
800
  type->dispose_ref = Napi::Persistent(dispose_func);
@@ -1005,7 +1011,7 @@ static bool ParseClassicFunction(const Napi::CallbackInfo &info, FunctionInfo *o
1005
1011
  parameters = info[3u].As<Napi::Array>();
1006
1012
  }
1007
1013
 
1008
- #ifdef _WIN32
1014
+ #if defined(_WIN32)
1009
1015
  if (name.IsNumber()) {
1010
1016
  out_func->ordinal_name = name.As<Napi::Number>().Int32Value();
1011
1017
  name = name.ToString();
@@ -1356,7 +1362,7 @@ static InstanceMemory *AllocateMemory(InstanceData *instance, Size stack_size, S
1356
1362
  RG_CRITICAL(mem->stack.ptr, "Failed to allocate %1 of memory", mem->stack.len);
1357
1363
  #endif
1358
1364
 
1359
- #ifdef __OpenBSD__
1365
+ #if defined(__OpenBSD__)
1360
1366
  // Make sure the SP points inside the MAP_STACK area, or (void) functions may crash on OpenBSD i386
1361
1367
  mem->stack.len -= 16;
1362
1368
  #endif
@@ -1365,7 +1371,7 @@ static InstanceMemory *AllocateMemory(InstanceData *instance, Size stack_size, S
1365
1371
  mem->stack0 = mem->stack;
1366
1372
 
1367
1373
  mem->heap.len = heap_size;
1368
- #ifdef _WIN32
1374
+ #if defined(_WIN32)
1369
1375
  mem->heap.ptr = (uint8_t *)VirtualAlloc(nullptr, mem->heap.len, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
1370
1376
  #else
1371
1377
  mem->heap.ptr = (uint8_t *)mmap(nullptr, mem->heap.len, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0);
@@ -1673,7 +1679,7 @@ static Napi::Value FindLibraryFunction(const Napi::CallbackInfo &info)
1673
1679
  func->parameters.Grow(32);
1674
1680
  }
1675
1681
 
1676
- #ifdef _WIN32
1682
+ #if defined(_WIN32)
1677
1683
  if (func->ordinal_name < 0) {
1678
1684
  if (func->decorated_name) {
1679
1685
  func->native = (void *)GetProcAddress((HMODULE)lib->module, func->decorated_name);
@@ -1725,7 +1731,7 @@ static Napi::Value FindSymbol(const Napi::CallbackInfo &info)
1725
1731
  if (!type)
1726
1732
  return env.Null();
1727
1733
 
1728
- #ifdef _WIN32
1734
+ #if defined(_WIN32)
1729
1735
  void *ptr = (void *)GetProcAddress((HMODULE)lib->module, name.c_str());
1730
1736
  #else
1731
1737
  void *ptr = (void *)dlsym(lib->module, name.c_str());
@@ -1769,7 +1775,7 @@ static Napi::Value LoadSharedLibrary(const Napi::CallbackInfo &info)
1769
1775
  return env.Null();
1770
1776
  }
1771
1777
 
1772
- #ifndef _WIN32
1778
+ #if !defined(_WIN32)
1773
1779
  int flags = 0;
1774
1780
 
1775
1781
  if (info.Length() >= 2) {
@@ -1777,7 +1783,7 @@ static Napi::Value LoadSharedLibrary(const Napi::CallbackInfo &info)
1777
1783
 
1778
1784
  flags |= options.Get("lazy").ToBoolean() ? RTLD_LAZY : RTLD_NOW;
1779
1785
  flags |= options.Get("global").ToBoolean() ? RTLD_GLOBAL : RTLD_LOCAL;
1780
- #ifdef RTLD_DEEPBIND
1786
+ #if defined(RTLD_DEEPBIND)
1781
1787
  flags |= options.Get("deep").ToBoolean() ? RTLD_DEEPBIND : 0;
1782
1788
  #endif
1783
1789
  } else {
@@ -1792,7 +1798,7 @@ static Napi::Value LoadSharedLibrary(const Napi::CallbackInfo &info)
1792
1798
 
1793
1799
  // Load shared library
1794
1800
  void *module = nullptr;
1795
- #ifdef _WIN32
1801
+ #if defined(_WIN32)
1796
1802
  if (info[0].IsString()) {
1797
1803
  std::string filename = info[0].As<Napi::String>();
1798
1804
  module = LoadWindowsLibrary(env, filename.c_str());
@@ -2155,7 +2161,7 @@ static Napi::Value ResetKoffi(const Napi::CallbackInfo &info)
2155
2161
  instance->broker = nullptr;
2156
2162
  }
2157
2163
 
2158
- instance->types.RemoveFrom(instance->base_types_len);
2164
+ instance->types.RemoveFrom(instance->base_types_count);
2159
2165
 
2160
2166
  {
2161
2167
  HashSet<const void *> base_types;
@@ -2181,7 +2187,7 @@ static Napi::Value ResetKoffi(const Napi::CallbackInfo &info)
2181
2187
 
2182
2188
  void LibraryHolder::Unload()
2183
2189
  {
2184
- #ifdef _WIN32
2190
+ #if defined(_WIN32)
2185
2191
  if (module && module != GetModuleHandle(nullptr)) {
2186
2192
  FreeLibrary((HMODULE)module);
2187
2193
  }
@@ -2229,7 +2235,7 @@ void FunctionInfo::Unref() const
2229
2235
 
2230
2236
  InstanceMemory::~InstanceMemory()
2231
2237
  {
2232
- #ifdef _WIN32
2238
+ #if defined(_WIN32)
2233
2239
  if (stack.ptr) {
2234
2240
  VirtualFree(stack.ptr, 0, MEM_RELEASE);
2235
2241
  }
@@ -2322,7 +2328,7 @@ static inline PrimitiveKind GetSignPrimitive(Size len, bool sign)
2322
2328
 
2323
2329
  static inline PrimitiveKind GetLittleEndianPrimitive(PrimitiveKind kind)
2324
2330
  {
2325
- #ifdef RG_BIG_ENDIAN
2331
+ #if defined(RG_BIG_ENDIAN)
2326
2332
  return (PrimitiveKind)((int)kind + 1);
2327
2333
  #else
2328
2334
  return kind;
@@ -2331,7 +2337,7 @@ static inline PrimitiveKind GetLittleEndianPrimitive(PrimitiveKind kind)
2331
2337
 
2332
2338
  static inline PrimitiveKind GetBigEndianPrimitive(PrimitiveKind kind)
2333
2339
  {
2334
- #ifdef RG_BIG_ENDIAN
2340
+ #if defined(RG_BIG_ENDIAN)
2335
2341
  return kind;
2336
2342
  #else
2337
2343
  return (PrimitiveKind)((int)kind + 1);
@@ -2347,7 +2353,7 @@ static InstanceData *CreateInstance()
2347
2353
 
2348
2354
  instance->debug = GetDebugFlag("DUMP_CALLS");
2349
2355
 
2350
- #ifdef _WIN32
2356
+ #if defined(_WIN32)
2351
2357
  TEB *teb = GetTEB();
2352
2358
 
2353
2359
  instance->main_stack_max = teb->StackBase;
@@ -2498,7 +2504,7 @@ static Napi::Object InitModule(Napi::Env env, Napi::Object exports)
2498
2504
 
2499
2505
  instance->active_symbol = Napi::Symbol::New(env, "active");
2500
2506
 
2501
- instance->base_types_len = instance->types.len;
2507
+ instance->base_types_count = instance->types.count;
2502
2508
  }
2503
2509
 
2504
2510
  // Expose internal Node stuff
@@ -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
 
26
26
  #include <napi.h>
27
27
 
@@ -229,7 +229,7 @@ struct FunctionInfo {
229
229
 
230
230
  const char *name;
231
231
  const char *decorated_name; // Only set for some platforms/calling conventions
232
- #ifdef _WIN32
232
+ #if defined(_WIN32)
233
233
  int ordinal_name = -1;
234
234
  #endif
235
235
  const LibraryHolder *lib = nullptr;
@@ -278,7 +278,7 @@ struct InstanceData {
278
278
  BucketArray<TypeInfo> types;
279
279
  HashMap<const char *, const TypeInfo *> types_map;
280
280
  BucketArray<FunctionInfo> callbacks;
281
- Size base_types_len;
281
+ Size base_types_count;
282
282
 
283
283
  bool debug;
284
284
 
@@ -299,7 +299,7 @@ struct InstanceData {
299
299
  std::thread::id main_thread_id;
300
300
  napi_threadsafe_function broker = nullptr;
301
301
 
302
- #ifdef _WIN32
302
+ #if defined(_WIN32)
303
303
  void *main_stack_max;
304
304
  void *main_stack_min;
305
305
 
@@ -1,4 +1,4 @@
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
4
  // this software and associated documentation files (the “Software”), to deal in
@@ -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,8 @@
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
+ #include "src/core/unicode/xid.hh"
23
24
  #include "ffi.hh"
24
25
  #include "parser.hh"
25
26
 
@@ -98,9 +99,9 @@ void PrototypeParser::Tokenize(const char *str)
98
99
 
99
100
  if (IsAsciiWhite(c)) {
100
101
  continue;
101
- } else if (IsAsciiAlpha(c) || c == '_') {
102
+ } else if (IsXidStart(c)) {
102
103
  Size j = i;
103
- while (str[++j] && (IsAsciiAlphaOrDigit(str[j]) || str[j] == '_'));
104
+ while (str[++j] && IsXidContinue(str[j]));
104
105
 
105
106
  Span<const char> tok = MakeSpan(str + i, j - i);
106
107
  tokens.Append(tok);
@@ -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 "util.hh"
26
26
 
27
27
  #include <napi.h>
@@ -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,
@@ -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"
@@ -337,7 +337,7 @@ const TypeInfo *ResolveType(Napi::Env env, Span<const char> str, int *out_direct
337
337
  TypeInfo *copy = instance->types.AppendDefault();
338
338
 
339
339
  memcpy((void *)copy, (const void *)type, RG_SIZE(*type));
340
- copy->name = Fmt(&instance->str_alloc, "<anonymous_%1>", instance->types.len).ptr;
340
+ copy->name = Fmt(&instance->str_alloc, "<anonymous_%1>", instance->types.count).ptr;
341
341
  copy->members.allocator = GetNullAllocator();
342
342
 
343
343
  copy->dispose = [](Napi::Env env, const TypeInfo *, const void *ptr) {
@@ -1170,7 +1170,7 @@ void DecodeNormalArray(Napi::Array array, const uint8_t *origin, const TypeInfo
1170
1170
  void DecodeBuffer(Span<uint8_t> buffer, const uint8_t *origin, const TypeInfo *ref)
1171
1171
  {
1172
1172
  // Go fast brrrrr!
1173
- memcpy_safe(buffer.ptr, origin, (size_t)buffer.len);
1173
+ MemCpy(buffer.ptr, origin, (size_t)buffer.len);
1174
1174
 
1175
1175
  #define SWAP(CType) \
1176
1176
  do { \
@@ -1694,16 +1694,16 @@ int AnalyseFlat(const TypeInfo *type, FunctionRef<void(const TypeInfo *type, int
1694
1694
  void DumpMemory(const char *type, Span<const uint8_t> bytes)
1695
1695
  {
1696
1696
  if (bytes.len) {
1697
- PrintLn(stderr, "%1 at 0x%2 (%3):", type, bytes.ptr, FmtMemSize(bytes.len));
1697
+ PrintLn(StdErr, "%1 at 0x%2 (%3):", type, bytes.ptr, FmtMemSize(bytes.len));
1698
1698
 
1699
1699
  for (const uint8_t *ptr = bytes.begin(); ptr < bytes.end();) {
1700
- Print(stderr, " [0x%1 %2 %3] ", FmtArg(ptr).Pad0(-16),
1700
+ Print(StdErr, " [0x%1 %2 %3] ", FmtArg(ptr).Pad0(-16),
1701
1701
  FmtArg((ptr - bytes.begin()) / sizeof(void *)).Pad(-4),
1702
1702
  FmtArg(ptr - bytes.begin()).Pad(-4));
1703
1703
  for (int i = 0; ptr < bytes.end() && i < (int)sizeof(void *); i++, ptr++) {
1704
- Print(stderr, " %1", FmtHex(*ptr).Pad0(-2));
1704
+ Print(StdErr, " %1", FmtHex(*ptr).Pad0(-2));
1705
1705
  }
1706
- PrintLn(stderr);
1706
+ PrintLn(StdErr);
1707
1707
  }
1708
1708
  }
1709
1709
  }
@@ -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
 
27
27
  #include <napi.h>
@@ -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,15 +19,15 @@
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 _WIN32
22
+ #if defined(_WIN32)
23
23
 
24
24
  #include "util.hh"
25
25
  #include "win32.hh"
26
26
 
27
- #ifndef NOMINMAX
27
+ #if !defined(NOMINMAX)
28
28
  #define NOMINMAX
29
29
  #endif
30
- #ifndef WIN32_LEAN_AND_MEAN
30
+ #if !defined(WIN32_LEAN_AND_MEAN)
31
31
  #define WIN32_LEAN_AND_MEAN
32
32
  #endif
33
33
  #include <windows.h>
@@ -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
 
26
26
  #include <intrin.h>
27
27
  #include <napi.h>
@@ -82,9 +82,9 @@ struct TEB {
82
82
  char _pad4[162];
83
83
  uint16_t SameTebFlags;
84
84
  };
85
- static_assert(RG_OFFSET_OF(TEB, DeallocationStack) == 0x1478);
86
- static_assert(RG_OFFSET_OF(TEB, GuaranteedStackBytes) == 0x1748);
87
- static_assert(RG_OFFSET_OF(TEB, SameTebFlags) == 0x17EE);
85
+ static_assert(offsetof(TEB, DeallocationStack) == 0x1478);
86
+ static_assert(offsetof(TEB, GuaranteedStackBytes) == 0x1748);
87
+ static_assert(offsetof(TEB, SameTebFlags) == 0x17EE);
88
88
 
89
89
  #else
90
90
 
@@ -101,9 +101,9 @@ struct TEB {
101
101
  char _pad4[78];
102
102
  uint16_t SameTebFlags;
103
103
  };
104
- static_assert(RG_OFFSET_OF(TEB, DeallocationStack) == 0xE0C);
105
- static_assert(RG_OFFSET_OF(TEB, GuaranteedStackBytes) == 0x0F78);
106
- static_assert(RG_OFFSET_OF(TEB, SameTebFlags) == 0xFCA);
104
+ static_assert(offsetof(TEB, DeallocationStack) == 0xE0C);
105
+ static_assert(offsetof(TEB, GuaranteedStackBytes) == 0x0F78);
106
+ static_assert(offsetof(TEB, SameTebFlags) == 0xFCA);
107
107
 
108
108
  #endif
109
109