koffi 2.3.0 → 2.3.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 +9 -1
- package/doc/calls.md +2 -3
- package/package.json +2 -2
- package/src/koffi/build/2.3.1/koffi_darwin_arm64.tar.gz +0 -0
- package/src/koffi/build/2.3.1/koffi_darwin_x64.tar.gz +0 -0
- package/src/koffi/build/2.3.1/koffi_freebsd_arm64.tar.gz +0 -0
- package/src/koffi/build/2.3.1/koffi_freebsd_ia32.tar.gz +0 -0
- package/src/koffi/build/2.3.1/koffi_freebsd_x64.tar.gz +0 -0
- package/src/koffi/build/2.3.1/koffi_linux_arm32hf.tar.gz +0 -0
- package/src/koffi/build/2.3.1/koffi_linux_arm64.tar.gz +0 -0
- package/src/koffi/build/2.3.1/koffi_linux_ia32.tar.gz +0 -0
- package/src/koffi/build/2.3.1/koffi_linux_riscv64hf64.tar.gz +0 -0
- package/src/koffi/build/2.3.1/koffi_linux_x64.tar.gz +0 -0
- package/src/koffi/build/2.3.1/koffi_openbsd_ia32.tar.gz +0 -0
- package/src/koffi/build/2.3.1/koffi_openbsd_x64.tar.gz +0 -0
- package/src/koffi/build/2.3.1/koffi_win32_arm64.tar.gz +0 -0
- package/src/koffi/build/2.3.1/koffi_win32_ia32.tar.gz +0 -0
- package/src/koffi/build/2.3.1/koffi_win32_x64.tar.gz +0 -0
- package/src/koffi/src/call.cc +12 -0
- package/src/koffi/src/index.d.ts +15 -16
- package/src/koffi/src/parser.cc +1 -0
- 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/CHANGELOG.md
CHANGED
|
@@ -4,12 +4,20 @@
|
|
|
4
4
|
|
|
5
5
|
### Koffi 2.3
|
|
6
6
|
|
|
7
|
+
#### Koffi 2.3.1
|
|
8
|
+
|
|
9
|
+
**Main changes:**
|
|
10
|
+
|
|
11
|
+
- Error out when trying to use ambiguous `void *` arguments (input and/or output)
|
|
12
|
+
- Adjust TypeScript definitions ([@insraq](https://github.com/insraq))
|
|
13
|
+
- Fix possible crash when parsing invalid prototype
|
|
14
|
+
|
|
7
15
|
#### Koffi 2.3.0
|
|
8
16
|
|
|
9
17
|
**Main changes:**
|
|
10
18
|
|
|
11
19
|
- 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-
|
|
20
|
+
- Support opaque buffers (TypedArray or ArrayBuffer) values in `koffi.decode()` to [decode output buffers](calls.md#output-buffers)
|
|
13
21
|
- Decode non-string types as arrays when an [explicit length is passed to koffi.decode()](callbacks.md#pointer-arguments)
|
|
14
22
|
|
|
15
23
|
**Other changes:**
|
package/doc/calls.md
CHANGED
|
@@ -159,7 +159,7 @@ console.log(out[0]);
|
|
|
159
159
|
|
|
160
160
|
## Polymorphic parameters
|
|
161
161
|
|
|
162
|
-
### Input
|
|
162
|
+
### Input polymorphism
|
|
163
163
|
|
|
164
164
|
*New in Koffi 2.1*
|
|
165
165
|
|
|
@@ -221,7 +221,7 @@ let hdr = {};
|
|
|
221
221
|
console.log('PNG header:', hdr);
|
|
222
222
|
```
|
|
223
223
|
|
|
224
|
-
### Output
|
|
224
|
+
### Output buffers
|
|
225
225
|
|
|
226
226
|
*New in Koffi 2.3*
|
|
227
227
|
|
|
@@ -287,7 +287,6 @@ The following example illustrates the use of a disposable type derived from *str
|
|
|
287
287
|
const koffi = require('koffi');
|
|
288
288
|
const lib = koffi.load('libc.so.6');
|
|
289
289
|
|
|
290
|
-
// You can also use: const strdup = lib.func('const char *! strdup(const char *str)')
|
|
291
290
|
const HeapStr = koffi.disposable('str');
|
|
292
291
|
const strdup = lib.cdecl('strdup', HeapStr, ['str']);
|
|
293
292
|
|
package/package.json
CHANGED
|
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
|
@@ -909,6 +909,12 @@ bool CallData::PushPointer(Napi::Value value, const TypeInfo *type, int directio
|
|
|
909
909
|
uint8_t *ptr = nullptr;
|
|
910
910
|
|
|
911
911
|
if (value.IsArray()) {
|
|
912
|
+
if (RG_UNLIKELY(!type->ref.type->size)) {
|
|
913
|
+
ThrowError<Napi::TypeError>(env, "Cannot pass %1 value to void *, use koffi.as()",
|
|
914
|
+
type->ref.type != instance->void_type ? "opaque" : "ambiguous");
|
|
915
|
+
return false;
|
|
916
|
+
}
|
|
917
|
+
|
|
912
918
|
Napi::Array array = value.As<Napi::Array>();
|
|
913
919
|
|
|
914
920
|
Size len = (Size)array.Length();
|
|
@@ -936,6 +942,12 @@ bool CallData::PushPointer(Napi::Value value, const TypeInfo *type, int directio
|
|
|
936
942
|
directions = 1;
|
|
937
943
|
}
|
|
938
944
|
} else if (RG_LIKELY(type->ref.type->primitive == PrimitiveKind::Record)) {
|
|
945
|
+
if (RG_UNLIKELY(!type->ref.type->size)) {
|
|
946
|
+
ThrowError<Napi::TypeError>(env, "Cannot pass %1 value to void *, use koffi.as()",
|
|
947
|
+
type->ref.type != instance->void_type ? "opaque" : "ambiguous");
|
|
948
|
+
return false;
|
|
949
|
+
}
|
|
950
|
+
|
|
939
951
|
Napi::Object obj = value.As<Napi::Object>();
|
|
940
952
|
RG_ASSERT(IsObject(value));
|
|
941
953
|
|
package/src/koffi/src/index.d.ts
CHANGED
|
@@ -21,15 +21,15 @@ declare module 'koffi' {
|
|
|
21
21
|
type TypeSpec = string | IKoffiCType;
|
|
22
22
|
type TypeSpecWithAlignment = TypeSpec | [number, TypeSpec];
|
|
23
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:
|
|
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: IKoffiCType, offset: number }>;
|
|
31
31
|
};
|
|
32
|
-
type KoffiFunction = Function
|
|
32
|
+
type KoffiFunction = Function & { async: Function };
|
|
33
33
|
|
|
34
34
|
export interface IKoffiLib {
|
|
35
35
|
func(definition: string): KoffiFunction;
|
|
@@ -64,7 +64,7 @@ declare module 'koffi' {
|
|
|
64
64
|
export function out(value: TypeSpec): IKoffiCType;
|
|
65
65
|
export function inout(value: TypeSpec): IKoffiCType;
|
|
66
66
|
|
|
67
|
-
export function as(value:
|
|
67
|
+
export function as(value: any, type: TypeSpec): IKoffiPointerCast;
|
|
68
68
|
|
|
69
69
|
export function disposable(type: TypeSpec): IKoffiCType;
|
|
70
70
|
export function disposable(name: string, type: TypeSpec): IKoffiCType;
|
|
@@ -73,15 +73,14 @@ declare module 'koffi' {
|
|
|
73
73
|
export function callback(definition: string): IKoffiCType;
|
|
74
74
|
export function callback(name: string, result: TypeSpec, arguments: TypeSpec[]): IKoffiCType;
|
|
75
75
|
|
|
76
|
-
interface IKoffiRegisteredCallback { __brand: 'IKoffiRegisteredCallback' }
|
|
77
76
|
export function register(callback: Function, type: TypeSpec): IKoffiRegisteredCallback;
|
|
78
77
|
export function register(thisValue: any, callback: Function, type: TypeSpec): IKoffiRegisteredCallback;
|
|
79
78
|
export function unregister(callback: IKoffiRegisteredCallback): void;
|
|
80
79
|
|
|
81
|
-
export function decode(value:
|
|
82
|
-
export function decode(value:
|
|
83
|
-
export function decode(value:
|
|
84
|
-
export function decode(value:
|
|
80
|
+
export function decode(value: any, type: TypeSpec): any;
|
|
81
|
+
export function decode(value: any, type: TypeSpec, len: number): any;
|
|
82
|
+
export function decode(value: any, offset: number, type: TypeSpec): any;
|
|
83
|
+
export function decode(value: any, offset: number, type: TypeSpec, len: number): any;
|
|
85
84
|
|
|
86
85
|
export function sizeof(type: TypeSpec): number;
|
|
87
86
|
export function alignof(type: TypeSpec): number;
|
|
@@ -91,6 +90,6 @@ declare module 'koffi' {
|
|
|
91
90
|
|
|
92
91
|
export function alias(name: string, type: TypeSpec): IKoffiCType;
|
|
93
92
|
|
|
94
|
-
export function config():
|
|
95
|
-
export function config(
|
|
93
|
+
export function config(): Record<string, unknown>;
|
|
94
|
+
export function config(cfg: Record<string, unknown>): Record<string, unknown>;
|
|
96
95
|
}
|
package/src/koffi/src/parser.cc
CHANGED
|
@@ -152,6 +152,7 @@ const TypeInfo *PrototypeParser::ParseType()
|
|
|
152
152
|
offset++;
|
|
153
153
|
}
|
|
154
154
|
offset += (offset < tokens.len && tokens[offset] == "!");
|
|
155
|
+
offset = std::min(tokens.len - 1, offset);
|
|
155
156
|
|
|
156
157
|
while (offset >= start) {
|
|
157
158
|
Span<const char> str = MakeSpan(tokens[start].ptr, tokens[offset].end() - tokens[start].ptr);
|
|
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
|