koffi 2.3.0-beta.1 → 2.3.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 +19 -0
- package/doc/callbacks.md +8 -2
- package/doc/calls.md +1 -1
- package/package.json +3 -2
- package/src/koffi/build/2.3.0/koffi_darwin_arm64.tar.gz +0 -0
- package/src/koffi/build/2.3.0/koffi_darwin_x64.tar.gz +0 -0
- package/src/koffi/build/2.3.0/koffi_freebsd_arm64.tar.gz +0 -0
- package/src/koffi/build/2.3.0/koffi_freebsd_ia32.tar.gz +0 -0
- package/src/koffi/build/2.3.0/koffi_freebsd_x64.tar.gz +0 -0
- package/src/koffi/build/2.3.0/koffi_linux_arm32hf.tar.gz +0 -0
- package/src/koffi/build/2.3.0/koffi_linux_arm64.tar.gz +0 -0
- package/src/koffi/build/2.3.0/koffi_linux_ia32.tar.gz +0 -0
- package/src/koffi/build/2.3.0/koffi_linux_riscv64hf64.tar.gz +0 -0
- package/src/koffi/build/2.3.0/koffi_linux_x64.tar.gz +0 -0
- package/src/koffi/build/2.3.0/koffi_openbsd_ia32.tar.gz +0 -0
- package/src/koffi/build/2.3.0/koffi_openbsd_x64.tar.gz +0 -0
- package/src/koffi/build/2.3.0/koffi_win32_arm64.tar.gz +0 -0
- package/src/koffi/build/2.3.0/koffi_win32_ia32.tar.gz +0 -0
- package/src/koffi/build/2.3.0/koffi_win32_x64.tar.gz +0 -0
- package/src/koffi/src/call.cc +6 -4
- package/src/koffi/src/index.d.ts +96 -0
- package/src/koffi/build/2.3.0-beta.1/koffi_darwin_arm64.tar.gz +0 -0
- package/src/koffi/build/2.3.0-beta.1/koffi_darwin_x64.tar.gz +0 -0
- package/src/koffi/build/2.3.0-beta.1/koffi_freebsd_arm64.tar.gz +0 -0
- package/src/koffi/build/2.3.0-beta.1/koffi_freebsd_ia32.tar.gz +0 -0
- package/src/koffi/build/2.3.0-beta.1/koffi_freebsd_x64.tar.gz +0 -0
- package/src/koffi/build/2.3.0-beta.1/koffi_linux_arm32hf.tar.gz +0 -0
- package/src/koffi/build/2.3.0-beta.1/koffi_linux_arm64.tar.gz +0 -0
- package/src/koffi/build/2.3.0-beta.1/koffi_linux_ia32.tar.gz +0 -0
- package/src/koffi/build/2.3.0-beta.1/koffi_linux_riscv64hf64.tar.gz +0 -0
- package/src/koffi/build/2.3.0-beta.1/koffi_linux_x64.tar.gz +0 -0
- package/src/koffi/build/2.3.0-beta.1/koffi_openbsd_ia32.tar.gz +0 -0
- package/src/koffi/build/2.3.0-beta.1/koffi_openbsd_x64.tar.gz +0 -0
- package/src/koffi/build/2.3.0-beta.1/koffi_win32_arm64.tar.gz +0 -0
- package/src/koffi/build/2.3.0-beta.1/koffi_win32_ia32.tar.gz +0 -0
- package/src/koffi/build/2.3.0-beta.1/koffi_win32_x64.tar.gz +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,25 @@
|
|
|
2
2
|
|
|
3
3
|
## Version history
|
|
4
4
|
|
|
5
|
+
### Koffi 2.3
|
|
6
|
+
|
|
7
|
+
#### Koffi 2.3.0
|
|
8
|
+
|
|
9
|
+
**Main changes:**
|
|
10
|
+
|
|
11
|
+
- Allow buffers (TypedArray or ArrayBuffer) values for input and/or output pointer arguments (for polymorphic arguments)
|
|
12
|
+
- Support opaque buffers (TypedArray or ArrayBuffer) values in `koffi.decode()` to [decode output buffers](calls.md#output-parameters)
|
|
13
|
+
- Decode non-string types as arrays when an [explicit length is passed to koffi.decode()](callbacks.md#pointer-arguments)
|
|
14
|
+
|
|
15
|
+
**Other changes:**
|
|
16
|
+
|
|
17
|
+
- Drop TypedArray type check for array and pointer values (only the size matters)
|
|
18
|
+
- Allow ArrayBuffer everywhere TypedArray is supported
|
|
19
|
+
- Add TypeScript definition for Koffi ([@insraq](https://github.com/insraq))
|
|
20
|
+
- Improve documentation about opaque and polymorphic structs
|
|
21
|
+
- Improve documentation for `koffi.decode()`
|
|
22
|
+
- Reduce NPM package size (from 100 MB to 25 MB) by removing test code and dependencies
|
|
23
|
+
|
|
5
24
|
### Koffi 2.2
|
|
6
25
|
|
|
7
26
|
#### Koffi 2.2.5
|
package/doc/callbacks.md
CHANGED
|
@@ -134,7 +134,9 @@ let cb1 = koffi.register(store.get, 'IntCallback *'); // If a C function calls c
|
|
|
134
134
|
let cb2 = koffi.register(store, store.get, 'IntCallback *'); // However in this case, this will match the store object
|
|
135
135
|
```
|
|
136
136
|
|
|
137
|
-
##
|
|
137
|
+
## Special considerations
|
|
138
|
+
|
|
139
|
+
### Decoding pointer arguments
|
|
138
140
|
|
|
139
141
|
*New in Koffi 2.2, changed in Koffi 2.3*
|
|
140
142
|
|
|
@@ -173,7 +175,11 @@ There is also an optional ending `length` argument that you can use in two cases
|
|
|
173
175
|
- Use it to give the number of bytes to decode in non-NUL terminated strings: `koffi.decode(value, 'char *', 5)`
|
|
174
176
|
- Decode consecutive values into an array. For example, here is how you can decode an array with 3 float values: `koffi.decode(value, 'float', 3)`. This is equivalent to `koffi.decode(value, koffi.array('float', 3))`.
|
|
175
177
|
|
|
176
|
-
|
|
178
|
+
```{note}
|
|
179
|
+
In Koffi 2.2 and earlier versions, the length argument is only used to decode strings and is ignored otherwise.
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
### Asynchronous callbacks
|
|
177
183
|
|
|
178
184
|
*New in Koffi 2.2.2*
|
|
179
185
|
|
package/doc/calls.md
CHANGED
|
@@ -261,7 +261,7 @@ console.log(vec1); // { x: 3, y: 2, z: 1 }
|
|
|
261
261
|
console.log(vec2); // { x: 1, y: 2, z: 3 }
|
|
262
262
|
```
|
|
263
263
|
|
|
264
|
-
See [pointer arguments](callbacks.md#pointer-arguments) for more information about the decode function.
|
|
264
|
+
See [pointer arguments](callbacks.md#decoding-pointer-arguments) for more information about the decode function.
|
|
265
265
|
|
|
266
266
|
## Heap-allocated values
|
|
267
267
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "koffi",
|
|
3
|
-
"version": "2.3.0
|
|
4
|
-
"stable": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
4
|
+
"stable": "2.3.0",
|
|
5
5
|
"description": "Fast and simple C FFI (foreign function interface) for Node.js",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"foreign",
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
"homepage": "https://koffi.dev/",
|
|
20
20
|
"author": "Niels Martignène <niels.martignene@protonmail.com>",
|
|
21
21
|
"main": "src/koffi/src/index.js",
|
|
22
|
+
"types": "src/koffi/src/index.d.ts",
|
|
22
23
|
"scripts": {
|
|
23
24
|
"install": "cnoke --prebuild -d src/koffi"
|
|
24
25
|
},
|
|
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/src/koffi/src/call.cc
CHANGED
|
@@ -923,15 +923,17 @@ bool CallData::PushPointer(Napi::Value value, const TypeInfo *type, int directio
|
|
|
923
923
|
memset_safe(ptr, 0, size);
|
|
924
924
|
}
|
|
925
925
|
} else if (IsRawBuffer(value)) {
|
|
926
|
-
Span<
|
|
926
|
+
Span<uint8_t> buffer = GetRawBuffer(value);
|
|
927
927
|
|
|
928
|
-
|
|
928
|
+
if (directions == 1) {
|
|
929
|
+
ptr = AllocHeap(buffer.len, 16);
|
|
929
930
|
|
|
930
|
-
if (directions & 1) {
|
|
931
931
|
if (!PushBuffer(buffer, buffer.len, type, ptr))
|
|
932
932
|
return false;
|
|
933
933
|
} else {
|
|
934
|
-
|
|
934
|
+
// Fast no-copy path
|
|
935
|
+
ptr = buffer.ptr;
|
|
936
|
+
directions = 1;
|
|
935
937
|
}
|
|
936
938
|
} else if (RG_LIKELY(type->ref.type->primitive == PrimitiveKind::Record)) {
|
|
937
939
|
Napi::Object obj = value.As<Napi::Object>();
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
// This program is free software: you can redistribute it and/or modify
|
|
2
|
+
// it under the terms of the GNU Lesser General Public License as published by
|
|
3
|
+
// the Free Software Foundation, either version 3 of the License, or
|
|
4
|
+
// (at your option) any later version.
|
|
5
|
+
//
|
|
6
|
+
// This program is distributed in the hope that it will be useful,
|
|
7
|
+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
8
|
+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
9
|
+
// GNU Lesser General Public License for more details.
|
|
10
|
+
//
|
|
11
|
+
// You should have received a copy of the GNU Lesser General Public License
|
|
12
|
+
// along with this program. If not, see https://www.gnu.org/licenses/.
|
|
13
|
+
|
|
14
|
+
declare module 'koffi' {
|
|
15
|
+
export function load(path: string): IKoffiLib;
|
|
16
|
+
|
|
17
|
+
interface IKoffiCType { __brand: 'IKoffiCType' }
|
|
18
|
+
interface IKoffiPointerCast { __brand: 'IKoffiPointerCast' }
|
|
19
|
+
interface IKoffiRegisteredCallback { __brand: 'IKoffiRegisteredCallback' }
|
|
20
|
+
|
|
21
|
+
type TypeSpec = string | IKoffiCType;
|
|
22
|
+
type TypeSpecWithAlignment = TypeSpec | [number, TypeSpec];
|
|
23
|
+
type TypeInfo = {
|
|
24
|
+
name: string,
|
|
25
|
+
primitive: string,
|
|
26
|
+
size: number,
|
|
27
|
+
alignment: number,
|
|
28
|
+
length: number,
|
|
29
|
+
ref: IKoffiCType,
|
|
30
|
+
members: Record<string, { name: string, type: {}, offset: number }>
|
|
31
|
+
};
|
|
32
|
+
type KoffiFunction = Function | { async: Function };
|
|
33
|
+
|
|
34
|
+
export interface IKoffiLib {
|
|
35
|
+
func(definition: string): KoffiFunction;
|
|
36
|
+
func(name: string, result: TypeSpec, arguments: TypeSpec[]): KoffiFunction;
|
|
37
|
+
|
|
38
|
+
cdecl(definition: string): KoffiFunction;
|
|
39
|
+
cdecl(name: string, result: TypeSpec, arguments: TypeSpec[]): KoffiFunction;
|
|
40
|
+
|
|
41
|
+
stdcall(definition: string): KoffiFunction;
|
|
42
|
+
stdcall(name: string, result: TypeSpec, arguments: TypeSpec[]): KoffiFunction;
|
|
43
|
+
|
|
44
|
+
fastcall(definition: string): KoffiFunction;
|
|
45
|
+
fastcall(name: string, result: TypeSpec, arguments: TypeSpec[]): KoffiFunction;
|
|
46
|
+
|
|
47
|
+
thiscall(definition: string): KoffiFunction;
|
|
48
|
+
thiscall(name: string, result: TypeSpec, arguments: TypeSpec[]): KoffiFunction;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function struct(name: string, def: Record<string, TypeSpecWithAlignment>): IKoffiCType;
|
|
52
|
+
export function struct(def: Record<string, TypeSpecWithAlignment>): IKoffiCType;
|
|
53
|
+
|
|
54
|
+
export function pack(name: string, def: Record<string, TypeSpecWithAlignment>): IKoffiCType;
|
|
55
|
+
export function pack(def: Record<string, TypeSpecWithAlignment>): IKoffiCType;
|
|
56
|
+
|
|
57
|
+
export function opaque(name: string): IKoffiCType;
|
|
58
|
+
export function opaque(): IKoffiCType;
|
|
59
|
+
|
|
60
|
+
export function pointer(value: TypeSpec): IKoffiCType;
|
|
61
|
+
export function pointer(value: TypeSpec, asteriskCount: number): IKoffiCType;
|
|
62
|
+
export function pointer(name: string, value: TypeSpec, asteriskCount: number): IKoffiCType;
|
|
63
|
+
|
|
64
|
+
export function out(value: TypeSpec): IKoffiCType;
|
|
65
|
+
export function inout(value: TypeSpec): IKoffiCType;
|
|
66
|
+
|
|
67
|
+
export function as(value: {}, type: TypeSpec): IKoffiPointerCast;
|
|
68
|
+
|
|
69
|
+
export function disposable(type: TypeSpec): IKoffiCType;
|
|
70
|
+
export function disposable(name: string, type: TypeSpec): IKoffiCType;
|
|
71
|
+
export function disposable(name: string, type: TypeSpec, freeFunction: Function): IKoffiCType;
|
|
72
|
+
|
|
73
|
+
export function callback(definition: string): IKoffiCType;
|
|
74
|
+
export function callback(name: string, result: TypeSpec, arguments: TypeSpec[]): IKoffiCType;
|
|
75
|
+
|
|
76
|
+
interface IKoffiRegisteredCallback { __brand: 'IKoffiRegisteredCallback' }
|
|
77
|
+
export function register(callback: Function, type: TypeSpec): IKoffiRegisteredCallback;
|
|
78
|
+
export function register(thisValue: any, callback: Function, type: TypeSpec): IKoffiRegisteredCallback;
|
|
79
|
+
export function unregister(callback: IKoffiRegisteredCallback): void;
|
|
80
|
+
|
|
81
|
+
export function decode(value: {}, type: TypeSpec): {};
|
|
82
|
+
export function decode(value: {}, type: TypeSpec, len: number): {};
|
|
83
|
+
export function decode(value: {}, offset: number, type: TypeSpec): {};
|
|
84
|
+
export function decode(value: {}, offset: number, type: TypeSpec, len: number): {};
|
|
85
|
+
|
|
86
|
+
export function sizeof(type: TypeSpec): number;
|
|
87
|
+
export function alignof(type: TypeSpec): number;
|
|
88
|
+
export function offsetof(type: TypeSpec): number;
|
|
89
|
+
export function resolve(type: TypeSpec): IKoffiCType;
|
|
90
|
+
export function introspect(type: TypeSpec): TypeInfo;
|
|
91
|
+
|
|
92
|
+
export function alias(name: string, type: TypeSpec): IKoffiCType;
|
|
93
|
+
|
|
94
|
+
export function config(): {}
|
|
95
|
+
export function config({}): {}
|
|
96
|
+
}
|
|
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
|