koffi 2.12.5-beta.1 → 2.13.0
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 +9 -0
- package/build/koffi/darwin_arm64/koffi.node +0 -0
- package/build/koffi/darwin_x64/koffi.node +0 -0
- package/build/koffi/freebsd_arm64/koffi.node +0 -0
- package/build/koffi/freebsd_ia32/koffi.node +0 -0
- package/build/koffi/freebsd_x64/koffi.node +0 -0
- package/build/koffi/linux_arm64/koffi.node +0 -0
- package/build/koffi/linux_armhf/koffi.node +0 -0
- package/build/koffi/linux_ia32/koffi.node +0 -0
- package/build/koffi/linux_loong64/koffi.node +0 -0
- package/build/koffi/linux_riscv64d/koffi.node +0 -0
- package/build/koffi/linux_x64/koffi.node +0 -0
- package/build/koffi/musl_arm64/koffi.node +0 -0
- package/build/koffi/musl_x64/koffi.node +0 -0
- package/build/koffi/openbsd_ia32/koffi.node +0 -0
- package/build/koffi/openbsd_x64/koffi.node +0 -0
- package/build/koffi/win32_arm64/koffi.node +0 -0
- package/build/koffi/win32_ia32/koffi.node +0 -0
- package/build/koffi/win32_x64/koffi.node +0 -0
- package/doc/pages/contribute.md +1 -1
- package/index.d.ts +4 -0
- package/index.js +8 -9
- package/indirect.js +8 -9
- package/package.json +1 -2
- package/src/koffi/src/ffi.cc +25 -18
- package/src/koffi/src/parser.cc +4 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,15 @@
|
|
|
5
5
|
|
|
6
6
|
## Koffi 2
|
|
7
7
|
|
|
8
|
+
### Koffi 2.13
|
|
9
|
+
|
|
10
|
+
#### Koffi 2.13.0
|
|
11
|
+
|
|
12
|
+
*Released on 2025-08-07*
|
|
13
|
+
|
|
14
|
+
- Support anonymous function prototype types (`koffi.proto()`)
|
|
15
|
+
- Accept null or undefined name to define anonymous composite or pointer types
|
|
16
|
+
|
|
8
17
|
### Koffi 2.12
|
|
9
18
|
|
|
10
19
|
#### Koffi 2.12.4
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/doc/pages/contribute.md
CHANGED
|
@@ -123,7 +123,7 @@ node qemu.js info debian_x64
|
|
|
123
123
|
|
|
124
124
|
First, you must update the code in three steps:
|
|
125
125
|
|
|
126
|
-
- Change the version
|
|
126
|
+
- Change the version number in `package.json`
|
|
127
127
|
- Add an entry to `CHANGELOG` to summarize the changes since last release
|
|
128
128
|
- Commit theses changes with the message *Bump Koffi to X.Y.Z*
|
|
129
129
|
|
package/index.d.ts
CHANGED
|
@@ -119,9 +119,13 @@ export function disposable(name: string | null | undefined, type: TypeSpec): IKo
|
|
|
119
119
|
export function disposable(name: string | null | undefined, type: TypeSpec, freeFunction: Function): IKoffiCType;
|
|
120
120
|
|
|
121
121
|
export function proto(definition: string): IKoffiCType;
|
|
122
|
+
export function proto(result: TypeSpec, arguments: TypeSpec[]): IKoffiCType;
|
|
123
|
+
export function proto(convention: string, result: TypeSpec, arguments: TypeSpec[]): IKoffiCType;
|
|
122
124
|
export function proto(name: string | null | undefined, result: TypeSpec, arguments: TypeSpec[]): IKoffiCType;
|
|
123
125
|
export function proto(convention: string, name: string | null | undefined, result: TypeSpec, arguments: TypeSpec[]): IKoffiCType;
|
|
124
126
|
/** @deprecated */ export function callback(definition: string): IKoffiCType;
|
|
127
|
+
/** @deprecated */ export function callback(result: TypeSpec, arguments: TypeSpec[]): IKoffiCType;
|
|
128
|
+
/** @deprecated */ export function callback(convention: string, result: TypeSpec, arguments: TypeSpec[]): IKoffiCType;
|
|
125
129
|
/** @deprecated */ export function callback(name: string | null | undefined, result: TypeSpec, arguments: TypeSpec[]): IKoffiCType;
|
|
126
130
|
/** @deprecated */ export function callback(convention: string, name: string | null | undefined, result: TypeSpec, arguments: TypeSpec[]): IKoffiCType;
|
|
127
131
|
|
package/index.js
CHANGED
|
@@ -4,9 +4,9 @@ var __commonJS = (cb, mod3) => function __require() {
|
|
|
4
4
|
return mod3 || (0, cb[__getOwnPropNames(cb)[0]])((mod3 = { exports: {} }).exports, mod3), mod3.exports;
|
|
5
5
|
};
|
|
6
6
|
|
|
7
|
-
// package/src/cnoke/src/tools.js
|
|
7
|
+
// ../../../bin/Koffi/package/src/cnoke/src/tools.js
|
|
8
8
|
var require_tools = __commonJS({
|
|
9
|
-
"package/src/cnoke/src/tools.js"(exports2, module2) {
|
|
9
|
+
"../../../bin/Koffi/package/src/cnoke/src/tools.js"(exports2, module2) {
|
|
10
10
|
"use strict";
|
|
11
11
|
var crypto = require("crypto");
|
|
12
12
|
var fs2 = require("fs");
|
|
@@ -397,13 +397,12 @@ var require_tools = __commonJS({
|
|
|
397
397
|
}
|
|
398
398
|
});
|
|
399
399
|
|
|
400
|
-
// package/src/koffi/package.json
|
|
400
|
+
// ../../../bin/Koffi/package/src/koffi/package.json
|
|
401
401
|
var require_package = __commonJS({
|
|
402
|
-
"package/src/koffi/package.json"(exports2, module2) {
|
|
402
|
+
"../../../bin/Koffi/package/src/koffi/package.json"(exports2, module2) {
|
|
403
403
|
module2.exports = {
|
|
404
404
|
name: "koffi",
|
|
405
|
-
version: "2.
|
|
406
|
-
stable: "2.12.4",
|
|
405
|
+
version: "2.13.0",
|
|
407
406
|
description: "Fast and simple C FFI (foreign function interface) for Node.js",
|
|
408
407
|
keywords: [
|
|
409
408
|
"foreign",
|
|
@@ -444,9 +443,9 @@ var require_package = __commonJS({
|
|
|
444
443
|
}
|
|
445
444
|
});
|
|
446
445
|
|
|
447
|
-
// package/src/koffi/src/init.js
|
|
446
|
+
// ../../../bin/Koffi/package/src/koffi/src/init.js
|
|
448
447
|
var require_init = __commonJS({
|
|
449
|
-
"package/src/koffi/src/init.js"(exports, module) {
|
|
448
|
+
"../../../bin/Koffi/package/src/koffi/src/init.js"(exports, module) {
|
|
450
449
|
var fs = require("fs");
|
|
451
450
|
var path = require("path");
|
|
452
451
|
var util = require("util");
|
|
@@ -529,7 +528,7 @@ var require_init = __commonJS({
|
|
|
529
528
|
}
|
|
530
529
|
});
|
|
531
530
|
|
|
532
|
-
// package/src/koffi/index.js
|
|
531
|
+
// ../../../bin/Koffi/package/src/koffi/index.js
|
|
533
532
|
var { detect: detect2, init: init2 } = require_init();
|
|
534
533
|
var triplet2 = detect2();
|
|
535
534
|
var native2 = null;
|
package/indirect.js
CHANGED
|
@@ -4,9 +4,9 @@ var __commonJS = (cb, mod3) => function __require() {
|
|
|
4
4
|
return mod3 || (0, cb[__getOwnPropNames(cb)[0]])((mod3 = { exports: {} }).exports, mod3), mod3.exports;
|
|
5
5
|
};
|
|
6
6
|
|
|
7
|
-
// package/src/cnoke/src/tools.js
|
|
7
|
+
// ../../../bin/Koffi/package/src/cnoke/src/tools.js
|
|
8
8
|
var require_tools = __commonJS({
|
|
9
|
-
"package/src/cnoke/src/tools.js"(exports2, module2) {
|
|
9
|
+
"../../../bin/Koffi/package/src/cnoke/src/tools.js"(exports2, module2) {
|
|
10
10
|
"use strict";
|
|
11
11
|
var crypto = require("crypto");
|
|
12
12
|
var fs2 = require("fs");
|
|
@@ -397,13 +397,12 @@ var require_tools = __commonJS({
|
|
|
397
397
|
}
|
|
398
398
|
});
|
|
399
399
|
|
|
400
|
-
// package/src/koffi/package.json
|
|
400
|
+
// ../../../bin/Koffi/package/src/koffi/package.json
|
|
401
401
|
var require_package = __commonJS({
|
|
402
|
-
"package/src/koffi/package.json"(exports2, module2) {
|
|
402
|
+
"../../../bin/Koffi/package/src/koffi/package.json"(exports2, module2) {
|
|
403
403
|
module2.exports = {
|
|
404
404
|
name: "koffi",
|
|
405
|
-
version: "2.
|
|
406
|
-
stable: "2.12.4",
|
|
405
|
+
version: "2.13.0",
|
|
407
406
|
description: "Fast and simple C FFI (foreign function interface) for Node.js",
|
|
408
407
|
keywords: [
|
|
409
408
|
"foreign",
|
|
@@ -444,9 +443,9 @@ var require_package = __commonJS({
|
|
|
444
443
|
}
|
|
445
444
|
});
|
|
446
445
|
|
|
447
|
-
// package/src/koffi/src/init.js
|
|
446
|
+
// ../../../bin/Koffi/package/src/koffi/src/init.js
|
|
448
447
|
var require_init = __commonJS({
|
|
449
|
-
"package/src/koffi/src/init.js"(exports, module) {
|
|
448
|
+
"../../../bin/Koffi/package/src/koffi/src/init.js"(exports, module) {
|
|
450
449
|
var fs = require("fs");
|
|
451
450
|
var path = require("path");
|
|
452
451
|
var util = require("util");
|
|
@@ -529,7 +528,7 @@ var require_init = __commonJS({
|
|
|
529
528
|
}
|
|
530
529
|
});
|
|
531
530
|
|
|
532
|
-
// package/src/koffi/indirect.js
|
|
531
|
+
// ../../../bin/Koffi/package/src/koffi/indirect.js
|
|
533
532
|
var { detect: detect2, init: init2 } = require_init();
|
|
534
533
|
var triplet2 = detect2();
|
|
535
534
|
var mod2 = init2(triplet2, null);
|
package/package.json
CHANGED
package/src/koffi/src/ffi.cc
CHANGED
|
@@ -995,6 +995,8 @@ static Napi::Value CreateArrayType(const Napi::CallbackInfo &info)
|
|
|
995
995
|
|
|
996
996
|
static bool ParseClassicFunction(const Napi::CallbackInfo &info, bool concrete, FunctionInfo *out_func)
|
|
997
997
|
{
|
|
998
|
+
RG_ASSERT(info.Length() >= 2);
|
|
999
|
+
|
|
998
1000
|
Napi::Env env = info.Env();
|
|
999
1001
|
InstanceData *instance = env.GetInstanceData<InstanceData>();
|
|
1000
1002
|
|
|
@@ -1004,31 +1006,36 @@ static bool ParseClassicFunction(const Napi::CallbackInfo &info, bool concrete,
|
|
|
1004
1006
|
|
|
1005
1007
|
// Detect optional call convention
|
|
1006
1008
|
if (name.IsString() && DetectCallConvention(name.Utf8Value().c_str(), &out_func->convention)) {
|
|
1007
|
-
if (info.Length() <
|
|
1008
|
-
ThrowError<Napi::TypeError>(env, "Expected 4 arguments, got %1", info.Length());
|
|
1009
|
+
if (info.Length() < 3) {
|
|
1010
|
+
ThrowError<Napi::TypeError>(env, "Expected 3 or 4 arguments, got %1", info.Length());
|
|
1009
1011
|
return false;
|
|
1010
1012
|
}
|
|
1011
1013
|
|
|
1012
1014
|
name = info[1u].As<Napi::String>();
|
|
1013
1015
|
ret = info[2u];
|
|
1014
|
-
parameters = info[3u].As<Napi::Array>();
|
|
1016
|
+
parameters = (info.Length() >= 4 ? info[3u] : env.Null()).As<Napi::Array>();
|
|
1015
1017
|
}
|
|
1016
1018
|
|
|
1017
|
-
bool named =
|
|
1019
|
+
bool named = parameters.IsArray();
|
|
1018
1020
|
|
|
1021
|
+
if (named) {
|
|
1019
1022
|
#if defined(_WIN32)
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1023
|
+
if (name.IsNumber()) {
|
|
1024
|
+
out_func->ordinal_name = name.As<Napi::Number>().Int32Value();
|
|
1025
|
+
name = name.ToString();
|
|
1026
|
+
}
|
|
1024
1027
|
#endif
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1028
|
+
if (!name.IsString()) {
|
|
1029
|
+
if (!concrete && IsNullOrUndefined(name)) {
|
|
1030
|
+
named = false;
|
|
1031
|
+
} else {
|
|
1032
|
+
ThrowError<Napi::TypeError>(env, "Unexpected %1 value for name, expected string or integer", GetValueType(instance, name));
|
|
1033
|
+
return false;
|
|
1034
|
+
}
|
|
1031
1035
|
}
|
|
1036
|
+
} else {
|
|
1037
|
+
parameters = ret.As<Napi::Array>();
|
|
1038
|
+
ret = name;
|
|
1032
1039
|
}
|
|
1033
1040
|
|
|
1034
1041
|
// Leave anonymous naming responsibility to caller
|
|
@@ -1096,7 +1103,7 @@ static Napi::Value CreateFunctionType(const Napi::CallbackInfo &info)
|
|
|
1096
1103
|
FunctionInfo *func = instance->callbacks.AppendDefault();
|
|
1097
1104
|
RG_DEFER_N(err_guard) { instance->callbacks.RemoveLast(1); };
|
|
1098
1105
|
|
|
1099
|
-
if (info.Length() >=
|
|
1106
|
+
if (info.Length() >= 2) {
|
|
1100
1107
|
if (!ParseClassicFunction(info, false, func))
|
|
1101
1108
|
return env.Null();
|
|
1102
1109
|
} else if (info.Length() >= 1) {
|
|
@@ -1109,7 +1116,7 @@ static Napi::Value CreateFunctionType(const Napi::CallbackInfo &info)
|
|
|
1109
1116
|
if (!ParsePrototype(env, proto.c_str(), false, func))
|
|
1110
1117
|
return env.Null();
|
|
1111
1118
|
} else {
|
|
1112
|
-
ThrowError<Napi::TypeError>(env, "Expected 1
|
|
1119
|
+
ThrowError<Napi::TypeError>(env, "Expected 1 to 4 arguments, got %1", info.Length());
|
|
1113
1120
|
return env.Null();
|
|
1114
1121
|
}
|
|
1115
1122
|
|
|
@@ -1665,7 +1672,7 @@ static Napi::Value FindLibraryFunction(const Napi::CallbackInfo &info)
|
|
|
1665
1672
|
|
|
1666
1673
|
func->lib = lib->Ref();
|
|
1667
1674
|
|
|
1668
|
-
if (info.Length() >=
|
|
1675
|
+
if (info.Length() >= 2) {
|
|
1669
1676
|
if (!ParseClassicFunction(info, true, func))
|
|
1670
1677
|
return env.Null();
|
|
1671
1678
|
} else if (info.Length() >= 1) {
|
|
@@ -1678,7 +1685,7 @@ static Napi::Value FindLibraryFunction(const Napi::CallbackInfo &info)
|
|
|
1678
1685
|
if (!ParsePrototype(env, proto.c_str(), true, func))
|
|
1679
1686
|
return env.Null();
|
|
1680
1687
|
} else {
|
|
1681
|
-
ThrowError<Napi::TypeError>(env, "Expected 1
|
|
1688
|
+
ThrowError<Napi::TypeError>(env, "Expected 1 to 4 arguments, got %1", info.Length());
|
|
1682
1689
|
return env.Null();
|
|
1683
1690
|
}
|
|
1684
1691
|
|
package/src/koffi/src/parser.cc
CHANGED
|
@@ -49,7 +49,10 @@ bool PrototypeParser::Parse(const char *str, bool concrete, FunctionInfo *out_fu
|
|
|
49
49
|
if (IsIdentifier(tokens[offset])) {
|
|
50
50
|
Span<const char> tok = tokens[offset++];
|
|
51
51
|
out_func->name = DuplicateString(tok, &instance->str_alloc).ptr;
|
|
52
|
-
} else if (concrete) {
|
|
52
|
+
} else if (!concrete) {
|
|
53
|
+
// Leave anonymous naming responsibility to caller
|
|
54
|
+
out_func->name = nullptr;
|
|
55
|
+
} else {
|
|
53
56
|
MarkError("Unexpected token '%1', expected identifier", tokens[offset]);
|
|
54
57
|
return false;
|
|
55
58
|
}
|