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/src/koffi/index.js
CHANGED
|
@@ -6,7 +6,7 @@ import { createRequire } from "node:module";
|
|
|
6
6
|
// ../cnoke/src/abi.js
|
|
7
7
|
import fs from "node:fs";
|
|
8
8
|
function determineAbi() {
|
|
9
|
-
let abi = process.arch;
|
|
9
|
+
let abi = process.arch.toString();
|
|
10
10
|
if (abi == "riscv32" || abi == "riscv64") {
|
|
11
11
|
let buf = readFileHeader(process.execPath, 512);
|
|
12
12
|
let header = decodeElfHeader(buf);
|
|
@@ -94,14 +94,14 @@ function decodeElfHeader(buf) {
|
|
|
94
94
|
}
|
|
95
95
|
|
|
96
96
|
// package.json
|
|
97
|
-
var package_default = { name: "koffi", version: "3.0.
|
|
97
|
+
var package_default = { name: "koffi", version: "3.0.1", cnoke: { api: "../../vendor/node-api-headers", output: "../../bin/Koffi/{{ toolchain }}", node: 16, napi: 8 } };
|
|
98
98
|
|
|
99
99
|
// src/init.js
|
|
100
100
|
var requireNative = createRequire(import.meta.url);
|
|
101
101
|
function detectPlatform() {
|
|
102
102
|
if (process.versions.napi == null || process.versions.napi < package_default.cnoke.napi) {
|
|
103
103
|
let major = parseInt(process.versions.node, 10);
|
|
104
|
-
throw new Error(`This engine is based on Node ${process.versions.node}, but ${package_default.name} does not support the Node ${major}.x branch (
|
|
104
|
+
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})`);
|
|
105
105
|
}
|
|
106
106
|
let abi = determineAbi();
|
|
107
107
|
let pkg2 = `${process.platform}-${process.arch}`;
|
|
@@ -114,9 +114,9 @@ function loadDynamic(root, pkg2, triplets2) {
|
|
|
114
114
|
let roots = [root];
|
|
115
115
|
let native2 = null;
|
|
116
116
|
let err = null;
|
|
117
|
-
if (process
|
|
118
|
-
roots.push(process
|
|
119
|
-
roots.push(process
|
|
117
|
+
if (process["resourcesPath"] != null) {
|
|
118
|
+
roots.push(process["resourcesPath"]);
|
|
119
|
+
roots.push(process["resourcesPath"] + "/node_modules/koffi");
|
|
120
120
|
}
|
|
121
121
|
let names = [
|
|
122
122
|
`${import.meta.dirname}/../../../@koromix/koffi-${pkg2}`,
|
|
@@ -141,27 +141,26 @@ function loadDynamic(root, pkg2, triplets2) {
|
|
|
141
141
|
function wrapNative(native2) {
|
|
142
142
|
let load = native2.load;
|
|
143
143
|
let register = native2.register;
|
|
144
|
-
|
|
145
|
-
native2.
|
|
144
|
+
let introspect = native2.introspect ?? native2.type;
|
|
145
|
+
native2.sizeof = (spec) => introspect(spec).size;
|
|
146
|
+
native2.alignof = (spec) => introspect(spec).alignment;
|
|
146
147
|
native2.offsetof = (spec, name) => {
|
|
147
|
-
let
|
|
148
|
-
if (
|
|
148
|
+
let info = introspect(spec);
|
|
149
|
+
if (info.primitive != "Record")
|
|
149
150
|
throw new TypeError("The offsetof() function can only be used with record types");
|
|
150
|
-
let member =
|
|
151
|
+
let member = info.members[name];
|
|
151
152
|
if (member == null)
|
|
152
|
-
throw new Error(`Record type ${
|
|
153
|
+
throw new Error(`Record type ${info.name} does not have member '${name}'`);
|
|
153
154
|
return member.offset;
|
|
154
155
|
};
|
|
155
156
|
native2.register = (...args) => {
|
|
156
157
|
if (args.length >= 3 && typeof args[1] == "function") {
|
|
157
|
-
process.emitWarning("Using koffi.register() with a custom this value was deprecated in Koffi
|
|
158
|
+
process.emitWarning("Using koffi.register() with a custom this value was deprecated in Koffi 2.17, use function.bind() instead", "DeprecationWarning", "KOFFI009");
|
|
158
159
|
args[1] = args[1].bind(args[0]);
|
|
159
160
|
args = args.slice(1);
|
|
160
161
|
}
|
|
161
162
|
return register(...args);
|
|
162
163
|
};
|
|
163
|
-
native2.resolve = util.deprecate(native2.type, "The koffi.resolve() function was deprecated in Koffi 3.0, use koffi.type() instead", "KOFFI007");
|
|
164
|
-
native2.introspect = util.deprecate(native2.type, "The koffi.introspect() function was deprecated in Koffi 3.0, use koffi.type() instead", "KOFFI008");
|
|
165
164
|
native2.load = (...args) => {
|
|
166
165
|
let lib = load(...args);
|
|
167
166
|
lib.cdecl = util.deprecate((...args2) => lib.func("__cdecl", ...args2), "The koffi.cdecl() function was deprecated in Koffi 2.7, use koffi.func(...) instead", "KOFFI003");
|
|
@@ -170,6 +169,12 @@ function wrapNative(native2) {
|
|
|
170
169
|
lib.thiscall = util.deprecate((...args2) => lib.func("__thiscall", ...args2), 'The koffi.thiscall() function was deprecated in Koffi 2.7, use koffi.func("__thiscall", ...) instead', "KOFFI006");
|
|
171
170
|
return lib;
|
|
172
171
|
};
|
|
172
|
+
if (native2.introspect == null) {
|
|
173
|
+
native2.resolve = util.deprecate(native2.type, "The koffi.resolve() function was deprecated in Koffi 3.0, use koffi.type() instead", "KOFFI007");
|
|
174
|
+
native2.introspect = util.deprecate(native2.type, "The koffi.introspect() function was deprecated in Koffi 3.0, use koffi.type() instead", "KOFFI008");
|
|
175
|
+
} else {
|
|
176
|
+
native2.resolve = native2.type;
|
|
177
|
+
}
|
|
173
178
|
}
|
|
174
179
|
|
|
175
180
|
// src/static.js
|
|
@@ -260,7 +265,91 @@ if (native == null)
|
|
|
260
265
|
if (native.version != version)
|
|
261
266
|
throw new Error("Mismatched native Koffi modules");
|
|
262
267
|
wrapNative(native);
|
|
268
|
+
var mod_LibraryHandle = native.LibraryHandle;
|
|
269
|
+
var mod_TypeObject = native.TypeObject;
|
|
270
|
+
var mod_Union = native.Union;
|
|
271
|
+
var mod_address = native.address;
|
|
272
|
+
var mod_alias = native.alias;
|
|
273
|
+
var mod_alignof = native.alignof;
|
|
274
|
+
var mod_alloc = native.alloc;
|
|
275
|
+
var mod_array = native.array;
|
|
276
|
+
var mod_as = native.as;
|
|
277
|
+
var mod_call = native.call;
|
|
278
|
+
var mod_config = native.config;
|
|
279
|
+
var mod_decode = native.decode;
|
|
280
|
+
var mod_disposable = native.disposable;
|
|
281
|
+
var mod_encode = native.encode;
|
|
282
|
+
var mod_enumeration = native.enumeration;
|
|
283
|
+
var mod_errno = native.errno;
|
|
284
|
+
var mod_extension = native.extension;
|
|
285
|
+
var mod_free = native.free;
|
|
286
|
+
var mod_in = native.in;
|
|
287
|
+
var mod_inout = native.inout;
|
|
288
|
+
var mod_introspect = native.introspect;
|
|
289
|
+
var mod_load = native.load;
|
|
290
|
+
var mod_node = native.node;
|
|
291
|
+
var mod_offsetof = native.offsetof;
|
|
292
|
+
var mod_opaque = native.opaque;
|
|
293
|
+
var mod_os = native.os;
|
|
294
|
+
var mod_out = native.out;
|
|
295
|
+
var mod_pack = native.pack;
|
|
296
|
+
var mod_pointer = native.pointer;
|
|
297
|
+
var mod_proto = native.proto;
|
|
298
|
+
var mod_register = native.register;
|
|
299
|
+
var mod_reset = native.reset;
|
|
300
|
+
var mod_resolve = native.resolve;
|
|
301
|
+
var mod_sizeof = native.sizeof;
|
|
302
|
+
var mod_stats = native.stats;
|
|
303
|
+
var mod_struct = native.struct;
|
|
304
|
+
var mod_type = native.type;
|
|
305
|
+
var mod_types = native.types;
|
|
306
|
+
var mod_union = native.union;
|
|
307
|
+
var mod_unregister = native.unregister;
|
|
308
|
+
var mod_version = native.version;
|
|
309
|
+
var mod_view = native.view;
|
|
263
310
|
var index_default = native;
|
|
264
311
|
export {
|
|
265
|
-
|
|
312
|
+
mod_LibraryHandle as LibraryHandle,
|
|
313
|
+
mod_TypeObject as TypeObject,
|
|
314
|
+
mod_Union as Union,
|
|
315
|
+
mod_address as address,
|
|
316
|
+
mod_alias as alias,
|
|
317
|
+
mod_alignof as alignof,
|
|
318
|
+
mod_alloc as alloc,
|
|
319
|
+
mod_array as array,
|
|
320
|
+
mod_as as as,
|
|
321
|
+
mod_call as call,
|
|
322
|
+
mod_config as config,
|
|
323
|
+
mod_decode as decode,
|
|
324
|
+
index_default as default,
|
|
325
|
+
mod_disposable as disposable,
|
|
326
|
+
mod_encode as encode,
|
|
327
|
+
mod_enumeration as enumeration,
|
|
328
|
+
mod_errno as errno,
|
|
329
|
+
mod_extension as extension,
|
|
330
|
+
mod_free as free,
|
|
331
|
+
mod_in as in,
|
|
332
|
+
mod_inout as inout,
|
|
333
|
+
mod_introspect as introspect,
|
|
334
|
+
mod_load as load,
|
|
335
|
+
mod_node as node,
|
|
336
|
+
mod_offsetof as offsetof,
|
|
337
|
+
mod_opaque as opaque,
|
|
338
|
+
mod_os as os,
|
|
339
|
+
mod_out as out,
|
|
340
|
+
mod_pack as pack,
|
|
341
|
+
mod_pointer as pointer,
|
|
342
|
+
mod_proto as proto,
|
|
343
|
+
mod_register as register,
|
|
344
|
+
mod_reset as reset,
|
|
345
|
+
mod_resolve as resolve,
|
|
346
|
+
mod_sizeof as sizeof,
|
|
347
|
+
mod_stats as stats,
|
|
348
|
+
mod_struct as struct,
|
|
349
|
+
mod_type as type,
|
|
350
|
+
mod_types as types,
|
|
351
|
+
mod_union as union,
|
|
352
|
+
mod_unregister as unregister,
|
|
353
|
+
mod_version as version,
|
|
354
|
+
mod_view as view
|
|
266
355
|
};
|
package/src/koffi/indirect.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({
|
|
@@ -324,4 +329,48 @@ if (native == null)
|
|
|
324
329
|
if (native.version != version)
|
|
325
330
|
throw new Error("Mismatched native Koffi modules");
|
|
326
331
|
wrapNative2(native);
|
|
327
|
-
module.exports =
|
|
332
|
+
module.exports = {
|
|
333
|
+
default: native,
|
|
334
|
+
"LibraryHandle": native["LibraryHandle"],
|
|
335
|
+
"TypeObject": native["TypeObject"],
|
|
336
|
+
"Union": native["Union"],
|
|
337
|
+
"address": native["address"],
|
|
338
|
+
"alias": native["alias"],
|
|
339
|
+
"alignof": native["alignof"],
|
|
340
|
+
"alloc": native["alloc"],
|
|
341
|
+
"array": native["array"],
|
|
342
|
+
"as": native["as"],
|
|
343
|
+
"call": native["call"],
|
|
344
|
+
"config": native["config"],
|
|
345
|
+
"decode": native["decode"],
|
|
346
|
+
"disposable": native["disposable"],
|
|
347
|
+
"encode": native["encode"],
|
|
348
|
+
"enumeration": native["enumeration"],
|
|
349
|
+
"errno": native["errno"],
|
|
350
|
+
"extension": native["extension"],
|
|
351
|
+
"free": native["free"],
|
|
352
|
+
"in": native["in"],
|
|
353
|
+
"inout": native["inout"],
|
|
354
|
+
"introspect": native["introspect"],
|
|
355
|
+
"load": native["load"],
|
|
356
|
+
"node": native["node"],
|
|
357
|
+
"offsetof": native["offsetof"],
|
|
358
|
+
"opaque": native["opaque"],
|
|
359
|
+
"os": native["os"],
|
|
360
|
+
"out": native["out"],
|
|
361
|
+
"pack": native["pack"],
|
|
362
|
+
"pointer": native["pointer"],
|
|
363
|
+
"proto": native["proto"],
|
|
364
|
+
"register": native["register"],
|
|
365
|
+
"reset": native["reset"],
|
|
366
|
+
"resolve": native["resolve"],
|
|
367
|
+
"sizeof": native["sizeof"],
|
|
368
|
+
"stats": native["stats"],
|
|
369
|
+
"struct": native["struct"],
|
|
370
|
+
"type": native["type"],
|
|
371
|
+
"types": native["types"],
|
|
372
|
+
"union": native["union"],
|
|
373
|
+
"unregister": native["unregister"],
|
|
374
|
+
"version": native["version"],
|
|
375
|
+
"view": native["view"]
|
|
376
|
+
};
|
package/src/koffi/indirect.js
CHANGED
|
@@ -6,7 +6,7 @@ import { createRequire } from "node:module";
|
|
|
6
6
|
// ../cnoke/src/abi.js
|
|
7
7
|
import fs from "node:fs";
|
|
8
8
|
function determineAbi() {
|
|
9
|
-
let abi = process.arch;
|
|
9
|
+
let abi = process.arch.toString();
|
|
10
10
|
if (abi == "riscv32" || abi == "riscv64") {
|
|
11
11
|
let buf = readFileHeader(process.execPath, 512);
|
|
12
12
|
let header = decodeElfHeader(buf);
|
|
@@ -94,14 +94,14 @@ function decodeElfHeader(buf) {
|
|
|
94
94
|
}
|
|
95
95
|
|
|
96
96
|
// package.json
|
|
97
|
-
var package_default = { name: "koffi", version: "3.0.
|
|
97
|
+
var package_default = { name: "koffi", version: "3.0.1", cnoke: { api: "../../vendor/node-api-headers", output: "../../bin/Koffi/{{ toolchain }}", node: 16, napi: 8 } };
|
|
98
98
|
|
|
99
99
|
// src/init.js
|
|
100
100
|
var requireNative = createRequire(import.meta.url);
|
|
101
101
|
function detectPlatform() {
|
|
102
102
|
if (process.versions.napi == null || process.versions.napi < package_default.cnoke.napi) {
|
|
103
103
|
let major = parseInt(process.versions.node, 10);
|
|
104
|
-
throw new Error(`This engine is based on Node ${process.versions.node}, but ${package_default.name} does not support the Node ${major}.x branch (
|
|
104
|
+
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})`);
|
|
105
105
|
}
|
|
106
106
|
let abi = determineAbi();
|
|
107
107
|
let pkg2 = `${process.platform}-${process.arch}`;
|
|
@@ -114,9 +114,9 @@ function loadDynamic(root, pkg2, triplets2) {
|
|
|
114
114
|
let roots = [root];
|
|
115
115
|
let native2 = null;
|
|
116
116
|
let err = null;
|
|
117
|
-
if (process
|
|
118
|
-
roots.push(process
|
|
119
|
-
roots.push(process
|
|
117
|
+
if (process["resourcesPath"] != null) {
|
|
118
|
+
roots.push(process["resourcesPath"]);
|
|
119
|
+
roots.push(process["resourcesPath"] + "/node_modules/koffi");
|
|
120
120
|
}
|
|
121
121
|
let names = [
|
|
122
122
|
`${import.meta.dirname}/../../../@koromix/koffi-${pkg2}`,
|
|
@@ -141,27 +141,26 @@ function loadDynamic(root, pkg2, triplets2) {
|
|
|
141
141
|
function wrapNative(native2) {
|
|
142
142
|
let load = native2.load;
|
|
143
143
|
let register = native2.register;
|
|
144
|
-
|
|
145
|
-
native2.
|
|
144
|
+
let introspect = native2.introspect ?? native2.type;
|
|
145
|
+
native2.sizeof = (spec) => introspect(spec).size;
|
|
146
|
+
native2.alignof = (spec) => introspect(spec).alignment;
|
|
146
147
|
native2.offsetof = (spec, name) => {
|
|
147
|
-
let
|
|
148
|
-
if (
|
|
148
|
+
let info = introspect(spec);
|
|
149
|
+
if (info.primitive != "Record")
|
|
149
150
|
throw new TypeError("The offsetof() function can only be used with record types");
|
|
150
|
-
let member =
|
|
151
|
+
let member = info.members[name];
|
|
151
152
|
if (member == null)
|
|
152
|
-
throw new Error(`Record type ${
|
|
153
|
+
throw new Error(`Record type ${info.name} does not have member '${name}'`);
|
|
153
154
|
return member.offset;
|
|
154
155
|
};
|
|
155
156
|
native2.register = (...args) => {
|
|
156
157
|
if (args.length >= 3 && typeof args[1] == "function") {
|
|
157
|
-
process.emitWarning("Using koffi.register() with a custom this value was deprecated in Koffi
|
|
158
|
+
process.emitWarning("Using koffi.register() with a custom this value was deprecated in Koffi 2.17, use function.bind() instead", "DeprecationWarning", "KOFFI009");
|
|
158
159
|
args[1] = args[1].bind(args[0]);
|
|
159
160
|
args = args.slice(1);
|
|
160
161
|
}
|
|
161
162
|
return register(...args);
|
|
162
163
|
};
|
|
163
|
-
native2.resolve = util.deprecate(native2.type, "The koffi.resolve() function was deprecated in Koffi 3.0, use koffi.type() instead", "KOFFI007");
|
|
164
|
-
native2.introspect = util.deprecate(native2.type, "The koffi.introspect() function was deprecated in Koffi 3.0, use koffi.type() instead", "KOFFI008");
|
|
165
164
|
native2.load = (...args) => {
|
|
166
165
|
let lib = load(...args);
|
|
167
166
|
lib.cdecl = util.deprecate((...args2) => lib.func("__cdecl", ...args2), "The koffi.cdecl() function was deprecated in Koffi 2.7, use koffi.func(...) instead", "KOFFI003");
|
|
@@ -170,6 +169,12 @@ function wrapNative(native2) {
|
|
|
170
169
|
lib.thiscall = util.deprecate((...args2) => lib.func("__thiscall", ...args2), 'The koffi.thiscall() function was deprecated in Koffi 2.7, use koffi.func("__thiscall", ...) instead', "KOFFI006");
|
|
171
170
|
return lib;
|
|
172
171
|
};
|
|
172
|
+
if (native2.introspect == null) {
|
|
173
|
+
native2.resolve = util.deprecate(native2.type, "The koffi.resolve() function was deprecated in Koffi 3.0, use koffi.type() instead", "KOFFI007");
|
|
174
|
+
native2.introspect = util.deprecate(native2.type, "The koffi.introspect() function was deprecated in Koffi 3.0, use koffi.type() instead", "KOFFI008");
|
|
175
|
+
} else {
|
|
176
|
+
native2.resolve = native2.type;
|
|
177
|
+
}
|
|
173
178
|
}
|
|
174
179
|
|
|
175
180
|
// src/static.js
|
|
@@ -185,7 +190,91 @@ if (native == null)
|
|
|
185
190
|
if (native.version != version)
|
|
186
191
|
throw new Error("Mismatched native Koffi modules");
|
|
187
192
|
wrapNative(native);
|
|
193
|
+
var mod_LibraryHandle = native.LibraryHandle;
|
|
194
|
+
var mod_TypeObject = native.TypeObject;
|
|
195
|
+
var mod_Union = native.Union;
|
|
196
|
+
var mod_address = native.address;
|
|
197
|
+
var mod_alias = native.alias;
|
|
198
|
+
var mod_alignof = native.alignof;
|
|
199
|
+
var mod_alloc = native.alloc;
|
|
200
|
+
var mod_array = native.array;
|
|
201
|
+
var mod_as = native.as;
|
|
202
|
+
var mod_call = native.call;
|
|
203
|
+
var mod_config = native.config;
|
|
204
|
+
var mod_decode = native.decode;
|
|
205
|
+
var mod_disposable = native.disposable;
|
|
206
|
+
var mod_encode = native.encode;
|
|
207
|
+
var mod_enumeration = native.enumeration;
|
|
208
|
+
var mod_errno = native.errno;
|
|
209
|
+
var mod_extension = native.extension;
|
|
210
|
+
var mod_free = native.free;
|
|
211
|
+
var mod_in = native.in;
|
|
212
|
+
var mod_inout = native.inout;
|
|
213
|
+
var mod_introspect = native.introspect;
|
|
214
|
+
var mod_load = native.load;
|
|
215
|
+
var mod_node = native.node;
|
|
216
|
+
var mod_offsetof = native.offsetof;
|
|
217
|
+
var mod_opaque = native.opaque;
|
|
218
|
+
var mod_os = native.os;
|
|
219
|
+
var mod_out = native.out;
|
|
220
|
+
var mod_pack = native.pack;
|
|
221
|
+
var mod_pointer = native.pointer;
|
|
222
|
+
var mod_proto = native.proto;
|
|
223
|
+
var mod_register = native.register;
|
|
224
|
+
var mod_reset = native.reset;
|
|
225
|
+
var mod_resolve = native.resolve;
|
|
226
|
+
var mod_sizeof = native.sizeof;
|
|
227
|
+
var mod_stats = native.stats;
|
|
228
|
+
var mod_struct = native.struct;
|
|
229
|
+
var mod_type = native.type;
|
|
230
|
+
var mod_types = native.types;
|
|
231
|
+
var mod_union = native.union;
|
|
232
|
+
var mod_unregister = native.unregister;
|
|
233
|
+
var mod_version = native.version;
|
|
234
|
+
var mod_view = native.view;
|
|
188
235
|
var index_default = native;
|
|
189
236
|
export {
|
|
190
|
-
|
|
237
|
+
mod_LibraryHandle as LibraryHandle,
|
|
238
|
+
mod_TypeObject as TypeObject,
|
|
239
|
+
mod_Union as Union,
|
|
240
|
+
mod_address as address,
|
|
241
|
+
mod_alias as alias,
|
|
242
|
+
mod_alignof as alignof,
|
|
243
|
+
mod_alloc as alloc,
|
|
244
|
+
mod_array as array,
|
|
245
|
+
mod_as as as,
|
|
246
|
+
mod_call as call,
|
|
247
|
+
mod_config as config,
|
|
248
|
+
mod_decode as decode,
|
|
249
|
+
index_default as default,
|
|
250
|
+
mod_disposable as disposable,
|
|
251
|
+
mod_encode as encode,
|
|
252
|
+
mod_enumeration as enumeration,
|
|
253
|
+
mod_errno as errno,
|
|
254
|
+
mod_extension as extension,
|
|
255
|
+
mod_free as free,
|
|
256
|
+
mod_in as in,
|
|
257
|
+
mod_inout as inout,
|
|
258
|
+
mod_introspect as introspect,
|
|
259
|
+
mod_load as load,
|
|
260
|
+
mod_node as node,
|
|
261
|
+
mod_offsetof as offsetof,
|
|
262
|
+
mod_opaque as opaque,
|
|
263
|
+
mod_os as os,
|
|
264
|
+
mod_out as out,
|
|
265
|
+
mod_pack as pack,
|
|
266
|
+
mod_pointer as pointer,
|
|
267
|
+
mod_proto as proto,
|
|
268
|
+
mod_register as register,
|
|
269
|
+
mod_reset as reset,
|
|
270
|
+
mod_resolve as resolve,
|
|
271
|
+
mod_sizeof as sizeof,
|
|
272
|
+
mod_stats as stats,
|
|
273
|
+
mod_struct as struct,
|
|
274
|
+
mod_type as type,
|
|
275
|
+
mod_types as types,
|
|
276
|
+
mod_union as union,
|
|
277
|
+
mod_unregister as unregister,
|
|
278
|
+
mod_version as version,
|
|
279
|
+
mod_view as view
|
|
191
280
|
};
|