koffi 2.4.1 → 2.5.0-beta.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.
- package/CHANGELOG.md +12 -2
- package/build/2.5.0-beta.1/koffi_darwin_arm64/koffi.node +0 -0
- package/build/2.5.0-beta.1/koffi_darwin_x64/koffi.node +0 -0
- package/build/2.5.0-beta.1/koffi_freebsd_arm64/koffi.node +0 -0
- package/build/2.5.0-beta.1/koffi_freebsd_ia32/koffi.node +0 -0
- package/build/2.5.0-beta.1/koffi_freebsd_x64/koffi.node +0 -0
- package/build/2.5.0-beta.1/koffi_linux_arm32hf/koffi.node +0 -0
- package/build/2.5.0-beta.1/koffi_linux_arm64/koffi.node +0 -0
- package/build/2.5.0-beta.1/koffi_linux_ia32/koffi.node +0 -0
- package/build/2.5.0-beta.1/koffi_linux_riscv64hf64/koffi.node +0 -0
- package/build/2.5.0-beta.1/koffi_linux_x64/koffi.node +0 -0
- package/build/2.5.0-beta.1/koffi_openbsd_ia32/koffi.node +0 -0
- package/build/{2.4.1 → 2.5.0-beta.1}/koffi_openbsd_x64/koffi.node +0 -0
- package/build/2.5.0-beta.1/koffi_win32_arm64/koffi.node +0 -0
- package/build/{2.4.1 → 2.5.0-beta.1}/koffi_win32_ia32/koffi.node +0 -0
- package/build/{2.4.1 → 2.5.0-beta.1}/koffi_win32_x64/koffi.node +0 -0
- package/build/2.5.0-beta.1/koffi_win32_x64/koffi.pdb +0 -0
- package/doc/callbacks.md +1 -1
- package/doc/conf.py +1 -1
- package/doc/functions.md +73 -4
- package/doc/parameters.md +0 -1
- package/doc/pointers.md +1 -1
- package/package.json +2 -2
- 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 +37 -22
- package/src/koffi/src/ffi.cc +253 -310
- package/src/koffi/src/ffi.hh +3 -1
- package/src/koffi/src/parser.cc +1 -1
- package/src/koffi/src/util.cc +24 -13
- package/src/koffi/src/util.hh +4 -2
- package/build/2.4.1/koffi_darwin_arm64/koffi.node +0 -0
- package/build/2.4.1/koffi_darwin_x64/koffi.node +0 -0
- package/build/2.4.1/koffi_freebsd_arm64/koffi.node +0 -0
- package/build/2.4.1/koffi_freebsd_ia32/koffi.node +0 -0
- package/build/2.4.1/koffi_freebsd_x64/koffi.node +0 -0
- package/build/2.4.1/koffi_linux_arm32hf/koffi.node +0 -0
- package/build/2.4.1/koffi_linux_arm64/koffi.node +0 -0
- package/build/2.4.1/koffi_linux_ia32/koffi.node +0 -0
- package/build/2.4.1/koffi_linux_riscv64hf64/koffi.node +0 -0
- package/build/2.4.1/koffi_linux_x64/koffi.node +0 -0
- package/build/2.4.1/koffi_openbsd_ia32/koffi.node +0 -0
- package/build/2.4.1/koffi_win32_arm64/koffi.node +0 -0
- /package/build/{2.4.1 → 2.5.0-beta.1}/koffi_win32_arm64/koffi.exp +0 -0
- /package/build/{2.4.1 → 2.5.0-beta.1}/koffi_win32_arm64/koffi.lib +0 -0
- /package/build/{2.4.1 → 2.5.0-beta.1}/koffi_win32_ia32/koffi.exp +0 -0
- /package/build/{2.4.1 → 2.5.0-beta.1}/koffi_win32_ia32/koffi.lib +0 -0
- /package/build/{2.4.1 → 2.5.0-beta.1}/koffi_win32_x64/koffi.exp +0 -0
- /package/build/{2.4.1 → 2.5.0-beta.1}/koffi_win32_x64/koffi.lib +0 -0
package/src/koffi/src/parser.cc
CHANGED
|
@@ -75,7 +75,7 @@ bool PrototypeParser::Parse(const char *str, FunctionInfo *out_func)
|
|
|
75
75
|
param.type = ParseType();
|
|
76
76
|
|
|
77
77
|
if (!CanPassType(param.type, param.directions)) {
|
|
78
|
-
MarkError("Type %1 cannot be used as a parameter
|
|
78
|
+
MarkError("Type %1 cannot be used as a parameter", param.type->name);
|
|
79
79
|
return false;
|
|
80
80
|
}
|
|
81
81
|
if (out_func->parameters.len >= MaxParameters) {
|
package/src/koffi/src/util.cc
CHANGED
|
@@ -58,14 +58,19 @@ Napi::Function MagicUnion::InitClass(Napi::Env env, const TypeInfo *type)
|
|
|
58
58
|
MagicUnion::MagicUnion(const Napi::CallbackInfo &info)
|
|
59
59
|
: Napi::ObjectWrap<MagicUnion>(info), type((const TypeInfo *)info.Data())
|
|
60
60
|
{
|
|
61
|
+
Napi::Env env = info.Env();
|
|
62
|
+
InstanceData *instance = env.GetInstanceData<InstanceData>();
|
|
63
|
+
|
|
64
|
+
active_symbol = instance->active_symbol;
|
|
61
65
|
}
|
|
62
66
|
|
|
63
67
|
void MagicUnion::SetRaw(const uint8_t *ptr)
|
|
64
68
|
{
|
|
65
|
-
raw
|
|
69
|
+
raw.RemoveFrom(0);
|
|
70
|
+
raw.Append(MakeSpan(ptr, type->size));
|
|
66
71
|
|
|
72
|
+
Value().Set(active_symbol, Env().Undefined());
|
|
67
73
|
active_idx = -1;
|
|
68
|
-
Value().Set("__active", Env().Undefined());
|
|
69
74
|
}
|
|
70
75
|
|
|
71
76
|
Napi::Value MagicUnion::Getter(const Napi::CallbackInfo &info)
|
|
@@ -76,18 +81,18 @@ Napi::Value MagicUnion::Getter(const Napi::CallbackInfo &info)
|
|
|
76
81
|
Napi::Value value;
|
|
77
82
|
|
|
78
83
|
if (idx == active_idx) {
|
|
79
|
-
value = Value().Get(
|
|
84
|
+
value = Value().Get(active_symbol);
|
|
80
85
|
} else {
|
|
81
86
|
Napi::Env env = info.Env();
|
|
82
87
|
|
|
83
|
-
if (RG_UNLIKELY(!raw)) {
|
|
88
|
+
if (RG_UNLIKELY(!raw.len)) {
|
|
84
89
|
ThrowError<Napi::Error>(env, "Cannont convert %1 union value", active_idx < 0 ? "empty" : "assigned");
|
|
85
90
|
return env.Null();
|
|
86
91
|
}
|
|
87
92
|
|
|
88
|
-
value = Decode(env, raw, member.type);
|
|
93
|
+
value = Decode(env, raw.ptr, member.type);
|
|
89
94
|
|
|
90
|
-
Value().Set(
|
|
95
|
+
Value().Set(active_symbol, value);
|
|
91
96
|
active_idx = idx;
|
|
92
97
|
}
|
|
93
98
|
|
|
@@ -99,10 +104,10 @@ void MagicUnion::Setter(const Napi::CallbackInfo &info, const Napi::Value &value
|
|
|
99
104
|
{
|
|
100
105
|
Size idx = (Size)info.Data();
|
|
101
106
|
|
|
102
|
-
Value().Set(
|
|
107
|
+
Value().Set(active_symbol, value);
|
|
103
108
|
active_idx = idx;
|
|
104
109
|
|
|
105
|
-
raw
|
|
110
|
+
raw.Clear();
|
|
106
111
|
}
|
|
107
112
|
|
|
108
113
|
const TypeInfo *ResolveType(Napi::Value value, int *out_directions)
|
|
@@ -272,10 +277,11 @@ const TypeInfo *MakePointerType(InstanceData *instance, const TypeInfo *ref, int
|
|
|
272
277
|
char name_buf[256];
|
|
273
278
|
Fmt(name_buf, "%1%2*", ref->name, EndsWith(ref->name, "*") ? "" : " ");
|
|
274
279
|
|
|
275
|
-
|
|
280
|
+
bool inserted;
|
|
281
|
+
auto bucket = instance->types_map.TrySetDefault(name_buf, &inserted);
|
|
276
282
|
|
|
277
|
-
if (
|
|
278
|
-
type = instance->types.AppendDefault();
|
|
283
|
+
if (inserted) {
|
|
284
|
+
TypeInfo *type = instance->types.AppendDefault();
|
|
279
285
|
|
|
280
286
|
type->name = DuplicateString(name_buf, &instance->str_alloc).ptr;
|
|
281
287
|
|
|
@@ -291,10 +297,11 @@ const TypeInfo *MakePointerType(InstanceData *instance, const TypeInfo *ref, int
|
|
|
291
297
|
type->ref.proto = ref->ref.proto;
|
|
292
298
|
}
|
|
293
299
|
|
|
294
|
-
|
|
300
|
+
bucket->key = type->name;
|
|
301
|
+
bucket->value = type;
|
|
295
302
|
}
|
|
296
303
|
|
|
297
|
-
ref =
|
|
304
|
+
ref = bucket->value;
|
|
298
305
|
}
|
|
299
306
|
|
|
300
307
|
return ref;
|
|
@@ -371,6 +378,8 @@ bool CanPassType(const TypeInfo *type, int directions)
|
|
|
371
378
|
return false;
|
|
372
379
|
if (type->primitive == PrimitiveKind::Prototype)
|
|
373
380
|
return false;
|
|
381
|
+
if (type->primitive == PrimitiveKind::Callback && type->ref.proto->variadic)
|
|
382
|
+
return false;
|
|
374
383
|
|
|
375
384
|
return true;
|
|
376
385
|
}
|
|
@@ -394,6 +403,8 @@ bool CanStoreType(const TypeInfo *type)
|
|
|
394
403
|
return false;
|
|
395
404
|
if (type->primitive == PrimitiveKind::Prototype)
|
|
396
405
|
return false;
|
|
406
|
+
if (type->primitive == PrimitiveKind::Callback && type->ref.proto->variadic)
|
|
407
|
+
return false;
|
|
397
408
|
|
|
398
409
|
return true;
|
|
399
410
|
}
|
package/src/koffi/src/util.hh
CHANGED
|
@@ -38,8 +38,10 @@ extern const int MagicUnionMarker;
|
|
|
38
38
|
class MagicUnion: public Napi::ObjectWrap<MagicUnion> {
|
|
39
39
|
const TypeInfo *type;
|
|
40
40
|
|
|
41
|
+
napi_value active_symbol;
|
|
41
42
|
Size active_idx = -1;
|
|
42
|
-
|
|
43
|
+
|
|
44
|
+
HeapArray<uint8_t> raw;
|
|
43
45
|
|
|
44
46
|
public:
|
|
45
47
|
static Napi::Function InitClass(Napi::Env env, const TypeInfo *type);
|
|
@@ -49,7 +51,7 @@ public:
|
|
|
49
51
|
const RecordMember *GetMember() const { return (active_idx >= 0) ? &type->members[active_idx] : nullptr; }
|
|
50
52
|
|
|
51
53
|
void SetRaw(const uint8_t *ptr);
|
|
52
|
-
const uint8_t *GetRaw() const { return raw; }
|
|
54
|
+
const uint8_t *GetRaw() const { return raw.ptr; }
|
|
53
55
|
|
|
54
56
|
private:
|
|
55
57
|
Napi::Value Getter(const Napi::CallbackInfo &info);
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|