koffi 3.0.0-alpha.3 → 3.0.0-alpha.4

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 (51) hide show
  1. package/build/koffi/darwin_arm64/koffi.node +0 -0
  2. package/build/koffi/darwin_x64/koffi.node +0 -0
  3. package/build/koffi/freebsd_arm64/koffi.node +0 -0
  4. package/build/koffi/freebsd_ia32/koffi.node +0 -0
  5. package/build/koffi/freebsd_x64/koffi.node +0 -0
  6. package/build/koffi/linux_arm64/koffi.node +0 -0
  7. package/build/koffi/linux_ia32/koffi.node +0 -0
  8. package/build/koffi/linux_x64/koffi.node +0 -0
  9. package/build/koffi/musl_arm64/koffi.node +0 -0
  10. package/build/koffi/musl_x64/koffi.node +0 -0
  11. package/build/koffi/openbsd_ia32/koffi.node +0 -0
  12. package/build/koffi/openbsd_x64/koffi.node +0 -0
  13. package/build/koffi/win32_ia32/koffi.node +0 -0
  14. package/build/koffi/win32_x64/koffi.node +0 -0
  15. package/index.cjs +1 -0
  16. package/index.js +1 -1
  17. package/indirect.cjs +1 -0
  18. package/indirect.js +1 -1
  19. package/lib/native/base/base.cc +15 -1
  20. package/lib/native/base/base.hh +16 -6
  21. package/package.json +5 -4
  22. package/src/koffi/index.cjs +453 -0
  23. package/src/koffi/index.js +273 -261
  24. package/src/koffi/indirect.cjs +452 -0
  25. package/src/koffi/indirect.js +191 -125
  26. package/src/koffi/src/ffi.cc +0 -1
  27. package/src/koffi/src/primitives.inc +1 -1
  28. package/src/koffi/src/uv.cc +0 -2
  29. package/src/koffi/src/uv.hh +59 -1
  30. package/vendor/node-addon-api/napi-inl.h +0 -4
  31. package/lib/native/base/crc.inc +0 -2214
  32. package/lib/native/base/crc_gen.py +0 -72
  33. package/lib/native/base/mimetypes.inc +0 -1248
  34. package/lib/native/base/mimetypes_gen.py +0 -58
  35. package/lib/native/base/tower.cc +0 -821
  36. package/lib/native/base/tower.hh +0 -81
  37. package/lib/native/base/unicode_gen.py +0 -152
  38. package/vendor/node-api-headers/include/uv/aix.h +0 -32
  39. package/vendor/node-api-headers/include/uv/bsd.h +0 -34
  40. package/vendor/node-api-headers/include/uv/darwin.h +0 -61
  41. package/vendor/node-api-headers/include/uv/errno.h +0 -483
  42. package/vendor/node-api-headers/include/uv/linux.h +0 -34
  43. package/vendor/node-api-headers/include/uv/os390.h +0 -33
  44. package/vendor/node-api-headers/include/uv/posix.h +0 -31
  45. package/vendor/node-api-headers/include/uv/sunos.h +0 -44
  46. package/vendor/node-api-headers/include/uv/threadpool.h +0 -37
  47. package/vendor/node-api-headers/include/uv/tree.h +0 -521
  48. package/vendor/node-api-headers/include/uv/unix.h +0 -512
  49. package/vendor/node-api-headers/include/uv/version.h +0 -43
  50. package/vendor/node-api-headers/include/uv/win.h +0 -698
  51. package/vendor/node-api-headers/include/uv.h +0 -1990
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/index.cjs ADDED
@@ -0,0 +1 @@
1
+ module.exports = require("./src/koffi/index.cjs");
package/index.js CHANGED
@@ -1 +1 @@
1
- module.exports = require("./src/koffi/index.js");
1
+ export koffi from "./src/koffi/index.js";
package/indirect.cjs ADDED
@@ -0,0 +1 @@
1
+ module.exports = require("./src/koffi/indirect.cjs");
package/indirect.js CHANGED
@@ -1 +1 @@
1
- module.exports = require("./src/koffi/indirect.js");
1
+ export koffi from "./src/koffi/indirect.js";
@@ -2,7 +2,9 @@
2
2
  // SPDX-FileCopyrightText: 2025 Niels Martignène <niels.martignene@protonmail.com>
3
3
 
4
4
  #include "base.hh"
5
- #include "crc.inc"
5
+ #if __has_include("crc.inc")
6
+ #include "crc.inc"
7
+ #endif
6
8
  #include "unicode.inc"
7
9
 
8
10
  #if __has_include("vendor/dragonbox/include/dragonbox/dragonbox.h")
@@ -10696,6 +10698,8 @@ const char *PromptPath(const char *prompt, const char *default_path, Span<const
10696
10698
  // Mime types
10697
10699
  // ------------------------------------------------------------------------
10698
10700
 
10701
+ #if __has_include("mimetypes.inc")
10702
+
10699
10703
  const char *GetMimeType(Span<const char> extension, const char *default_type)
10700
10704
  {
10701
10705
  static const HashMap<Span<const char>, const char *> mimetypes = {
@@ -10771,6 +10775,8 @@ bool CanCompressFile(const char *filename)
10771
10775
  return true;
10772
10776
  }
10773
10777
 
10778
+ #endif
10779
+
10774
10780
  // ------------------------------------------------------------------------
10775
10781
  // Unicode
10776
10782
  // ------------------------------------------------------------------------
@@ -10792,6 +10798,8 @@ bool IsValidUtf8(Span<const char> str)
10792
10798
  return i == str.len;
10793
10799
  }
10794
10800
 
10801
+ #if __has_include("unicode.inc")
10802
+
10795
10803
  static bool TestUnicodeTable(Span<const int32_t> table, int32_t uc)
10796
10804
  {
10797
10805
  K_ASSERT(table.len > 0);
@@ -10862,10 +10870,14 @@ bool IsXidContinue(int32_t uc)
10862
10870
  return false;
10863
10871
  }
10864
10872
 
10873
+ #endif
10874
+
10865
10875
  // ------------------------------------------------------------------------
10866
10876
  // CRC
10867
10877
  // ------------------------------------------------------------------------
10868
10878
 
10879
+ #if __has_include("crc.inc")
10880
+
10869
10881
  uint32_t CRC32(uint32_t state, Span<const uint8_t> buf)
10870
10882
  {
10871
10883
  state = ~state;
@@ -10990,4 +11002,6 @@ uint64_t CRC64nvme(uint64_t state, Span<const uint8_t> buf)
10990
11002
  return ~state;
10991
11003
  }
10992
11004
 
11005
+ #endif
11006
+
10993
11007
  }
@@ -107,17 +107,14 @@ extern StreamReader *const StdIn;
107
107
  extern StreamWriter *const StdOut;
108
108
  extern StreamWriter *const StdErr;
109
109
 
110
- #if defined(__x86_64__) || defined(_M_X64) || defined(__aarch64__) || defined(_M_ARM64) || __riscv_xlen == 64 || defined(__loongarch64)
110
+ #if INTPTR_MAX == INT64_MAX
111
111
  typedef int64_t Size;
112
112
  #define K_SIZE_MAX INT64_MAX
113
- #elif defined(_WIN32) || defined(__APPLE__) || defined(__unix__)
114
- typedef int32_t Size;
115
- #define K_SIZE_MAX INT32_MAX
116
- #elif defined(__thumb__) || defined(__arm__) || defined(__wasm32__)
113
+ #elif INTPTR_MAX == INT32_MAX
117
114
  typedef int32_t Size;
118
115
  #define K_SIZE_MAX INT32_MAX
119
116
  #else
120
- #error Machine architecture not supported
117
+ #error This code base is not designed to support non-32-or-64-bit platforms
121
118
  #endif
122
119
 
123
120
  #if defined(_MSC_VER) || __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
@@ -135,6 +132,7 @@ extern StreamWriter *const StdErr;
135
132
  #error This code base is not designed to support non-64-bits long long types
136
133
  #endif
137
134
  static_assert(sizeof(double) == 8, "This code base is not designed to support single-precision double floats");
135
+ static_assert(sizeof(intptr_t) == sizeof(size_t), "This code base assumes that intptr_t and size_t are the same size");
138
136
 
139
137
  #define K_STRINGIFY_(a) #a
140
138
  #define K_STRINGIFY(a) K_STRINGIFY_(a)
@@ -5893,10 +5891,14 @@ static inline const char *PromptPath(const char *prompt, Allocator *alloc)
5893
5891
  // Mime types
5894
5892
  // ------------------------------------------------------------------------
5895
5893
 
5894
+ #if __has_include("mimetypes.inc")
5895
+
5896
5896
  const char *GetMimeType(Span<const char> extension, const char *default_type = "application/octet-stream");
5897
5897
 
5898
5898
  bool CanCompressFile(const char *filename);
5899
5899
 
5900
+ #endif
5901
+
5900
5902
  // ------------------------------------------------------------------------
5901
5903
  // Unicode
5902
5904
  // ------------------------------------------------------------------------
@@ -6012,19 +6014,27 @@ static inline Size EncodeUtf8(int32_t c, char out_buf[4])
6012
6014
 
6013
6015
  bool IsValidUtf8(Span<const char> str);
6014
6016
 
6017
+ #if __has_include("unicode.inc")
6018
+
6015
6019
  int ComputeUnicodeWidth(Span<const char> str);
6016
6020
 
6017
6021
  bool IsXidStart(int32_t uc);
6018
6022
  bool IsXidContinue(int32_t uc);
6019
6023
 
6024
+ #endif
6025
+
6020
6026
  // ------------------------------------------------------------------------
6021
6027
  // CRC
6022
6028
  // ------------------------------------------------------------------------
6023
6029
 
6030
+ #if __has_include("crc.inc")
6031
+
6024
6032
  uint32_t CRC32(uint32_t state, Span<const uint8_t> buf);
6025
6033
  uint32_t CRC32C(uint32_t state, Span<const uint8_t> buf);
6026
6034
 
6027
6035
  uint64_t CRC64xz(uint64_t state, Span<const uint8_t> buf);
6028
6036
  uint64_t CRC64nvme(uint64_t state, Span<const uint8_t> buf);
6029
6037
 
6038
+ #endif
6039
+
6030
6040
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "koffi",
3
- "version": "3.0.0-alpha.3",
3
+ "version": "3.0.0-alpha.4",
4
4
  "description": "Fast and simple C FFI (foreign function interface) for Node.js",
5
5
  "keywords": [
6
6
  "foreign",
@@ -21,8 +21,7 @@
21
21
  "email": "niels.martignene@protonmail.com",
22
22
  "url": "https://koromix.dev/"
23
23
  },
24
- "main": "./index.js",
25
- "types": "./index.d.ts",
24
+ "module": "./index.js",
26
25
  "scripts": {
27
26
  "install": "node src/build.js -P . -D src/koffi --prebuild --release"
28
27
  },
@@ -33,5 +32,7 @@
33
32
  "node": 16,
34
33
  "napi": 8
35
34
  },
36
- "funding": "https://liberapay.com/Koromix"
35
+ "funding": "https://liberapay.com/Koromix",
36
+ "main": "./index.cjs",
37
+ "types": "./index.d.ts"
37
38
  }
@@ -0,0 +1,453 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __commonJS = (cb, mod) => function __require() {
8
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
9
+ };
10
+ var __export = (target, all) => {
11
+ for (var name in all)
12
+ __defProp(target, name, { get: all[name], enumerable: true });
13
+ };
14
+ var __copyProps = (to, from, except, desc) => {
15
+ if (from && typeof from === "object" || typeof from === "function") {
16
+ for (let key of __getOwnPropNames(from))
17
+ if (!__hasOwnProp.call(to, key) && key !== except)
18
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
19
+ }
20
+ return to;
21
+ };
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
23
+ // If the importer is in node compatibility mode or this is not an ESM
24
+ // file that has been converted to a CommonJS file using a Babel-
25
+ // compatible transform (i.e. "__esModule" has not been set), then set
26
+ // "default" to the CommonJS "module.exports" for node compatibility.
27
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
28
+ mod
29
+ ));
30
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
31
+
32
+ // src/static.js
33
+ var require_static = __commonJS({
34
+ "src/static.js"(exports2, module2) {
35
+ var { createRequire: createRequire2 } = require("node:module");
36
+ var requireNative2 = createRequire2(__dirname);
37
+ function loadStatic2(pkg2) {
38
+ let native2 = null;
39
+ if (native2 == null && pkg2 == "linux-arm64") {
40
+ try {
41
+ native2 = requireNative2("../../build/koffi/linux_arm64/koffi.node");
42
+ } catch (err) {
43
+ }
44
+ }
45
+ if (native2 == null && pkg2 == "linux-arm64") {
46
+ try {
47
+ native2 = requireNative2("../../build/koffi/musl_arm64/koffi.node");
48
+ } catch (err) {
49
+ }
50
+ }
51
+ if (native2 == null && pkg2 == "linux-ia32") {
52
+ try {
53
+ native2 = requireNative2("../../build/koffi/linux_ia32/koffi.node");
54
+ } catch (err) {
55
+ }
56
+ }
57
+ if (native2 == null && pkg2 == "linux-x64") {
58
+ try {
59
+ native2 = requireNative2("../../build/koffi/linux_x64/koffi.node");
60
+ } catch (err) {
61
+ }
62
+ }
63
+ if (native2 == null && pkg2 == "linux-x64") {
64
+ try {
65
+ native2 = requireNative2("../../build/koffi/musl_x64/koffi.node");
66
+ } catch (err) {
67
+ }
68
+ }
69
+ if (native2 == null && pkg2 == "freebsd-ia32") {
70
+ try {
71
+ native2 = requireNative2("../../build/koffi/freebsd_ia32/koffi.node");
72
+ } catch (err) {
73
+ }
74
+ }
75
+ if (native2 == null && pkg2 == "freebsd-x64") {
76
+ try {
77
+ native2 = requireNative2("../../build/koffi/freebsd_x64/koffi.node");
78
+ } catch (err) {
79
+ }
80
+ }
81
+ if (native2 == null && pkg2 == "freebsd-arm64") {
82
+ try {
83
+ native2 = requireNative2("../../build/koffi/freebsd_arm64/koffi.node");
84
+ } catch (err) {
85
+ }
86
+ }
87
+ if (native2 == null && pkg2 == "openbsd-ia32") {
88
+ try {
89
+ native2 = requireNative2("../../build/koffi/openbsd_ia32/koffi.node");
90
+ } catch (err) {
91
+ }
92
+ }
93
+ if (native2 == null && pkg2 == "openbsd-x64") {
94
+ try {
95
+ native2 = requireNative2("../../build/koffi/openbsd_x64/koffi.node");
96
+ } catch (err) {
97
+ }
98
+ }
99
+ if (native2 == null && pkg2 == "win32-ia32") {
100
+ try {
101
+ native2 = requireNative2("../../build/koffi/win32_ia32/koffi.node");
102
+ } catch (err) {
103
+ }
104
+ }
105
+ if (native2 == null && pkg2 == "win32-x64") {
106
+ try {
107
+ native2 = requireNative2("../../build/koffi/win32_x64/koffi.node");
108
+ } catch (err) {
109
+ }
110
+ }
111
+ if (native2 == null && pkg2 == "darwin-x64") {
112
+ try {
113
+ native2 = requireNative2("../../build/koffi/darwin_x64/koffi.node");
114
+ } catch (err) {
115
+ }
116
+ }
117
+ if (native2 == null && pkg2 == "darwin-arm64") {
118
+ try {
119
+ native2 = requireNative2("../../build/koffi/darwin_arm64/koffi.node");
120
+ } catch (err) {
121
+ }
122
+ }
123
+ return native2;
124
+ }
125
+ module2.exports = { loadStatic: loadStatic2 };
126
+ }
127
+ });
128
+
129
+ // index.js
130
+ var index_exports = {};
131
+ __export(index_exports, {
132
+ Union: () => _Union,
133
+ address: () => _address,
134
+ alias: () => _alias,
135
+ alignof: () => _alignof,
136
+ alloc: () => _alloc,
137
+ array: () => _array,
138
+ as: () => _as,
139
+ call: () => _call,
140
+ config: () => _config,
141
+ decode: () => _decode,
142
+ disposable: () => _disposable,
143
+ encode: () => _encode,
144
+ errno: () => _errno,
145
+ extension: () => _extension,
146
+ free: () => _free,
147
+ in: () => _in,
148
+ inout: () => _inout,
149
+ introspect: () => _introspect,
150
+ load: () => _load,
151
+ node: () => _node,
152
+ offsetof: () => _offsetof,
153
+ opaque: () => _opaque,
154
+ os: () => _os,
155
+ out: () => _out,
156
+ pack: () => _pack,
157
+ pointer: () => _pointer,
158
+ proto: () => _proto,
159
+ register: () => _register,
160
+ reset: () => _reset,
161
+ resolve: () => _resolve,
162
+ sizeof: () => _sizeof,
163
+ stats: () => _stats,
164
+ struct: () => _struct,
165
+ types: () => _types,
166
+ union: () => _union,
167
+ unregister: () => _unregister,
168
+ version: () => _version,
169
+ view: () => _view
170
+ });
171
+ module.exports = __toCommonJS(index_exports);
172
+
173
+ // src/init.js
174
+ var import_util = __toESM(require("util"));
175
+ var import_fs2 = __toESM(require("fs"));
176
+ var import_node_module = require("node:module");
177
+
178
+ // ../cnoke/src/abi.js
179
+ var import_fs = __toESM(require("fs"), 1);
180
+ function determineAbi() {
181
+ let abi = process.arch;
182
+ if (abi == "riscv32" || abi == "riscv64") {
183
+ let buf = readFileHeader(process.execPath, 512);
184
+ let header = decodeElfHeader(buf);
185
+ let float_abi = header.e_flags & 6;
186
+ switch (float_abi) {
187
+ case 0:
188
+ {
189
+ }
190
+ break;
191
+ case 2:
192
+ {
193
+ abi += "f";
194
+ }
195
+ break;
196
+ case 4:
197
+ {
198
+ abi += "d";
199
+ }
200
+ break;
201
+ case 6:
202
+ {
203
+ abi += "q";
204
+ }
205
+ break;
206
+ }
207
+ } else if (abi == "arm") {
208
+ let buf = readFileHeader(process.execPath, 512);
209
+ let header = decodeElfHeader(buf);
210
+ if (header.e_flags & 1024) {
211
+ abi += "hf";
212
+ } else if (header.e_flags & 512) {
213
+ abi += "sf";
214
+ } else {
215
+ throw new Error("Unknown ARM floating-point ABI");
216
+ }
217
+ }
218
+ return abi;
219
+ }
220
+ function readFileHeader(filename, read) {
221
+ let fd = null;
222
+ try {
223
+ let fd2 = import_fs.default.openSync(filename);
224
+ let buf = Buffer.allocUnsafe(read);
225
+ let len = import_fs.default.readSync(fd2, buf);
226
+ return buf.subarray(0, len);
227
+ } finally {
228
+ if (fd != null)
229
+ import_fs.default.closeSync(fd);
230
+ }
231
+ }
232
+ function decodeElfHeader(buf) {
233
+ let header = {};
234
+ if (buf.length < 16)
235
+ throw new Error("Truncated header");
236
+ if (buf[0] != 127 || buf[1] != 69 || buf[2] != 76 || buf[3] != 70)
237
+ throw new Error("Invalid magic number");
238
+ if (buf[6] != 1)
239
+ throw new Error("Invalid ELF version");
240
+ if (buf[5] != 1)
241
+ throw new Error("Big-endian architectures are not supported");
242
+ header.e_machine = buf.readUInt16LE(18);
243
+ switch (buf[4]) {
244
+ case 1:
245
+ {
246
+ buf = buf.subarray(0, 68);
247
+ if (buf.length < 68)
248
+ throw new Error("Truncated ELF header");
249
+ header.ei_class = 32;
250
+ header.e_flags = buf.readUInt32LE(36);
251
+ }
252
+ break;
253
+ case 2:
254
+ {
255
+ buf = buf.subarray(0, 120);
256
+ if (buf.length < 120)
257
+ throw new Error("Truncated ELF header");
258
+ header.ei_class = 64;
259
+ header.e_flags = buf.readUInt32LE(48);
260
+ }
261
+ break;
262
+ default:
263
+ throw new Error("Invalid ELF class");
264
+ }
265
+ return header;
266
+ }
267
+
268
+ // package.json
269
+ var package_default = {
270
+ name: "koffi",
271
+ version: "3.0.0-alpha.4",
272
+ description: "Fast and simple C FFI (foreign function interface) for Node.js",
273
+ keywords: [
274
+ "foreign",
275
+ "function",
276
+ "interface",
277
+ "ffi",
278
+ "binding",
279
+ "c",
280
+ "napi"
281
+ ],
282
+ repository: {
283
+ type: "git",
284
+ url: "https://github.com/Koromix/koffi"
285
+ },
286
+ homepage: "https://koffi.dev/",
287
+ author: {
288
+ name: "Niels Martign\xE8ne",
289
+ email: "niels.martignene@protonmail.com",
290
+ url: "https://koromix.dev/"
291
+ },
292
+ main: "./index.cjs",
293
+ module: "./index.js",
294
+ types: "./index.d.ts",
295
+ scripts: {
296
+ test: "node tools/brew.js test",
297
+ prepack: `echo 'Use "npm run package" instead' && false`,
298
+ prepublishOnly: `echo 'Use "npm run package" instead' && false`,
299
+ package: "node tools/brew.js build"
300
+ },
301
+ license: "MIT",
302
+ cnoke: {
303
+ api: "../../vendor/node-api-headers",
304
+ output: "../../bin/Koffi/{{ toolchain }}",
305
+ node: 16,
306
+ napi: 8
307
+ },
308
+ funding: "https://liberapay.com/Koromix"
309
+ };
310
+
311
+ // src/init.js
312
+ var requireNative = (0, import_node_module.createRequire)(__dirname);
313
+ function detectPlatform() {
314
+ if (process.versions.napi == null || process.versions.napi < package_default.cnoke.napi) {
315
+ let major = parseInt(process.versions.node, 10);
316
+ throw new Error(`This engine is based on Node ${process.versions.node}, but ${package_default.name} does not support the Node ${major}.x branch (N-API < ${package_default.cnoke.napi})`);
317
+ }
318
+ let abi = determineAbi();
319
+ let pkg2 = `${process.platform}-${process.arch}`;
320
+ let triplets2 = [`${process.platform}_${abi}`];
321
+ if (process.platform == "linux")
322
+ triplets2.push(`musl_${abi}`);
323
+ return [package_default.version, pkg2, triplets2];
324
+ }
325
+ function loadDynamic(root, pkg2, triplets2) {
326
+ let roots = [root];
327
+ let native2 = null;
328
+ let err = null;
329
+ if (process.resourcesPath != null)
330
+ roots.push(process.resourcesPath);
331
+ let filenames = roots.flatMap((dir) => triplets2.flatMap((triplet) => [
332
+ `${dir}/build/koffi/${triplet}/koffi.node`,
333
+ `${dir}/bin/Koffi/${triplet}/koffi.node`,
334
+ `${dir}/node_modules/koffi/build/koffi/${triplet}/koffi.node`,
335
+ `${dir}/../@koromix/koffi-${pkg2}/${triplet}/koffi.node`
336
+ ]));
337
+ for (let filename of filenames) {
338
+ if (!import_fs2.default.existsSync(filename))
339
+ continue;
340
+ try {
341
+ native2 = requireNative(filename);
342
+ break;
343
+ } catch (e) {
344
+ err ??= e;
345
+ }
346
+ }
347
+ if (native2 == null) {
348
+ err ??= new Error("Cannot find the native Koffi module; did you bundle it correctly?");
349
+ throw err;
350
+ }
351
+ return native2;
352
+ }
353
+ function wrapNative(native2) {
354
+ let load = native2.load;
355
+ native2.load = (...args) => {
356
+ let lib = load(...args);
357
+ lib.cdecl = import_util.default.deprecate((...args2) => lib.func("__cdecl", ...args2), "The koffi.cdecl() function was deprecated in Koffi 2.7, use koffi.func(...) instead", "KOFFI003");
358
+ lib.stdcall = import_util.default.deprecate((...args2) => lib.func("__stdcall", ...args2), 'The koffi.stdcall() function was deprecated in Koffi 2.7, use koffi.func("__stdcall", ...) instead', "KOFFI004");
359
+ lib.fastcall = import_util.default.deprecate((...args2) => lib.func("__fastcall", ...args2), 'The koffi.fastcall() function was deprecated in Koffi 2.7, use koffi.func("__fastcall", ...) instead', "KOFFI005");
360
+ lib.thiscall = import_util.default.deprecate((...args2) => lib.func("__thiscall", ...args2), 'The koffi.thiscall() function was deprecated in Koffi 2.7, use koffi.func("__thiscall", ...) instead', "KOFFI006");
361
+ return lib;
362
+ };
363
+ }
364
+
365
+ // index.js
366
+ var import_static = __toESM(require_static());
367
+ var [version, pkg, triplets] = detectPlatform();
368
+ var native = null;
369
+ STATIC: native = (0, import_static.loadStatic)(pkg);
370
+ if (native == null)
371
+ native = loadDynamic(__dirname + "/../..", pkg, triplets);
372
+ if (native.version != version)
373
+ throw new Error("Mismatched native Koffi modules");
374
+ wrapNative(native);
375
+ var _config = native.config;
376
+ var _stats = native.stats;
377
+ var _struct = native.struct;
378
+ var _pack = native.pack;
379
+ var _union = native.union;
380
+ var _Union = native.Union;
381
+ var _opaque = native.opaque;
382
+ var _pointer = native.pointer;
383
+ var _array = native.array;
384
+ var _proto = native.proto;
385
+ var _alias = native.alias;
386
+ var _sizeof = native.sizeof;
387
+ var _alignof = native.alignof;
388
+ var _offsetof = native.offsetof;
389
+ var _resolve = native.resolve;
390
+ var _introspect = native.introspect;
391
+ var _load = native.load;
392
+ var _in = native.in;
393
+ var _out = native.out;
394
+ var _inout = native.inout;
395
+ var _disposable = native.disposable;
396
+ var _alloc = native.alloc;
397
+ var _free = native.free;
398
+ var _register = native.register;
399
+ var _unregister = native.unregister;
400
+ var _as = native.as;
401
+ var _decode = native.decode;
402
+ var _address = native.address;
403
+ var _call = native.call;
404
+ var _encode = native.encode;
405
+ var _view = native.view;
406
+ var _reset = native.reset;
407
+ var _errno = native.errno;
408
+ var _os = native.os;
409
+ var _extension = native.extension;
410
+ var _types = native.types;
411
+ var _node = native.node;
412
+ var _version = native.version;
413
+ // Annotate the CommonJS export names for ESM import in node:
414
+ 0 && (module.exports = {
415
+ Union,
416
+ address,
417
+ alias,
418
+ alignof,
419
+ alloc,
420
+ array,
421
+ as,
422
+ call,
423
+ config,
424
+ decode,
425
+ disposable,
426
+ encode,
427
+ errno,
428
+ extension,
429
+ free,
430
+ in: null,
431
+ inout,
432
+ introspect,
433
+ load,
434
+ node,
435
+ offsetof,
436
+ opaque,
437
+ os,
438
+ out,
439
+ pack,
440
+ pointer,
441
+ proto,
442
+ register,
443
+ reset,
444
+ resolve,
445
+ sizeof,
446
+ stats,
447
+ struct,
448
+ types,
449
+ union,
450
+ unregister,
451
+ version,
452
+ view
453
+ });