koffi 3.0.0 → 3.0.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/README.md +5 -4
- package/cnoke.cjs +3 -3
- package/doc/benchmarks.md +23 -46
- package/doc/callbacks.md +4 -13
- package/doc/contribute.md +3 -3
- package/doc/index.md +3 -2
- package/doc/migration.md +100 -0
- package/doc/start.md +7 -5
- package/index.d.ts +308 -308
- package/index.js +2 -1
- package/indirect.d.ts +322 -0
- package/indirect.js +2 -1
- package/package.json +20 -18
- package/src/koffi/CMakeLists.txt +19 -12
- package/src/koffi/index.cjs +65 -16
- package/src/koffi/index.js +105 -16
- package/src/koffi/indirect.cjs +65 -16
- package/src/koffi/indirect.js +105 -16
- package/src/koffi/src/abi/arm64.cc +29 -29
- package/src/koffi/src/abi/riscv64.cc +29 -29
- package/src/koffi/src/abi/x64sysv.cc +25 -25
- package/src/koffi/src/abi/x64win.cc +63 -63
- package/src/koffi/src/abi/x86.cc +66 -65
- package/src/koffi/src/call.cc +2 -2
- package/src/koffi/src/ffi.cc +64 -8
- package/src/koffi/src/ffi.hh +9 -6
- package/src/koffi/src/primitives.inc +1 -4
- package/src/koffi/src/util.cc +175 -121
- package/src/koffi/src/util.hh +13 -14
package/indirect.d.ts
ADDED
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
// SPDX-FileCopyrightText: 2026 Niels Martignène <niels.martignene@protonmail.com>
|
|
3
|
+
|
|
4
|
+
declare module "koffi/indirect" {
|
|
5
|
+
type PrimitiveKind = 'Void' | 'Bool' | 'Int8' | 'UInt8' | 'Int16' | 'Int16S' | 'UInt16' | 'UInt16S' |
|
|
6
|
+
'Int32' | 'Int32S' | 'UInt32' | 'UInt32S' | 'Int64' | 'Int64S' | 'UInt64' | 'UInt64S' |
|
|
7
|
+
'String' | 'String16' | 'Pointer' | 'Record' | 'Union' | 'Array' | 'Float32' | 'Float64' |
|
|
8
|
+
'Prototype' | 'Callback';
|
|
9
|
+
type ArrayHint = 'Array' | 'Typed' | 'String';
|
|
10
|
+
|
|
11
|
+
type PrototypeInfo = {
|
|
12
|
+
name: string;
|
|
13
|
+
arguments: TypeObject[];
|
|
14
|
+
result: TypeObject
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
interface IKoffiDirectionMarker { __brand: 'IKoffiDirectionMarker' }
|
|
18
|
+
interface IKoffiPointerCast { __brand: 'IKoffiPointerCast' }
|
|
19
|
+
|
|
20
|
+
export type TypeObject = {
|
|
21
|
+
name: string;
|
|
22
|
+
primitive: PrimitiveKind;
|
|
23
|
+
size: number;
|
|
24
|
+
alignment: number;
|
|
25
|
+
disposable: boolean;
|
|
26
|
+
length?: number;
|
|
27
|
+
hint?: ArrayHint;
|
|
28
|
+
ref?: TypeObject;
|
|
29
|
+
members?: Record<string, { name: string, type: TypeObject, offset: number }>;
|
|
30
|
+
proto?: PrototypeInfo;
|
|
31
|
+
values?: Record<string, number | bigint>;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
type TypeSpec = string | TypeObject | IKoffiDirectionMarker;
|
|
35
|
+
type TypeSpecWithAlignment = TypeSpec | [number, TypeSpec];
|
|
36
|
+
|
|
37
|
+
type KoffiFunction = {
|
|
38
|
+
(...args: any[]) : any;
|
|
39
|
+
async: (...args: any[]) => any;
|
|
40
|
+
info: PrototypeInfo;
|
|
41
|
+
};
|
|
42
|
+
export type KoffiFunc<T extends (...args: any) => any> = T & {
|
|
43
|
+
async: (...args: [...Parameters<T>, (err: any, result: ReturnType<T>) => void]) => void;
|
|
44
|
+
info: PrototypeInfo;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
type LoadOptions = {
|
|
48
|
+
lazy?: boolean,
|
|
49
|
+
global?: boolean,
|
|
50
|
+
deep?: boolean
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export type LibraryHandle = {
|
|
54
|
+
func(definition: string): KoffiFunction;
|
|
55
|
+
func(name: string | number, result: TypeSpec, arguments: TypeSpec[]): KoffiFunction;
|
|
56
|
+
func(convention: string, name: string | number, result: TypeSpec, arguments: TypeSpec[]): KoffiFunction;
|
|
57
|
+
|
|
58
|
+
/** @deprecated */ cdecl(definition: string): KoffiFunction;
|
|
59
|
+
/** @deprecated */ cdecl(name: string | number, result: TypeSpec, arguments: TypeSpec[]): KoffiFunction;
|
|
60
|
+
/** @deprecated */ stdcall(definition: string): KoffiFunction;
|
|
61
|
+
/** @deprecated */ stdcall(name: string | number, result: TypeSpec, arguments: TypeSpec[]): KoffiFunction;
|
|
62
|
+
/** @deprecated */ fastcall(definition: string): KoffiFunction;
|
|
63
|
+
/** @deprecated */ fastcall(name: string | number, result: TypeSpec, arguments: TypeSpec[]): KoffiFunction;
|
|
64
|
+
/** @deprecated */ thiscall(definition: string): KoffiFunction;
|
|
65
|
+
/** @deprecated */ thiscall(name: string | number, result: TypeSpec, arguments: TypeSpec[]): KoffiFunction;
|
|
66
|
+
|
|
67
|
+
symbol(name: string, type: TypeSpec): any;
|
|
68
|
+
|
|
69
|
+
unload(): void;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export function load(path: string | null, options?: LoadOptions): LibraryHandle;
|
|
73
|
+
|
|
74
|
+
export function struct(name: string | null | undefined, def: Record<string, TypeSpecWithAlignment>): TypeObject;
|
|
75
|
+
export function struct(ref: TypeObject, def: Record<string, TypeSpecWithAlignment>): TypeObject;
|
|
76
|
+
export function struct(def: Record<string, TypeSpecWithAlignment>): TypeObject;
|
|
77
|
+
export function pack(name: string | null | undefined, def: Record<string, TypeSpecWithAlignment>): TypeObject;
|
|
78
|
+
export function pack(ref: TypeObject, def: Record<string, TypeSpecWithAlignment>): TypeObject;
|
|
79
|
+
export function pack(def: Record<string, TypeSpecWithAlignment>): TypeObject;
|
|
80
|
+
|
|
81
|
+
export function union(name: string | null | undefined, def: Record<string, TypeSpecWithAlignment>): TypeObject;
|
|
82
|
+
export function union(ref: TypeObject, def: Record<string, TypeSpecWithAlignment>): TypeObject;
|
|
83
|
+
export function union(def: Record<string, TypeSpecWithAlignment>): TypeObject;
|
|
84
|
+
|
|
85
|
+
export class Union {
|
|
86
|
+
constructor(type: TypeSpec);
|
|
87
|
+
[s: string]: any;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export function enumeration(name: string | null | undefined, def: Record<string, number | bigint>, storage?: TypeSpec | null) : TypeObject;
|
|
91
|
+
export function enumeration(def: Record<string, number | bigint>, storage?: TypeSpec | null) : TypeObject;
|
|
92
|
+
|
|
93
|
+
export function array(ref: TypeSpec, len: number, hint?: ArrayHint | null): TypeObject;
|
|
94
|
+
export function array(ref: TypeSpec, countedBy: string, maxLen: number, hint?: ArrayHint | null): TypeObject;
|
|
95
|
+
|
|
96
|
+
export function opaque(name: string | null | undefined): TypeObject;
|
|
97
|
+
export function opaque(): TypeObject;
|
|
98
|
+
|
|
99
|
+
export function pointer(ref: TypeSpec): TypeObject;
|
|
100
|
+
export function pointer(ref: TypeSpec, count: number): TypeObject;
|
|
101
|
+
export function pointer(name: string | null | undefined, ref: TypeSpec, countedBy?: string | null): TypeObject;
|
|
102
|
+
export function pointer(name: string | null | undefined, ref: TypeSpec, count: number): TypeObject;
|
|
103
|
+
|
|
104
|
+
export function out(type: TypeSpec): IKoffiDirectionMarker;
|
|
105
|
+
export function inout(type: TypeSpec): IKoffiDirectionMarker;
|
|
106
|
+
|
|
107
|
+
export function disposable(type: TypeSpec): TypeObject;
|
|
108
|
+
export function disposable(type: TypeSpec, freeFunction: Function): TypeObject;
|
|
109
|
+
export function disposable(name: string | null | undefined, type: TypeSpec): TypeObject;
|
|
110
|
+
export function disposable(name: string | null | undefined, type: TypeSpec, freeFunction: Function): TypeObject;
|
|
111
|
+
|
|
112
|
+
export function proto(definition: string): TypeObject;
|
|
113
|
+
export function proto(result: TypeSpec, arguments: TypeSpec[]): TypeObject;
|
|
114
|
+
export function proto(convention: string, result: TypeSpec, arguments: TypeSpec[]): TypeObject;
|
|
115
|
+
export function proto(name: string | null | undefined, result: TypeSpec, arguments: TypeSpec[]): TypeObject;
|
|
116
|
+
export function proto(convention: string, name: string | null | undefined, result: TypeSpec, arguments: TypeSpec[]): TypeObject;
|
|
117
|
+
|
|
118
|
+
export function register(callback: Function, type: TypeSpec): bigint;
|
|
119
|
+
/** @deprecated */ export function register(thisValue: any, callback: Function, type: TypeSpec): bigint;
|
|
120
|
+
export function unregister(callback: bigint): void;
|
|
121
|
+
|
|
122
|
+
export function as(value: any, type: TypeSpec): IKoffiPointerCast;
|
|
123
|
+
export function address(value: any): bigint;
|
|
124
|
+
export function call(value: any, type: TypeSpec, ...args: any[]): any;
|
|
125
|
+
export function view(ref: any, len: number): ArrayBuffer;
|
|
126
|
+
|
|
127
|
+
export const decode: {
|
|
128
|
+
(value: any, type: TypeSpec): any;
|
|
129
|
+
(value: any, type: TypeSpec, len: number): any;
|
|
130
|
+
(value: any, offset: number, type: TypeSpec): any;
|
|
131
|
+
(value: any, offset: number, type: TypeSpec, len: number): any;
|
|
132
|
+
|
|
133
|
+
char(ptr: any): number;
|
|
134
|
+
short(ptr: any): number;
|
|
135
|
+
int(ptr: any): number;
|
|
136
|
+
long(ptr: any): number | bigint;
|
|
137
|
+
longlong(ptr: any): number | bigint;
|
|
138
|
+
uchar(ptr: any): number;
|
|
139
|
+
ushort(ptr: any): number;
|
|
140
|
+
uint(ptr: any): number;
|
|
141
|
+
ulong(ptr: any): number | bigint;
|
|
142
|
+
ulonglong(ptr: any): number | bigint;
|
|
143
|
+
|
|
144
|
+
int8(ptr: any): number;
|
|
145
|
+
int16(ptr: any): number;
|
|
146
|
+
int32(ptr: any): number;
|
|
147
|
+
int64(ptr: any): number | bigint;
|
|
148
|
+
uint8(ptr: any): number;
|
|
149
|
+
uint16(ptr: any): number;
|
|
150
|
+
uint32(ptr: any): number;
|
|
151
|
+
uint64(ptr: any): number | bigint;
|
|
152
|
+
|
|
153
|
+
float(ptr: any): number;
|
|
154
|
+
double(ptr: any): number;
|
|
155
|
+
|
|
156
|
+
string(ptr: any, length?: number | bigint | null): string;
|
|
157
|
+
string16(ptr: any, length?: number | bigint | null): string;
|
|
158
|
+
string32(ptr: any, length?: number | bigint | null): string;
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
export function encode(ref: any, type: TypeSpec, value: any): void;
|
|
162
|
+
export function encode(ref: any, type: TypeSpec, value: any, len: number): void;
|
|
163
|
+
export function encode(ref: any, offset: number, type: TypeSpec): void;
|
|
164
|
+
export function encode(ref: any, offset: number, type: TypeSpec, value: any): void;
|
|
165
|
+
export function encode(ref: any, offset: number, type: TypeSpec, value: any, len: number): void;
|
|
166
|
+
|
|
167
|
+
export function type(type: TypeSpec): TypeObject;
|
|
168
|
+
export function sizeof(type: TypeSpec): number;
|
|
169
|
+
export function alignof(type: TypeSpec): number;
|
|
170
|
+
export function offsetof(type: TypeSpec, member_name: string): number;
|
|
171
|
+
/** @deprecated */ export function resolve(type: TypeSpec): TypeObject;
|
|
172
|
+
/** @deprecated */ export function introspect(type: TypeSpec): TypeObject;
|
|
173
|
+
|
|
174
|
+
export function alias(name: string, type: TypeSpec): TypeObject;
|
|
175
|
+
|
|
176
|
+
type KoffiConfig = {
|
|
177
|
+
sync_stack_size?: number;
|
|
178
|
+
sync_heap_size?: number;
|
|
179
|
+
async_stack_size?: number;
|
|
180
|
+
async_heap_size?: number;
|
|
181
|
+
resident_async_pools?: number;
|
|
182
|
+
max_async_calls?: number;
|
|
183
|
+
max_type_size?: number;
|
|
184
|
+
};
|
|
185
|
+
type KoffiStats = {
|
|
186
|
+
disposed: number
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
export function config(): KoffiConfig;
|
|
190
|
+
export function config(cfg: KoffiConfig): KoffiConfig;
|
|
191
|
+
export function stats(): KoffiStats;
|
|
192
|
+
|
|
193
|
+
export function alloc(type: TypeSpec, length: number): any;
|
|
194
|
+
export function free(value: any): void;
|
|
195
|
+
|
|
196
|
+
export function errno(): number;
|
|
197
|
+
export function errno(value: number): number;
|
|
198
|
+
|
|
199
|
+
export function reset(): void;
|
|
200
|
+
|
|
201
|
+
export const internal: boolean;
|
|
202
|
+
export const extension: string;
|
|
203
|
+
|
|
204
|
+
export const os: {
|
|
205
|
+
errno: Record<string, number>
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
// https://koffi.dev/input#standard-types
|
|
209
|
+
type PrimitiveTypes =
|
|
210
|
+
| 'bool'
|
|
211
|
+
| 'char'
|
|
212
|
+
| 'char16_t'
|
|
213
|
+
| 'char16'
|
|
214
|
+
| 'char32_t'
|
|
215
|
+
| 'char32'
|
|
216
|
+
| 'double'
|
|
217
|
+
| 'float'
|
|
218
|
+
| 'float32'
|
|
219
|
+
| 'float64'
|
|
220
|
+
| 'int'
|
|
221
|
+
| 'int8_t'
|
|
222
|
+
| 'int8'
|
|
223
|
+
| 'int16_be_t'
|
|
224
|
+
| 'int16_be'
|
|
225
|
+
| 'int16_le_t'
|
|
226
|
+
| 'int16_le'
|
|
227
|
+
| 'int16_t'
|
|
228
|
+
| 'int16'
|
|
229
|
+
| 'int32_be_t'
|
|
230
|
+
| 'int32_be'
|
|
231
|
+
| 'int32_le_t'
|
|
232
|
+
| 'int32_le'
|
|
233
|
+
| 'int32_t'
|
|
234
|
+
| 'int32'
|
|
235
|
+
| 'int64_be_t'
|
|
236
|
+
| 'int64_be'
|
|
237
|
+
| 'int64_le_t'
|
|
238
|
+
| 'int64_le'
|
|
239
|
+
| 'int64_t'
|
|
240
|
+
| 'int64'
|
|
241
|
+
| 'intptr_t'
|
|
242
|
+
| 'intptr'
|
|
243
|
+
| 'long long'
|
|
244
|
+
| 'long'
|
|
245
|
+
| 'longlong'
|
|
246
|
+
| 'short'
|
|
247
|
+
| 'size_t'
|
|
248
|
+
| 'str'
|
|
249
|
+
| 'str16'
|
|
250
|
+
| 'str32'
|
|
251
|
+
| 'string'
|
|
252
|
+
| 'string16'
|
|
253
|
+
| 'string32'
|
|
254
|
+
| 'uchar'
|
|
255
|
+
| 'uint'
|
|
256
|
+
| 'uint8_t'
|
|
257
|
+
| 'uint8'
|
|
258
|
+
| 'uint16_be_t'
|
|
259
|
+
| 'uint16_be'
|
|
260
|
+
| 'uint16_le_t'
|
|
261
|
+
| 'uint16_le'
|
|
262
|
+
| 'uint16_t'
|
|
263
|
+
| 'uint16'
|
|
264
|
+
| 'uint32_be_t'
|
|
265
|
+
| 'uint32_be'
|
|
266
|
+
| 'uint32_le_t'
|
|
267
|
+
| 'uint32_le'
|
|
268
|
+
| 'uint32_t'
|
|
269
|
+
| 'uint32'
|
|
270
|
+
| 'uint64_be_t'
|
|
271
|
+
| 'uint64_be'
|
|
272
|
+
| 'uint64_le_t'
|
|
273
|
+
| 'uint64_le'
|
|
274
|
+
| 'uint64_t'
|
|
275
|
+
| 'uint64'
|
|
276
|
+
| 'uintptr_t'
|
|
277
|
+
| 'uintptr'
|
|
278
|
+
| 'ulong'
|
|
279
|
+
| 'ulonglong'
|
|
280
|
+
| 'unsigned char'
|
|
281
|
+
| 'unsigned int'
|
|
282
|
+
| 'unsigned long long'
|
|
283
|
+
| 'unsigned long'
|
|
284
|
+
| 'unsigned short'
|
|
285
|
+
| 'ushort'
|
|
286
|
+
| 'void'
|
|
287
|
+
| 'wchar'
|
|
288
|
+
| 'wchar_t';
|
|
289
|
+
export const types: Record<PrimitiveTypes, TypeObject>;
|
|
290
|
+
|
|
291
|
+
export namespace node {
|
|
292
|
+
export const env: { __brand: 'IKoffiNodeEnv' };
|
|
293
|
+
|
|
294
|
+
type PollOptions = {
|
|
295
|
+
readable?: boolean;
|
|
296
|
+
writable?: boolean;
|
|
297
|
+
disconnect?: boolean;
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
type PollEvents = {
|
|
301
|
+
readable: boolean;
|
|
302
|
+
writable: boolean;
|
|
303
|
+
disconnect: boolean;
|
|
304
|
+
};
|
|
305
|
+
|
|
306
|
+
export class PollHandle {
|
|
307
|
+
start(opts: PollOptions, callback: (ev: PollEvents) => void): void;
|
|
308
|
+
start(callback: (ev: PollEvents) => void): void;
|
|
309
|
+
stop(): void;
|
|
310
|
+
|
|
311
|
+
close(): void;
|
|
312
|
+
|
|
313
|
+
unref(): void;
|
|
314
|
+
ref(): void;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
export function poll(fd: number, opts: PollOptions, callback: (ev: PollEvents) => void): PollHandle;
|
|
318
|
+
export function poll(fd: number, callback: (ev: PollEvents) => void): PollHandle;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
export const version: string;
|
|
322
|
+
}
|
package/indirect.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export { default } from "./src/koffi/indirect.js";
|
|
1
|
+
export { default } from "./src/koffi/indirect.js";
|
|
2
|
+
export * from "./src/koffi/indirect.js";
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "koffi",
|
|
3
|
-
"version": "3.0.
|
|
4
|
-
"description": "Fast and
|
|
3
|
+
"version": "3.0.1",
|
|
4
|
+
"description": "Fast and easy-to-use dynamic C FFI (foreign function interface) for Node.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"foreign",
|
|
7
7
|
"function",
|
|
@@ -33,20 +33,20 @@
|
|
|
33
33
|
},
|
|
34
34
|
"funding": "https://liberapay.com/Koromix",
|
|
35
35
|
"optionalDependencies": {
|
|
36
|
-
"@koromix/koffi-linux-arm64": "3.0.
|
|
37
|
-
"@koromix/koffi-linux-ia32": "3.0.
|
|
38
|
-
"@koromix/koffi-linux-x64": "3.0.
|
|
39
|
-
"@koromix/koffi-linux-riscv64": "3.0.
|
|
40
|
-
"@koromix/koffi-freebsd-ia32": "3.0.
|
|
41
|
-
"@koromix/koffi-freebsd-x64": "3.0.
|
|
42
|
-
"@koromix/koffi-freebsd-arm64": "3.0.
|
|
43
|
-
"@koromix/koffi-openbsd-ia32": "3.0.
|
|
44
|
-
"@koromix/koffi-openbsd-x64": "3.0.
|
|
45
|
-
"@koromix/koffi-win32-ia32": "3.0.
|
|
46
|
-
"@koromix/koffi-win32-x64": "3.0.
|
|
47
|
-
"@koromix/koffi-darwin-x64": "3.0.
|
|
48
|
-
"@koromix/koffi-darwin-arm64": "3.0.
|
|
49
|
-
"@koromix/koffi-linux-loong64": "3.0.
|
|
36
|
+
"@koromix/koffi-linux-arm64": "3.0.1",
|
|
37
|
+
"@koromix/koffi-linux-ia32": "3.0.1",
|
|
38
|
+
"@koromix/koffi-linux-x64": "3.0.1",
|
|
39
|
+
"@koromix/koffi-linux-riscv64": "3.0.1",
|
|
40
|
+
"@koromix/koffi-freebsd-ia32": "3.0.1",
|
|
41
|
+
"@koromix/koffi-freebsd-x64": "3.0.1",
|
|
42
|
+
"@koromix/koffi-freebsd-arm64": "3.0.1",
|
|
43
|
+
"@koromix/koffi-openbsd-ia32": "3.0.1",
|
|
44
|
+
"@koromix/koffi-openbsd-x64": "3.0.1",
|
|
45
|
+
"@koromix/koffi-win32-ia32": "3.0.1",
|
|
46
|
+
"@koromix/koffi-win32-x64": "3.0.1",
|
|
47
|
+
"@koromix/koffi-darwin-x64": "3.0.1",
|
|
48
|
+
"@koromix/koffi-darwin-arm64": "3.0.1",
|
|
49
|
+
"@koromix/koffi-linux-loong64": "3.0.1"
|
|
50
50
|
},
|
|
51
51
|
"type": "module",
|
|
52
52
|
"main": "./index.cjs",
|
|
@@ -54,11 +54,13 @@
|
|
|
54
54
|
"exports": {
|
|
55
55
|
".": {
|
|
56
56
|
"import": "./index.js",
|
|
57
|
-
"require": "./index.cjs"
|
|
57
|
+
"require": "./index.cjs",
|
|
58
|
+
"types": "./index.d.ts"
|
|
58
59
|
},
|
|
59
60
|
"./indirect": {
|
|
60
61
|
"import": "./indirect.js",
|
|
61
|
-
"require": "./indirect.cjs"
|
|
62
|
+
"require": "./indirect.cjs",
|
|
63
|
+
"types": "./indirect.d.ts"
|
|
62
64
|
}
|
|
63
65
|
},
|
|
64
66
|
"types": "./index.d.ts"
|
package/src/koffi/CMakeLists.txt
CHANGED
|
@@ -137,6 +137,7 @@ if(WIN32)
|
|
|
137
137
|
endif()
|
|
138
138
|
|
|
139
139
|
target_compile_definitions(koffi PRIVATE FELIX_TARGET=koffi NAPI_DISABLE_CPP_EXCEPTIONS NAPI_VERSION=NAPI_VERSION_EXPERIMENTAL)
|
|
140
|
+
|
|
140
141
|
if(WIN32)
|
|
141
142
|
target_compile_definitions(koffi PRIVATE _CRT_SECURE_NO_WARNINGS _CRT_NONSTDC_NO_DEPRECATE)
|
|
142
143
|
target_link_libraries(koffi PRIVATE ws2_32)
|
|
@@ -152,27 +153,33 @@ endif()
|
|
|
152
153
|
option(PGO_GENERATE "Build with PGO profile generation" "")
|
|
153
154
|
option(PGO_USE "Optimize with PGO profile" "")
|
|
154
155
|
|
|
155
|
-
if(MSVC
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
if(CMAKE_C_COMPILER_ID MATCHES "[Cc]lang")
|
|
159
|
-
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /clang:-O3")
|
|
156
|
+
if(MSVC)
|
|
157
|
+
if (NOT CMAKE_C_COMPILER_ID MATCHES "[Cc]lang")
|
|
158
|
+
target_compile_options(koffi PRIVATE $<$<COMPILE_LANGUAGE:CXX>:/EHsc>)
|
|
160
159
|
endif()
|
|
161
160
|
|
|
162
|
-
if(CMAKE_BUILD_TYPE STREQUAL "Release")
|
|
163
|
-
target_compile_options(koffi PRIVATE $<$<COMPILE_LANGUAGE:CXX>:/
|
|
161
|
+
if(CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
|
|
162
|
+
target_compile_options(koffi PRIVATE $<$<COMPILE_LANGUAGE:CXX>:/GS- /Ob2>)
|
|
163
|
+
|
|
164
|
+
if(CMAKE_C_COMPILER_ID MATCHES "[Cc]lang")
|
|
165
|
+
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /clang:-O3")
|
|
166
|
+
endif()
|
|
167
|
+
|
|
168
|
+
if(CMAKE_BUILD_TYPE STREQUAL "Release")
|
|
169
|
+
target_compile_options(koffi PRIVATE $<$<COMPILE_LANGUAGE:CXX>:/Oy->)
|
|
170
|
+
endif()
|
|
164
171
|
endif()
|
|
165
172
|
endif()
|
|
166
173
|
|
|
167
174
|
if(NOT MSVC OR CMAKE_C_COMPILER_ID MATCHES "[Cc]lang")
|
|
168
175
|
# Restore C/C++ compiler sanity
|
|
169
176
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
177
|
+
target_compile_options(koffi PRIVATE $<$<COMPILE_LANGUAGE:CXX>:-fno-exceptions -fno-rtti -fno-strict-aliasing
|
|
178
|
+
-fno-delete-null-pointer-checks>)
|
|
179
|
+
if(MSVC)
|
|
180
|
+
target_compile_options(koffi PRIVATE $<$<COMPILE_LANGUAGE:CXX>:/clang:-fwrapv>)
|
|
173
181
|
else()
|
|
174
|
-
target_compile_options(koffi PRIVATE $<$<COMPILE_LANGUAGE:CXX>:-
|
|
175
|
-
-fno-delete-null-pointer-checks>)
|
|
182
|
+
target_compile_options(koffi PRIVATE $<$<COMPILE_LANGUAGE:CXX>:-fwrapv>)
|
|
176
183
|
endif()
|
|
177
184
|
|
|
178
185
|
check_cxx_compiler_flag(-fno-finite-loops use_no_finite_loops)
|
package/src/koffi/index.cjs
CHANGED
|
@@ -34,7 +34,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
34
34
|
|
|
35
35
|
// ../cnoke/src/abi.js
|
|
36
36
|
function determineAbi() {
|
|
37
|
-
let abi = process.arch;
|
|
37
|
+
let abi = process.arch.toString();
|
|
38
38
|
if (abi == "riscv32" || abi == "riscv64") {
|
|
39
39
|
let buf = readFileHeader(process.execPath, 512);
|
|
40
40
|
let header = decodeElfHeader(buf);
|
|
@@ -131,7 +131,7 @@ var init_abi = __esm({
|
|
|
131
131
|
var package_default;
|
|
132
132
|
var init_package = __esm({
|
|
133
133
|
"package.json"() {
|
|
134
|
-
package_default = { name: "koffi", version: "3.0.
|
|
134
|
+
package_default = { name: "koffi", version: "3.0.1", cnoke: { api: "../../vendor/node-api-headers", output: "../../bin/Koffi/{{ toolchain }}", node: 16, napi: 8 } };
|
|
135
135
|
}
|
|
136
136
|
});
|
|
137
137
|
|
|
@@ -145,7 +145,7 @@ __export(init_exports, {
|
|
|
145
145
|
function detectPlatform() {
|
|
146
146
|
if (process.versions.napi == null || process.versions.napi < package_default.cnoke.napi) {
|
|
147
147
|
let major = parseInt(process.versions.node, 10);
|
|
148
|
-
throw new Error(`This engine is based on Node ${process.versions.node}, but ${package_default.name} does not support the Node ${major}.x branch (
|
|
148
|
+
throw new Error(`This engine is based on Node ${process.versions.node}, but ${package_default.name} does not support the Node ${major}.x branch (Node-API < ${package_default.cnoke.napi})`);
|
|
149
149
|
}
|
|
150
150
|
let abi = determineAbi();
|
|
151
151
|
let pkg2 = `${process.platform}-${process.arch}`;
|
|
@@ -158,9 +158,9 @@ function loadDynamic(root, pkg2, triplets2) {
|
|
|
158
158
|
let roots = [root];
|
|
159
159
|
let native2 = null;
|
|
160
160
|
let err = null;
|
|
161
|
-
if (process
|
|
162
|
-
roots.push(process
|
|
163
|
-
roots.push(process
|
|
161
|
+
if (process["resourcesPath"] != null) {
|
|
162
|
+
roots.push(process["resourcesPath"]);
|
|
163
|
+
roots.push(process["resourcesPath"] + "/node_modules/koffi");
|
|
164
164
|
}
|
|
165
165
|
let names = [
|
|
166
166
|
`${__dirname}/../../../@koromix/koffi-${pkg2}`,
|
|
@@ -185,27 +185,26 @@ function loadDynamic(root, pkg2, triplets2) {
|
|
|
185
185
|
function wrapNative(native2) {
|
|
186
186
|
let load = native2.load;
|
|
187
187
|
let register = native2.register;
|
|
188
|
-
|
|
189
|
-
native2.
|
|
188
|
+
let introspect = native2.introspect ?? native2.type;
|
|
189
|
+
native2.sizeof = (spec) => introspect(spec).size;
|
|
190
|
+
native2.alignof = (spec) => introspect(spec).alignment;
|
|
190
191
|
native2.offsetof = (spec, name) => {
|
|
191
|
-
let
|
|
192
|
-
if (
|
|
192
|
+
let info = introspect(spec);
|
|
193
|
+
if (info.primitive != "Record")
|
|
193
194
|
throw new TypeError("The offsetof() function can only be used with record types");
|
|
194
|
-
let member =
|
|
195
|
+
let member = info.members[name];
|
|
195
196
|
if (member == null)
|
|
196
|
-
throw new Error(`Record type ${
|
|
197
|
+
throw new Error(`Record type ${info.name} does not have member '${name}'`);
|
|
197
198
|
return member.offset;
|
|
198
199
|
};
|
|
199
200
|
native2.register = (...args) => {
|
|
200
201
|
if (args.length >= 3 && typeof args[1] == "function") {
|
|
201
|
-
process.emitWarning("Using koffi.register() with a custom this value was deprecated in Koffi
|
|
202
|
+
process.emitWarning("Using koffi.register() with a custom this value was deprecated in Koffi 2.17, use function.bind() instead", "DeprecationWarning", "KOFFI009");
|
|
202
203
|
args[1] = args[1].bind(args[0]);
|
|
203
204
|
args = args.slice(1);
|
|
204
205
|
}
|
|
205
206
|
return register(...args);
|
|
206
207
|
};
|
|
207
|
-
native2.resolve = import_node_util.default.deprecate(native2.type, "The koffi.resolve() function was deprecated in Koffi 3.0, use koffi.type() instead", "KOFFI007");
|
|
208
|
-
native2.introspect = import_node_util.default.deprecate(native2.type, "The koffi.introspect() function was deprecated in Koffi 3.0, use koffi.type() instead", "KOFFI008");
|
|
209
208
|
native2.load = (...args) => {
|
|
210
209
|
let lib = load(...args);
|
|
211
210
|
lib.cdecl = import_node_util.default.deprecate((...args2) => lib.func("__cdecl", ...args2), "The koffi.cdecl() function was deprecated in Koffi 2.7, use koffi.func(...) instead", "KOFFI003");
|
|
@@ -214,6 +213,12 @@ function wrapNative(native2) {
|
|
|
214
213
|
lib.thiscall = import_node_util.default.deprecate((...args2) => lib.func("__thiscall", ...args2), 'The koffi.thiscall() function was deprecated in Koffi 2.7, use koffi.func("__thiscall", ...) instead', "KOFFI006");
|
|
215
214
|
return lib;
|
|
216
215
|
};
|
|
216
|
+
if (native2.introspect == null) {
|
|
217
|
+
native2.resolve = import_node_util.default.deprecate(native2.type, "The koffi.resolve() function was deprecated in Koffi 3.0, use koffi.type() instead", "KOFFI007");
|
|
218
|
+
native2.introspect = import_node_util.default.deprecate(native2.type, "The koffi.introspect() function was deprecated in Koffi 3.0, use koffi.type() instead", "KOFFI008");
|
|
219
|
+
} else {
|
|
220
|
+
native2.resolve = native2.type;
|
|
221
|
+
}
|
|
217
222
|
}
|
|
218
223
|
var import_node_util, import_node_fs2, import_node_module, requireNative;
|
|
219
224
|
var init_init = __esm({
|
|
@@ -325,4 +330,48 @@ if (native == null)
|
|
|
325
330
|
if (native.version != version)
|
|
326
331
|
throw new Error("Mismatched native Koffi modules");
|
|
327
332
|
wrapNative2(native);
|
|
328
|
-
module.exports =
|
|
333
|
+
module.exports = {
|
|
334
|
+
default: native,
|
|
335
|
+
"LibraryHandle": native["LibraryHandle"],
|
|
336
|
+
"TypeObject": native["TypeObject"],
|
|
337
|
+
"Union": native["Union"],
|
|
338
|
+
"address": native["address"],
|
|
339
|
+
"alias": native["alias"],
|
|
340
|
+
"alignof": native["alignof"],
|
|
341
|
+
"alloc": native["alloc"],
|
|
342
|
+
"array": native["array"],
|
|
343
|
+
"as": native["as"],
|
|
344
|
+
"call": native["call"],
|
|
345
|
+
"config": native["config"],
|
|
346
|
+
"decode": native["decode"],
|
|
347
|
+
"disposable": native["disposable"],
|
|
348
|
+
"encode": native["encode"],
|
|
349
|
+
"enumeration": native["enumeration"],
|
|
350
|
+
"errno": native["errno"],
|
|
351
|
+
"extension": native["extension"],
|
|
352
|
+
"free": native["free"],
|
|
353
|
+
"in": native["in"],
|
|
354
|
+
"inout": native["inout"],
|
|
355
|
+
"introspect": native["introspect"],
|
|
356
|
+
"load": native["load"],
|
|
357
|
+
"node": native["node"],
|
|
358
|
+
"offsetof": native["offsetof"],
|
|
359
|
+
"opaque": native["opaque"],
|
|
360
|
+
"os": native["os"],
|
|
361
|
+
"out": native["out"],
|
|
362
|
+
"pack": native["pack"],
|
|
363
|
+
"pointer": native["pointer"],
|
|
364
|
+
"proto": native["proto"],
|
|
365
|
+
"register": native["register"],
|
|
366
|
+
"reset": native["reset"],
|
|
367
|
+
"resolve": native["resolve"],
|
|
368
|
+
"sizeof": native["sizeof"],
|
|
369
|
+
"stats": native["stats"],
|
|
370
|
+
"struct": native["struct"],
|
|
371
|
+
"type": native["type"],
|
|
372
|
+
"types": native["types"],
|
|
373
|
+
"union": native["union"],
|
|
374
|
+
"unregister": native["unregister"],
|
|
375
|
+
"version": native["version"],
|
|
376
|
+
"view": native["view"]
|
|
377
|
+
};
|