koffi 1.2.4 → 1.3.0-rc.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 (126) hide show
  1. package/README.md +7 -489
  2. package/benchmark/CMakeLists.txt +13 -9
  3. package/benchmark/raylib_node_raylib.js +67 -0
  4. package/build/qemu/1.3.0-rc.1/koffi_darwin_arm64.tar.gz +0 -0
  5. package/build/qemu/1.3.0-rc.1/koffi_darwin_x64.tar.gz +0 -0
  6. package/build/qemu/1.3.0-rc.1/koffi_freebsd_arm64.tar.gz +0 -0
  7. package/build/qemu/1.3.0-rc.1/koffi_freebsd_ia32.tar.gz +0 -0
  8. package/build/qemu/1.3.0-rc.1/koffi_freebsd_x64.tar.gz +0 -0
  9. package/build/qemu/1.3.0-rc.1/koffi_linux_arm32hf.tar.gz +0 -0
  10. package/build/qemu/1.3.0-rc.1/koffi_linux_arm64.tar.gz +0 -0
  11. package/build/qemu/1.3.0-rc.1/koffi_linux_ia32.tar.gz +0 -0
  12. package/build/qemu/1.3.0-rc.1/koffi_linux_riscv64hf64.tar.gz +0 -0
  13. package/build/qemu/1.3.0-rc.1/koffi_linux_x64.tar.gz +0 -0
  14. package/build/qemu/1.3.0-rc.1/koffi_openbsd_ia32.tar.gz +0 -0
  15. package/build/qemu/1.3.0-rc.1/koffi_openbsd_x64.tar.gz +0 -0
  16. package/build/qemu/1.3.0-rc.1/koffi_win32_arm64.tar.gz +0 -0
  17. package/build/qemu/1.3.0-rc.1/koffi_win32_ia32.tar.gz +0 -0
  18. package/build/qemu/1.3.0-rc.1/koffi_win32_x64.tar.gz +0 -0
  19. package/doc/Makefile +20 -0
  20. package/doc/_static/bench_linux.png +0 -0
  21. package/doc/_static/bench_windows.png +0 -0
  22. package/doc/_static/custom.css +22 -0
  23. package/doc/benchmarks.md +113 -0
  24. package/doc/benchmarks.xlsx +0 -0
  25. package/doc/conf.py +54 -0
  26. package/doc/contribute.md +115 -0
  27. package/doc/dist/doctrees/benchmarks.doctree +0 -0
  28. package/doc/dist/doctrees/contribute.doctree +0 -0
  29. package/doc/dist/doctrees/environment.pickle +0 -0
  30. package/doc/dist/doctrees/functions.doctree +0 -0
  31. package/doc/dist/doctrees/index.doctree +0 -0
  32. package/doc/dist/doctrees/memory.doctree +0 -0
  33. package/doc/dist/doctrees/platforms.doctree +0 -0
  34. package/doc/dist/doctrees/start.doctree +0 -0
  35. package/doc/dist/doctrees/types.doctree +0 -0
  36. package/doc/dist/html/.buildinfo +4 -0
  37. package/doc/dist/html/_sources/benchmarks.md.txt +113 -0
  38. package/doc/dist/html/_sources/contribute.md.txt +115 -0
  39. package/doc/dist/html/_sources/functions.md.txt +224 -0
  40. package/doc/dist/html/_sources/index.rst.txt +33 -0
  41. package/doc/dist/html/_sources/memory.md.txt +29 -0
  42. package/doc/dist/html/_sources/platforms.md.txt +17 -0
  43. package/doc/dist/html/_sources/start.md.txt +89 -0
  44. package/doc/dist/html/_sources/types.md.txt +514 -0
  45. package/doc/dist/html/_static/_sphinx_javascript_frameworks_compat.js +134 -0
  46. package/doc/dist/html/_static/basic.css +932 -0
  47. package/doc/dist/html/_static/bench_linux.png +0 -0
  48. package/doc/dist/html/_static/bench_windows.png +0 -0
  49. package/doc/dist/html/_static/custom.css +22 -0
  50. package/doc/dist/html/_static/debug.css +69 -0
  51. package/doc/dist/html/_static/doctools.js +264 -0
  52. package/doc/dist/html/_static/documentation_options.js +14 -0
  53. package/doc/dist/html/_static/file.png +0 -0
  54. package/doc/dist/html/_static/jquery-3.6.0.js +10881 -0
  55. package/doc/dist/html/_static/jquery.js +2 -0
  56. package/doc/dist/html/_static/language_data.js +199 -0
  57. package/doc/dist/html/_static/minus.png +0 -0
  58. package/doc/dist/html/_static/plus.png +0 -0
  59. package/doc/dist/html/_static/pygments.css +252 -0
  60. package/doc/dist/html/_static/scripts/furo-extensions.js +0 -0
  61. package/doc/dist/html/_static/scripts/furo.js +3 -0
  62. package/doc/dist/html/_static/scripts/furo.js.LICENSE.txt +7 -0
  63. package/doc/dist/html/_static/scripts/furo.js.map +1 -0
  64. package/doc/dist/html/_static/searchtools.js +531 -0
  65. package/doc/dist/html/_static/skeleton.css +296 -0
  66. package/doc/dist/html/_static/styles/furo-extensions.css +2 -0
  67. package/doc/dist/html/_static/styles/furo-extensions.css.map +1 -0
  68. package/doc/dist/html/_static/styles/furo.css +2 -0
  69. package/doc/dist/html/_static/styles/furo.css.map +1 -0
  70. package/doc/dist/html/_static/underscore-1.13.1.js +2042 -0
  71. package/doc/dist/html/_static/underscore.js +6 -0
  72. package/doc/dist/html/benchmarks.html +547 -0
  73. package/doc/dist/html/contribute.html +382 -0
  74. package/doc/dist/html/functions.html +530 -0
  75. package/doc/dist/html/genindex.html +249 -0
  76. package/doc/dist/html/index.html +342 -0
  77. package/doc/dist/html/memory.html +337 -0
  78. package/doc/dist/html/objects.inv +0 -0
  79. package/doc/dist/html/platforms.html +332 -0
  80. package/doc/dist/html/search.html +257 -0
  81. package/doc/dist/html/searchindex.js +1 -0
  82. package/doc/dist/html/start.html +367 -0
  83. package/doc/dist/html/types.html +1001 -0
  84. package/doc/functions.md +224 -0
  85. package/doc/index.rst +33 -0
  86. package/doc/make.bat +35 -0
  87. package/doc/memory.md +29 -0
  88. package/doc/platforms.md +17 -0
  89. package/doc/start.md +89 -0
  90. package/doc/types.md +514 -0
  91. package/package.json +5 -2
  92. package/qemu/qemu.js +41 -27
  93. package/qemu/registry/machines.json +59 -79
  94. package/qemu/registry/sha256sum.txt +4 -4
  95. package/src/abi_arm32.cc +20 -48
  96. package/src/abi_arm64.cc +18 -46
  97. package/src/abi_arm64_fwd.S +5 -0
  98. package/src/abi_riscv64.cc +19 -47
  99. package/src/abi_x64_sysv.cc +18 -46
  100. package/src/abi_x64_win.cc +19 -47
  101. package/src/abi_x86.cc +21 -49
  102. package/src/call.cc +505 -242
  103. package/src/call.hh +14 -7
  104. package/src/ffi.cc +47 -26
  105. package/src/ffi.hh +1 -1
  106. package/src/parser.cc +2 -20
  107. package/src/util.cc +50 -11
  108. package/src/util.hh +2 -0
  109. package/test/misc.c +31 -0
  110. package/test/sync.js +41 -4
  111. package/benchmark/atoi_cc.cc +0 -59
  112. package/build/qemu/1.2.4/koffi_darwin_arm64.tar.gz +0 -0
  113. package/build/qemu/1.2.4/koffi_darwin_x64.tar.gz +0 -0
  114. package/build/qemu/1.2.4/koffi_freebsd_arm64.tar.gz +0 -0
  115. package/build/qemu/1.2.4/koffi_freebsd_ia32.tar.gz +0 -0
  116. package/build/qemu/1.2.4/koffi_freebsd_x64.tar.gz +0 -0
  117. package/build/qemu/1.2.4/koffi_linux_arm.tar.gz +0 -0
  118. package/build/qemu/1.2.4/koffi_linux_arm64.tar.gz +0 -0
  119. package/build/qemu/1.2.4/koffi_linux_ia32.tar.gz +0 -0
  120. package/build/qemu/1.2.4/koffi_linux_riscv64.tar.gz +0 -0
  121. package/build/qemu/1.2.4/koffi_linux_x64.tar.gz +0 -0
  122. package/build/qemu/1.2.4/koffi_openbsd_ia32.tar.gz +0 -0
  123. package/build/qemu/1.2.4/koffi_openbsd_x64.tar.gz +0 -0
  124. package/build/qemu/1.2.4/koffi_win32_arm64.tar.gz +0 -0
  125. package/build/qemu/1.2.4/koffi_win32_ia32.tar.gz +0 -0
  126. package/build/qemu/1.2.4/koffi_win32_x64.tar.gz +0 -0
@@ -276,7 +276,7 @@ bool CallData::Prepare(const Napi::CallbackInfo &info)
276
276
 
277
277
  case PrimitiveKind::Bool: {
278
278
  if (RG_UNLIKELY(!value.IsBoolean())) {
279
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argmument %2, expected boolean", GetValueType(instance, value), i + 1);
279
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argmument %2, expected boolean", GetValueType(instance, value), param.offset + 1);
280
280
  return false;
281
281
  }
282
282
 
@@ -291,7 +291,7 @@ bool CallData::Prepare(const Napi::CallbackInfo &info)
291
291
  case PrimitiveKind::UInt32:
292
292
  case PrimitiveKind::Int64: {
293
293
  if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
294
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), i + 1);
294
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), param.offset + 1);
295
295
  return false;
296
296
  }
297
297
 
@@ -300,7 +300,7 @@ bool CallData::Prepare(const Napi::CallbackInfo &info)
300
300
  } break;
301
301
  case PrimitiveKind::UInt64: {
302
302
  if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
303
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), i + 1);
303
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), param.offset + 1);
304
304
  return false;
305
305
  }
306
306
 
@@ -316,7 +316,7 @@ bool CallData::Prepare(const Napi::CallbackInfo &info)
316
316
  } else if (IsNullOrUndefined(value)) {
317
317
  str = nullptr;
318
318
  } else {
319
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected string", GetValueType(instance, value), i + 1);
319
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected string", GetValueType(instance, value), param.offset + 1);
320
320
  return false;
321
321
  }
322
322
 
@@ -331,47 +331,22 @@ bool CallData::Prepare(const Napi::CallbackInfo &info)
331
331
  } else if (IsNullOrUndefined(value)) {
332
332
  str16 = nullptr;
333
333
  } else {
334
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected string", GetValueType(instance, value), i + 1);
334
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected string", GetValueType(instance, value), param.offset + 1);
335
335
  return false;
336
336
  }
337
337
 
338
338
  *(const char16_t **)((param.gpr_count ? gpr_ptr : args_ptr)++) = str16;
339
339
  } break;
340
340
  case PrimitiveKind::Pointer: {
341
- uint8_t *ptr;
342
-
343
- if (CheckValueTag(instance, value, param.type)) {
344
- ptr = value.As<Napi::External<uint8_t>>().Data();
345
- } else if (IsObject(value) && param.type->ref->primitive == PrimitiveKind::Record) {
346
- Napi::Object obj = value.As<Napi::Object>();
347
-
348
- ptr = AllocHeap(param.type->ref->size, 16);
349
-
350
- if (param.directions & 1) {
351
- if (!PushObject(obj, param.type->ref, ptr))
352
- return false;
353
- } else {
354
- memset(ptr, 0, param.type->size);
355
- }
356
- if (param.directions & 2) {
357
- OutObject *out = out_objects.AppendDefault();
358
-
359
- out->ref.Reset(obj, 1);
360
- out->ptr = ptr;
361
- out->type = param.type->ref;
362
- }
363
- } else if (IsNullOrUndefined(value)) {
364
- ptr = nullptr;
365
- } else {
366
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected %3", GetValueType(instance, value), i + 1, param.type->name);
341
+ void *ptr;
342
+ if (RG_UNLIKELY(!PushPointer(value, param, &ptr)))
367
343
  return false;
368
- }
369
344
 
370
345
  *(void **)((param.gpr_count ? gpr_ptr : args_ptr)++) = ptr;
371
346
  } break;
372
347
  case PrimitiveKind::Record: {
373
348
  if (RG_UNLIKELY(!IsObject(value))) {
374
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected object", GetValueType(instance, value), i + 1);
349
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected object", GetValueType(instance, value), param.offset + 1);
375
350
  return false;
376
351
  }
377
352
 
@@ -410,7 +385,7 @@ bool CallData::Prepare(const Napi::CallbackInfo &info)
410
385
  case PrimitiveKind::Array: { RG_UNREACHABLE(); } break;
411
386
  case PrimitiveKind::Float32: {
412
387
  if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
413
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), i + 1);
388
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), param.offset + 1);
414
389
  return false;
415
390
  }
416
391
 
@@ -422,7 +397,7 @@ bool CallData::Prepare(const Napi::CallbackInfo &info)
422
397
  } break;
423
398
  case PrimitiveKind::Float64: {
424
399
  if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
425
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), i + 1);
400
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), param.offset + 1);
426
401
  return false;
427
402
  }
428
403
 
@@ -443,7 +418,7 @@ bool CallData::Prepare(const Napi::CallbackInfo &info)
443
418
  } else if (IsNullOrUndefined(value)) {
444
419
  ptr = nullptr;
445
420
  } else {
446
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected %3", GetValueType(instance, value), i + 1, param.type->name);
421
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected %3", GetValueType(instance, value), param.offset + 1, param.type->name);
447
422
  return false;
448
423
  }
449
424
 
@@ -509,10 +484,7 @@ void CallData::Execute()
509
484
 
510
485
  Napi::Value CallData::Complete()
511
486
  {
512
- for (const OutObject &out: out_objects) {
513
- Napi::Object obj = out.ref.Value().As<Napi::Object>();
514
- PopObject(obj, out.ptr, out.type);
515
- }
487
+ PopOutArguments();
516
488
 
517
489
  switch (func->ret.type->primitive) {
518
490
  case PrimitiveKind::Void: return env.Null();
@@ -525,8 +497,8 @@ Napi::Value CallData::Complete()
525
497
  case PrimitiveKind::UInt32: return Napi::Number::New(env, (double)result.u32);
526
498
  case PrimitiveKind::Int64: return Napi::BigInt::New(env, (int64_t)result.u64);
527
499
  case PrimitiveKind::UInt64: return Napi::BigInt::New(env, result.u64);
528
- case PrimitiveKind::String: return Napi::String::New(env, (const char *)result.ptr);
529
- case PrimitiveKind::String16: return Napi::String::New(env, (const char16_t *)result.ptr);
500
+ case PrimitiveKind::String: return result.ptr ? Napi::String::New(env, (const char *)result.ptr) : env.Null();
501
+ case PrimitiveKind::String16: return result.ptr ? Napi::String::New(env, (const char16_t *)result.ptr) : env.Null();
530
502
  case PrimitiveKind::Pointer:
531
503
  case PrimitiveKind::Callback: {
532
504
  if (result.ptr) {
@@ -632,13 +604,13 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
632
604
  case PrimitiveKind::String: {
633
605
  const char *str = *(const char **)((param.gpr_count ? gpr_ptr : args_ptr)++);
634
606
 
635
- Napi::Value arg = Napi::String::New(env, str);
607
+ Napi::Value arg = str ? Napi::String::New(env, str) : env.Null();
636
608
  arguments.Append(arg);
637
609
  } break;
638
610
  case PrimitiveKind::String16: {
639
611
  const char16_t *str16 = *(const char16_t **)((param.gpr_count ? gpr_ptr : args_ptr)++);
640
612
 
641
- Napi::Value arg = Napi::String::New(env, str16);
613
+ Napi::Value arg = str16 ? Napi::String::New(env, str16) : env.Null();
642
614
  arguments.Append(arg);
643
615
  } break;
644
616
  case PrimitiveKind::Pointer:
@@ -849,9 +821,9 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
849
821
  void *ptr;
850
822
 
851
823
  if (value.IsFunction()) {
852
- Napi::Function func = value.As<Napi::Function>();
824
+ Napi::Function func2 = value.As<Napi::Function>();
853
825
 
854
- ptr = ReserveTrampoline(type->proto, func);
826
+ ptr = ReserveTrampoline(type->proto, func2);
855
827
  if (RG_UNLIKELY(!ptr))
856
828
  return;
857
829
  } else if (CheckValueTag(instance, value, type)) {
@@ -121,7 +121,7 @@ bool CallData::Prepare(const Napi::CallbackInfo &info)
121
121
 
122
122
  case PrimitiveKind::Bool: {
123
123
  if (RG_UNLIKELY(!value.IsBoolean())) {
124
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected boolean", GetValueType(instance, value), i + 1);
124
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected boolean", GetValueType(instance, value), param.offset + 1);
125
125
  return false;
126
126
  }
127
127
 
@@ -137,7 +137,7 @@ bool CallData::Prepare(const Napi::CallbackInfo &info)
137
137
  case PrimitiveKind::UInt32:
138
138
  case PrimitiveKind::Int64: {
139
139
  if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
140
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), i + 1);
140
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), param.offset + 1);
141
141
  return false;
142
142
  }
143
143
 
@@ -146,7 +146,7 @@ bool CallData::Prepare(const Napi::CallbackInfo &info)
146
146
  } break;
147
147
  case PrimitiveKind::UInt64: {
148
148
  if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
149
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), i + 1);
149
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), param.offset + 1);
150
150
  return false;
151
151
  }
152
152
 
@@ -162,7 +162,7 @@ bool CallData::Prepare(const Napi::CallbackInfo &info)
162
162
  } else if (IsNullOrUndefined(value)) {
163
163
  str = nullptr;
164
164
  } else {
165
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected string", GetValueType(instance, value), i + 1);
165
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected string", GetValueType(instance, value), param.offset + 1);
166
166
  return false;
167
167
  }
168
168
 
@@ -177,47 +177,22 @@ bool CallData::Prepare(const Napi::CallbackInfo &info)
177
177
  } else if (IsNullOrUndefined(value)) {
178
178
  str16 = nullptr;
179
179
  } else {
180
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected string", GetValueType(instance, value), i + 1);
180
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected string", GetValueType(instance, value), param.offset + 1);
181
181
  return false;
182
182
  }
183
183
 
184
184
  *(const char16_t **)(args_ptr++) = str16;
185
185
  } break;
186
186
  case PrimitiveKind::Pointer: {
187
- uint8_t *ptr;
188
-
189
- if (CheckValueTag(instance, value, param.type)) {
190
- ptr = value.As<Napi::External<uint8_t>>().Data();
191
- } else if (IsObject(value) && param.type->ref->primitive == PrimitiveKind::Record) {
192
- Napi::Object obj = value.As<Napi::Object>();
193
-
194
- ptr = AllocHeap(param.type->ref->size, 16);
195
-
196
- if (param.directions & 1) {
197
- if (!PushObject(obj, param.type->ref, ptr))
198
- return false;
199
- } else {
200
- memset(ptr, 0, param.type->size);
201
- }
202
- if (param.directions & 2) {
203
- OutObject *out = out_objects.AppendDefault();
204
-
205
- out->ref.Reset(obj, 1);
206
- out->ptr = ptr;
207
- out->type = param.type->ref;
208
- }
209
- } else if (IsNullOrUndefined(value)) {
210
- ptr = nullptr;
211
- } else {
212
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected %3", GetValueType(instance, value), i + 1, param.type->name);
187
+ void *ptr;
188
+ if (RG_UNLIKELY(!PushPointer(value, param, &ptr)))
213
189
  return false;
214
- }
215
190
 
216
- *(uint8_t **)(args_ptr++) = ptr;
191
+ *(void **)(args_ptr++) = ptr;
217
192
  } break;
218
193
  case PrimitiveKind::Record: {
219
194
  if (RG_UNLIKELY(!IsObject(value))) {
220
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected object", GetValueType(instance, value), i + 1);
195
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected object", GetValueType(instance, value), param.offset + 1);
221
196
  return false;
222
197
  }
223
198
 
@@ -236,7 +211,7 @@ bool CallData::Prepare(const Napi::CallbackInfo &info)
236
211
  case PrimitiveKind::Array: { RG_UNREACHABLE(); } break;
237
212
  case PrimitiveKind::Float32: {
238
213
  if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
239
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), i + 1);
214
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), param.offset + 1);
240
215
  return false;
241
216
  }
242
217
 
@@ -247,7 +222,7 @@ bool CallData::Prepare(const Napi::CallbackInfo &info)
247
222
  } break;
248
223
  case PrimitiveKind::Float64: {
249
224
  if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
250
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), i + 1);
225
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), param.offset + 1);
251
226
  return false;
252
227
  }
253
228
 
@@ -268,7 +243,7 @@ bool CallData::Prepare(const Napi::CallbackInfo &info)
268
243
  } else if (IsNullOrUndefined(value)) {
269
244
  ptr = nullptr;
270
245
  } else {
271
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected %3", GetValueType(instance, value), i + 1, param.type->name);
246
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected %3", GetValueType(instance, value), param.offset + 1, param.type->name);
272
247
  return false;
273
248
  }
274
249
 
@@ -319,10 +294,7 @@ void CallData::Execute()
319
294
 
320
295
  Napi::Value CallData::Complete()
321
296
  {
322
- for (const OutObject &out: out_objects) {
323
- Napi::Object obj = out.ref.Value().As<Napi::Object>();
324
- PopObject(obj, out.ptr, out.type);
325
- }
297
+ PopOutArguments();
326
298
 
327
299
  switch (func->ret.type->primitive) {
328
300
  case PrimitiveKind::Void: return env.Null();
@@ -335,8 +307,8 @@ Napi::Value CallData::Complete()
335
307
  case PrimitiveKind::UInt32: return Napi::Number::New(env, (double)result.u32);
336
308
  case PrimitiveKind::Int64: return Napi::BigInt::New(env, (int64_t)result.u64);
337
309
  case PrimitiveKind::UInt64: return Napi::BigInt::New(env, result.u64);
338
- case PrimitiveKind::String: return Napi::String::New(env, (const char *)result.ptr);
339
- case PrimitiveKind::String16: return Napi::String::New(env, (const char16_t *)result.ptr);
310
+ case PrimitiveKind::String: return result.ptr ? Napi::String::New(env, (const char *)result.ptr) : env.Null();
311
+ case PrimitiveKind::String16: return result.ptr ? Napi::String::New(env, (const char16_t *)result.ptr) : env.Null();
340
312
  case PrimitiveKind::Pointer:
341
313
  case PrimitiveKind::Callback: {
342
314
  if (result.ptr) {
@@ -451,14 +423,14 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
451
423
  const char *str = *(const char **)(j < 4 ? gpr_ptr + j : args_ptr);
452
424
  args_ptr += (j >= 4);
453
425
 
454
- Napi::Value arg = Napi::String::New(env, str);
426
+ Napi::Value arg = str ? Napi::String::New(env, str) : env.Null();
455
427
  arguments.Append(arg);
456
428
  } break;
457
429
  case PrimitiveKind::String16: {
458
430
  const char16_t *str16 = *(const char16_t **)(j < 4 ? gpr_ptr + j : args_ptr);
459
431
  args_ptr += (j >= 4);
460
432
 
461
- Napi::Value arg = Napi::String::New(env, str16);
433
+ Napi::Value arg = str16 ? Napi::String::New(env, str16) : env.Null();
462
434
  arguments.Append(arg);
463
435
  } break;
464
436
  case PrimitiveKind::Pointer:
@@ -631,9 +603,9 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
631
603
  void *ptr;
632
604
 
633
605
  if (value.IsFunction()) {
634
- Napi::Function func = value.As<Napi::Function>();
606
+ Napi::Function func2 = value.As<Napi::Function>();
635
607
 
636
- ptr = ReserveTrampoline(type->proto, func);
608
+ ptr = ReserveTrampoline(type->proto, func2);
637
609
  if (RG_UNLIKELY(!ptr))
638
610
  return;
639
611
  } else if (CheckValueTag(instance, value, type)) {
package/src/abi_x86.cc CHANGED
@@ -177,7 +177,7 @@ bool CallData::Prepare(const Napi::CallbackInfo &info)
177
177
 
178
178
  case PrimitiveKind::Bool: {
179
179
  if (RG_UNLIKELY(!value.IsBoolean())) {
180
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected boolean", GetValueType(instance, value), i + 1);
180
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected boolean", GetValueType(instance, value), param.offset + 1);
181
181
  return false;
182
182
  }
183
183
 
@@ -190,7 +190,7 @@ bool CallData::Prepare(const Napi::CallbackInfo &info)
190
190
  case PrimitiveKind::UInt16:
191
191
  case PrimitiveKind::Int32: {
192
192
  if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
193
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), i + 1);
193
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), param.offset + 1);
194
194
  return false;
195
195
  }
196
196
 
@@ -199,7 +199,7 @@ bool CallData::Prepare(const Napi::CallbackInfo &info)
199
199
  } break;
200
200
  case PrimitiveKind::UInt32: {
201
201
  if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
202
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), i + 1);
202
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), param.offset + 1);
203
203
  return false;
204
204
  }
205
205
 
@@ -208,7 +208,7 @@ bool CallData::Prepare(const Napi::CallbackInfo &info)
208
208
  } break;
209
209
  case PrimitiveKind::Int64: {
210
210
  if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
211
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), i + 1);
211
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), param.offset + 1);
212
212
  return false;
213
213
  }
214
214
 
@@ -218,7 +218,7 @@ bool CallData::Prepare(const Napi::CallbackInfo &info)
218
218
  } break;
219
219
  case PrimitiveKind::UInt64: {
220
220
  if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
221
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), i + 1);
221
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), param.offset + 1);
222
222
  return false;
223
223
  }
224
224
 
@@ -235,7 +235,7 @@ bool CallData::Prepare(const Napi::CallbackInfo &info)
235
235
  } else if (IsNullOrUndefined(value)) {
236
236
  str = nullptr;
237
237
  } else {
238
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected string", GetValueType(instance, value), i + 1);
238
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected string", GetValueType(instance, value), param.offset + 1);
239
239
  return false;
240
240
  }
241
241
 
@@ -250,47 +250,22 @@ bool CallData::Prepare(const Napi::CallbackInfo &info)
250
250
  } else if (IsNullOrUndefined(value)) {
251
251
  str16 = nullptr;
252
252
  } else {
253
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected string", GetValueType(instance, value), i + 1);
253
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected string", GetValueType(instance, value), param.offset + 1);
254
254
  return false;
255
255
  }
256
256
 
257
257
  *(const char16_t **)((param.fast ? fast_ptr : args_ptr)++) = str16;
258
258
  } break;
259
259
  case PrimitiveKind::Pointer: {
260
- uint8_t *ptr;
261
-
262
- if (CheckValueTag(instance, value, param.type)) {
263
- ptr = value.As<Napi::External<uint8_t>>().Data();
264
- } else if (IsObject(value) && param.type->ref->primitive == PrimitiveKind::Record) {
265
- Napi::Object obj = value.As<Napi::Object>();
266
-
267
- ptr = AllocHeap(param.type->ref->size, 16);
268
-
269
- if (param.directions & 1) {
270
- if (!PushObject(obj, param.type->ref, ptr))
271
- return false;
272
- } else {
273
- memset(ptr, 0, param.type->size);
274
- }
275
- if (param.directions & 2) {
276
- OutObject *out = out_objects.AppendDefault();
277
-
278
- out->ref.Reset(obj, 1);
279
- out->ptr = ptr;
280
- out->type = param.type->ref;
281
- }
282
- } else if (IsNullOrUndefined(value)) {
283
- ptr = nullptr;
284
- } else {
285
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected %3", GetValueType(instance, value), i + 1, param.type->name);
260
+ void *ptr;
261
+ if (RG_UNLIKELY(!PushPointer(value, param, &ptr)))
286
262
  return false;
287
- }
288
263
 
289
- *(uint8_t **)((param.fast ? fast_ptr : args_ptr)++) = ptr;
264
+ *(void **)((param.fast ? fast_ptr : args_ptr)++) = ptr;
290
265
  } break;
291
266
  case PrimitiveKind::Record: {
292
267
  if (RG_UNLIKELY(!IsObject(value))) {
293
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected object", GetValueType(instance, value), i + 1);
268
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected object", GetValueType(instance, value), param.offset + 1);
294
269
  return false;
295
270
  }
296
271
 
@@ -310,7 +285,7 @@ bool CallData::Prepare(const Napi::CallbackInfo &info)
310
285
  case PrimitiveKind::Array: { RG_UNREACHABLE(); } break;
311
286
  case PrimitiveKind::Float32: {
312
287
  if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
313
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), i + 1);
288
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), param.offset + 1);
314
289
  return false;
315
290
  }
316
291
 
@@ -319,7 +294,7 @@ bool CallData::Prepare(const Napi::CallbackInfo &info)
319
294
  } break;
320
295
  case PrimitiveKind::Float64: {
321
296
  if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
322
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), i + 1);
297
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), param.offset + 1);
323
298
  return false;
324
299
  }
325
300
 
@@ -341,7 +316,7 @@ bool CallData::Prepare(const Napi::CallbackInfo &info)
341
316
  } else if (IsNullOrUndefined(value)) {
342
317
  ptr = nullptr;
343
318
  } else {
344
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected %3", GetValueType(instance, value), i + 1, param.type->name);
319
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected %3", GetValueType(instance, value), param.offset + 1, param.type->name);
345
320
  return false;
346
321
  }
347
322
 
@@ -393,10 +368,7 @@ void CallData::Execute()
393
368
 
394
369
  Napi::Value CallData::Complete()
395
370
  {
396
- for (const OutObject &out: out_objects) {
397
- Napi::Object obj = out.ref.Value().As<Napi::Object>();
398
- PopObject(obj, out.ptr, out.type);
399
- }
371
+ PopOutArguments();
400
372
 
401
373
  switch (func->ret.type->primitive) {
402
374
  case PrimitiveKind::Void: return env.Null();
@@ -409,8 +381,8 @@ Napi::Value CallData::Complete()
409
381
  case PrimitiveKind::UInt32: return Napi::Number::New(env, (double)result.u32);
410
382
  case PrimitiveKind::Int64: return Napi::BigInt::New(env, (int64_t)result.u64);
411
383
  case PrimitiveKind::UInt64: return Napi::BigInt::New(env, result.u64);
412
- case PrimitiveKind::String: return Napi::String::New(env, (const char *)result.ptr);
413
- case PrimitiveKind::String16: return Napi::String::New(env, (const char16_t *)result.ptr);
384
+ case PrimitiveKind::String: return result.ptr ? Napi::String::New(env, (const char *)result.ptr) : env.Null();
385
+ case PrimitiveKind::String16: return result.ptr ? Napi::String::New(env, (const char16_t *)result.ptr) : env.Null();
414
386
  case PrimitiveKind::Pointer:
415
387
  case PrimitiveKind::Callback: {
416
388
  if (result.ptr) {
@@ -526,13 +498,13 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
526
498
  case PrimitiveKind::String: {
527
499
  const char *str = *(const char **)(args_ptr++);
528
500
 
529
- Napi::Value arg = Napi::String::New(env, str);
501
+ Napi::Value arg = str ? Napi::String::New(env, str) : env.Null();
530
502
  arguments.Append(arg);
531
503
  } break;
532
504
  case PrimitiveKind::String16: {
533
505
  const char16_t *str16 = *(const char16_t **)(args_ptr++);
534
506
 
535
- Napi::Value arg = Napi::String::New(env, str16);
507
+ Napi::Value arg = str16 ? Napi::String::New(env, str16) : env.Null();
536
508
  arguments.Append(arg);
537
509
  } break;
538
510
  case PrimitiveKind::Pointer:
@@ -708,9 +680,9 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
708
680
  void *ptr;
709
681
 
710
682
  if (value.IsFunction()) {
711
- Napi::Function func = value.As<Napi::Function>();
683
+ Napi::Function func2 = value.As<Napi::Function>();
712
684
 
713
- ptr = ReserveTrampoline(type->proto, func);
685
+ ptr = ReserveTrampoline(type->proto, func2);
714
686
  if (RG_UNLIKELY(!ptr))
715
687
  return;
716
688
  } else if (CheckValueTag(instance, value, type)) {