koffi 2.5.0 → 2.5.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 (48) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/build/2.5.2/koffi_darwin_arm64/koffi.node +0 -0
  3. package/build/{2.5.0 → 2.5.2}/koffi_darwin_x64/koffi.node +0 -0
  4. package/build/{2.5.0 → 2.5.2}/koffi_freebsd_arm64/koffi.node +0 -0
  5. package/build/{2.5.0 → 2.5.2}/koffi_freebsd_ia32/koffi.node +0 -0
  6. package/build/{2.5.0 → 2.5.2}/koffi_freebsd_x64/koffi.node +0 -0
  7. package/build/2.5.2/koffi_linux_arm32hf/koffi.node +0 -0
  8. package/build/2.5.2/koffi_linux_arm64/koffi.node +0 -0
  9. package/build/{2.5.0 → 2.5.2}/koffi_linux_ia32/koffi.node +0 -0
  10. package/build/{2.5.0 → 2.5.2}/koffi_linux_riscv64hf64/koffi.node +0 -0
  11. package/build/{2.5.0 → 2.5.2}/koffi_linux_x64/koffi.node +0 -0
  12. package/build/{2.5.0 → 2.5.2}/koffi_openbsd_ia32/koffi.node +0 -0
  13. package/build/{2.5.0 → 2.5.2}/koffi_openbsd_x64/koffi.node +0 -0
  14. package/build/2.5.2/koffi_win32_arm64/koffi.node +0 -0
  15. package/build/{2.5.0 → 2.5.2}/koffi_win32_ia32/koffi.node +0 -0
  16. package/build/{2.5.0 → 2.5.2}/koffi_win32_x64/koffi.node +0 -0
  17. package/package.json +2 -2
  18. package/src/core/libcc/brotli.cc +1 -1
  19. package/src/core/libcc/libcc.cc +53 -65
  20. package/src/core/libcc/libcc.hh +67 -28
  21. package/src/core/libcc/miniz.cc +2 -2
  22. package/src/koffi/CMakeLists.txt +1 -5
  23. package/src/koffi/src/abi_arm32.cc +35 -35
  24. package/src/koffi/src/abi_arm64.cc +34 -34
  25. package/src/koffi/src/abi_riscv64.cc +29 -29
  26. package/src/koffi/src/abi_x64_sysv.cc +29 -28
  27. package/src/koffi/src/abi_x64_win.cc +23 -23
  28. package/src/koffi/src/abi_x86.cc +27 -27
  29. package/src/koffi/src/call.cc +65 -72
  30. package/src/koffi/src/call.hh +2 -2
  31. package/src/koffi/src/ffi.cc +24 -24
  32. package/src/koffi/src/ffi.hh +4 -4
  33. package/src/koffi/src/parser.cc +1 -1
  34. package/src/koffi/src/trampolines/prototypes.inc +1 -1
  35. package/src/koffi/src/util.cc +7 -7
  36. package/src/koffi/src/util.hh +1 -1
  37. package/src/koffi/src/win32.hh +4 -4
  38. package/build/2.5.0/koffi_darwin_arm64/koffi.node +0 -0
  39. package/build/2.5.0/koffi_linux_arm32hf/koffi.node +0 -0
  40. package/build/2.5.0/koffi_linux_arm64/koffi.node +0 -0
  41. package/build/2.5.0/koffi_win32_arm64/koffi.node +0 -0
  42. package/build/2.5.0/koffi_win32_x64/koffi.pdb +0 -0
  43. /package/build/{2.5.0 → 2.5.2}/koffi_win32_arm64/koffi.exp +0 -0
  44. /package/build/{2.5.0 → 2.5.2}/koffi_win32_arm64/koffi.lib +0 -0
  45. /package/build/{2.5.0 → 2.5.2}/koffi_win32_ia32/koffi.exp +0 -0
  46. /package/build/{2.5.0 → 2.5.2}/koffi_win32_ia32/koffi.lib +0 -0
  47. /package/build/{2.5.0 → 2.5.2}/koffi_win32_x64/koffi.exp +0 -0
  48. /package/build/{2.5.0 → 2.5.2}/koffi_win32_x64/koffi.lib +0 -0
@@ -1186,7 +1186,7 @@ static InstanceMemory *AllocateMemory(InstanceData *instance, Size stack_size, S
1186
1186
 
1187
1187
  bool temporary = (instance->memories.len > instance->config.resident_async_pools);
1188
1188
 
1189
- if (RG_UNLIKELY(temporary && instance->temporaries >= instance->config.max_temporaries))
1189
+ if (temporary && instance->temporaries >= instance->config.max_temporaries) [[unlikely]]
1190
1190
  return nullptr;
1191
1191
 
1192
1192
  InstanceMemory *mem = new InstanceMemory();
@@ -1243,7 +1243,7 @@ static Napi::Value TranslateNormalCall(const FunctionInfo *func, void *native,
1243
1243
  Napi::Env env = info.Env();
1244
1244
  InstanceData *instance = env.GetInstanceData<InstanceData>();
1245
1245
 
1246
- if (RG_UNLIKELY(info.Length() < (uint32_t)func->required_parameters)) {
1246
+ if (info.Length() < (uint32_t)func->required_parameters) [[unlikely]] {
1247
1247
  ThrowError<Napi::TypeError>(env, "Expected %1 arguments, got %2", func->parameters.len, info.Length());
1248
1248
  return env.Null();
1249
1249
  }
@@ -1251,7 +1251,7 @@ static Napi::Value TranslateNormalCall(const FunctionInfo *func, void *native,
1251
1251
  InstanceMemory *mem = instance->memories[0];
1252
1252
  CallData call(env, instance, mem);
1253
1253
 
1254
- if (!RG_UNLIKELY(call.Prepare(func, info)))
1254
+ if (!call.Prepare(func, info)) [[unlikely]]
1255
1255
  return env.Null();
1256
1256
 
1257
1257
  if (instance->debug) {
@@ -1291,11 +1291,11 @@ static Napi::Value TranslateVariadicCall(const FunctionInfo *func, void *native,
1291
1291
  copy.parameters.Leak();
1292
1292
  };
1293
1293
 
1294
- if (RG_UNLIKELY(info.Length() < (uint32_t)copy.required_parameters)) {
1294
+ if (info.Length() < (uint32_t)copy.required_parameters) [[unlikely]] {
1295
1295
  ThrowError<Napi::TypeError>(env, "Expected %1 arguments or more, got %2", copy.parameters.len, info.Length());
1296
1296
  return env.Null();
1297
1297
  }
1298
- if (RG_UNLIKELY((info.Length() - copy.required_parameters) % 2)) {
1298
+ if ((info.Length() - copy.required_parameters) % 2) [[unlikely]] {
1299
1299
  ThrowError<Napi::Error>(env, "Missing value argument for variadic call");
1300
1300
  return env.Null();
1301
1301
  }
@@ -1305,17 +1305,17 @@ static Napi::Value TranslateVariadicCall(const FunctionInfo *func, void *native,
1305
1305
 
1306
1306
  param.type = ResolveType(info[(uint32_t)i], &param.directions);
1307
1307
 
1308
- if (RG_UNLIKELY(!param.type))
1308
+ if (!param.type) [[unlikely]]
1309
1309
  return env.Null();
1310
- if (RG_UNLIKELY(!CanPassType(param.type, param.directions))) {
1310
+ if (!CanPassType(param.type, param.directions)) [[unlikely]] {
1311
1311
  ThrowError<Napi::TypeError>(env, "Type %1 cannot be used as a parameter", param.type->name);
1312
1312
  return env.Null();
1313
1313
  }
1314
- if (RG_UNLIKELY(copy.parameters.len >= MaxParameters)) {
1314
+ if (copy.parameters.len >= MaxParameters) [[unlikely]] {
1315
1315
  ThrowError<Napi::TypeError>(env, "Functions cannot have more than %1 parameters", MaxParameters);
1316
1316
  return env.Null();
1317
1317
  }
1318
- if (RG_UNLIKELY((param.directions & 2) && ++copy.out_parameters >= MaxOutParameters)) {
1318
+ if ((param.directions & 2) && ++copy.out_parameters >= MaxOutParameters) [[unlikely]] {
1319
1319
  ThrowError<Napi::TypeError>(env, "Functions cannot have more than %1 output parameters", MaxOutParameters);
1320
1320
  return env.Null();
1321
1321
  }
@@ -1326,13 +1326,13 @@ static Napi::Value TranslateVariadicCall(const FunctionInfo *func, void *native,
1326
1326
  copy.parameters.Append(param);
1327
1327
  }
1328
1328
 
1329
- if (RG_UNLIKELY(!AnalyseFunction(env, instance, &copy)))
1329
+ if (!AnalyseFunction(env, instance, &copy)) [[unlikely]]
1330
1330
  return env.Null();
1331
1331
 
1332
1332
  InstanceMemory *mem = instance->memories[0];
1333
1333
  CallData call(env, instance, mem);
1334
1334
 
1335
- if (!RG_UNLIKELY(call.Prepare(&copy, info)))
1335
+ if (!call.Prepare(&copy, info)) [[unlikely]]
1336
1336
  return env.Null();
1337
1337
 
1338
1338
  if (instance->debug) {
@@ -1434,7 +1434,7 @@ static Napi::Value TranslateAsyncCall(const FunctionInfo *func, void *native,
1434
1434
  }
1435
1435
 
1436
1436
  InstanceMemory *mem = AllocateMemory(instance, instance->config.async_stack_size, instance->config.async_heap_size);
1437
- if (RG_UNLIKELY(!mem)) {
1437
+ if (!mem) [[unlikely]] {
1438
1438
  ThrowError<Napi::Error>(env, "Too many asynchronous calls are running");
1439
1439
  return env.Null();
1440
1440
  }
@@ -1456,7 +1456,7 @@ Napi::Value TranslateAsyncCall(const Napi::CallbackInfo &info)
1456
1456
 
1457
1457
  extern "C" void RelayCallback(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegisters *out_reg)
1458
1458
  {
1459
- if (RG_LIKELY(exec_call)) {
1459
+ if (exec_call) [[likely]] {
1460
1460
  exec_call->RelaySafe(idx, own_sp, caller_sp, false, out_reg);
1461
1461
  } else {
1462
1462
  // This happens if the callback pointer is called from a different thread
@@ -1468,7 +1468,7 @@ extern "C" void RelayCallback(Size idx, uint8_t *own_sp, uint8_t *caller_sp, Bac
1468
1468
  InstanceData *instance = env.GetInstanceData<InstanceData>();
1469
1469
 
1470
1470
  InstanceMemory *mem = AllocateMemory(instance, instance->config.async_stack_size, instance->config.async_heap_size);
1471
- if (RG_UNLIKELY(!mem)) {
1471
+ if (!mem) [[unlikely]] {
1472
1472
  ThrowError<Napi::Error>(env, "Too many asynchronous calls are running");
1473
1473
  return;
1474
1474
  }
@@ -1680,7 +1680,7 @@ static Napi::Value RegisterCallback(const Napi::CallbackInfo &info)
1680
1680
  {
1681
1681
  std::lock_guard<std::mutex> lock(shared.mutex);
1682
1682
 
1683
- if (RG_UNLIKELY(!shared.available.len)) {
1683
+ if (!shared.available.len) [[unlikely]] {
1684
1684
  ThrowError<Napi::Error>(env, "Too many callbacks are in use (max = %1)", MaxTrampolines);
1685
1685
  return env.Null();
1686
1686
  }
@@ -1732,7 +1732,7 @@ static Napi::Value UnregisterCallback(const Napi::CallbackInfo &info)
1732
1732
  {
1733
1733
  int16_t *it = instance->trampolines_map.Find(ptr);
1734
1734
 
1735
- if (RG_UNLIKELY(!it)) {
1735
+ if (!it) [[unlikely]] {
1736
1736
  ThrowError<Napi::Error>(env, "Could not find matching registered callback");
1737
1737
  return env.Null();
1738
1738
  }
@@ -1762,7 +1762,7 @@ static Napi::Value CastValue(const Napi::CallbackInfo &info)
1762
1762
  Napi::Env env = info.Env();
1763
1763
  InstanceData *instance = env.GetInstanceData<InstanceData>();
1764
1764
 
1765
- if (RG_UNLIKELY(info.Length() < 2)) {
1765
+ if (info.Length() < 2) [[unlikely]] {
1766
1766
  ThrowError<Napi::TypeError>(env, "Expected 2 arguments, got %1", info.Length());
1767
1767
  return env.Null();
1768
1768
  }
@@ -1770,7 +1770,7 @@ static Napi::Value CastValue(const Napi::CallbackInfo &info)
1770
1770
  Napi::Value value = info[0];
1771
1771
 
1772
1772
  const TypeInfo *type = ResolveType(info[1]);
1773
- if (RG_UNLIKELY(!type))
1773
+ if (!type) [[unlikely]]
1774
1774
  return env.Null();
1775
1775
  if (type->primitive != PrimitiveKind::Pointer &&
1776
1776
  type->primitive != PrimitiveKind::String &&
@@ -1797,13 +1797,13 @@ static Napi::Value DecodeValue(const Napi::CallbackInfo &info)
1797
1797
  bool has_offset = (info.Length() >= 2 && info[1].IsNumber());
1798
1798
  bool has_len = (info.Length() >= 3u + has_offset && info[2u + has_offset].IsNumber());
1799
1799
 
1800
- if (RG_UNLIKELY(info.Length() < 2u + has_offset)) {
1800
+ if (info.Length() < 2u + has_offset) [[unlikely]] {
1801
1801
  ThrowError<Napi::TypeError>(env, "Expected %1 to 4 arguments, got %2", 2 + has_offset, info.Length());
1802
1802
  return env.Null();
1803
1803
  }
1804
1804
 
1805
1805
  const TypeInfo *type = ResolveType(info[1u + has_offset]);
1806
- if (RG_UNLIKELY(!type))
1806
+ if (!type) [[unlikely]]
1807
1807
  return env.Null();
1808
1808
 
1809
1809
  Napi::Value value = info[0];
@@ -1844,19 +1844,19 @@ static Napi::Value CallPointerSync(const Napi::CallbackInfo &info)
1844
1844
  Napi::Env env = info.Env();
1845
1845
  InstanceData *instance = env.GetInstanceData<InstanceData>();
1846
1846
 
1847
- if (RG_UNLIKELY(info.Length() < 2)) {
1847
+ if (info.Length() < 2) [[unlikely]] {
1848
1848
  ThrowError<Napi::TypeError>(env, "Expected 2 or more arguments, got %1", info.Length());
1849
1849
  return env.Null();
1850
1850
  }
1851
1851
 
1852
1852
  void *ptr = nullptr;
1853
- if (RG_UNLIKELY(!GetExternalPointer(env, info[0], &ptr)))
1853
+ if (!GetExternalPointer(env, info[0], &ptr)) [[unlikely]]
1854
1854
  return env.Null();
1855
1855
 
1856
1856
  const TypeInfo *type = ResolveType(info[1]);
1857
- if (RG_UNLIKELY(!type))
1857
+ if (!type) [[unlikely]]
1858
1858
  return env.Null();
1859
- if (RG_UNLIKELY(type->primitive != PrimitiveKind::Prototype)) {
1859
+ if (type->primitive != PrimitiveKind::Prototype) [[unlikely]] {
1860
1860
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value for type, expected function type", GetValueType(instance, info[1]));
1861
1861
  return env.Null();
1862
1862
  }
@@ -305,9 +305,9 @@ struct InstanceData {
305
305
  int64_t disposed = 0;
306
306
  } stats;
307
307
  };
308
- RG_STATIC_ASSERT(DefaultResidentAsyncPools <= RG_LEN(InstanceData::memories.data) - 1);
309
- RG_STATIC_ASSERT(DefaultMaxAsyncCalls >= DefaultResidentAsyncPools);
310
- RG_STATIC_ASSERT(MaxAsyncCalls >= DefaultMaxAsyncCalls);
308
+ static_assert(DefaultResidentAsyncPools <= RG_LEN(InstanceData::memories.data) - 1);
309
+ static_assert(DefaultMaxAsyncCalls >= DefaultResidentAsyncPools);
310
+ static_assert(MaxAsyncCalls >= DefaultMaxAsyncCalls);
311
311
 
312
312
  struct TrampolineInfo {
313
313
  InstanceData *instance;
@@ -334,7 +334,7 @@ struct SharedData {
334
334
  }
335
335
  }
336
336
  };
337
- RG_STATIC_ASSERT(MaxTrampolines <= INT16_MAX);
337
+ static_assert(MaxTrampolines <= INT16_MAX);
338
338
 
339
339
  extern SharedData shared;
340
340
 
@@ -172,7 +172,7 @@ const TypeInfo *PrototypeParser::ParseType()
172
172
  offset++;
173
173
  return type;
174
174
  }
175
- if (RG_UNLIKELY(env.IsExceptionPending()))
175
+ if (env.IsExceptionPending()) [[unlikely]]
176
176
  return instance->void_type;
177
177
 
178
178
  offset--;
@@ -16406,4 +16406,4 @@ static void *const Trampolines[][2] = {
16406
16406
  { &Trampoline8190, &TrampolineX8190 },
16407
16407
  { &Trampoline8191, &TrampolineX8191 }
16408
16408
  };
16409
- RG_STATIC_ASSERT(RG_LEN(Trampolines) == MaxTrampolines);
16409
+ static_assert(RG_LEN(Trampolines) == MaxTrampolines);
@@ -85,7 +85,7 @@ Napi::Value MagicUnion::Getter(const Napi::CallbackInfo &info)
85
85
  } else {
86
86
  Napi::Env env = info.Env();
87
87
 
88
- if (RG_UNLIKELY(!raw.len)) {
88
+ if (!raw.len) [[unlikely]] {
89
89
  ThrowError<Napi::Error>(env, "Cannont convert %1 union value", active_idx < 0 ? "empty" : "assigned");
90
90
  return env.Null();
91
91
  }
@@ -190,7 +190,7 @@ const TypeInfo *ResolveType(Napi::Env env, Span<const char> str, int *out_direct
190
190
  remain = remain.Take(1, remain.len - 1);
191
191
  indirect++;
192
192
 
193
- if (RG_UNLIKELY(indirect) >= RG_SIZE(disposables) * 8) {
193
+ if (indirect >= RG_SIZE(disposables) * 8) [[unlikely]] {
194
194
  ThrowError<Napi::Error>(env, "Too many pointer indirections");
195
195
  return nullptr;
196
196
  }
@@ -233,9 +233,9 @@ const TypeInfo *ResolveType(Napi::Env env, Span<const char> str, int *out_direct
233
233
 
234
234
  for (int i = 0;; i++) {
235
235
  if (disposables & (1u << i)) {
236
- if (RG_UNLIKELY(type->primitive != PrimitiveKind::Pointer &&
237
- type->primitive != PrimitiveKind::String &&
238
- type->primitive != PrimitiveKind::String16)) {
236
+ if (type->primitive != PrimitiveKind::Pointer &&
237
+ type->primitive != PrimitiveKind::String &&
238
+ type->primitive != PrimitiveKind::String16) [[unlikely]] {
239
239
  ThrowError<Napi::Error>(env, "Cannot create disposable type for non-pointer");
240
240
  return nullptr;
241
241
  }
@@ -1035,7 +1035,7 @@ Napi::Value Decode(Napi::Value value, Size offset, const TypeInfo *type, const S
1035
1035
  } else if (IsRawBuffer(value)) {
1036
1036
  Span<uint8_t> buffer = GetRawBuffer(value);
1037
1037
 
1038
- if (RG_UNLIKELY(buffer.len - offset < type->size)) {
1038
+ if (buffer.len - offset < type->size) [[unlikely]] {
1039
1039
  ThrowError<Napi::Error>(env, "Expected buffer with size superior or equal to type %1 (%2 bytes)",
1040
1040
  type->name, type->size + offset);
1041
1041
  return env.Null();
@@ -1065,7 +1065,7 @@ Napi::Value Decode(Napi::Env env, const uint8_t *ptr, const TypeInfo *type, cons
1065
1065
  if (*len >= 0) {
1066
1066
  type = MakeArrayType(instance, type, *len);
1067
1067
  } else {
1068
- if (RG_UNLIKELY(!(type->flags & (int)TypeFlag::IsCharLike))) {
1068
+ if (!(type->flags & (int)TypeFlag::IsCharLike)) [[unlikely]] {
1069
1069
  ThrowError<Napi::TypeError>(env, "Only char-like types can find their length automatically", type->name);
1070
1070
  return env.Null();
1071
1071
  }
@@ -147,7 +147,7 @@ T GetNumber(Napi::Value value)
147
147
  {
148
148
  RG_ASSERT(value.IsNumber() || value.IsBigInt());
149
149
 
150
- if (RG_LIKELY(value.IsNumber())) {
150
+ if (value.IsNumber()) [[likely]] {
151
151
  return (T)value.As<Napi::Number>().DoubleValue();
152
152
  } else if (value.IsBigInt()) {
153
153
  Napi::BigInt bigint = value.As<Napi::BigInt>();
@@ -38,8 +38,8 @@ struct TEB {
38
38
  char _pad2[712];
39
39
  uint32_t GuaranteedStackBytes;
40
40
  };
41
- RG_STATIC_ASSERT(RG_OFFSET_OF(TEB, DeallocationStack) == 0x1478);
42
- RG_STATIC_ASSERT(RG_OFFSET_OF(TEB, GuaranteedStackBytes) == 0x1748);
41
+ static_assert(RG_OFFSET_OF(TEB, DeallocationStack) == 0x1478);
42
+ static_assert(RG_OFFSET_OF(TEB, GuaranteedStackBytes) == 0x1748);
43
43
 
44
44
  #else
45
45
 
@@ -52,8 +52,8 @@ struct TEB {
52
52
  char _pad2[360];
53
53
  uint32_t GuaranteedStackBytes;
54
54
  };
55
- RG_STATIC_ASSERT(RG_OFFSET_OF(TEB, DeallocationStack) == 0xE0C);
56
- RG_STATIC_ASSERT(RG_OFFSET_OF(TEB, GuaranteedStackBytes) == 0x0F78);
55
+ static_assert(RG_OFFSET_OF(TEB, DeallocationStack) == 0xE0C);
56
+ static_assert(RG_OFFSET_OF(TEB, GuaranteedStackBytes) == 0x0F78);
57
57
 
58
58
  #endif
59
59