koffi 2.5.0-beta.2 → 2.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/build/2.5.1/koffi_darwin_arm64/koffi.node +0 -0
  3. package/build/{2.5.0-beta.2 → 2.5.1}/koffi_darwin_x64/koffi.node +0 -0
  4. package/build/{2.5.0-beta.2 → 2.5.1}/koffi_freebsd_arm64/koffi.node +0 -0
  5. package/build/{2.5.0-beta.2 → 2.5.1}/koffi_freebsd_ia32/koffi.node +0 -0
  6. package/build/{2.5.0-beta.2 → 2.5.1}/koffi_freebsd_x64/koffi.node +0 -0
  7. package/build/2.5.1/koffi_linux_arm32hf/koffi.node +0 -0
  8. package/build/2.5.1/koffi_linux_arm64/koffi.node +0 -0
  9. package/build/{2.5.0-beta.2 → 2.5.1}/koffi_linux_ia32/koffi.node +0 -0
  10. package/build/{2.5.0-beta.2 → 2.5.1}/koffi_linux_riscv64hf64/koffi.node +0 -0
  11. package/build/{2.5.0-beta.2 → 2.5.1}/koffi_linux_x64/koffi.node +0 -0
  12. package/build/{2.5.0-beta.2 → 2.5.1}/koffi_openbsd_ia32/koffi.node +0 -0
  13. package/build/{2.5.0-beta.2 → 2.5.1}/koffi_openbsd_x64/koffi.node +0 -0
  14. package/build/2.5.1/koffi_win32_arm64/koffi.node +0 -0
  15. package/build/{2.5.0-beta.2 → 2.5.1}/koffi_win32_ia32/koffi.node +0 -0
  16. package/build/{2.5.0-beta.2 → 2.5.1}/koffi_win32_x64/koffi.node +0 -0
  17. package/doc/functions.md +1 -1
  18. package/doc/unions.md +3 -3
  19. package/package.json +2 -2
  20. package/src/core/libcc/brotli.cc +1 -1
  21. package/src/core/libcc/libcc.cc +53 -65
  22. package/src/core/libcc/libcc.hh +67 -28
  23. package/src/core/libcc/miniz.cc +2 -2
  24. package/src/koffi/CMakeLists.txt +1 -5
  25. package/src/koffi/src/abi_arm32.cc +35 -35
  26. package/src/koffi/src/abi_arm64.cc +34 -34
  27. package/src/koffi/src/abi_riscv64.cc +29 -29
  28. package/src/koffi/src/abi_x64_sysv.cc +29 -28
  29. package/src/koffi/src/abi_x64_win.cc +23 -23
  30. package/src/koffi/src/abi_x86.cc +27 -27
  31. package/src/koffi/src/call.cc +62 -69
  32. package/src/koffi/src/call.hh +2 -2
  33. package/src/koffi/src/ffi.cc +24 -24
  34. package/src/koffi/src/ffi.hh +4 -4
  35. package/src/koffi/src/parser.cc +1 -1
  36. package/src/koffi/src/trampolines/prototypes.inc +1 -1
  37. package/src/koffi/src/util.cc +7 -7
  38. package/src/koffi/src/util.hh +1 -1
  39. package/src/koffi/src/win32.hh +4 -4
  40. package/build/2.5.0-beta.2/koffi_darwin_arm64/koffi.node +0 -0
  41. package/build/2.5.0-beta.2/koffi_linux_arm32hf/koffi.node +0 -0
  42. package/build/2.5.0-beta.2/koffi_linux_arm64/koffi.node +0 -0
  43. package/build/2.5.0-beta.2/koffi_win32_arm64/koffi.node +0 -0
  44. package/build/2.5.0-beta.2/koffi_win32_x64/koffi.pdb +0 -0
  45. /package/build/{2.5.0-beta.2 → 2.5.1}/koffi_win32_arm64/koffi.exp +0 -0
  46. /package/build/{2.5.0-beta.2 → 2.5.1}/koffi_win32_arm64/koffi.lib +0 -0
  47. /package/build/{2.5.0-beta.2 → 2.5.1}/koffi_win32_ia32/koffi.exp +0 -0
  48. /package/build/{2.5.0-beta.2 → 2.5.1}/koffi_win32_ia32/koffi.lib +0 -0
  49. /package/build/{2.5.0-beta.2 → 2.5.1}/koffi_win32_x64/koffi.exp +0 -0
  50. /package/build/{2.5.0-beta.2 → 2.5.1}/koffi_win32_x64/koffi.lib +0 -0
@@ -162,8 +162,6 @@ static_assert(sizeof(double) == 8, "This code base is not designed to support si
162
162
  #else
163
163
  #define RG_THREAD_LOCAL __thread
164
164
  #endif
165
- #define RG_LIKELY(Cond) __builtin_expect(!!(Cond), 1)
166
- #define RG_UNLIKELY(Cond) __builtin_expect(!!(Cond), 0)
167
165
 
168
166
  #ifndef SCNd8
169
167
  #define SCNd8 "hhd"
@@ -179,8 +177,6 @@ static_assert(sizeof(double) == 8, "This code base is not designed to support si
179
177
  #define RG_POP_NO_WARNINGS __pragma(warning(pop))
180
178
 
181
179
  #define RG_THREAD_LOCAL thread_local
182
- #define RG_LIKELY(Cond) (Cond)
183
- #define RG_UNLIKELY(Cond) (Cond)
184
180
  #else
185
181
  #error Compiler not supported
186
182
  #endif
@@ -217,7 +213,7 @@ extern "C" void AssertMessage(const char *filename, int line, const char *cond);
217
213
 
218
214
  #define RG_CRITICAL(Cond, ...) \
219
215
  do { \
220
- if (RG_UNLIKELY(!(Cond))) { \
216
+ if (!(Cond)) [[unlikely]] { \
221
217
  PrintLn(stderr, __VA_ARGS__); \
222
218
  abort(); \
223
219
  } \
@@ -225,7 +221,7 @@ extern "C" void AssertMessage(const char *filename, int line, const char *cond);
225
221
  #ifdef RG_DEBUG
226
222
  #define RG_ASSERT(Cond) \
227
223
  do { \
228
- if (RG_UNLIKELY(!(Cond))) { \
224
+ if (!(Cond)) [[unlikely]] { \
229
225
  RG::AssertMessage(__FILE__, __LINE__, RG_STRINGIFY(Cond)); \
230
226
  RG_DEBUG_BREAK(); \
231
227
  abort(); \
@@ -237,8 +233,6 @@ extern "C" void AssertMessage(const char *filename, int line, const char *cond);
237
233
  (void)sizeof(Cond); \
238
234
  } while (false)
239
235
  #endif
240
- #define RG_STATIC_ASSERT(Cond) \
241
- static_assert((Cond), RG_STRINGIFY(Cond))
242
236
 
243
237
  #if defined(RG_DEBUG)
244
238
  #define RG_UNREACHABLE() \
@@ -2104,7 +2098,7 @@ public:
2104
2098
 
2105
2099
  void RemoveAll()
2106
2100
  {
2107
- RG_STATIC_ASSERT(!std::is_pointer<ValueType>::value);
2101
+ static_assert(!std::is_pointer<ValueType>::value);
2108
2102
 
2109
2103
  for (Size i = 0; i < capacity; i++) {
2110
2104
  if (!IsEmpty(i)) {
@@ -3436,6 +3430,53 @@ static inline Span<const char> SplitStr(Span<const char> str, char split_char, S
3436
3430
  static inline Span<const char> SplitStr(const char *str, char split_char, const char **out_remainder = nullptr)
3437
3431
  { return SplitStr((char *)str, split_char, (char **)out_remainder); }
3438
3432
 
3433
+ static inline Span<char> SplitStr(Span<char> str, const char *split_str, Span<char> *out_remainder = nullptr)
3434
+ {
3435
+ RG_ASSERT(split_str[0]);
3436
+
3437
+ Size part_len = 0;
3438
+ while (part_len < str.len) {
3439
+ if (StartsWith(str.Take(part_len, str.len - part_len), split_str)) {
3440
+ if (out_remainder) {
3441
+ Size split_len = strlen(split_str);
3442
+ *out_remainder = str.Take(part_len + split_len, str.len - part_len - split_len);
3443
+ }
3444
+ return str.Take(0, part_len);
3445
+ }
3446
+ part_len++;
3447
+ }
3448
+
3449
+ if (out_remainder) {
3450
+ *out_remainder = str.Take(str.len, 0);
3451
+ }
3452
+ return str;
3453
+ }
3454
+ static inline Span<char> SplitStr(char *str, const char *split_str, char **out_remainder = nullptr)
3455
+ {
3456
+ RG_ASSERT(split_str[0]);
3457
+
3458
+ Size part_len = 0;
3459
+ while (str[part_len]) {
3460
+ if (StartsWith(str + part_len, split_str)) {
3461
+ if (out_remainder) {
3462
+ Size split_len = strlen(split_str);
3463
+ *out_remainder = str + part_len + split_len;
3464
+ }
3465
+ return MakeSpan(str, part_len);
3466
+ }
3467
+ part_len++;
3468
+ }
3469
+
3470
+ if (out_remainder) {
3471
+ *out_remainder = str + part_len;
3472
+ }
3473
+ return MakeSpan(str, part_len);
3474
+ }
3475
+ static inline Span<const char> SplitStr(Span<const char> str, const char *split_str, Span<const char> *out_remainder = nullptr)
3476
+ { return SplitStr(MakeSpan((char *)str.ptr, str.len), split_str, (Span<char> *)out_remainder); }
3477
+ static inline Span<const char> SplitStr(const char *str, const char *split_str, const char **out_remainder = nullptr)
3478
+ { return SplitStr((char *)str, split_str, (char **)out_remainder); }
3479
+
3439
3480
  static inline Span<char> SplitStrLine(Span<char> str, Span<char> *out_remainder = nullptr)
3440
3481
  {
3441
3482
  Span<char> part = SplitStr(str, '\n', out_remainder);
@@ -3603,7 +3644,7 @@ template <typename T>
3603
3644
  bool ParseInt(Span<const char> str, T *out_value, unsigned int flags = RG_DEFAULT_PARSE_FLAGS,
3604
3645
  Span<const char> *out_remaining = nullptr)
3605
3646
  {
3606
- if (RG_UNLIKELY(!str.len)) {
3647
+ if (!str.len) [[unlikely]] {
3607
3648
  if (flags & (int)ParseFlag::Log) {
3608
3649
  LogError("Cannot convert empty string to integer");
3609
3650
  }
@@ -3625,7 +3666,7 @@ bool ParseInt(Span<const char> str, T *out_value, unsigned int flags = RG_DEFAUL
3625
3666
 
3626
3667
  for (; pos < str.len; pos++) {
3627
3668
  unsigned int digit = (unsigned int)(str[pos] - '0');
3628
- if (RG_UNLIKELY(digit > 9)) {
3669
+ if (digit > 9) [[unlikely]] {
3629
3670
  if (!pos || flags & (int)ParseFlag::End) {
3630
3671
  if (flags & (int)ParseFlag::Log) {
3631
3672
  LogError("Malformed integer number '%1'", str);
@@ -3637,11 +3678,11 @@ bool ParseInt(Span<const char> str, T *out_value, unsigned int flags = RG_DEFAUL
3637
3678
  }
3638
3679
 
3639
3680
  uint64_t new_value = (value * 10) + digit;
3640
- if (RG_UNLIKELY(new_value < value))
3681
+ if (new_value < value) [[unlikely]]
3641
3682
  goto overflow;
3642
3683
  value = new_value;
3643
3684
  }
3644
- if (RG_UNLIKELY(value > (uint64_t)std::numeric_limits<T>::max()))
3685
+ if (value > (uint64_t)std::numeric_limits<T>::max()) [[unlikely]]
3645
3686
  goto overflow;
3646
3687
  value = ((value ^ neg) - neg);
3647
3688
 
@@ -3704,18 +3745,18 @@ static inline Size DecodeUtf8(const char *str, int32_t *out_c)
3704
3745
  if (ptr[0] < 0x80) {
3705
3746
  *out_c = ptr[0];
3706
3747
  return 1;
3707
- } else if (RG_UNLIKELY(ptr[0] - 0xC2 > 0xF4 - 0xC2)) {
3748
+ } else if (ptr[0] - 0xC2 > 0xF4 - 0xC2) [[unlikely]] {
3708
3749
  return 0;
3709
- } else if (RG_LIKELY(ptr[1])) {
3750
+ } else if (ptr[1]) [[likely]] {
3710
3751
  if (ptr[0] < 0xE0 && (ptr[1] & 0xC0) == 0x80) {
3711
3752
  *out_c = ((ptr[0] & 0x1F) << 6) | (ptr[1] & 0x3F);
3712
3753
  return 2;
3713
- } else if (RG_LIKELY(ptr[2])) {
3754
+ } else if (ptr[2]) [[likely]] {
3714
3755
  if (ptr[0] < 0xF0 && (ptr[1] & 0xC0) == 0x80 &&
3715
3756
  (ptr[2] & 0xC0) == 0x80) {
3716
3757
  *out_c = ((ptr[0] & 0xF) << 12) | ((ptr[1] & 0x3F) << 6) | (ptr[2] & 0x3F);
3717
3758
  return 3;
3718
- } else if (RG_LIKELY(ptr[3])) {
3759
+ } else if (ptr[3]) [[likely]] {
3719
3760
  if ((ptr[1] & 0xC0) == 0x80 &&
3720
3761
  (ptr[2] & 0xC0) == 0x80 &&
3721
3762
  (ptr[3] & 0xC0) == 0x80) {
@@ -3739,20 +3780,18 @@ static inline Size DecodeUtf8(Span<const char> str, Size offset, int32_t *out_c)
3739
3780
  if (ptr[0] < 0x80) {
3740
3781
  *out_c = ptr[0];
3741
3782
  return 1;
3742
- } else if (RG_UNLIKELY(ptr[0] - 0xC2 > 0xF4 - 0xC2)) {
3783
+ } else if (ptr[0] - 0xC2 > 0xF4 - 0xC2) [[unlikely]] {
3743
3784
  return 0;
3744
- } else if (ptr[0] < 0xE0 &&
3745
- RG_LIKELY(available >= 2 && (ptr[1] & 0xC0) == 0x80)) {
3785
+ } else if (ptr[0] < 0xE0 && available >= 2 && (ptr[1] & 0xC0) == 0x80) {
3746
3786
  *out_c = ((ptr[0] & 0x1F) << 6) | (ptr[1] & 0x3F);
3747
3787
  return 2;
3748
- } else if (ptr[0] < 0xF0 &&
3749
- RG_LIKELY(available >= 3 && (ptr[1] & 0xC0) == 0x80 &&
3750
- (ptr[2] & 0xC0) == 0x80)) {
3788
+ } else if (ptr[0] < 0xF0 && available >= 3 && (ptr[1] & 0xC0) == 0x80 &&
3789
+ (ptr[2] & 0xC0) == 0x80) {
3751
3790
  *out_c = ((ptr[0] & 0xF) << 12) | ((ptr[1] & 0x3F) << 6) | (ptr[2] & 0x3F);
3752
3791
  return 3;
3753
- } else if (RG_LIKELY(available >= 4 && (ptr[1] & 0xC0) == 0x80 &&
3754
- (ptr[2] & 0xC0) == 0x80 &&
3755
- (ptr[3] & 0xC0) == 0x80)) {
3792
+ } else if (available >= 4 && (ptr[1] & 0xC0) == 0x80 &&
3793
+ (ptr[2] & 0xC0) == 0x80 &&
3794
+ (ptr[3] & 0xC0) == 0x80) {
3756
3795
  *out_c = ((ptr[0] & 0x7) << 18) | ((ptr[1] & 0x3F) << 12) | ((ptr[2] & 0x3F) << 6) | (ptr[3] & 0x3F);
3757
3796
  return 4;
3758
3797
  } else {
@@ -4092,8 +4131,8 @@ private:
4092
4131
 
4093
4132
  template <int Min = 0, int Max = INT_MAX>
4094
4133
  class FastRandomInt {
4095
- RG_STATIC_ASSERT(Min >= 0);
4096
- RG_STATIC_ASSERT(Max > Min);
4134
+ static_assert(Min >= 0);
4135
+ static_assert(Max > Min);
4097
4136
 
4098
4137
  FastRandom rng;
4099
4138
 
@@ -54,7 +54,7 @@ public:
54
54
 
55
55
  bool MinizDecompressor::Init(CompressionType type)
56
56
  {
57
- RG_STATIC_ASSERT(RG_SIZE(out_buf) >= TINFL_LZ_DICT_SIZE);
57
+ static_assert(RG_SIZE(out_buf) >= TINFL_LZ_DICT_SIZE);
58
58
 
59
59
  tinfl_init(&inflator);
60
60
  is_gzip = (type == CompressionType::Gzip);
@@ -177,7 +177,7 @@ Size MinizDecompressor::Read(Size max_len, void *user_buf)
177
177
  // Gzip footer (CRC and size check)
178
178
  if (is_gzip) {
179
179
  uint32_t footer[2];
180
- RG_STATIC_ASSERT(RG_SIZE(footer) == 8);
180
+ static_assert(RG_SIZE(footer) == 8);
181
181
 
182
182
  if (in_len < RG_SIZE(footer)) {
183
183
  memcpy_safe(footer, in_ptr, (size_t)in_len);
@@ -28,11 +28,7 @@ include(CheckCXXCompilerFlag)
28
28
 
29
29
  find_package(CNoke)
30
30
 
31
- if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.8.0")
32
- set(CMAKE_CXX_STANDARD 17)
33
- else()
34
- set(CMAKE_CXX_STANDARD 14)
35
- endif()
31
+ set(CMAKE_CXX_STANDARD 17)
36
32
  if(MSVC)
37
33
  set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreaded)
38
34
 
@@ -226,11 +226,11 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
226
226
  // registers just before the stack (so behind the vector ones).
227
227
  // In the armv7hf calling convention, some arguments can end up
228
228
  // partially in GPR, partially in the stack.
229
- if (RG_UNLIKELY(!AllocStack(func->args_size, 16, &args_ptr)))
229
+ if (!AllocStack(func->args_size, 16, &args_ptr)) [[unlikely]]
230
230
  return false;
231
- if (RG_UNLIKELY(!AllocStack(4 * 4, 8, &gpr_ptr)))
231
+ if (!AllocStack(4 * 4, 8, &gpr_ptr)) [[unlikely]]
232
232
  return false;
233
- if (RG_UNLIKELY(!AllocStack(8 * 8, 8, &vec_ptr)))
233
+ if (!AllocStack(8 * 8, 8, &vec_ptr)) [[unlikely]]
234
234
  return false;
235
235
  if (func->ret.use_memory) {
236
236
  return_ptr = AllocHeap(func->ret.type->size, 16);
@@ -239,7 +239,7 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
239
239
 
240
240
  #define PUSH_INTEGER_32(CType) \
241
241
  do { \
242
- if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) { \
242
+ if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] { \
243
243
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value)); \
244
244
  return false; \
245
245
  } \
@@ -249,7 +249,7 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
249
249
  } while (false)
250
250
  #define PUSH_INTEGER_32_SWAP(CType) \
251
251
  do { \
252
- if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) { \
252
+ if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] { \
253
253
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value)); \
254
254
  return false; \
255
255
  } \
@@ -259,14 +259,14 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
259
259
  } while (false)
260
260
  #define PUSH_INTEGER_64(CType) \
261
261
  do { \
262
- if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) { \
262
+ if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] { \
263
263
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value)); \
264
264
  return false; \
265
265
  } \
266
266
  \
267
267
  CType v = GetNumber<CType>(value); \
268
268
  \
269
- if (RG_LIKELY(param.gpr_count)) { \
269
+ if (param.gpr_count) [[likely]] { \
270
270
  gpr_ptr = AlignUp(gpr_ptr, 8); \
271
271
  *(uint64_t *)gpr_ptr = (uint64_t)v; \
272
272
  gpr_ptr += param.gpr_count; \
@@ -278,14 +278,14 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
278
278
  } while (false)
279
279
  #define PUSH_INTEGER_64_SWAP(CType) \
280
280
  do { \
281
- if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) { \
281
+ if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] { \
282
282
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value)); \
283
283
  return false; \
284
284
  } \
285
285
  \
286
286
  CType v = GetNumber<CType>(value); \
287
287
  \
288
- if (RG_LIKELY(param.gpr_count)) { \
288
+ if (param.gpr_count) [[likely]] { \
289
289
  gpr_ptr = AlignUp(gpr_ptr, 8); \
290
290
  *(uint64_t *)gpr_ptr = (uint64_t)ReverseBytes(v); \
291
291
  gpr_ptr += param.gpr_count; \
@@ -307,7 +307,7 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
307
307
  case PrimitiveKind::Void: { RG_UNREACHABLE(); } break;
308
308
 
309
309
  case PrimitiveKind::Bool: {
310
- if (RG_UNLIKELY(!value.IsBoolean())) {
310
+ if (!value.IsBoolean()) [[unlikely]] {
311
311
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected boolean", GetValueType(instance, value));
312
312
  return false;
313
313
  }
@@ -331,28 +331,28 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
331
331
  case PrimitiveKind::UInt64S: { PUSH_INTEGER_64_SWAP(uint64_t); } break;
332
332
  case PrimitiveKind::String: {
333
333
  const char *str;
334
- if (RG_UNLIKELY(!PushString(value, param.directions, &str)))
334
+ if (!PushString(value, param.directions, &str)) [[unlikely]]
335
335
  return false;
336
336
 
337
337
  *(const char **)((param.gpr_count ? gpr_ptr : args_ptr)++) = str;
338
338
  } break;
339
339
  case PrimitiveKind::String16: {
340
340
  const char16_t *str16;
341
- if (RG_UNLIKELY(!PushString16(value, param.directions, &str16)))
341
+ if (!PushString16(value, param.directions, &str16)) [[unlikely]]
342
342
  return false;
343
343
 
344
344
  *(const char16_t **)((param.gpr_count ? gpr_ptr : args_ptr)++) = str16;
345
345
  } break;
346
346
  case PrimitiveKind::Pointer: {
347
347
  void *ptr;
348
- if (RG_UNLIKELY(!PushPointer(value, param.type, param.directions, &ptr)))
348
+ if (!PushPointer(value, param.type, param.directions, &ptr)) [[unlikely]]
349
349
  return false;
350
350
 
351
351
  *(void **)((param.gpr_count ? gpr_ptr : args_ptr)++) = ptr;
352
352
  } break;
353
353
  case PrimitiveKind::Record:
354
354
  case PrimitiveKind::Union: {
355
- if (RG_UNLIKELY(!IsObject(value))) {
355
+ if (!IsObject(value)) [[unlikely]] {
356
356
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected object", GetValueType(instance, value));
357
357
  return false;
358
358
  }
@@ -385,14 +385,14 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
385
385
  } break;
386
386
  case PrimitiveKind::Array: { RG_UNREACHABLE(); } break;
387
387
  case PrimitiveKind::Float32: {
388
- if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
388
+ if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] {
389
389
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value));
390
390
  return false;
391
391
  }
392
392
 
393
393
  float f = GetNumber<float>(value);
394
394
 
395
- if (RG_LIKELY(param.vec_count)) {
395
+ if (param.vec_count) [[likely]] {
396
396
  *(float *)(vec_ptr++) = f;
397
397
  } else if (param.gpr_count) {
398
398
  *(float *)(gpr_ptr++) = f;
@@ -401,14 +401,14 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
401
401
  }
402
402
  } break;
403
403
  case PrimitiveKind::Float64: {
404
- if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
404
+ if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] {
405
405
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value));
406
406
  return false;
407
407
  }
408
408
 
409
409
  double d = GetNumber<double>(value);
410
410
 
411
- if (RG_LIKELY(param.vec_count)) {
411
+ if (param.vec_count) [[likely]] {
412
412
  *(double *)vec_ptr = d;
413
413
  vec_ptr += 2;
414
414
  } else if (param.gpr_count) {
@@ -428,7 +428,7 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
428
428
  Napi::Function func = value.As<Napi::Function>();
429
429
 
430
430
  ptr = ReserveTrampoline(param.type->ref.proto, func);
431
- if (RG_UNLIKELY(!ptr))
431
+ if (!ptr) [[unlikely]]
432
432
  return false;
433
433
  } else if (CheckValueTag(instance, value, param.type->ref.marker)) {
434
434
  ptr = value.As<Napi::External<void>>().Data();
@@ -566,7 +566,7 @@ Napi::Value CallData::Complete(const FunctionInfo *func)
566
566
 
567
567
  void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool async, BackRegisters *out_reg)
568
568
  {
569
- if (RG_UNLIKELY(env.IsExceptionPending()))
569
+ if (env.IsExceptionPending()) [[unlikely]]
570
570
  return;
571
571
 
572
572
  const TrampolineInfo &trampoline = shared.trampolines[idx];
@@ -583,7 +583,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool async,
583
583
 
584
584
  RG_DEFER_N(err_guard) { memset(out_reg, 0, RG_SIZE(*out_reg)); };
585
585
 
586
- if (RG_UNLIKELY(trampoline.generation >= 0 && trampoline.generation != (int32_t)mem->generation)) {
586
+ if (trampoline.generation >= 0 && trampoline.generation != (int32_t)mem->generation) [[unlikely]] {
587
587
  ThrowError<Napi::Error>(env, "Cannot use non-registered callback beyond FFI call");
588
588
  return;
589
589
  }
@@ -789,7 +789,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool async,
789
789
  case PrimitiveKind::Array: { RG_UNREACHABLE(); } break;
790
790
  case PrimitiveKind::Float32: {
791
791
  float f;
792
- if (RG_LIKELY(param.vec_count)) {
792
+ if (param.vec_count) [[likely]] {
793
793
  f = *(float *)(vec_ptr++);
794
794
  } else if (param.gpr_count) {
795
795
  f = *(float *)(gpr_ptr++);
@@ -802,7 +802,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool async,
802
802
  } break;
803
803
  case PrimitiveKind::Float64: {
804
804
  double d;
805
- if (RG_LIKELY(param.vec_count)) {
805
+ if (param.vec_count) [[likely]] {
806
806
  d = *(double *)vec_ptr;
807
807
  vec_ptr += 2;
808
808
  } else if (param.gpr_count) {
@@ -835,12 +835,12 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool async,
835
835
  }
836
836
  Napi::Value value(env, ret);
837
837
 
838
- if (RG_UNLIKELY(env.IsExceptionPending()))
838
+ if (env.IsExceptionPending()) [[unlikely]]
839
839
  return;
840
840
 
841
841
  #define RETURN_INTEGER_32(CType) \
842
842
  do { \
843
- if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) { \
843
+ if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] { \
844
844
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value for return value, expected number", GetValueType(instance, value)); \
845
845
  return; \
846
846
  } \
@@ -850,7 +850,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool async,
850
850
  } while (false)
851
851
  #define RETURN_INTEGER_32_SWAP(CType) \
852
852
  do { \
853
- if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) { \
853
+ if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] { \
854
854
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value)); \
855
855
  return; \
856
856
  } \
@@ -860,7 +860,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool async,
860
860
  } while (false)
861
861
  #define RETURN_INTEGER_64(CType) \
862
862
  do { \
863
- if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) { \
863
+ if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] { \
864
864
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value)); \
865
865
  return; \
866
866
  } \
@@ -872,7 +872,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool async,
872
872
  } while (false)
873
873
  #define RETURN_INTEGER_64_SWAP(CType) \
874
874
  do { \
875
- if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) { \
875
+ if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] { \
876
876
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value)); \
877
877
  return; \
878
878
  } \
@@ -887,7 +887,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool async,
887
887
  switch (type->primitive) {
888
888
  case PrimitiveKind::Void: {} break;
889
889
  case PrimitiveKind::Bool: {
890
- if (RG_UNLIKELY(!value.IsBoolean())) {
890
+ if (!value.IsBoolean()) [[unlikely]] {
891
891
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected boolean", GetValueType(instance, value));
892
892
  return;
893
893
  }
@@ -911,14 +911,14 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool async,
911
911
  case PrimitiveKind::UInt64S: { RETURN_INTEGER_64_SWAP(uint64_t); } break;
912
912
  case PrimitiveKind::String: {
913
913
  const char *str;
914
- if (RG_UNLIKELY(!PushString(value, 1, &str)))
914
+ if (!PushString(value, 1, &str)) [[unlikely]]
915
915
  return;
916
916
 
917
917
  out_reg->r0 = (uint32_t)str;
918
918
  } break;
919
919
  case PrimitiveKind::String16: {
920
920
  const char16_t *str16;
921
- if (RG_UNLIKELY(!PushString16(value, 1, &str16)))
921
+ if (!PushString16(value, 1, &str16)) [[unlikely]]
922
922
  return;
923
923
 
924
924
  out_reg->r0 = (uint32_t)str16;
@@ -947,7 +947,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool async,
947
947
  } break;
948
948
  case PrimitiveKind::Record:
949
949
  case PrimitiveKind::Union: {
950
- if (RG_UNLIKELY(!IsObject(value))) {
950
+ if (!IsObject(value)) [[unlikely]] {
951
951
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected object", GetValueType(instance, value));
952
952
  return;
953
953
  }
@@ -966,7 +966,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool async,
966
966
  } break;
967
967
  case PrimitiveKind::Array: { RG_UNREACHABLE(); } break;
968
968
  case PrimitiveKind::Float32: {
969
- if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
969
+ if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] {
970
970
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value));
971
971
  return;
972
972
  }
@@ -979,7 +979,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool async,
979
979
  #endif
980
980
  } break;
981
981
  case PrimitiveKind::Float64: {
982
- if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
982
+ if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] {
983
983
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value));
984
984
  return;
985
985
  }
@@ -998,7 +998,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool async,
998
998
  Napi::Function func2 = value.As<Napi::Function>();
999
999
 
1000
1000
  ptr = ReserveTrampoline(type->ref.proto, func2);
1001
- if (RG_UNLIKELY(!ptr))
1001
+ if (!ptr) [[unlikely]]
1002
1002
  return;
1003
1003
  } else if (CheckValueTag(instance, value, type->ref.marker)) {
1004
1004
  ptr = value.As<Napi::External<void>>().Data();