koffi 3.0.0-alpha.10 → 3.0.0-alpha.12

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 (41) 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_loong64/koffi.node +0 -0
  9. package/build/koffi/linux_riscv64d/koffi.node +0 -0
  10. package/build/koffi/linux_x64/koffi.node +0 -0
  11. package/build/koffi/musl_arm64/koffi.node +0 -0
  12. package/build/koffi/musl_x64/koffi.node +0 -0
  13. package/build/koffi/openbsd_ia32/koffi.node +0 -0
  14. package/build/koffi/openbsd_x64/koffi.node +0 -0
  15. package/build/koffi/win32_ia32/koffi.exp +0 -0
  16. package/build/koffi/win32_ia32/koffi.lib +0 -0
  17. package/build/koffi/win32_ia32/koffi.node +0 -0
  18. package/build/koffi/win32_x64/koffi.exp +0 -0
  19. package/build/koffi/win32_x64/koffi.lib +0 -0
  20. package/build/koffi/win32_x64/koffi.node +0 -0
  21. package/index.d.ts +39 -12
  22. package/lib/native/base/base.cc +3 -0
  23. package/package.json +1 -1
  24. package/src/koffi/index.cjs +22 -1
  25. package/src/koffi/index.js +22 -1
  26. package/src/koffi/indirect.cjs +22 -1
  27. package/src/koffi/indirect.js +10 -1
  28. package/src/koffi/src/abi/arm64.cc +51 -145
  29. package/src/koffi/src/abi/loong64_asm.S +50 -50
  30. package/src/koffi/src/abi/riscv64.cc +1009 -567
  31. package/src/koffi/src/abi/riscv64_asm.S +50 -50
  32. package/src/koffi/src/abi/x64sysv.cc +98 -102
  33. package/src/koffi/src/abi/x64win.cc +56 -77
  34. package/src/koffi/src/abi/x86.cc +58 -94
  35. package/src/koffi/src/abi/x86_asm.S +2 -2
  36. package/src/koffi/src/call.cc +707 -62
  37. package/src/koffi/src/call.hh +26 -1
  38. package/src/koffi/src/ffi.cc +349 -584
  39. package/src/koffi/src/ffi.hh +37 -39
  40. package/src/koffi/src/util.cc +106 -96
  41. package/src/koffi/src/util.hh +75 -76
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
package/index.d.ts CHANGED
@@ -43,10 +43,6 @@ export type KoffiFunc<T extends (...args: any) => any> = T & {
43
43
  info: PrototypeInfo;
44
44
  };
45
45
 
46
- export type CallbackHandle = {
47
- [Symbol.dispose](): void;
48
- };
49
-
50
46
  type LoadOptions = {
51
47
  lazy?: boolean,
52
48
  global?: boolean,
@@ -120,23 +116,54 @@ export function proto(convention: string, result: TypeSpec, arguments: TypeSpec[
120
116
  export function proto(name: string | null | undefined, result: TypeSpec, arguments: TypeSpec[]): TypeObject;
121
117
  export function proto(convention: string, name: string | null | undefined, result: TypeSpec, arguments: TypeSpec[]): TypeObject;
122
118
 
123
- export function register(callback: Function, type: TypeSpec): CallbackHandle;
124
- export function register(thisValue: any, callback: Function, type: TypeSpec): CallbackHandle;
125
- export function unregister(callback: CallbackHandle): void;
119
+ export function register(callback: Function, type: TypeSpec): bigint;
120
+ /** @deprecated */ export function register(thisValue: any, callback: Function, type: TypeSpec): bigint;
121
+ export function unregister(callback: bigint): void;
126
122
 
127
123
  export function as(value: any, type: TypeSpec): IKoffiPointerCast;
128
- export function decode(value: any, type: TypeSpec): any;
129
- export function decode(value: any, type: TypeSpec, len: number): any;
130
- export function decode(value: any, offset: number, type: TypeSpec): any;
131
- export function decode(value: any, offset: number, type: TypeSpec, len: number): any;
132
124
  export function address(value: any): bigint;
133
125
  export function call(value: any, type: TypeSpec, ...args: any[]): any;
126
+ export function view(ref: any, len: number): ArrayBuffer;
127
+
128
+ export const decode: {
129
+ (value: any, type: TypeSpec): any;
130
+ (value: any, type: TypeSpec, len: number): any;
131
+ (value: any, offset: number, type: TypeSpec): any;
132
+ (value: any, offset: number, type: TypeSpec, len: number): any;
133
+
134
+ char(ptr: any): number;
135
+ short(ptr: any): number;
136
+ int(ptr: any): number;
137
+ long(ptr: any): number | bigint;
138
+ longlong(ptr: any): number | bigint;
139
+ uchar(ptr: any): number;
140
+ ushort(ptr: any): number;
141
+ uint(ptr: any): number;
142
+ ulong(ptr: any): number | bigint;
143
+ ulonglong(ptr: any): number | bigint;
144
+
145
+ int8(ptr: any): number;
146
+ int16(ptr: any): number;
147
+ int32(ptr: any): number;
148
+ int64(ptr: any): number | bigint;
149
+ uint8(ptr: any): number;
150
+ uint16(ptr: any): number;
151
+ uint32(ptr: any): number;
152
+ uint64(ptr: any): number | bigint;
153
+
154
+ float(ptr: any): number;
155
+ double(ptr: any): number;
156
+
157
+ string(ptr: any, length?: number | bigint | null): string;
158
+ string16(ptr: any, length?: number | bigint | null): string;
159
+ string32(ptr: any, length?: number | bigint | null): string;
160
+ };
161
+
134
162
  export function encode(ref: any, type: TypeSpec, value: any): void;
135
163
  export function encode(ref: any, type: TypeSpec, value: any, len: number): void;
136
164
  export function encode(ref: any, offset: number, type: TypeSpec): void;
137
165
  export function encode(ref: any, offset: number, type: TypeSpec, value: any): void;
138
166
  export function encode(ref: any, offset: number, type: TypeSpec, value: any, len: number): void;
139
- export function view(ref: any, len: number): ArrayBuffer;
140
167
 
141
168
  export function type(type: TypeSpec): TypeObject;
142
169
  export function sizeof(type: TypeSpec): number;
@@ -2082,6 +2082,9 @@ bool GetDebugFlag(const char *name)
2082
2082
  if (!ParseBool(debug, &ret, K_DEFAULT_PARSE_FLAGS & ~(int)ParseFlag::Log)) {
2083
2083
  LogError("Environment variable '%1' is not a boolean", name);
2084
2084
  }
2085
+ if (ret) {
2086
+ LogWarning("Debug flag '%1' is in effect", name);
2087
+ }
2085
2088
  return ret;
2086
2089
  } else {
2087
2090
  return false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "koffi",
3
- "version": "3.0.0-alpha.10",
3
+ "version": "3.0.0-alpha.12",
4
4
  "description": "Fast and simple C FFI (foreign function interface) for Node.js",
5
5
  "keywords": [
6
6
  "foreign",
@@ -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.0-alpha.10", cnoke: { api: "../../vendor/node-api-headers", output: "../../bin/Koffi/{{ toolchain }}", node: 16, napi: 8 } };
134
+ package_default = { name: "koffi", version: "3.0.0-alpha.12", cnoke: { api: "../../vendor/node-api-headers", output: "../../bin/Koffi/{{ toolchain }}", node: 16, napi: 8 } };
135
135
  }
136
136
  });
137
137
 
@@ -184,6 +184,7 @@ function loadDynamic(root, pkg2, triplets2) {
184
184
  }
185
185
  function wrapNative(native2) {
186
186
  let load = native2.load;
187
+ let register = native2.register;
187
188
  native2.sizeof = (spec) => native2.type(spec).size;
188
189
  native2.alignof = (spec) => native2.type(spec).alignment;
189
190
  native2.offsetof = (spec, name) => {
@@ -195,6 +196,14 @@ function wrapNative(native2) {
195
196
  throw new Error(`Record type ${type.name} does not have member '${name}'`);
196
197
  return member.offset;
197
198
  };
199
+ native2.register = (...args) => {
200
+ if (args.length >= 3 && typeof args[1] == "function") {
201
+ process.emitWarning("Using koffi.register() with a custom this value was deprecated in Koffi 3.0, use function.bind() instead", "Warning", "KOFFI009");
202
+ args[1] = args[1].bind(args[0]);
203
+ args = args.slice(1);
204
+ }
205
+ return register(...args);
206
+ };
198
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");
199
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");
200
209
  native2.load = (...args) => {
@@ -256,6 +265,12 @@ var require_static = __commonJS({
256
265
  } catch (err) {
257
266
  }
258
267
  }
268
+ if (native2 == null && pkg2 == "linux-riscv64d") {
269
+ try {
270
+ native2 = requireNative2("../../build/koffi/linux_riscv64d/koffi.node");
271
+ } catch (err) {
272
+ }
273
+ }
259
274
  if (native2 == null && pkg2 == "freebsd-ia32") {
260
275
  try {
261
276
  native2 = requireNative2("../../build/koffi/freebsd_ia32/koffi.node");
@@ -310,6 +325,12 @@ var require_static = __commonJS({
310
325
  } catch (err) {
311
326
  }
312
327
  }
328
+ if (native2 == null && pkg2 == "linux-loong64") {
329
+ try {
330
+ native2 = requireNative2("../../build/koffi/linux_loong64/koffi.node");
331
+ } catch (err) {
332
+ }
333
+ }
313
334
  return native2;
314
335
  }
315
336
  module2.exports = {
@@ -94,7 +94,7 @@ function decodeElfHeader(buf) {
94
94
  }
95
95
 
96
96
  // package.json
97
- var package_default = { name: "koffi", version: "3.0.0-alpha.10", cnoke: { api: "../../vendor/node-api-headers", output: "../../bin/Koffi/{{ toolchain }}", node: 16, napi: 8 } };
97
+ var package_default = { name: "koffi", version: "3.0.0-alpha.12", 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);
@@ -140,6 +140,7 @@ function loadDynamic(root, pkg2, triplets2) {
140
140
  }
141
141
  function wrapNative(native2) {
142
142
  let load = native2.load;
143
+ let register = native2.register;
143
144
  native2.sizeof = (spec) => native2.type(spec).size;
144
145
  native2.alignof = (spec) => native2.type(spec).alignment;
145
146
  native2.offsetof = (spec, name) => {
@@ -151,6 +152,14 @@ function wrapNative(native2) {
151
152
  throw new Error(`Record type ${type.name} does not have member '${name}'`);
152
153
  return member.offset;
153
154
  };
155
+ native2.register = (...args) => {
156
+ if (args.length >= 3 && typeof args[1] == "function") {
157
+ process.emitWarning("Using koffi.register() with a custom this value was deprecated in Koffi 3.0, use function.bind() instead", "Warning", "KOFFI009");
158
+ args[1] = args[1].bind(args[0]);
159
+ args = args.slice(1);
160
+ }
161
+ return register(...args);
162
+ };
154
163
  native2.resolve = util.deprecate(native2.type, "The koffi.resolve() function was deprecated in Koffi 3.0, use koffi.type() instead", "KOFFI007");
155
164
  native2.introspect = util.deprecate(native2.type, "The koffi.introspect() function was deprecated in Koffi 3.0, use koffi.type() instead", "KOFFI008");
156
165
  native2.load = (...args) => {
@@ -199,6 +208,12 @@ function loadStatic(pkg2) {
199
208
  } catch (err) {
200
209
  }
201
210
  }
211
+ if (native2 == null && pkg2 == "linux-riscv64d") {
212
+ try {
213
+ native2 = requireNative2("../../build/koffi/linux_riscv64d/koffi.node");
214
+ } catch (err) {
215
+ }
216
+ }
202
217
  if (native2 == null && pkg2 == "freebsd-ia32") {
203
218
  try {
204
219
  native2 = requireNative2("../../build/koffi/freebsd_ia32/koffi.node");
@@ -253,6 +268,12 @@ function loadStatic(pkg2) {
253
268
  } catch (err) {
254
269
  }
255
270
  }
271
+ if (native2 == null && pkg2 == "linux-loong64") {
272
+ try {
273
+ native2 = requireNative2("../../build/koffi/linux_loong64/koffi.node");
274
+ } catch (err) {
275
+ }
276
+ }
256
277
  return native2;
257
278
  }
258
279
 
@@ -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.0-alpha.10", cnoke: { api: "../../vendor/node-api-headers", output: "../../bin/Koffi/{{ toolchain }}", node: 16, napi: 8 } };
134
+ package_default = { name: "koffi", version: "3.0.0-alpha.12", cnoke: { api: "../../vendor/node-api-headers", output: "../../bin/Koffi/{{ toolchain }}", node: 16, napi: 8 } };
135
135
  }
136
136
  });
137
137
 
@@ -184,6 +184,7 @@ function loadDynamic(root, pkg2, triplets2) {
184
184
  }
185
185
  function wrapNative(native2) {
186
186
  let load = native2.load;
187
+ let register = native2.register;
187
188
  native2.sizeof = (spec) => native2.type(spec).size;
188
189
  native2.alignof = (spec) => native2.type(spec).alignment;
189
190
  native2.offsetof = (spec, name) => {
@@ -195,6 +196,14 @@ function wrapNative(native2) {
195
196
  throw new Error(`Record type ${type.name} does not have member '${name}'`);
196
197
  return member.offset;
197
198
  };
199
+ native2.register = (...args) => {
200
+ if (args.length >= 3 && typeof args[1] == "function") {
201
+ process.emitWarning("Using koffi.register() with a custom this value was deprecated in Koffi 3.0, use function.bind() instead", "Warning", "KOFFI009");
202
+ args[1] = args[1].bind(args[0]);
203
+ args = args.slice(1);
204
+ }
205
+ return register(...args);
206
+ };
198
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");
199
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");
200
209
  native2.load = (...args) => {
@@ -256,6 +265,12 @@ var require_static = __commonJS({
256
265
  } catch (err) {
257
266
  }
258
267
  }
268
+ if (native2 == null && pkg2 == "linux-riscv64d") {
269
+ try {
270
+ native2 = requireNative2("../../build/koffi/linux_riscv64d/koffi.node");
271
+ } catch (err) {
272
+ }
273
+ }
259
274
  if (native2 == null && pkg2 == "freebsd-ia32") {
260
275
  try {
261
276
  native2 = requireNative2("../../build/koffi/freebsd_ia32/koffi.node");
@@ -310,6 +325,12 @@ var require_static = __commonJS({
310
325
  } catch (err) {
311
326
  }
312
327
  }
328
+ if (native2 == null && pkg2 == "linux-loong64") {
329
+ try {
330
+ native2 = requireNative2("../../build/koffi/linux_loong64/koffi.node");
331
+ } catch (err) {
332
+ }
333
+ }
313
334
  return native2;
314
335
  }
315
336
  module2.exports = {
@@ -94,7 +94,7 @@ function decodeElfHeader(buf) {
94
94
  }
95
95
 
96
96
  // package.json
97
- var package_default = { name: "koffi", version: "3.0.0-alpha.10", cnoke: { api: "../../vendor/node-api-headers", output: "../../bin/Koffi/{{ toolchain }}", node: 16, napi: 8 } };
97
+ var package_default = { name: "koffi", version: "3.0.0-alpha.12", 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);
@@ -140,6 +140,7 @@ function loadDynamic(root, pkg2, triplets2) {
140
140
  }
141
141
  function wrapNative(native2) {
142
142
  let load = native2.load;
143
+ let register = native2.register;
143
144
  native2.sizeof = (spec) => native2.type(spec).size;
144
145
  native2.alignof = (spec) => native2.type(spec).alignment;
145
146
  native2.offsetof = (spec, name) => {
@@ -151,6 +152,14 @@ function wrapNative(native2) {
151
152
  throw new Error(`Record type ${type.name} does not have member '${name}'`);
152
153
  return member.offset;
153
154
  };
155
+ native2.register = (...args) => {
156
+ if (args.length >= 3 && typeof args[1] == "function") {
157
+ process.emitWarning("Using koffi.register() with a custom this value was deprecated in Koffi 3.0, use function.bind() instead", "Warning", "KOFFI009");
158
+ args[1] = args[1].bind(args[0]);
159
+ args = args.slice(1);
160
+ }
161
+ return register(...args);
162
+ };
154
163
  native2.resolve = util.deprecate(native2.type, "The koffi.resolve() function was deprecated in Koffi 3.0, use koffi.type() instead", "KOFFI007");
155
164
  native2.introspect = util.deprecate(native2.type, "The koffi.introspect() function was deprecated in Koffi 3.0, use koffi.type() instead", "KOFFI008");
156
165
  native2.load = (...args) => {