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
@@ -271,11 +271,11 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
271
271
  uint64_t *vec_ptr = nullptr;
272
272
 
273
273
  // Return through registers unless it's too big
274
- if (RG_UNLIKELY(!AllocStack(func->args_size, 16, &args_ptr)))
274
+ if (!AllocStack(func->args_size, 16, &args_ptr)) [[unlikely]]
275
275
  return false;
276
- if (RG_UNLIKELY(!AllocStack(8 * 8, 8, &vec_ptr)))
276
+ if (!AllocStack(8 * 8, 8, &vec_ptr)) [[unlikely]]
277
277
  return false;
278
- if (RG_UNLIKELY(!AllocStack(9 * 8, 8, &gpr_ptr)))
278
+ if (!AllocStack(9 * 8, 8, &gpr_ptr)) [[unlikely]]
279
279
  return false;
280
280
  if (func->ret.use_memory) {
281
281
  return_ptr = AllocHeap(func->ret.type->size, 16);
@@ -297,14 +297,14 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
297
297
  #ifdef __APPLE__
298
298
  #define PUSH_INTEGER(CType) \
299
299
  do { \
300
- if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) { \
300
+ if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] { \
301
301
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value)); \
302
302
  return false; \
303
303
  } \
304
304
  \
305
305
  CType v = GetNumber<CType>(value); \
306
306
  \
307
- if (RG_LIKELY(param.gpr_count)) { \
307
+ if (param.gpr_count) [[likely]] { \
308
308
  *(gpr_ptr++) = (uint64_t)v; \
309
309
  } else { \
310
310
  args_ptr = AlignUp(args_ptr, param.type->align); \
@@ -314,14 +314,14 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
314
314
  } while (false)
315
315
  #define PUSH_INTEGER_SWAP(CType) \
316
316
  do { \
317
- if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) { \
317
+ if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] { \
318
318
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value)); \
319
319
  return false; \
320
320
  } \
321
321
  \
322
322
  CType v = GetNumber<CType>(value); \
323
323
  \
324
- if (RG_LIKELY(param.gpr_count)) { \
324
+ if (param.gpr_count) [[likely]] { \
325
325
  *(gpr_ptr++) = (uint64_t)ReverseBytes(v); \
326
326
  } else { \
327
327
  args_ptr = AlignUp(args_ptr, param.type->align); \
@@ -332,7 +332,7 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
332
332
  #else
333
333
  #define PUSH_INTEGER(CType) \
334
334
  do { \
335
- if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) { \
335
+ if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] { \
336
336
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value)); \
337
337
  return false; \
338
338
  } \
@@ -342,7 +342,7 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
342
342
  } while (false)
343
343
  #define PUSH_INTEGER_SWAP(CType) \
344
344
  do { \
345
- if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) { \
345
+ if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] { \
346
346
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value)); \
347
347
  return false; \
348
348
  } \
@@ -363,7 +363,7 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
363
363
  case PrimitiveKind::Void: { RG_UNREACHABLE(); } break;
364
364
 
365
365
  case PrimitiveKind::Bool: {
366
- if (RG_UNLIKELY(!value.IsBoolean())) {
366
+ if (!value.IsBoolean()) [[unlikely]] {
367
367
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected boolean", GetValueType(instance, value));
368
368
  return false;
369
369
  }
@@ -371,7 +371,7 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
371
371
  bool b = value.As<Napi::Boolean>();
372
372
 
373
373
  #ifdef __APPLE__
374
- if (RG_LIKELY(param.gpr_count)) {
374
+ if (param.gpr_count) [[likely]] {
375
375
  *(gpr_ptr++) = (uint64_t)b;
376
376
  } else {
377
377
  *(uint8_t *)args_ptr = b;
@@ -397,7 +397,7 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
397
397
  case PrimitiveKind::UInt64S: { PUSH_INTEGER_SWAP(uint64_t); } break;
398
398
  case PrimitiveKind::String: {
399
399
  const char *str;
400
- if (RG_UNLIKELY(!PushString(value, param.directions, &str)))
400
+ if (!PushString(value, param.directions, &str)) [[unlikely]]
401
401
  return false;
402
402
 
403
403
  #ifdef __APPLE__
@@ -407,7 +407,7 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
407
407
  } break;
408
408
  case PrimitiveKind::String16: {
409
409
  const char16_t *str16;
410
- if (RG_UNLIKELY(!PushString16(value, param.directions, &str16)))
410
+ if (!PushString16(value, param.directions, &str16)) [[unlikely]]
411
411
  return false;
412
412
 
413
413
  #ifdef __APPLE__
@@ -417,7 +417,7 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
417
417
  } break;
418
418
  case PrimitiveKind::Pointer: {
419
419
  void *ptr;
420
- if (RG_UNLIKELY(!PushPointer(value, param.type, param.directions, &ptr)))
420
+ if (!PushPointer(value, param.type, param.directions, &ptr)) [[unlikely]]
421
421
  return false;
422
422
 
423
423
  #ifdef __APPLE__
@@ -427,7 +427,7 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
427
427
  } break;
428
428
  case PrimitiveKind::Record:
429
429
  case PrimitiveKind::Union: {
430
- if (RG_UNLIKELY(!IsObject(value))) {
430
+ if (!IsObject(value)) [[unlikely]] {
431
431
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected object", GetValueType(instance, value));
432
432
  return false;
433
433
  }
@@ -478,14 +478,14 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
478
478
  } break;
479
479
  case PrimitiveKind::Array: { RG_UNREACHABLE(); } break;
480
480
  case PrimitiveKind::Float32: {
481
- if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
481
+ if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] {
482
482
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value));
483
483
  return false;
484
484
  }
485
485
 
486
486
  float f = GetNumber<float>(value);
487
487
 
488
- if (RG_LIKELY(param.vec_count)) {
488
+ if (param.vec_count) [[likely]] {
489
489
  memset((uint8_t *)vec_ptr + 4, 0, 4);
490
490
  *(float *)(vec_ptr++) = f;
491
491
  #ifdef _WIN32
@@ -505,14 +505,14 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
505
505
  }
506
506
  } break;
507
507
  case PrimitiveKind::Float64: {
508
- if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
508
+ if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] {
509
509
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value));
510
510
  return false;
511
511
  }
512
512
 
513
513
  double d = GetNumber<double>(value);
514
514
 
515
- if (RG_LIKELY(param.vec_count)) {
515
+ if (param.vec_count) [[likely]] {
516
516
  *(double *)(vec_ptr++) = d;
517
517
  #ifdef _WIN32
518
518
  } else if (param.gpr_count) {
@@ -532,7 +532,7 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
532
532
  Napi::Function func = value.As<Napi::Function>();
533
533
 
534
534
  ptr = ReserveTrampoline(param.type->ref.proto, func);
535
- if (RG_UNLIKELY(!ptr))
535
+ if (!ptr) [[unlikely]]
536
536
  return false;
537
537
  } else if (CheckValueTag(instance, value, param.type->ref.marker)) {
538
538
  ptr = value.As<Napi::External<void>>().Data();
@@ -707,7 +707,7 @@ Napi::Value CallData::Complete(const FunctionInfo *func)
707
707
 
708
708
  void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool async, BackRegisters *out_reg)
709
709
  {
710
- if (RG_UNLIKELY(env.IsExceptionPending()))
710
+ if (env.IsExceptionPending()) [[unlikely]]
711
711
  return;
712
712
 
713
713
  #ifdef _WIN32
@@ -741,7 +741,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool async,
741
741
 
742
742
  RG_DEFER_N(err_guard) { memset(out_reg, 0, RG_SIZE(*out_reg)); };
743
743
 
744
- if (RG_UNLIKELY(trampoline.generation >= 0 && trampoline.generation != (int32_t)mem->generation)) {
744
+ if (trampoline.generation >= 0 && trampoline.generation != (int32_t)mem->generation) [[unlikely]] {
745
745
  ThrowError<Napi::Error>(env, "Cannot use non-registered callback beyond FFI call");
746
746
  return;
747
747
  }
@@ -1092,7 +1092,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool async,
1092
1092
  case PrimitiveKind::Array: { RG_UNREACHABLE(); } break;
1093
1093
  case PrimitiveKind::Float32: {
1094
1094
  float f;
1095
- if (RG_LIKELY(param.vec_count)) {
1095
+ if (param.vec_count) [[likely]] {
1096
1096
  f = *(float *)(vec_ptr++);
1097
1097
  #ifdef _WIN32
1098
1098
  } else if (param.gpr_count) {
@@ -1113,7 +1113,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool async,
1113
1113
  } break;
1114
1114
  case PrimitiveKind::Float64: {
1115
1115
  double d;
1116
- if (RG_LIKELY(param.vec_count)) {
1116
+ if (param.vec_count) [[likely]] {
1117
1117
  d = *(double *)(vec_ptr++);
1118
1118
  #ifdef _WIN32
1119
1119
  } else if (param.gpr_count) {
@@ -1147,12 +1147,12 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool async,
1147
1147
  }
1148
1148
  Napi::Value value(env, ret);
1149
1149
 
1150
- if (RG_UNLIKELY(env.IsExceptionPending()))
1150
+ if (env.IsExceptionPending()) [[unlikely]]
1151
1151
  return;
1152
1152
 
1153
1153
  #define RETURN_INTEGER(CType) \
1154
1154
  do { \
1155
- if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) { \
1155
+ if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] { \
1156
1156
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value)); \
1157
1157
  return; \
1158
1158
  } \
@@ -1162,7 +1162,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool async,
1162
1162
  } while (false)
1163
1163
  #define RETURN_INTEGER_SWAP(CType) \
1164
1164
  do { \
1165
- if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) { \
1165
+ if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] { \
1166
1166
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value)); \
1167
1167
  return; \
1168
1168
  } \
@@ -1175,7 +1175,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool async,
1175
1175
  switch (type->primitive) {
1176
1176
  case PrimitiveKind::Void: {} break;
1177
1177
  case PrimitiveKind::Bool: {
1178
- if (RG_UNLIKELY(!value.IsBoolean())) {
1178
+ if (!value.IsBoolean()) [[unlikely]] {
1179
1179
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected boolean", GetValueType(instance, value));
1180
1180
  return;
1181
1181
  }
@@ -1199,14 +1199,14 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool async,
1199
1199
  case PrimitiveKind::UInt64S: { RETURN_INTEGER_SWAP(uint64_t); } break;
1200
1200
  case PrimitiveKind::String: {
1201
1201
  const char *str;
1202
- if (RG_UNLIKELY(!PushString(value, 1, &str)))
1202
+ if (!PushString(value, 1, &str)) [[unlikely]]
1203
1203
  return;
1204
1204
 
1205
1205
  out_reg->x0 = (uint64_t)str;
1206
1206
  } break;
1207
1207
  case PrimitiveKind::String16: {
1208
1208
  const char16_t *str16;
1209
- if (RG_UNLIKELY(!PushString16(value, 1, &str16)))
1209
+ if (!PushString16(value, 1, &str16)) [[unlikely]]
1210
1210
  return;
1211
1211
 
1212
1212
  out_reg->x0 = (uint64_t)str16;
@@ -1235,7 +1235,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool async,
1235
1235
  } break;
1236
1236
  case PrimitiveKind::Record:
1237
1237
  case PrimitiveKind::Union: {
1238
- if (RG_UNLIKELY(!IsObject(value))) {
1238
+ if (!IsObject(value)) [[unlikely]] {
1239
1239
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected object", GetValueType(instance, value));
1240
1240
  return;
1241
1241
  }
@@ -1257,7 +1257,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool async,
1257
1257
  } break;
1258
1258
  case PrimitiveKind::Array: { RG_UNREACHABLE(); } break;
1259
1259
  case PrimitiveKind::Float32: {
1260
- if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
1260
+ if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] {
1261
1261
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value));
1262
1262
  return;
1263
1263
  }
@@ -1268,7 +1268,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool async,
1268
1268
  memcpy(&out_reg->d0, &f, 4);
1269
1269
  } break;
1270
1270
  case PrimitiveKind::Float64: {
1271
- if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
1271
+ if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] {
1272
1272
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value));
1273
1273
  return;
1274
1274
  }
@@ -1283,7 +1283,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool async,
1283
1283
  Napi::Function func2 = value.As<Napi::Function>();
1284
1284
 
1285
1285
  ptr = ReserveTrampoline(type->ref.proto, func2);
1286
- if (RG_UNLIKELY(!ptr))
1286
+ if (!ptr) [[unlikely]]
1287
1287
  return;
1288
1288
  } else if (CheckValueTag(instance, value, type->ref.marker)) {
1289
1289
  ptr = value.As<Napi::External<void>>().Data();
@@ -173,11 +173,11 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
173
173
  uint64_t *vec_ptr = nullptr;
174
174
 
175
175
  // Return through registers unless it's too big
176
- if (RG_UNLIKELY(!AllocStack(func->args_size, 16, &args_ptr)))
176
+ if (!AllocStack(func->args_size, 16, &args_ptr)) [[unlikely]]
177
177
  return false;
178
- if (RG_UNLIKELY(!AllocStack(8 * 8, 8, &gpr_ptr)))
178
+ if (!AllocStack(8 * 8, 8, &gpr_ptr)) [[unlikely]]
179
179
  return false;
180
- if (RG_UNLIKELY(!AllocStack(8 * 8, 8, &vec_ptr)))
180
+ if (!AllocStack(8 * 8, 8, &vec_ptr)) [[unlikely]]
181
181
  return false;
182
182
  if (func->ret.use_memory) {
183
183
  return_ptr = AllocHeap(func->ret.type->size, 16);
@@ -186,7 +186,7 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
186
186
 
187
187
  #define PUSH_INTEGER(CType) \
188
188
  do { \
189
- if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) { \
189
+ if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] { \
190
190
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value)); \
191
191
  return false; \
192
192
  } \
@@ -196,7 +196,7 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
196
196
  } while (false)
197
197
  #define PUSH_INTEGER_SWAP(CType) \
198
198
  do { \
199
- if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) { \
199
+ if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] { \
200
200
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value)); \
201
201
  return false; \
202
202
  } \
@@ -216,7 +216,7 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
216
216
  case PrimitiveKind::Void: { RG_UNREACHABLE(); } break;
217
217
 
218
218
  case PrimitiveKind::Bool: {
219
- if (RG_UNLIKELY(!value.IsBoolean())) {
219
+ if (!value.IsBoolean()) [[unlikely]] {
220
220
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected boolean", GetValueType(instance, value));
221
221
  return false;
222
222
  }
@@ -240,28 +240,28 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
240
240
  case PrimitiveKind::UInt64S: { PUSH_INTEGER_SWAP(uint64_t); } break;
241
241
  case PrimitiveKind::String: {
242
242
  const char *str;
243
- if (RG_UNLIKELY(!PushString(value, param.directions, &str)))
243
+ if (!PushString(value, param.directions, &str)) [[unlikely]]
244
244
  return false;
245
245
 
246
246
  *(const char **)((param.gpr_count ? gpr_ptr : args_ptr)++) = str;
247
247
  } break;
248
248
  case PrimitiveKind::String16: {
249
249
  const char16_t *str16;
250
- if (RG_UNLIKELY(!PushString16(value, param.directions, &str16)))
250
+ if (!PushString16(value, param.directions, &str16)) [[unlikely]]
251
251
  return false;
252
252
 
253
253
  *(const char16_t **)((param.gpr_count ? gpr_ptr : args_ptr)++) = str16;
254
254
  } break;
255
255
  case PrimitiveKind::Pointer: {
256
256
  void *ptr;
257
- if (RG_UNLIKELY(!PushPointer(value, param.type, param.directions, &ptr)))
257
+ if (!PushPointer(value, param.type, param.directions, &ptr)) [[unlikely]]
258
258
  return false;
259
259
 
260
260
  *(void **)((param.gpr_count ? gpr_ptr : args_ptr)++) = ptr;
261
261
  } break;
262
262
  case PrimitiveKind::Record:
263
263
  case PrimitiveKind::Union: {
264
- if (RG_UNLIKELY(!IsObject(value))) {
264
+ if (!IsObject(value)) [[unlikely]] {
265
265
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected object", GetValueType(instance, value));
266
266
  return false;
267
267
  }
@@ -319,14 +319,14 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
319
319
  } break;
320
320
  case PrimitiveKind::Array: { RG_UNREACHABLE(); } break;
321
321
  case PrimitiveKind::Float32: {
322
- if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
322
+ if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] {
323
323
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value));
324
324
  return false;
325
325
  }
326
326
 
327
327
  float f = GetNumber<float>(value);
328
328
 
329
- if (RG_LIKELY(param.vec_count)) {
329
+ if (param.vec_count) [[likely]] {
330
330
  memset((uint8_t *)vec_ptr + 4, 0xFF, 4);
331
331
  *(float *)(vec_ptr++) = f;
332
332
  } else if (param.gpr_count) {
@@ -338,14 +338,14 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
338
338
  }
339
339
  } break;
340
340
  case PrimitiveKind::Float64: {
341
- if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
341
+ if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] {
342
342
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value));
343
343
  return false;
344
344
  }
345
345
 
346
346
  double d = GetNumber<double>(value);
347
347
 
348
- if (RG_LIKELY(param.vec_count)) {
348
+ if (param.vec_count) [[likely]] {
349
349
  *(double *)(vec_ptr++) = d;
350
350
  } else if (param.gpr_count) {
351
351
  *(double *)(gpr_ptr++) = d;
@@ -360,7 +360,7 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
360
360
  Napi::Function func = value.As<Napi::Function>();
361
361
 
362
362
  ptr = ReserveTrampoline(param.type->ref.proto, func);
363
- if (RG_UNLIKELY(!ptr))
363
+ if (!ptr) [[unlikely]]
364
364
  return false;
365
365
  } else if (CheckValueTag(instance, value, param.type->ref.marker)) {
366
366
  ptr = value.As<Napi::External<void>>().Data();
@@ -508,7 +508,7 @@ Napi::Value CallData::Complete(const FunctionInfo *func)
508
508
 
509
509
  void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool async, BackRegisters *out_reg)
510
510
  {
511
- if (RG_UNLIKELY(env.IsExceptionPending()))
511
+ if (env.IsExceptionPending()) [[unlikely]]
512
512
  return;
513
513
 
514
514
  const TrampolineInfo &trampoline = shared.trampolines[idx];
@@ -525,7 +525,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool async,
525
525
 
526
526
  RG_DEFER_N(err_guard) { memset(out_reg, 0, RG_SIZE(*out_reg)); };
527
527
 
528
- if (RG_UNLIKELY(trampoline.generation >= 0 && trampoline.generation != (int32_t)mem->generation)) {
528
+ if (trampoline.generation >= 0 && trampoline.generation != (int32_t)mem->generation) [[unlikely]] {
529
529
  ThrowError<Napi::Error>(env, "Cannot use non-registered callback beyond FFI call");
530
530
  return;
531
531
  }
@@ -707,7 +707,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool async,
707
707
  case PrimitiveKind::Array: { RG_UNREACHABLE(); } break;
708
708
  case PrimitiveKind::Float32: {
709
709
  float f;
710
- if (RG_LIKELY(param.vec_count)) {
710
+ if (param.vec_count) [[likely]] {
711
711
  f = *(float *)(vec_ptr++);
712
712
  } else if (param.gpr_count) {
713
713
  f = *(float *)(gpr_ptr++);
@@ -720,7 +720,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool async,
720
720
  } break;
721
721
  case PrimitiveKind::Float64: {
722
722
  double d;
723
- if (RG_LIKELY(param.vec_count)) {
723
+ if (param.vec_count) [[likely]] {
724
724
  d = *(double *)(vec_ptr++);
725
725
  } else if (param.gpr_count) {
726
726
  d = *(double *)(gpr_ptr++);
@@ -748,12 +748,12 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool async,
748
748
  }
749
749
  Napi::Value value(env, ret);
750
750
 
751
- if (RG_UNLIKELY(env.IsExceptionPending()))
751
+ if (env.IsExceptionPending()) [[unlikely]]
752
752
  return;
753
753
 
754
754
  #define RETURN_INTEGER(CType) \
755
755
  do { \
756
- if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) { \
756
+ if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] { \
757
757
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value)); \
758
758
  return; \
759
759
  } \
@@ -763,7 +763,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool async,
763
763
  } while (false)
764
764
  #define RETURN_INTEGER_SWAP(CType) \
765
765
  do { \
766
- if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) { \
766
+ if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] { \
767
767
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value)); \
768
768
  return; \
769
769
  } \
@@ -776,7 +776,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool async,
776
776
  switch (type->primitive) {
777
777
  case PrimitiveKind::Void: {} break;
778
778
  case PrimitiveKind::Bool: {
779
- if (RG_UNLIKELY(!value.IsBoolean())) {
779
+ if (!value.IsBoolean()) [[unlikely]] {
780
780
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected boolean", GetValueType(instance, value));
781
781
  return;
782
782
  }
@@ -800,14 +800,14 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool async,
800
800
  case PrimitiveKind::UInt64S: { RETURN_INTEGER_SWAP(uint64_t); } break;
801
801
  case PrimitiveKind::String: {
802
802
  const char *str;
803
- if (RG_UNLIKELY(!PushString(value, 1, &str)))
803
+ if (!PushString(value, 1, &str)) [[unlikely]]
804
804
  return;
805
805
 
806
806
  out_reg->a0 = (uint64_t)str;
807
807
  } break;
808
808
  case PrimitiveKind::String16: {
809
809
  const char16_t *str16;
810
- if (RG_UNLIKELY(!PushString16(value, 1, &str16)))
810
+ if (!PushString16(value, 1, &str16)) [[unlikely]]
811
811
  return;
812
812
 
813
813
  out_reg->a0 = (uint64_t)str16;
@@ -836,7 +836,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool async,
836
836
  } break;
837
837
  case PrimitiveKind::Record:
838
838
  case PrimitiveKind::Union: {
839
- if (RG_UNLIKELY(!IsObject(value))) {
839
+ if (!IsObject(value)) [[unlikely]] {
840
840
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected object", GetValueType(instance, value));
841
841
  return;
842
842
  }
@@ -873,7 +873,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool async,
873
873
  } break;
874
874
  case PrimitiveKind::Array: { RG_UNREACHABLE(); } break;
875
875
  case PrimitiveKind::Float32: {
876
- if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
876
+ if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] {
877
877
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value));
878
878
  return;
879
879
  }
@@ -883,7 +883,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool async,
883
883
  memcpy(&out_reg->fa0, &f, 4);
884
884
  } break;
885
885
  case PrimitiveKind::Float64: {
886
- if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
886
+ if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] {
887
887
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value));
888
888
  return;
889
889
  }
@@ -898,7 +898,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool async,
898
898
  Napi::Function func2 = value.As<Napi::Function>();
899
899
 
900
900
  ptr = ReserveTrampoline(type->ref.proto, func2);
901
- if (RG_UNLIKELY(!ptr))
901
+ if (!ptr) [[unlikely]]
902
902
  return;
903
903
  } else if (CheckValueTag(instance, value, type->ref.marker)) {
904
904
  ptr = value.As<Napi::External<void>>().Data();