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
@@ -148,7 +148,7 @@ void CallData::RelayAsync(napi_env, napi_value, void *, void *udata)
148
148
  bool CallData::PushString(Napi::Value value, int directions, const char **out_str)
149
149
  {
150
150
  if (value.IsString()) {
151
- if (RG_UNLIKELY(directions & 2)) {
151
+ if (directions & 2) [[unlikely]] {
152
152
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected [string]", GetValueType(instance, value));
153
153
  return false;
154
154
  }
@@ -161,24 +161,24 @@ bool CallData::PushString(Napi::Value value, int directions, const char **out_st
161
161
  } else if (value.IsArray()) {
162
162
  Napi::Array array = value.As<Napi::Array>();
163
163
 
164
- if (RG_UNLIKELY(!(directions & 2))) {
164
+ if (!(directions & 2)) [[unlikely]] {
165
165
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected string", GetValueType(instance, value));
166
166
  return false;
167
167
  }
168
- if (RG_UNLIKELY(array.Length() != 1)) {
168
+ if (array.Length() != 1) [[unlikely]] {
169
169
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected [string]", GetValueType(instance, value));
170
170
  return false;
171
171
  }
172
172
 
173
173
  value = array[0u];
174
174
 
175
- if (RG_UNLIKELY(!value.IsString())) {
175
+ if (!value.IsString()) [[unlikely]] {
176
176
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected [string]", GetValueType(instance, array[0u]));
177
177
  return false;
178
178
  }
179
179
 
180
180
  Size len = PushStringValue(value, out_str);
181
- if (RG_UNLIKELY(len < 0))
181
+ if (len < 0) [[unlikely]]
182
182
  return false;
183
183
 
184
184
  // Create array type
@@ -228,7 +228,7 @@ Size CallData::PushStringValue(Napi::Value value, const char **out_str)
228
228
 
229
229
  len++;
230
230
 
231
- if (RG_LIKELY(len < (size_t)buf.len)) {
231
+ if (len < (size_t)buf.len) [[likely]] {
232
232
  mem->heap.ptr += (Size)len;
233
233
  mem->heap.len -= (Size)len;
234
234
  } else {
@@ -250,7 +250,7 @@ Size CallData::PushStringValue(Napi::Value value, const char **out_str)
250
250
  bool CallData::PushString16(Napi::Value value, int directions, const char16_t **out_str16)
251
251
  {
252
252
  if (value.IsString()) {
253
- if (RG_UNLIKELY(directions & 2)) {
253
+ if (directions & 2) [[unlikely]] {
254
254
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected string", GetValueType(instance, value));
255
255
  return false;
256
256
  }
@@ -263,24 +263,24 @@ bool CallData::PushString16(Napi::Value value, int directions, const char16_t **
263
263
  } else if (value.IsArray()) {
264
264
  Napi::Array array = value.As<Napi::Array>();
265
265
 
266
- if (RG_UNLIKELY(!(directions & 2))) {
266
+ if (!(directions & 2)) [[unlikely]] {
267
267
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected string", GetValueType(instance, value));
268
268
  return false;
269
269
  }
270
- if (RG_UNLIKELY(array.Length() != 1)) {
270
+ if (array.Length() != 1) [[unlikely]] {
271
271
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected [string]", GetValueType(instance, value));
272
272
  return false;
273
273
  }
274
274
 
275
275
  value = array[0u];
276
276
 
277
- if (RG_UNLIKELY(!value.IsString())) {
277
+ if (!value.IsString()) [[unlikely]] {
278
278
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected [string]", GetValueType(instance, array[0u]));
279
279
  return false;
280
280
  }
281
281
 
282
282
  Size len = PushString16Value(value, out_str16);
283
- if (RG_UNLIKELY(len < 0))
283
+ if (len < 0) [[unlikely]]
284
284
  return false;
285
285
 
286
286
  // Create array type
@@ -330,7 +330,7 @@ Size CallData::PushString16Value(Napi::Value value, const char16_t **out_str16)
330
330
 
331
331
  len++;
332
332
 
333
- if (RG_LIKELY(len < (size_t)buf.len)) {
333
+ if (len < (size_t)buf.len) [[likely]] {
334
334
  mem->heap.ptr += (Size)len * 2;
335
335
  mem->heap.len -= (Size)len * 2;
336
336
  } else {
@@ -364,7 +364,7 @@ bool CallData::PushObject(Napi::Object obj, const TypeInfo *type, uint8_t *origi
364
364
  MagicUnion *u = MagicUnion::Unwrap(obj);
365
365
  const uint8_t *raw = u->GetRaw();
366
366
 
367
- if (RG_UNLIKELY(u->GetType() != type)) {
367
+ if (u->GetType() != type) [[unlikely]] {
368
368
  ThrowError<Napi::TypeError>(env, "Expected union type %1, got %2", type->name, u->GetType()->name);
369
369
  return false;
370
370
  }
@@ -378,14 +378,14 @@ bool CallData::PushObject(Napi::Object obj, const TypeInfo *type, uint8_t *origi
378
378
  members.ptr = u->GetMember();
379
379
  members.len = 1;
380
380
 
381
- if (RG_UNLIKELY(!members.ptr)) {
381
+ if (!members.ptr) [[unlikely]] {
382
382
  ThrowError<Napi::Error>(env, "Cannot use ambiguous empty union");
383
383
  return false;
384
384
  }
385
385
  } else {
386
386
  Napi::Array properties = obj.GetPropertyNames();
387
387
 
388
- if (RG_UNLIKELY(properties.Length() != 1 || !properties.Get(0u).IsString())) {
388
+ if (properties.Length() != 1 || !properties.Get(0u).IsString()) [[unlikely]] {
389
389
  ThrowError<Napi::Error>(env, "Expected object with single property name for union");
390
390
  return false;
391
391
  }
@@ -396,7 +396,7 @@ bool CallData::PushObject(Napi::Object obj, const TypeInfo *type, uint8_t *origi
396
396
  [&](const RecordMember &member) { return TestStr(property.c_str(), member.name); });
397
397
  members.len = 1;
398
398
 
399
- if (RG_UNLIKELY(members.ptr == type->members.end())) {
399
+ if (members.ptr == type->members.end()) [[unlikely]] {
400
400
  ThrowError<Napi::Error>(env, "Unknown member %1 in union type %2", property.c_str(), type->name);
401
401
  return false;
402
402
  }
@@ -405,14 +405,14 @@ bool CallData::PushObject(Napi::Object obj, const TypeInfo *type, uint8_t *origi
405
405
  RG_UNREACHABLE();
406
406
  }
407
407
 
408
+ memset(origin, 0, type->size);
409
+
408
410
  for (Size i = 0; i < members.len; i++) {
409
411
  const RecordMember &member = members[i];
410
412
  Napi::Value value = obj.Get(member.name);
411
413
 
412
- if (RG_UNLIKELY(value.IsUndefined())) {
413
- ThrowError<Napi::TypeError>(env, "Missing expected object property '%1'", member.name);
414
- return false;
415
- }
414
+ if (value.IsUndefined())
415
+ continue;
416
416
 
417
417
  uint8_t *dest = origin + member.offset;
418
418
 
@@ -420,7 +420,7 @@ bool CallData::PushObject(Napi::Object obj, const TypeInfo *type, uint8_t *origi
420
420
  case PrimitiveKind::Void: { RG_UNREACHABLE(); } break;
421
421
 
422
422
  case PrimitiveKind::Bool: {
423
- if (RG_UNLIKELY(!value.IsBoolean())) {
423
+ if (!value.IsBoolean()) [[unlikely]] {
424
424
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected boolean", GetValueType(instance, value));
425
425
  return false;
426
426
  }
@@ -429,7 +429,7 @@ bool CallData::PushObject(Napi::Object obj, const TypeInfo *type, uint8_t *origi
429
429
  *(bool *)dest = b;
430
430
  } break;
431
431
  case PrimitiveKind::Int8: {
432
- if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
432
+ if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] {
433
433
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value));
434
434
  return false;
435
435
  }
@@ -438,7 +438,7 @@ bool CallData::PushObject(Napi::Object obj, const TypeInfo *type, uint8_t *origi
438
438
  *(int8_t *)dest = v;
439
439
  } break;
440
440
  case PrimitiveKind::UInt8: {
441
- if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
441
+ if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] {
442
442
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value));
443
443
  return false;
444
444
  }
@@ -447,7 +447,7 @@ bool CallData::PushObject(Napi::Object obj, const TypeInfo *type, uint8_t *origi
447
447
  *(uint8_t *)dest = v;
448
448
  } break;
449
449
  case PrimitiveKind::Int16: {
450
- if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
450
+ if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] {
451
451
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value));
452
452
  return false;
453
453
  }
@@ -456,7 +456,7 @@ bool CallData::PushObject(Napi::Object obj, const TypeInfo *type, uint8_t *origi
456
456
  *(int16_t *)dest = v;
457
457
  } break;
458
458
  case PrimitiveKind::Int16S: {
459
- if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
459
+ if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] {
460
460
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value));
461
461
  return false;
462
462
  }
@@ -465,7 +465,7 @@ bool CallData::PushObject(Napi::Object obj, const TypeInfo *type, uint8_t *origi
465
465
  *(int16_t *)dest = ReverseBytes(v);
466
466
  } break;
467
467
  case PrimitiveKind::UInt16: {
468
- if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
468
+ if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] {
469
469
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value));
470
470
  return false;
471
471
  }
@@ -474,7 +474,7 @@ bool CallData::PushObject(Napi::Object obj, const TypeInfo *type, uint8_t *origi
474
474
  *(uint16_t *)dest = v;
475
475
  } break;
476
476
  case PrimitiveKind::UInt16S: {
477
- if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
477
+ if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] {
478
478
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value));
479
479
  return false;
480
480
  }
@@ -483,7 +483,7 @@ bool CallData::PushObject(Napi::Object obj, const TypeInfo *type, uint8_t *origi
483
483
  *(uint16_t *)dest = ReverseBytes(v);
484
484
  } break;
485
485
  case PrimitiveKind::Int32: {
486
- if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
486
+ if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] {
487
487
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value));
488
488
  return false;
489
489
  }
@@ -492,7 +492,7 @@ bool CallData::PushObject(Napi::Object obj, const TypeInfo *type, uint8_t *origi
492
492
  *(int32_t *)dest = v;
493
493
  } break;
494
494
  case PrimitiveKind::Int32S: {
495
- if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
495
+ if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] {
496
496
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value));
497
497
  return false;
498
498
  }
@@ -501,7 +501,7 @@ bool CallData::PushObject(Napi::Object obj, const TypeInfo *type, uint8_t *origi
501
501
  *(int32_t *)dest = ReverseBytes(v);
502
502
  } break;
503
503
  case PrimitiveKind::UInt32: {
504
- if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
504
+ if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] {
505
505
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value));
506
506
  return false;
507
507
  }
@@ -510,7 +510,7 @@ bool CallData::PushObject(Napi::Object obj, const TypeInfo *type, uint8_t *origi
510
510
  *(uint32_t *)dest = v;
511
511
  } break;
512
512
  case PrimitiveKind::UInt32S: {
513
- if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
513
+ if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] {
514
514
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value));
515
515
  return false;
516
516
  }
@@ -519,7 +519,7 @@ bool CallData::PushObject(Napi::Object obj, const TypeInfo *type, uint8_t *origi
519
519
  *(uint32_t *)dest = ReverseBytes(v);
520
520
  } break;
521
521
  case PrimitiveKind::Int64: {
522
- if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
522
+ if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] {
523
523
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value));
524
524
  return false;
525
525
  }
@@ -528,7 +528,7 @@ bool CallData::PushObject(Napi::Object obj, const TypeInfo *type, uint8_t *origi
528
528
  *(int64_t *)dest = v;
529
529
  } break;
530
530
  case PrimitiveKind::Int64S: {
531
- if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
531
+ if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] {
532
532
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value));
533
533
  return false;
534
534
  }
@@ -537,7 +537,7 @@ bool CallData::PushObject(Napi::Object obj, const TypeInfo *type, uint8_t *origi
537
537
  *(int64_t *)dest = ReverseBytes(v);
538
538
  } break;
539
539
  case PrimitiveKind::UInt64: {
540
- if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
540
+ if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] {
541
541
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value));
542
542
  return false;
543
543
  }
@@ -546,7 +546,7 @@ bool CallData::PushObject(Napi::Object obj, const TypeInfo *type, uint8_t *origi
546
546
  *(uint64_t *)dest = v;
547
547
  } break;
548
548
  case PrimitiveKind::UInt64S: {
549
- if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
549
+ if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] {
550
550
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value));
551
551
  return false;
552
552
  }
@@ -556,28 +556,28 @@ bool CallData::PushObject(Napi::Object obj, const TypeInfo *type, uint8_t *origi
556
556
  } break;
557
557
  case PrimitiveKind::String: {
558
558
  const char *str;
559
- if (RG_UNLIKELY(!PushString(value, 1, &str)))
559
+ if (!PushString(value, 1, &str)) [[unlikely]]
560
560
  return false;
561
561
 
562
562
  *(const char **)dest = str;
563
563
  } break;
564
564
  case PrimitiveKind::String16: {
565
565
  const char16_t *str16;
566
- if (RG_UNLIKELY(!PushString16(value, 1, &str16)))
566
+ if (!PushString16(value, 1, &str16)) [[unlikely]]
567
567
  return false;
568
568
 
569
569
  *(const char16_t **)dest = str16;
570
570
  } break;
571
571
  case PrimitiveKind::Pointer: {
572
572
  void *ptr;
573
- if (RG_UNLIKELY(!PushPointer(value, member.type, 1, &ptr)))
573
+ if (!PushPointer(value, member.type, 1, &ptr)) [[unlikely]]
574
574
  return false;
575
575
 
576
576
  *(void **)dest = ptr;
577
577
  } break;
578
578
  case PrimitiveKind::Record:
579
579
  case PrimitiveKind::Union: {
580
- if (RG_UNLIKELY(!IsObject(value))) {
580
+ if (!IsObject(value)) [[unlikely]] {
581
581
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected object", GetValueType(instance, value));
582
582
  return false;
583
583
  }
@@ -607,7 +607,7 @@ bool CallData::PushObject(Napi::Object obj, const TypeInfo *type, uint8_t *origi
607
607
  }
608
608
  } break;
609
609
  case PrimitiveKind::Float32: {
610
- if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
610
+ if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] {
611
611
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value));
612
612
  return false;
613
613
  }
@@ -616,7 +616,7 @@ bool CallData::PushObject(Napi::Object obj, const TypeInfo *type, uint8_t *origi
616
616
  *(float *)dest = f;
617
617
  } break;
618
618
  case PrimitiveKind::Float64: {
619
- if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
619
+ if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] {
620
620
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value));
621
621
  return false;
622
622
  }
@@ -631,7 +631,7 @@ bool CallData::PushObject(Napi::Object obj, const TypeInfo *type, uint8_t *origi
631
631
  Napi::Function func = value.As<Napi::Function>();
632
632
 
633
633
  ptr = ReserveTrampoline(member.type->ref.proto, func);
634
- if (RG_UNLIKELY(!ptr))
634
+ if (!ptr) [[unlikely]]
635
635
  return false;
636
636
  } else if (CheckValueTag(instance, value, member.type->ref.marker)) {
637
637
  Napi::External<void> external = value.As<Napi::External<void>>();
@@ -659,7 +659,7 @@ bool CallData::PushNormalArray(Napi::Array array, Size len, const TypeInfo *type
659
659
 
660
660
  const TypeInfo *ref = type->ref.type;
661
661
 
662
- if (RG_UNLIKELY(array.Length() != (size_t)len)) {
662
+ if (array.Length() != (size_t)len) [[unlikely]] {
663
663
  ThrowError<Napi::Error>(env, "Expected array of length %1, got %2", len, array.Length());
664
664
  return false;
665
665
  }
@@ -674,7 +674,7 @@ bool CallData::PushNormalArray(Napi::Array array, Size len, const TypeInfo *type
674
674
  offset = AlignLen(offset, ref->align); \
675
675
  uint8_t *dest = origin + offset; \
676
676
  \
677
- if (RG_UNLIKELY(!(Check))) { \
677
+ if (!(Check)) [[unlikely]] { \
678
678
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected %2", GetValueType(instance, value), (Expected)); \
679
679
  return false; \
680
680
  } \
@@ -784,7 +784,7 @@ bool CallData::PushNormalArray(Napi::Array array, Size len, const TypeInfo *type
784
784
  case PrimitiveKind::String: {
785
785
  PUSH_ARRAY(true, "string", {
786
786
  const char *str;
787
- if (RG_UNLIKELY(!PushString(value, 1, &str)))
787
+ if (!PushString(value, 1, &str)) [[unlikely]]
788
788
  return false;
789
789
 
790
790
  *(const char **)dest = str;
@@ -793,7 +793,7 @@ bool CallData::PushNormalArray(Napi::Array array, Size len, const TypeInfo *type
793
793
  case PrimitiveKind::String16: {
794
794
  PUSH_ARRAY(true, "string", {
795
795
  const char16_t *str16;
796
- if (RG_UNLIKELY(!PushString16(value, 1, &str16)))
796
+ if (!PushString16(value, 1, &str16)) [[unlikely]]
797
797
  return false;
798
798
 
799
799
  *(const char16_t **)dest = str16;
@@ -802,7 +802,7 @@ bool CallData::PushNormalArray(Napi::Array array, Size len, const TypeInfo *type
802
802
  case PrimitiveKind::Pointer: {
803
803
  PUSH_ARRAY(true, ref->name, {
804
804
  void *ptr;
805
- if (RG_UNLIKELY(!PushPointer(value, ref, 1, &ptr)))
805
+ if (!PushPointer(value, ref, 1, &ptr)) [[unlikely]]
806
806
  return false;
807
807
 
808
808
  *(const void **)dest = ptr;
@@ -872,7 +872,7 @@ bool CallData::PushNormalArray(Napi::Array array, Size len, const TypeInfo *type
872
872
  Napi::Function func = value.As<Napi::Function>();
873
873
 
874
874
  ptr = ReserveTrampoline(ref->ref.proto, func);
875
- if (RG_UNLIKELY(!ptr))
875
+ if (!ptr) [[unlikely]]
876
876
  return false;
877
877
  } else if (CheckValueTag(instance, value, ref->ref.marker)) {
878
878
  Napi::External<void> external = value.As<Napi::External<void>>();
@@ -900,7 +900,7 @@ bool CallData::PushNormalArray(Napi::Array array, Size len, const TypeInfo *type
900
900
 
901
901
  bool CallData::PushBuffer(Span<const uint8_t> buffer, Size size, const TypeInfo *type, uint8_t *origin)
902
902
  {
903
- if (RG_UNLIKELY(buffer.len != size)) {
903
+ if (buffer.len != size) [[unlikely]] {
904
904
  ThrowError<Napi::Error>(env, "Expected array or buffer of size %1, got %2", size, buffer.len);
905
905
  return false;
906
906
  }
@@ -985,9 +985,9 @@ bool CallData::PushPointer(Napi::Value value, const TypeInfo *type, int directio
985
985
  case napi_external: {
986
986
  RG_ASSERT(type->primitive == PrimitiveKind::Pointer);
987
987
 
988
- if (RG_UNLIKELY(!CheckValueTag(instance, value, type->ref.marker) &&
989
- !CheckValueTag(instance, value, instance->void_type) &&
990
- type->ref.type != instance->void_type))
988
+ if (!CheckValueTag(instance, value, type->ref.marker) &&
989
+ !CheckValueTag(instance, value, instance->void_type) &&
990
+ type->ref.type != instance->void_type) [[unlikely]]
991
991
  goto unexpected;
992
992
 
993
993
  *out_ptr = value.As<Napi::External<uint8_t>>().Data();
@@ -1005,7 +1005,7 @@ bool CallData::PushPointer(Napi::Value value, const TypeInfo *type, int directio
1005
1005
  Size len = PushIndirectString(array, type->ref.type, &ptr);
1006
1006
 
1007
1007
  if (len >= 0) {
1008
- if (RG_UNLIKELY(!type->ref.type->size && type->ref.type != instance->void_type)) {
1008
+ if (!type->ref.type->size && type->ref.type != instance->void_type) [[unlikely]] {
1009
1009
  ThrowError<Napi::TypeError>(env, "Cannot pass [string] value to %1", type->name);
1010
1010
  return false;
1011
1011
  }
@@ -1013,7 +1013,7 @@ bool CallData::PushPointer(Napi::Value value, const TypeInfo *type, int directio
1013
1013
  out_kind = (type->ref.type->size == 2) ? OutArgument::Kind::String16 : OutArgument::Kind::String;
1014
1014
  out_max_len = len;
1015
1015
  } else {
1016
- if (RG_UNLIKELY(!type->ref.type->size)) {
1016
+ if (!type->ref.type->size) [[unlikely]] {
1017
1017
  ThrowError<Napi::TypeError>(env, "Cannot pass %1 value to %2, use koffi.as()",
1018
1018
  type->ref.type != instance->void_type ? "opaque" : "ambiguous", type->name);
1019
1019
  return false;
@@ -1036,21 +1036,14 @@ bool CallData::PushPointer(Napi::Value value, const TypeInfo *type, int directio
1036
1036
  } else if (IsRawBuffer(value)) {
1037
1037
  Span<uint8_t> buffer = GetRawBuffer(value);
1038
1038
 
1039
- if (directions == 1) {
1040
- ptr = AllocHeap(buffer.len, 16);
1041
-
1042
- if (!PushBuffer(buffer, buffer.len, type, ptr))
1043
- return false;
1044
- } else {
1045
- // Fast no-copy path
1046
- ptr = buffer.ptr;
1047
- directions = 1;
1048
- }
1039
+ // We can fast path
1040
+ ptr = buffer.ptr;
1041
+ directions = 1;
1049
1042
 
1050
1043
  out_kind = OutArgument::Kind::Buffer;
1051
- } else if (RG_LIKELY(type->ref.type->primitive == PrimitiveKind::Record ||
1052
- type->ref.type->primitive == PrimitiveKind::Union)) {
1053
- if (RG_UNLIKELY(!type->ref.type->size)) {
1044
+ } else if (type->ref.type->primitive == PrimitiveKind::Record ||
1045
+ type->ref.type->primitive == PrimitiveKind::Union) [[likely]] {
1046
+ if (!type->ref.type->size) [[unlikely]] {
1054
1047
  ThrowError<Napi::TypeError>(env, "Cannot pass %1 value to %2, use koffi.as()",
1055
1048
  type->ref.type != instance->void_type ? "opaque" : "ambiguous", type->name);
1056
1049
  return false;
@@ -1061,8 +1054,8 @@ bool CallData::PushPointer(Napi::Value value, const TypeInfo *type, int directio
1061
1054
 
1062
1055
  ptr = AllocHeap(type->ref.type->size, 16);
1063
1056
 
1064
- if (RG_UNLIKELY(type->ref.type->primitive == PrimitiveKind::Union &&
1065
- (directions & 2) && !CheckValueTag(instance, obj, &MagicUnionMarker))) {
1057
+ if (type->ref.type->primitive == PrimitiveKind::Union &&
1058
+ (directions & 2) && !CheckValueTag(instance, obj, &MagicUnionMarker)) [[unlikely]] {
1066
1059
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected union value", GetValueType(instance, obj));
1067
1060
  return false;
1068
1061
  }
@@ -1098,7 +1091,7 @@ bool CallData::PushPointer(Napi::Value value, const TypeInfo *type, int directio
1098
1091
  case napi_string: {
1099
1092
  RG_ASSERT(type->primitive == PrimitiveKind::Pointer);
1100
1093
 
1101
- if (RG_UNLIKELY(directions & 2))
1094
+ if (directions & 2) [[unlikely]]
1102
1095
  goto unexpected;
1103
1096
 
1104
1097
  if (type->ref.type == instance->void_type) {
@@ -1237,11 +1230,11 @@ void *CallData::ReserveTrampoline(const FunctionInfo *proto, Napi::Function func
1237
1230
  {
1238
1231
  std::lock_guard<std::mutex> lock(shared.mutex);
1239
1232
 
1240
- if (RG_UNLIKELY(!shared.available.len)) {
1233
+ if (!shared.available.len) [[unlikely]] {
1241
1234
  ThrowError<Napi::Error>(env, "Too many callbacks are in use (max = %1)", MaxTrampolines);
1242
1235
  return env.Null();
1243
1236
  }
1244
- if (RG_UNLIKELY(!used_trampolines.Available())) {
1237
+ if (!used_trampolines.Available()) [[unlikely]] {
1245
1238
  ThrowError<Napi::Error>(env, "This call uses too many temporary callbacks (max = %1)", RG_LEN(used_trampolines.data));
1246
1239
  return env.Null();
1247
1240
  }
@@ -142,7 +142,7 @@ inline bool CallData::AllocStack(Size size, Size align, T **out_ptr)
142
142
  Size delta = mem->stack.end() - ptr;
143
143
 
144
144
  // Keep 512 bytes for redzone (required in some ABIs)
145
- if (RG_UNLIKELY(mem->stack.len - 512 < delta)) {
145
+ if (mem->stack.len - 512 < delta) [[unlikely]] {
146
146
  ThrowError<Napi::Error>(env, "FFI call is taking up too much memory");
147
147
  return false;
148
148
  }
@@ -163,7 +163,7 @@ inline T *CallData::AllocHeap(Size size, Size align)
163
163
  uint8_t *ptr = AlignUp(mem->heap.ptr, align);
164
164
  Size delta = size + (ptr - mem->heap.ptr);
165
165
 
166
- if (RG_LIKELY(size < 4096 && delta <= mem->heap.len)) {
166
+ if (size < 4096 && delta <= mem->heap.len) [[likely]] {
167
167
  #ifdef RG_DEBUG
168
168
  memset(mem->heap.ptr, 0, (size_t)delta);
169
169
  #endif