koffi 2.4.2 → 2.5.0-beta.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.
- package/build/2.5.0-beta.2/koffi_darwin_arm64/koffi.node +0 -0
- package/build/2.5.0-beta.2/koffi_darwin_x64/koffi.node +0 -0
- package/build/2.5.0-beta.2/koffi_freebsd_arm64/koffi.node +0 -0
- package/build/2.5.0-beta.2/koffi_freebsd_ia32/koffi.node +0 -0
- package/build/2.5.0-beta.2/koffi_freebsd_x64/koffi.node +0 -0
- package/build/2.5.0-beta.2/koffi_linux_arm32hf/koffi.node +0 -0
- package/build/2.5.0-beta.2/koffi_linux_arm64/koffi.node +0 -0
- package/build/2.5.0-beta.2/koffi_linux_ia32/koffi.node +0 -0
- package/build/2.5.0-beta.2/koffi_linux_riscv64hf64/koffi.node +0 -0
- package/build/2.5.0-beta.2/koffi_linux_x64/koffi.node +0 -0
- package/build/2.5.0-beta.2/koffi_openbsd_ia32/koffi.node +0 -0
- package/build/{2.4.2 → 2.5.0-beta.2}/koffi_openbsd_x64/koffi.node +0 -0
- package/build/2.5.0-beta.2/koffi_win32_arm64/koffi.node +0 -0
- package/build/{2.4.2 → 2.5.0-beta.2}/koffi_win32_ia32/koffi.node +0 -0
- package/build/{2.4.2 → 2.5.0-beta.2}/koffi_win32_x64/koffi.node +0 -0
- package/build/2.5.0-beta.2/koffi_win32_x64/koffi.pdb +0 -0
- package/doc/callbacks.md +1 -1
- package/doc/conf.py +1 -1
- package/doc/functions.md +1 -1
- package/doc/index.rst +1 -0
- package/doc/parameters.md +1 -1
- package/doc/pointers.md +1 -1
- package/doc/unions.md +187 -0
- package/package.json +1 -1
- package/src/core/libcc/libcc.cc +58 -54
- package/src/core/libcc/libcc.hh +33 -19
- package/src/koffi/src/abi_x86.cc +31 -4
- package/src/koffi/src/call.cc +42 -22
- package/src/koffi/src/ffi.cc +259 -311
- package/src/koffi/src/ffi.hh +3 -1
- package/src/koffi/src/util.cc +20 -13
- package/src/koffi/src/util.hh +5 -2
- package/vendor/node-addon-api/CHANGELOG.md +31 -0
- package/vendor/node-addon-api/README.md +3 -2
- package/vendor/node-addon-api/doc/async_worker.md +1 -0
- package/vendor/node-addon-api/doc/creating_a_release.md +21 -0
- package/vendor/node-addon-api/doc/value.md +7 -0
- package/vendor/node-addon-api/napi-inl.h +23 -7
- package/vendor/node-addon-api/package.json +9 -1
- package/vendor/node-addon-api/test/async_progress_queue_worker.cc +155 -0
- package/vendor/node-addon-api/test/async_progress_queue_worker.js +134 -0
- package/vendor/node-addon-api/test/async_progress_worker.cc +155 -0
- package/vendor/node-addon-api/test/async_progress_worker.js +134 -0
- package/vendor/node-addon-api/test/common/index.js +45 -0
- package/vendor/node-addon-api/test/objectwrap.js +9 -0
- package/build/2.4.2/koffi_darwin_arm64/koffi.node +0 -0
- package/build/2.4.2/koffi_darwin_x64/koffi.node +0 -0
- package/build/2.4.2/koffi_freebsd_arm64/koffi.node +0 -0
- package/build/2.4.2/koffi_freebsd_ia32/koffi.node +0 -0
- package/build/2.4.2/koffi_freebsd_x64/koffi.node +0 -0
- package/build/2.4.2/koffi_linux_arm32hf/koffi.node +0 -0
- package/build/2.4.2/koffi_linux_arm64/koffi.node +0 -0
- package/build/2.4.2/koffi_linux_ia32/koffi.node +0 -0
- package/build/2.4.2/koffi_linux_riscv64hf64/koffi.node +0 -0
- package/build/2.4.2/koffi_linux_x64/koffi.node +0 -0
- package/build/2.4.2/koffi_openbsd_ia32/koffi.node +0 -0
- package/build/2.4.2/koffi_win32_arm64/koffi.node +0 -0
- /package/build/{2.4.2 → 2.5.0-beta.2}/koffi_win32_arm64/koffi.exp +0 -0
- /package/build/{2.4.2 → 2.5.0-beta.2}/koffi_win32_arm64/koffi.lib +0 -0
- /package/build/{2.4.2 → 2.5.0-beta.2}/koffi_win32_ia32/koffi.exp +0 -0
- /package/build/{2.4.2 → 2.5.0-beta.2}/koffi_win32_ia32/koffi.lib +0 -0
- /package/build/{2.4.2 → 2.5.0-beta.2}/koffi_win32_x64/koffi.exp +0 -0
- /package/build/{2.4.2 → 2.5.0-beta.2}/koffi_win32_x64/koffi.lib +0 -0
package/src/koffi/src/call.cc
CHANGED
|
@@ -360,26 +360,46 @@ bool CallData::PushObject(Napi::Object obj, const TypeInfo *type, uint8_t *origi
|
|
|
360
360
|
if (type->primitive == PrimitiveKind::Record) {
|
|
361
361
|
members = type->members;
|
|
362
362
|
} else if (type->primitive == PrimitiveKind::Union) {
|
|
363
|
-
if (
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
}
|
|
363
|
+
if (CheckValueTag(instance, obj, &MagicUnionMarker)) {
|
|
364
|
+
MagicUnion *u = MagicUnion::Unwrap(obj);
|
|
365
|
+
const uint8_t *raw = u->GetRaw();
|
|
367
366
|
|
|
368
|
-
|
|
369
|
-
|
|
367
|
+
if (RG_UNLIKELY(u->GetType() != type)) {
|
|
368
|
+
ThrowError<Napi::TypeError>(env, "Expected union type %1, got %2", type->name, u->GetType()->name);
|
|
369
|
+
return false;
|
|
370
|
+
}
|
|
370
371
|
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
372
|
+
// Fast path: encoded value already exists, just copy!
|
|
373
|
+
if (raw) {
|
|
374
|
+
memcpy(origin, raw, type->size);
|
|
375
|
+
return true;
|
|
376
|
+
}
|
|
376
377
|
|
|
377
|
-
|
|
378
|
-
|
|
378
|
+
members.ptr = u->GetMember();
|
|
379
|
+
members.len = 1;
|
|
379
380
|
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
381
|
+
if (RG_UNLIKELY(!members.ptr)) {
|
|
382
|
+
ThrowError<Napi::Error>(env, "Cannot use ambiguous empty union");
|
|
383
|
+
return false;
|
|
384
|
+
}
|
|
385
|
+
} else {
|
|
386
|
+
Napi::Array properties = obj.GetPropertyNames();
|
|
387
|
+
|
|
388
|
+
if (RG_UNLIKELY(properties.Length() != 1 || !properties.Get(0u).IsString())) {
|
|
389
|
+
ThrowError<Napi::Error>(env, "Expected object with single property name for union");
|
|
390
|
+
return false;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
std::string property = properties.Get(0u).As<Napi::String>();
|
|
394
|
+
|
|
395
|
+
members.ptr = std::find_if(type->members.begin(), type->members.end(),
|
|
396
|
+
[&](const RecordMember &member) { return TestStr(property.c_str(), member.name); });
|
|
397
|
+
members.len = 1;
|
|
398
|
+
|
|
399
|
+
if (RG_UNLIKELY(members.ptr == type->members.end())) {
|
|
400
|
+
ThrowError<Napi::Error>(env, "Unknown member %1 in union type %2", property.c_str(), type->name);
|
|
401
|
+
return false;
|
|
402
|
+
}
|
|
383
403
|
}
|
|
384
404
|
} else {
|
|
385
405
|
RG_UNREACHABLE();
|
|
@@ -1041,16 +1061,16 @@ bool CallData::PushPointer(Napi::Value value, const TypeInfo *type, int directio
|
|
|
1041
1061
|
|
|
1042
1062
|
ptr = AllocHeap(type->ref.type->size, 16);
|
|
1043
1063
|
|
|
1064
|
+
if (RG_UNLIKELY(type->ref.type->primitive == PrimitiveKind::Union &&
|
|
1065
|
+
(directions & 2) && !CheckValueTag(instance, obj, &MagicUnionMarker))) {
|
|
1066
|
+
ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected union value", GetValueType(instance, obj));
|
|
1067
|
+
return false;
|
|
1068
|
+
}
|
|
1069
|
+
|
|
1044
1070
|
if (directions & 1) {
|
|
1045
1071
|
if (!PushObject(obj, type->ref.type, ptr))
|
|
1046
1072
|
return false;
|
|
1047
1073
|
} else {
|
|
1048
|
-
if (RG_UNLIKELY(type->ref.type->primitive == PrimitiveKind::Union &&
|
|
1049
|
-
!CheckValueTag(instance, obj, &MagicUnionMarker))) {
|
|
1050
|
-
ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected union value", GetValueType(instance, obj));
|
|
1051
|
-
return false;
|
|
1052
|
-
}
|
|
1053
|
-
|
|
1054
1074
|
memset_safe(ptr, 0, type->size);
|
|
1055
1075
|
}
|
|
1056
1076
|
|