koffi 2.8.10 → 2.9.0-beta.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.
Files changed (47) hide show
  1. package/CHANGELOG.md +12 -1
  2. package/build/koffi/darwin_arm64/koffi.node +0 -0
  3. package/build/koffi/darwin_x64/koffi.node +0 -0
  4. package/build/koffi/freebsd_arm64/koffi.node +0 -0
  5. package/build/koffi/freebsd_i386/koffi.node +0 -0
  6. package/build/koffi/freebsd_x64/koffi.node +0 -0
  7. package/build/koffi/linux_arm32/koffi.node +0 -0
  8. package/build/koffi/linux_arm64/koffi.node +0 -0
  9. package/build/koffi/linux_i386/koffi.node +0 -0
  10. package/build/koffi/linux_riscv64/koffi.node +0 -0
  11. package/build/koffi/linux_x64/koffi.node +0 -0
  12. package/build/koffi/musl_x64/koffi.node +0 -0
  13. package/build/koffi/openbsd_i386/koffi.node +0 -0
  14. package/build/koffi/openbsd_x64/koffi.node +0 -0
  15. package/build/koffi/windows_arm64/koffi.node +0 -0
  16. package/build/koffi/{win32_ia32 → windows_i386}/koffi.node +0 -0
  17. package/build/koffi/{win32_x64 → windows_x64}/koffi.node +0 -0
  18. package/doc/contribute.md +3 -2
  19. package/doc/input.md +23 -13
  20. package/index.js +160 -97
  21. package/indirect.js +113 -81
  22. package/package.json +3 -3
  23. package/src/koffi/src/abi_arm32.cc +23 -0
  24. package/src/koffi/src/abi_arm64.cc +30 -0
  25. package/src/koffi/src/abi_riscv64.cc +22 -0
  26. package/src/koffi/src/abi_x64_sysv.cc +23 -0
  27. package/src/koffi/src/abi_x64_win.cc +23 -0
  28. package/src/koffi/src/abi_x86.cc +22 -0
  29. package/src/koffi/src/call.cc +155 -5
  30. package/src/koffi/src/call.hh +3 -0
  31. package/src/koffi/src/ffi.cc +26 -4
  32. package/src/koffi/src/ffi.hh +4 -0
  33. package/src/koffi/src/init.js +122 -0
  34. package/src/koffi/src/util.cc +85 -2
  35. package/src/koffi/src/util.hh +13 -0
  36. package/build/koffi/freebsd_ia32/koffi.node +0 -0
  37. package/build/koffi/linux_armhf/koffi.node +0 -0
  38. package/build/koffi/linux_ia32/koffi.node +0 -0
  39. package/build/koffi/linux_riscv64d/koffi.node +0 -0
  40. package/build/koffi/openbsd_ia32/koffi.node +0 -0
  41. package/build/koffi/win32_arm64/koffi.node +0 -0
  42. /package/build/koffi/{win32_arm64 → windows_arm64}/koffi.exp +0 -0
  43. /package/build/koffi/{win32_arm64 → windows_arm64}/koffi.lib +0 -0
  44. /package/build/koffi/{win32_ia32 → windows_i386}/koffi.exp +0 -0
  45. /package/build/koffi/{win32_ia32 → windows_i386}/koffi.lib +0 -0
  46. /package/build/koffi/{win32_x64 → windows_x64}/koffi.exp +0 -0
  47. /package/build/koffi/{win32_x64 → windows_x64}/koffi.lib +0 -0
package/CHANGELOG.md CHANGED
@@ -2,12 +2,23 @@
2
2
 
3
3
  ## Version history
4
4
 
5
+ ### Koffi 2.9
6
+
7
+ #### Koffi 2.9.0-beta.1 (2024-07-11)
8
+
9
+ - Add support for char32_t and wchar_t (wide) strings
10
+ - Include Linux/musl x64 prebuild (based on Alpine)
11
+
5
12
  ### Koffi 2.8
6
13
 
7
- #### Koffi 2.8.10 (2024-06-17)
14
+ #### Koffi 2.8.11 (2024-06-19)
8
15
 
9
16
  - Work around MSVC compiler bug introduced in Visual Studio 17.10
10
17
 
18
+ ```{warning}
19
+ Use on platforms without pre-built binaries is broken in Koffi 2.8.10, skip this version.
20
+ ```
21
+
11
22
  #### Koffi 2.8.9 (2024-05-17)
12
23
 
13
24
  - Fix ABI issue regarding bool return values on x86_64 (and possibly other platforms)
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
package/doc/contribute.md CHANGED
@@ -72,9 +72,10 @@ These machines are not included directly in this repository (for license and siz
72
72
  For example, if you want to run the tests on Debian ARM64, run the following commands:
73
73
 
74
74
  ```sh
75
- cd src/koffi/tools/
75
+ cd deploy/qemu/
76
+
76
77
  wget -q -O- https://koromix.dev/files/machines/qemu_debian_arm64.tar.zst | zstd -d | tar xv
77
- sha256sum -c --ignore-missing registry/sha256sum.txt
78
+ b3sum -c b3sum.txt
78
79
  ```
79
80
 
80
81
  Note that the machine disk content may change each time the machine runs, so the checksum test will fail once a machine has been used at least once.
package/doc/input.md CHANGED
@@ -18,6 +18,7 @@ int16, int16_t | Number (integer) | 2 | Signed |
18
18
  uint16, uint16_t | Number (integer) | 2 | Unsigned |
19
19
  short | Number (integer) | 2 | Signed |
20
20
  ushort, unsigned short | Number (integer) | 2 | Unsigned |
21
+ char32, char32_t | Number (integer) | 4 | Signed |
21
22
  int32, int32_t | Number (integer) | 4 | Signed |
22
23
  uint32, uint32_t | Number (integer) | 4 | Unsigned |
23
24
  int | Number (integer) | 4 | Signed |
@@ -35,18 +36,20 @@ Koffi also accepts BigInt values when converting from JS to C integers. If the v
35
36
 
36
37
  Koffi defines a few more types that can change size depending on the OS and the architecture:
37
38
 
38
- C type | JS type | Signedness | Note
39
- ---------------- | ---------------- | ---------- | ------------------------------------------------
40
- bool | Boolean | | Usually one byte
41
- long | Number (integer) | Signed | 4 or 8 bytes depending on platform (LP64, LLP64)
42
- ulong | Number (integer) | Unsigned | 4 or 8 bytes depending on platform (LP64, LLP64)
43
- unsigned long | Number (integer) | Unsigned | 4 or 8 bytes depending on platform (LP64, LLP64)
44
- intptr | Number (integer) | Signed | 4 or 8 bytes depending on register width
45
- intptr_t | Number (integer) | Signed | 4 or 8 bytes depending on register width
46
- uintptr | Number (integer) | Unsigned | 4 or 8 bytes depending on register width
47
- uintptr_t | Number (integer) | Unsigned | 4 or 8 bytes depending on register width
48
- str, string | String | | JS strings are converted to and from UTF-8
49
- str16, string16 | String | | JS strings are converted to and from UTF-16 (LE)
39
+ C type | JS type | Signedness | Note
40
+ ---------------- | ---------------- | ----------- | ------------------------------------------------
41
+ bool | Boolean | | Usually one byte
42
+ long | Number (integer) | Signed | 4 or 8 bytes depending on platform (LP64, LLP64)
43
+ ulong | Number (integer) | Unsigned | 4 or 8 bytes depending on platform (LP64, LLP64)
44
+ unsigned long | Number (integer) | Unsigned | 4 or 8 bytes depending on platform (LP64, LLP64)
45
+ intptr | Number (integer) | Signed | 4 or 8 bytes depending on register width
46
+ intptr_t | Number (integer) | Signed | 4 or 8 bytes depending on register width
47
+ uintptr | Number (integer) | Unsigned | 4 or 8 bytes depending on register width
48
+ uintptr_t | Number (integer) | Unsigned | 4 or 8 bytes depending on register width
49
+ wchar_t | Number (integer) | *Undefined* | 2 bytes on Windows, 4 bytes Linux, macOS and BSD
50
+ str, string | String | | JS strings are converted to and from UTF-8
51
+ str16, string16 | String | | JS strings are converted to and from UTF-16 (LE)
52
+ str32, string32 | String | | JS strings are converted to and from UTF-32 (LE)
50
53
 
51
54
  Primitive types can be specified by name (in a string) or through `koffi.types`:
52
55
 
@@ -384,12 +387,19 @@ The short C-like syntax was introduced in Koffi 2.7.1, use `koffi.array()` for o
384
387
 
385
388
  ### Fixed-size string buffers
386
389
 
390
+ *Changed in Koffi 2.9.0*
391
+
387
392
  Koffi can also convert JS strings to fixed-sized arrays in the following cases:
388
393
 
389
394
  - **char arrays** are filled with the UTF-8 encoded string, truncated if needed. The buffer is always NUL-terminated.
390
395
  - **char16 (or char16_t) arrays** are filled with the UTF-16 encoded string, truncated if needed. The buffer is always NUL-terminated.
396
+ - **char32 (or char32_t) arrays** are filled with the UTF-32 encoded string, truncated if needed. The buffer is always NUL-terminated.
397
+
398
+ ```{note}
399
+ Support for UTF-32 and wchar_t (wide) strings was introduced in Koffi 2.9.0.
400
+ ```
391
401
 
392
- The reverse case is also true, Koffi can convert a C fixed-size buffer to a JS string. This happens by default for char, char16 and char16_t arrays, but you can also explicitly ask for this with the `String` array hint (e.g. `koffi.array('char', 8, 'String')`).
402
+ The reverse case is also true, Koffi can convert a C fixed-size buffer to a JS string. This happens by default for char, char16_t and char32_t arrays, but you can also explicitly ask for this with the `String` array hint (e.g. `koffi.array('char', 8, 'String')`).
393
403
 
394
404
  ### Dynamic arrays (pointers)
395
405
 
package/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  var __getOwnPropNames = Object.getOwnPropertyNames;
3
- var __commonJS = (cb, mod) => function __require() {
4
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
3
+ var __commonJS = (cb, mod3) => function __require() {
4
+ return mod3 || (0, cb[__getOwnPropNames(cb)[0]])((mod3 = { exports: {} }).exports, mod3), mod3.exports;
5
5
  };
6
6
 
7
7
  // ../../bin/Koffi/package/src/cnoke/src/tools.js
@@ -11,7 +11,7 @@ var require_tools = __commonJS({
11
11
  var crypto = require("crypto");
12
12
  var fs2 = require("fs");
13
13
  var http = require("https");
14
- var path = require("path");
14
+ var path2 = require("path");
15
15
  var zlib = require("zlib");
16
16
  async function download_http(url, dest) {
17
17
  console.log(">> Downloading " + url);
@@ -107,7 +107,7 @@ var require_tools = __commonJS({
107
107
  data = data.subarray(0, header.size);
108
108
  if (header.type == "0" || header.type == "7") {
109
109
  let filename3 = dest_dir + "/" + header.filename;
110
- let dirname = path.dirname(filename3);
110
+ let dirname = path2.dirname(filename3);
111
111
  fs2.mkdirSync(dirname, { recursive: true, mode: 493 });
112
112
  fs2.writeFileSync(filename3, data, { mode: header.mode });
113
113
  } else if (header.type == "5") {
@@ -151,21 +151,21 @@ var require_tools = __commonJS({
151
151
  reader.on("end", resolve);
152
152
  });
153
153
  }
154
- function path_is_absolute(path2) {
155
- if (process.platform == "win32" && path2.match(/^[a-zA-Z]:/))
156
- path2 = path2.substr(2);
157
- return is_path_separator(path2[0]);
154
+ function path_is_absolute(path3) {
155
+ if (process.platform == "win32" && path3.match(/^[a-zA-Z]:/))
156
+ path3 = path3.substr(2);
157
+ return is_path_separator(path3[0]);
158
158
  }
159
- function path_has_dotdot(path2) {
159
+ function path_has_dotdot(path3) {
160
160
  let start = 0;
161
161
  for (; ; ) {
162
- let offset = path2.indexOf("..", start);
162
+ let offset = path3.indexOf("..", start);
163
163
  if (offset < 0)
164
164
  break;
165
165
  start = offset + 2;
166
- if (offset && !is_path_separator(path2[offset - 1]))
166
+ if (offset && !is_path_separator(path3[offset - 1]))
167
167
  continue;
168
- if (offset + 2 < path2.length && !is_path_separator(path2[offset + 2]))
168
+ if (offset + 2 < path3.length && !is_path_separator(path3[offset + 2]))
169
169
  continue;
170
170
  return true;
171
171
  }
@@ -179,8 +179,8 @@ var require_tools = __commonJS({
179
179
  return false;
180
180
  }
181
181
  function determine_arch2() {
182
- let arch2 = process.arch;
183
- if (arch2 == "riscv32" || arch2 == "riscv64") {
182
+ let arch = process.arch;
183
+ if (arch == "riscv32" || arch == "riscv64") {
184
184
  let buf = read_file_header(process.execPath, 512);
185
185
  let header = decode_elf_header(buf);
186
186
  let float_abi = header.e_flags & 6;
@@ -191,32 +191,32 @@ var require_tools = __commonJS({
191
191
  break;
192
192
  case 2:
193
193
  {
194
- arch2 += "f";
194
+ arch += "f";
195
195
  }
196
196
  break;
197
197
  case 4:
198
198
  {
199
- arch2 += "d";
199
+ arch += "d";
200
200
  }
201
201
  break;
202
202
  case 6:
203
203
  {
204
- arch2 += "q";
204
+ arch += "q";
205
205
  }
206
206
  break;
207
207
  }
208
- } else if (arch2 == "arm") {
208
+ } else if (arch == "arm") {
209
209
  let buf = read_file_header(process.execPath, 512);
210
210
  let header = decode_elf_header(buf);
211
211
  if (header.e_flags & 1024) {
212
- arch2 += "hf";
212
+ arch += "hf";
213
213
  } else if (header.e_flags & 512) {
214
- arch2 += "sf";
214
+ arch += "sf";
215
215
  } else {
216
216
  throw new Error("Unknown ARM floating-point ABI");
217
217
  }
218
218
  }
219
- return arch2;
219
+ return arch;
220
220
  }
221
221
  function read_file_header(filename2, read) {
222
222
  let fd = null;
@@ -305,12 +305,12 @@ var require_tools = __commonJS({
305
305
  }
306
306
  return header;
307
307
  }
308
- function unlink_recursive(path2) {
308
+ function unlink_recursive(path3) {
309
309
  try {
310
310
  if (fs2.rmSync != null) {
311
- fs2.rmSync(path2, { recursive: true, maxRetries: process.platform == "win32" ? 3 : 0 });
311
+ fs2.rmSync(path3, { recursive: true, maxRetries: process.platform == "win32" ? 3 : 0 });
312
312
  } else {
313
- fs2.rmdirSync(path2, { recursive: true, maxRetries: process.platform == "win32" ? 3 : 0 });
313
+ fs2.rmdirSync(path3, { recursive: true, maxRetries: process.platform == "win32" ? 3 : 0 });
314
314
  }
315
315
  } catch (err) {
316
316
  if (err.code !== "ENOENT")
@@ -363,8 +363,8 @@ var require_package = __commonJS({
363
363
  "../../bin/Koffi/package/src/koffi/package.json"(exports2, module2) {
364
364
  module2.exports = {
365
365
  name: "koffi",
366
- version: "2.8.10",
367
- stable: "2.8.10",
366
+ version: "2.9.0-beta.1",
367
+ stable: "2.8.11",
368
368
  description: "Fast and simple C FFI (foreign function interface) for Node.js",
369
369
  keywords: [
370
370
  "foreign",
@@ -408,141 +408,204 @@ var require_package = __commonJS({
408
408
  }
409
409
  });
410
410
 
411
- // ../../bin/Koffi/package/src/koffi/index.js
412
- var util = require("util");
413
- var fs = require("fs");
414
- var { get_napi_version, determine_arch } = require_tools();
415
- var pkg = require_package();
416
- if (process.versions.napi == null || process.versions.napi < pkg.cnoke.napi) {
417
- let major = parseInt(process.versions.node, 10);
418
- let required = get_napi_version(pkg.cnoke.napi, major);
419
- if (required != null) {
420
- throw new Error(`This engine is based on Node ${process.versions.node}, but ${pkg.name} requires Node >= ${required} in the Node ${major}.x branch (N-API >= ${pkg.cnoke.napi})`);
421
- } else {
422
- throw new Error(`This engine is based on Node ${process.versions.node}, but ${pkg.name} does not support the Node ${major}.x branch (N-API < ${pkg.cnoke.napi})`);
411
+ // ../../bin/Koffi/package/src/koffi/src/init.js
412
+ var require_init = __commonJS({
413
+ "../../bin/Koffi/package/src/koffi/src/init.js"(exports, module) {
414
+ var fs = require("fs");
415
+ var path = require("path");
416
+ var util = require("util");
417
+ var { get_napi_version, determine_arch } = require_tools();
418
+ var pkg = require_package();
419
+ function detect() {
420
+ if (process.versions.napi == null || process.versions.napi < pkg.cnoke.napi) {
421
+ let major = parseInt(process.versions.node, 10);
422
+ let required = get_napi_version(pkg.cnoke.napi, major);
423
+ if (required != null) {
424
+ throw new Error(`This engine is based on Node ${process.versions.node}, but ${pkg.name} requires Node >= ${required} in the Node ${major}.x branch (N-API >= ${pkg.cnoke.napi})`);
425
+ } else {
426
+ throw new Error(`This engine is based on Node ${process.versions.node}, but ${pkg.name} does not support the Node ${major}.x branch (N-API < ${pkg.cnoke.napi})`);
427
+ }
428
+ }
429
+ let arch = determine_arch();
430
+ let triplet3 = `${process.platform}_${arch}`;
431
+ return triplet3;
432
+ }
433
+ function init(triplet, native) {
434
+ if (native == null) {
435
+ let roots = [path.join(__dirname, "..")];
436
+ let triplets = [triplet];
437
+ if (process.resourcesPath != null)
438
+ roots.push(process.resourcesPath);
439
+ if (triplet.startsWith("linux_")) {
440
+ let musl = triplet.replace(/^linux_/, "musl_");
441
+ triplets.push(musl);
442
+ }
443
+ let filenames = roots.flatMap((root) => triplets.flatMap((triplet3) => [
444
+ `${root}/build/koffi/${triplet3}/koffi.node`,
445
+ `${root}/koffi/${triplet3}/koffi.node`,
446
+ `${root}/node_modules/koffi/build/koffi/${triplet3}/koffi.node`,
447
+ `${root}/../../bin/Koffi/${triplet3}/koffi.node`
448
+ ]));
449
+ let first_err = null;
450
+ for (let filename of filenames) {
451
+ if (!fs.existsSync(filename))
452
+ continue;
453
+ try {
454
+ native = eval("require")(filename);
455
+ } catch (err) {
456
+ if (first_err == null)
457
+ first_err = err;
458
+ continue;
459
+ }
460
+ break;
461
+ }
462
+ if (first_err != null)
463
+ throw first_err;
464
+ }
465
+ if (native == null)
466
+ throw new Error("Cannot find the native Koffi module; did you bundle it correctly?");
467
+ if (native.version != pkg.version)
468
+ throw new Error("Mismatched native Koffi modules");
469
+ let mod = wrap(native);
470
+ return mod;
471
+ }
472
+ function wrap(native3) {
473
+ let obj = {
474
+ ...native3,
475
+ // Deprecated functions
476
+ handle: util.deprecate(native3.opaque, "The koffi.handle() function was deprecated in Koffi 2.1, use koffi.opaque() instead", "KOFFI001"),
477
+ callback: util.deprecate(native3.proto, "The koffi.callback() function was deprecated in Koffi 2.4, use koffi.proto() instead", "KOFFI002")
478
+ };
479
+ obj.load = (...args) => {
480
+ let lib = native3.load(...args);
481
+ lib.cdecl = util.deprecate((...args2) => lib.func("__cdecl", ...args2), "The koffi.cdecl() function was deprecated in Koffi 2.7, use koffi.func(...) instead", "KOFFI003");
482
+ lib.stdcall = util.deprecate((...args2) => lib.func("__stdcall", ...args2), 'The koffi.stdcall() function was deprecated in Koffi 2.7, use koffi.func("__stdcall", ...) instead', "KOFFI004");
483
+ lib.fastcall = util.deprecate((...args2) => lib.func("__fastcall", ...args2), 'The koffi.fastcall() function was deprecated in Koffi 2.7, use koffi.func("__fastcall", ...) instead', "KOFFI005");
484
+ 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");
485
+ return lib;
486
+ };
487
+ return obj;
488
+ }
489
+ module.exports = {
490
+ detect,
491
+ init
492
+ };
423
493
  }
424
- }
425
- var arch = determine_arch();
426
- var triplet = `${process.platform}_${arch}`;
427
- var native = null;
494
+ });
495
+
496
+ // ../../bin/Koffi/package/src/koffi/index.js
497
+ var { detect: detect2, init: init2 } = require_init();
498
+ var triplet2 = detect2();
499
+ var native2 = null;
428
500
  try {
429
- switch (triplet) {
501
+ switch (triplet2) {
430
502
  case "darwin_arm64":
431
503
  {
432
- native = require("./build/koffi/darwin_arm64/koffi.node");
504
+ native2 = require("./build/koffi/darwin_arm64/koffi.node");
433
505
  }
434
506
  break;
435
507
  case "darwin_x64":
436
508
  {
437
- native = require("./build/koffi/darwin_x64/koffi.node");
509
+ native2 = require("./build/koffi/darwin_x64/koffi.node");
438
510
  }
439
511
  break;
440
512
  case "freebsd_arm64":
441
513
  {
442
- native = require("./build/koffi/freebsd_arm64/koffi.node");
514
+ native2 = require("./build/koffi/freebsd_arm64/koffi.node");
443
515
  }
444
516
  break;
445
517
  case "freebsd_ia32":
446
518
  {
447
- native = require("./build/koffi/freebsd_ia32/koffi.node");
519
+ native2 = require("./build/koffi/freebsd_ia32/koffi.node");
448
520
  }
449
521
  break;
450
522
  case "freebsd_x64":
451
523
  {
452
- native = require("./build/koffi/freebsd_x64/koffi.node");
524
+ native2 = require("./build/koffi/freebsd_x64/koffi.node");
453
525
  }
454
526
  break;
455
527
  case "linux_armhf":
456
528
  {
457
- native = require("./build/koffi/linux_armhf/koffi.node");
529
+ native2 = require("./build/koffi/linux_armhf/koffi.node");
458
530
  }
459
531
  break;
460
532
  case "linux_arm64":
461
533
  {
462
- native = require("./build/koffi/linux_arm64/koffi.node");
534
+ native2 = require("./build/koffi/linux_arm64/koffi.node");
463
535
  }
464
536
  break;
465
537
  case "linux_ia32":
466
538
  {
467
- native = require("./build/koffi/linux_ia32/koffi.node");
539
+ native2 = require("./build/koffi/linux_ia32/koffi.node");
468
540
  }
469
541
  break;
470
542
  case "linux_riscv64d":
471
543
  {
472
- native = require("./build/koffi/linux_riscv64d/koffi.node");
544
+ native2 = require("./build/koffi/linux_riscv64d/koffi.node");
473
545
  }
474
546
  break;
475
547
  case "linux_x64":
476
548
  {
477
- native = require("./build/koffi/linux_x64/koffi.node");
549
+ native2 = require("./build/koffi/linux_x64/koffi.node");
478
550
  }
479
551
  break;
480
552
  case "openbsd_ia32":
481
553
  {
482
- native = require("./build/koffi/openbsd_ia32/koffi.node");
554
+ native2 = require("./build/koffi/openbsd_ia32/koffi.node");
483
555
  }
484
556
  break;
485
557
  case "openbsd_x64":
486
558
  {
487
- native = require("./build/koffi/openbsd_x64/koffi.node");
559
+ native2 = require("./build/koffi/openbsd_x64/koffi.node");
488
560
  }
489
561
  break;
490
562
  case "win32_arm64":
491
563
  {
492
- native = require("./build/koffi/win32_arm64/koffi.node");
564
+ native2 = require("./build/koffi/win32_arm64/koffi.node");
493
565
  }
494
566
  break;
495
567
  case "win32_ia32":
496
568
  {
497
- native = require("./build/koffi/win32_ia32/koffi.node");
569
+ native2 = require("./build/koffi/win32_ia32/koffi.node");
498
570
  }
499
571
  break;
500
572
  case "win32_x64":
501
573
  {
502
- native = require("./build/koffi/win32_x64/koffi.node");
574
+ native2 = require("./build/koffi/win32_x64/koffi.node");
503
575
  }
504
576
  break;
505
577
  }
506
- } catch (err) {
507
- }
508
- if (native == null) {
509
- let roots = [__dirname];
510
- if (process.resourcesPath != null)
511
- roots.push(process.resourcesPath);
512
- let names = [
513
- `/build/koffi/${process.platform}_${arch}/koffi.node`,
514
- `/koffi/${process.platform}_${arch}/koffi.node`,
515
- `/node_modules/koffi/build/koffi/${process.platform}_${arch}/koffi.node`,
516
- `/../../bin/Koffi/${process.platform}_${arch}/koffi.node`
517
- ];
518
- for (let root of roots) {
519
- for (let name of names) {
520
- let filename = root + name;
521
- if (fs.existsSync(filename)) {
522
- native = eval("require")(filename);
578
+ } catch {
579
+ try {
580
+ switch (triplet2) {
581
+ case "linux_armhf":
582
+ {
583
+ native2 = require("./build/koffi/musl_armhf/koffi.node");
584
+ }
585
+ break;
586
+ case "linux_arm64":
587
+ {
588
+ native2 = require("./build/koffi/musl_arm64/koffi.node");
589
+ }
590
+ break;
591
+ case "linux_ia32":
592
+ {
593
+ native2 = require("./build/koffi/musl_ia32/koffi.node");
594
+ }
595
+ break;
596
+ case "linux_riscv64d":
597
+ {
598
+ native2 = require("./build/koffi/musl_riscv64d/koffi.node");
599
+ }
600
+ break;
601
+ case "linux_x64":
602
+ {
603
+ native2 = require("./build/koffi/musl_x64/koffi.node");
604
+ }
523
605
  break;
524
- }
525
606
  }
526
- if (native != null)
527
- break;
607
+ } catch {
528
608
  }
529
609
  }
530
- if (native == null)
531
- throw new Error("Cannot find the native Koffi module; did you bundle it correctly?");
532
- if (native.version != pkg.version)
533
- throw new Error("Mismatched native Koffi modules");
534
- module.exports = {
535
- ...native,
536
- // Deprecated functions
537
- handle: util.deprecate(native.opaque, "The koffi.handle() function was deprecated in Koffi 2.1, use koffi.opaque() instead", "KOFFI001"),
538
- callback: util.deprecate(native.proto, "The koffi.callback() function was deprecated in Koffi 2.4, use koffi.proto() instead", "KOFFI002")
539
- };
540
- var load = module.exports.load;
541
- module.exports.load = (...args) => {
542
- let lib = load(...args);
543
- lib.cdecl = util.deprecate((...args2) => lib.func("__cdecl", ...args2), "The koffi.stdcall() function was deprecated in Koffi 2.7, use koffi.func(...) instead", "KOFFI003");
544
- lib.stdcall = util.deprecate((...args2) => lib.func("__stdcall", ...args2), 'The koffi.stdcall() function was deprecated in Koffi 2.7, use koffi.func("__stdcall", ...) instead', "KOFFI004");
545
- lib.fastcall = util.deprecate((...args2) => lib.func("__fastcall", ...args2), 'The koffi.fastcall() function was deprecated in Koffi 2.7, use koffi.func("__fastcall", ...) instead', "KOFFI005");
546
- 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");
547
- return lib;
548
- };
610
+ var mod2 = init2(triplet2, native2);
611
+ module.exports = mod2;