koffi 2.5.11 → 2.5.13

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 (37) hide show
  1. package/CHANGELOG.md +80 -70
  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_ia32/koffi.node +0 -0
  6. package/build/koffi/freebsd_x64/koffi.node +0 -0
  7. package/build/koffi/linux_arm32hf/koffi.node +0 -0
  8. package/build/koffi/linux_arm64/koffi.node +0 -0
  9. package/build/koffi/linux_ia32/koffi.node +0 -0
  10. package/build/koffi/linux_riscv64hf64/koffi.node +0 -0
  11. package/build/koffi/linux_x64/koffi.node +0 -0
  12. package/build/koffi/openbsd_ia32/koffi.node +0 -0
  13. package/build/koffi/openbsd_x64/koffi.node +0 -0
  14. package/build/koffi/win32_arm64/koffi.node +0 -0
  15. package/build/koffi/win32_ia32/koffi.node +0 -0
  16. package/build/koffi/win32_x64/koffi.node +0 -0
  17. package/doc/callbacks.md +1 -1
  18. package/doc/conf.py +2 -1
  19. package/doc/functions.md +11 -0
  20. package/doc/index.rst +5 -2
  21. package/doc/{types.md → input.md} +43 -39
  22. package/doc/migration.md +4 -4
  23. package/doc/output.md +169 -0
  24. package/doc/packaging.md +1 -1
  25. package/doc/pointers.md +52 -2
  26. package/doc/polymorphism.md +108 -0
  27. package/package.json +7 -3
  28. package/src/cnoke/assets/win_delay_hook.c +12 -2
  29. package/src/cnoke/package.json +5 -1
  30. package/src/core/libcc/libcc.cc +2 -4
  31. package/src/core/libcc/libcc.hh +4 -1
  32. package/src/index.js +2 -2
  33. package/src/koffi/src/call.hh +1 -1
  34. package/src/koffi/src/ffi.cc +4 -4
  35. package/src/koffi/src/ffi.hh +1 -1
  36. package/src/koffi/src/util.cc +1 -1
  37. package/doc/parameters.md +0 -336
package/doc/migration.md CHANGED
@@ -10,7 +10,7 @@ You may need to change your code if you use:
10
10
  - Opaque types
11
11
  - `koffi.introspect()`
12
12
 
13
- ### Callback types
13
+ ### Callback type changes
14
14
 
15
15
  In Koffi 1.x, callbacks were defined in a way that made them usable directly as parameter and return types, obscuring the underlying pointer. Now, you must use them through a pointer: `void CallIt(CallbackType func)` in Koffi 1.x becomes `void CallIt(CallbackType *func)` in version 2.0 and newer.
16
16
 
@@ -61,13 +61,13 @@ let ret = TransferToJS('Niels', 27, (str, age) => {
61
61
  console.log(ret);
62
62
  ```
63
63
 
64
- Koffi 1.x only supported [transient callbacks](callbacks.md#callbacks), you must use Koffi 2.x for registered callbacks.
64
+ Koffi 1.x only supported [transient callbacks](callbacks.md#javascript-callbacks), you must use Koffi 2.x for registered callbacks.
65
65
 
66
66
  ```{note}
67
67
  The function `koffi.proto()` was introduced in Koffi 2.4, it was called `koffi.callback()` in earlier versions.
68
68
  ```
69
69
 
70
- ### Opaque types
70
+ ### Opaque type changes
71
71
 
72
72
  In Koffi 1.x, opaque handles were defined in a way that made them usable directly as parameter and return types, obscuring the underlying pointer. Now, in Koffi 2.0, you must use them through a pointer, and use an array for output parameters.
73
73
 
@@ -145,7 +145,7 @@ db = ptr[0];
145
145
  sqlite3_close_v2(db);
146
146
  ```
147
147
 
148
- ### koffi.introspect()
148
+ ### New koffi.introspect()
149
149
 
150
150
  In Koffi 1.x, `koffi.introspect()` would only work with struct types, and return the object passed to `koffi.struct()` to initialize the type. Now this function works with all types.
151
151
 
package/doc/output.md ADDED
@@ -0,0 +1,169 @@
1
+ # Output parameters
2
+
3
+ ## Output and input/output
4
+
5
+ For simplicity, and because Javascript only has value semantics for primitive types, Koffi can marshal out (or in/out) multiple types of parameters:
6
+
7
+ - [Structs](input.md#struct-types) (to/from JS objects)
8
+ - [Unions](unions.md)
9
+ - [Opaque types](input.md#opaque-types)
10
+ - String buffers
11
+
12
+ In order to change an argument from input-only to output or input/output, use the following functions:
13
+
14
+ - `koffi.out()` on a pointer, e.g. `koffi.out(koffi.pointer(timeval))` (where timeval is a struct type)
15
+ - `koffi.inout()` for dual input/output parameters
16
+
17
+ The same can be done when declaring a function with a C-like prototype string, with the MSDN-like type qualifiers:
18
+
19
+ - `_Out_` for output parameters
20
+ - `_Inout_` for dual input/output parameters
21
+
22
+ ### Primitive value
23
+
24
+ This Windows example enumerate all Chrome windows along with their PID and their title. The `GetWindowThreadProcessId()` function illustrates how to get a primitive value from an output argument.
25
+
26
+ ```js
27
+ // ES6 syntax: import koffi from 'koffi';
28
+ const koffi = require('koffi');
29
+
30
+ const user32 = koffi.load('user32.dll');
31
+
32
+ const DWORD = koffi.alias('DWORD', 'uint32_t');
33
+ const HANDLE = koffi.pointer(koffi.opaque('HANDLE'));
34
+ const HWND = koffi.alias('HWND', HANDLE);
35
+
36
+ const FindWindowEx = user32.func('HWND __stdcall FindWindowExW(HWND hWndParent, HWND hWndChildAfter, const char16_t *lpszClass, const char16_t *lpszWindow)');
37
+ const GetWindowThreadProcessId = user32.func('DWORD __stdcall GetWindowThreadProcessId(HWND hWnd, _Out_ DWORD *lpdwProcessId)');
38
+ const GetWindowText = user32.func('int __stdcall GetWindowTextA(HWND hWnd, _Out_ uint8_t *lpString, int nMaxCount)');
39
+
40
+ for (let hwnd = null;;) {
41
+ hwnd = FindWindowEx(0, hwnd, 'Chrome_WidgetWin_1', null);
42
+
43
+ if (!hwnd)
44
+ break;
45
+
46
+ // Get PID
47
+ let pid;
48
+ {
49
+ let ptr = [null];
50
+ let tid = GetWindowThreadProcessId(hwnd, ptr);
51
+
52
+ if (!tid) {
53
+ // Maybe the process ended in-between?
54
+ continue;
55
+ }
56
+
57
+ pid = ptr[0];
58
+ }
59
+
60
+ // Get window title
61
+ let title;
62
+ {
63
+ let buf = Buffer.allocUnsafe(1024);
64
+ let length = GetWindowText(hwnd, buf, buf.length);
65
+
66
+ if (!length) {
67
+ // Maybe the process ended in-between?
68
+ continue;
69
+ }
70
+
71
+ title = koffi.decode(buf, 'char', length);
72
+ }
73
+
74
+ console.log({ PID: pid, Title: title });
75
+ }
76
+ ```
77
+
78
+ ### Struct example
79
+
80
+ This example calls the POSIX function `gettimeofday()`, and uses the prototype-like syntax.
81
+
82
+ ```js
83
+ // ES6 syntax: import koffi from 'koffi';
84
+ const koffi = require('koffi');
85
+
86
+ const lib = koffi.load('libc.so.6');
87
+
88
+ const timeval = koffi.struct('timeval', {
89
+ tv_sec: 'unsigned int',
90
+ tv_usec: 'unsigned int'
91
+ });
92
+ const timezone = koffi.struct('timezone', {
93
+ tz_minuteswest: 'int',
94
+ tz_dsttime: 'int'
95
+ });
96
+
97
+ // The _Out_ qualifiers instruct Koffi to marshal out the values
98
+ const gettimeofday = lib.func('int gettimeofday(_Out_ timeval *tv, _Out_ timezone *tz)');
99
+
100
+ let tv = {};
101
+ gettimeofday(tv, null);
102
+
103
+ console.log(tv);
104
+ ```
105
+
106
+ ### Opaque type example
107
+
108
+ This example opens an in-memory SQLite database, and uses the node-ffi-style function declaration syntax.
109
+
110
+ ```js
111
+ // ES6 syntax: import koffi from 'koffi';
112
+ const koffi = require('koffi');
113
+
114
+ const lib = koffi.load('sqlite3.so');
115
+
116
+ const sqlite3 = koffi.opaque('sqlite3');
117
+
118
+ // Use koffi.out() on a double pointer to copy out (from C to JS) after the call
119
+ const sqlite3_open_v2 = lib.func('sqlite3_open_v2', 'int', ['str', koffi.out(koffi.pointer(sqlite3, 2)), 'int', 'str']);
120
+ const sqlite3_close_v2 = lib.func('sqlite3_close_v2', 'int', [koffi.pointer(sqlite3)]);
121
+
122
+ const SQLITE_OPEN_READWRITE = 0x2;
123
+ const SQLITE_OPEN_CREATE = 0x4;
124
+
125
+ let out = [null];
126
+ if (sqlite3_open_v2(':memory:', out, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, null) != 0)
127
+ throw new Error('Failed to open database');
128
+ let db = out[0];
129
+
130
+ sqlite3_close_v2(db);
131
+ ```
132
+
133
+ ### String buffer example
134
+
135
+ *New in Koffi 2.2*
136
+
137
+ This example calls a C function to concatenate two strings to a pre-allocated string buffer. Since JS strings are immutable, you must pass an array with a single string instead.
138
+
139
+ ```c
140
+ void ConcatToBuffer(const char *str1, const char *str2, char *out)
141
+ {
142
+ size_t len = 0;
143
+
144
+ for (size_t i = 0; str1[i]; i++) {
145
+ out[len++] = str1[i];
146
+ }
147
+ for (size_t i = 0; str2[i]; i++) {
148
+ out[len++] = str2[i];
149
+ }
150
+
151
+ out[len] = 0;
152
+ }
153
+ ```
154
+
155
+ ```js
156
+ const ConcatToBuffer = lib.func('void ConcatToBuffer(const char *str1, const char *str2, _Out_ char *out)');
157
+
158
+ let str1 = 'Hello ';
159
+ let str2 = 'Friends!';
160
+
161
+ // We need to reserve space for the output buffer! Including the NUL terminator
162
+ // because ConcatToBuffer() expects so, but Koffi can convert back to a JS string
163
+ // without it (if we reserve the right size).
164
+ let out = ['\0'.repeat(str1.length + str2.length + 1)];
165
+
166
+ ConcatToBuffer(str1, str2, out);
167
+
168
+ console.log(out[0]);
169
+ ```
package/doc/packaging.md CHANGED
@@ -1,4 +1,4 @@
1
- # Packaging
1
+ # Bundlers and Koffi
2
2
 
3
3
  ## Bundling and native modules
4
4
 
package/doc/pointers.md CHANGED
@@ -130,13 +130,63 @@ let total = ComputeTotalLength(strings);
130
130
  console.log(total); // Prints 14
131
131
  ```
132
132
 
133
- By default, just like for objects, array arguments are copied from JS to C but not vice-versa. You can however change the direction as documented in the section on [output parameters](parameters.md#output-parameters).
133
+ By default, just like for objects, array arguments are copied from JS to C but not vice-versa. You can however change the direction as documented in the section on [output parameters](output.md).
134
134
 
135
135
  ## Disposable types
136
136
 
137
+ *New in Koffi 2.0*
138
+
137
139
  Disposable types allow you to register a function that will automatically called after each C to JS conversion performed by Koffi. This can be used to avoid leaking heap-allocated strings, for example.
138
140
 
139
- Read the documentation for [disposable types](parameters.md#heap-allocated-values) on the page about special parameters.
141
+ Some C functions return heap-allocated values directly or through output parameters. While Koffi automatically converts values from C to JS (to a string or an object), it does not know when something needs to be freed, or how.
142
+
143
+ For opaque types, such as FILE, this does not matter because you will explicitly call `fclose()` on them. But some values (such as strings) get implicitly converted by Koffi, and you lose access to the original pointer. This creates a leak if the string is heap-allocated.
144
+
145
+ To avoid this, you can instruct Koffi to call a function on the original pointer once the conversion is done, by creating a **disposable type** with `koffi.dispose(name, type, func)`. This creates a type derived from another type, the only difference being that *func* gets called with the original pointer once the value has been converted and is not needed anymore.
146
+
147
+ The *name* can be omitted to create an anonymous disposable type. If *func* is omitted or is null, Koffi will use `koffi.free(ptr)` (which calls the standard C library *free* function under the hood).
148
+
149
+ ```js
150
+ const AnonHeapStr = koffi.disposable('str'); // Anonymous type (cannot be used in function prototypes)
151
+ const NamedHeapStr = koffi.disposable('HeapStr', 'str'); // Same thing, but named so usable in function prototypes
152
+ const ExplicitFree = koffi.disposable('HeapStr16', 'str16', koffi.free); // You can specify any other JS function
153
+ ```
154
+
155
+ The following example illustrates the use of a disposable type derived from *str*.
156
+
157
+ ```js
158
+ // ES6 syntax: import koffi from 'koffi';
159
+ const koffi = require('koffi');
160
+
161
+ const lib = koffi.load('libc.so.6');
162
+
163
+ const HeapStr = koffi.disposable('str');
164
+ const strdup = lib.cdecl('strdup', HeapStr, ['str']);
165
+
166
+ let copy = strdup('Hello!');
167
+ console.log(copy); // Prints Hello!
168
+ ```
169
+
170
+ When you declare functions with the [prototype-like syntax](functions.md#definition-syntax), you can either use named disposable types or use the '!' shortcut qualifier with compatibles types, as shown in the example below. This qualifier creates an anonymous disposable type that calls `koffi.free(ptr)`.
171
+
172
+ ```js
173
+ // ES6 syntax: import koffi from 'koffi';
174
+ const koffi = require('koffi');
175
+
176
+ const lib = koffi.load('libc.so.6');
177
+
178
+ // You can also use: const strdup = lib.func('const char *! strdup(const char *str)')
179
+ const strdup = lib.func('str! strdup(const char *str)');
180
+
181
+ let copy = strdup('World!');
182
+ console.log(copy); // Prints World!
183
+ ```
184
+
185
+ Disposable types can only be created from pointer or string types.
186
+
187
+ ```{warning}
188
+ Be careful on Windows: if your shared library uses a different CRT (such as msvcrt), the memory could have been allocated by a different malloc/free implementation or heap, resulting in undefined behavior if you use `koffi.free()`.
189
+ ```
140
190
 
141
191
  ## Unwrap pointers
142
192
 
@@ -0,0 +1,108 @@
1
+ # Polymorphic arguments
2
+
3
+ ## Input polymorphism
4
+
5
+ *New in Koffi 2.1*
6
+
7
+ Many C functions use `void *` parameters in order to pass polymorphic objects and arrays, meaning that the data format changes can change depending on one other argument, or on some kind of struct tag member.
8
+
9
+ Koffi provides two features to deal with this:
10
+
11
+ - Buffers and typed JS arrays can be used as values in place everywhere a pointer is expected. See [dynamic arrays](pointers.md#array-pointers-dynamic-arrays) for more information, for input or output.
12
+ - You can use `koffi.as(value, type)` to tell Koffi what kind of type is actually expected.
13
+
14
+ The example below shows the use of `koffi.as()` to read the header of a PNG file with `fread()`.
15
+
16
+ ```js
17
+ // ES6 syntax: import koffi from 'koffi';
18
+ const koffi = require('koffi');
19
+
20
+ const lib = koffi.load('libc.so.6');
21
+
22
+ const FILE = koffi.opaque('FILE');
23
+
24
+ const PngHeader = koffi.pack('PngHeader', {
25
+ signature: koffi.array('uint8_t', 8),
26
+ ihdr: koffi.pack({
27
+ length: 'uint32_be_t',
28
+ chunk: koffi.array('char', 4),
29
+ width: 'uint32_be_t',
30
+ height: 'uint32_be_t',
31
+ depth: 'uint8_t',
32
+ color: 'uint8_t',
33
+ compression: 'uint8_t',
34
+ filter: 'uint8_t',
35
+ interlace: 'uint8_t',
36
+ crc: 'uint32_be_t'
37
+ })
38
+ });
39
+
40
+ const fopen = lib.func('FILE *fopen(const char *path, const char *mode)');
41
+ const fclose = lib.func('int fclose(FILE *fp)');
42
+ const fread = lib.func('size_t fread(_Out_ void *ptr, size_t size, size_t nmemb, FILE *fp)');
43
+
44
+ let filename = process.argv[2];
45
+ if (filename == null)
46
+ throw new Error('Usage: node png.js <image.png>');
47
+
48
+ let hdr = {};
49
+ {
50
+ let fp = fopen(filename, 'rb');
51
+ if (!fp)
52
+ throw new Error(`Failed to open '${filename}'`);
53
+
54
+ try {
55
+ let len = fread(koffi.as(hdr, 'PngHeader *'), 1, koffi.sizeof(PngHeader), fp);
56
+ if (len < koffi.sizeof(PngHeader))
57
+ throw new Error('Failed to read PNG header');
58
+ } finally {
59
+ fclose(fp);
60
+ }
61
+ }
62
+
63
+ console.log('PNG header:', hdr);
64
+ ```
65
+
66
+ ## Output buffers
67
+
68
+ *New in Koffi 2.3*
69
+
70
+ You can use buffers and typed arrays for output (and input/output) pointer parameters. Simply pass the buffer as an argument and the native function will receive a pointer to its contents.
71
+
72
+ Once the native function returns, you can decode the content with `koffi.decode(value, type)` as in the following example:
73
+
74
+ ```js
75
+ // ES6 syntax: import koffi from 'koffi';
76
+ const koffi = require('koffi');
77
+
78
+ const lib = koffi.load('libc.so.6');
79
+
80
+ const Vec3 = koffi.struct('Vec3', {
81
+ x: 'float32',
82
+ y: 'float32',
83
+ z: 'float32'
84
+ })
85
+
86
+ const memcpy = lib.func('void *memcpy(_Out_ void *dest, const void *src, size_t size)');
87
+
88
+ let vec1 = { x: 1, y: 2, z: 3 };
89
+ let vec2 = null;
90
+
91
+ // Copy the vector in a convoluted way through memcpy
92
+ {
93
+ let src = koffi.as(vec1, 'Vec3 *');
94
+ let dest = Buffer.allocUnsafe(koffi.sizeof(Vec3));
95
+
96
+ memcpy(dest, src, koffi.sizeof(Vec3));
97
+
98
+ vec2 = koffi.decode(dest, Vec3);
99
+ }
100
+
101
+ // CHange vector1, leaving copy alone
102
+ [vec1.x, vec1.y, vec1.z] = [vec1.z, vec1.y, vec1.x];
103
+
104
+ console.log(vec1); // { x: 3, y: 2, z: 1 }
105
+ console.log(vec2); // { x: 1, y: 2, z: 3 }
106
+ ```
107
+
108
+ See [pointer arguments](callbacks.md#decoding-pointer-arguments) for another example with the decode function.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koffi",
3
- "version": "2.5.11",
4
- "stable": "2.5.11",
3
+ "version": "2.5.13",
4
+ "stable": "2.5.13",
5
5
  "description": "Fast and simple C FFI (foreign function interface) for Node.js",
6
6
  "keywords": [
7
7
  "foreign",
@@ -17,7 +17,11 @@
17
17
  "url": "https://github.com/Koromix/koffi"
18
18
  },
19
19
  "homepage": "https://koffi.dev/",
20
- "author": "Niels Martignène <niels.martignene@protonmail.com>",
20
+ "author": {
21
+ "name": "Niels Martignène",
22
+ "email": "niels.martignene@protonmail.com",
23
+ "url": "https://koromix.dev/"
24
+ },
21
25
  "main": "src/index.js",
22
26
  "types": "src/index.d.ts",
23
27
  "scripts": {
@@ -31,9 +31,19 @@
31
31
 
32
32
  static FARPROC WINAPI self_exe_hook(unsigned int event, DelayLoadInfo *info)
33
33
  {
34
+ static const wchar_t *const NodeLibraries[] = {
35
+ L"node.dll",
36
+ NULL
37
+ };
38
+
34
39
  if (event == dliNotePreLoadLibrary && !stricmp(info->szDll, "node.exe")) {
35
- HMODULE h = GetModuleHandle(NULL);
36
- return (FARPROC)h;
40
+ for (int i = 0; i < sizeof(NodeLibraries) / sizeof(*NodeLibraries); i++) {
41
+ const wchar_t *name = NodeLibraries[i];
42
+ HMODULE h = GetModuleHandleW(name);
43
+
44
+ if (h)
45
+ return (FARPROC)h;
46
+ }
37
47
  }
38
48
 
39
49
  return NULL;
@@ -13,7 +13,11 @@
13
13
  "type": "git",
14
14
  "url": "https://github.com/Koromix/rygel.git"
15
15
  },
16
- "author": "Niels Martignène <niels.martignene@protonmail.com>",
16
+ "author": {
17
+ "name": "Niels Martignène",
18
+ "email": "niels.martignene@protonmail.com",
19
+ "url": "https://koromix.dev/"
20
+ },
17
21
  "index": "src/index.js",
18
22
  "bin": "cnoke.js",
19
23
  "license": "MIT"
@@ -2678,14 +2678,12 @@ bool TestFile(const char *filename)
2678
2678
 
2679
2679
  bool TestFile(const char *filename, FileType type)
2680
2680
  {
2681
- RG_ASSERT(type != FileType::Link);
2682
-
2683
2681
  FileInfo file_info;
2684
2682
  if (StatFile(filename, (int)StatFlag::IgnoreMissing, &file_info) != StatResult::Success)
2685
2683
  return false;
2686
2684
 
2687
2685
  // Don't follow, but don't warn if we just wanted a file
2688
- if (file_info.type == FileType::Link) {
2686
+ if (type != FileType::Link && file_info.type == FileType::Link) {
2689
2687
  file_info.type = FileType::File;
2690
2688
  }
2691
2689
 
@@ -4494,7 +4492,7 @@ Size ReadCommandOutput(const char *cmd_line, Span<char> out_output)
4494
4492
  bool ReadCommandOutput(const char *cmd_line, HeapArray<char> *out_output)
4495
4493
  {
4496
4494
  int exit_code;
4497
- if (!ExecuteCommandLine(cmd_line, nullptr, {}, Kilobytes(4), out_output, &exit_code))
4495
+ if (!ExecuteCommandLine(cmd_line, nullptr, {}, Mebibytes(1), out_output, &exit_code))
4498
4496
  return false;
4499
4497
  if (exit_code) {
4500
4498
  LogDebug("Command '%1 failed (exit code: %2)", cmd_line, exit_code);
@@ -272,6 +272,7 @@ constexpr Size Kilobytes(Size len) { return len * 1000; }
272
272
  #define RG_SIZE(Type) ((RG::Size)sizeof(Type))
273
273
  template <typename T, unsigned N>
274
274
  char (&ComputeArraySize(T const (&)[N]))[N];
275
+ #define RG_BITS(Type) (8 * RG_SIZE(Type))
275
276
  #define RG_LEN(Array) RG_SIZE(RG::ComputeArraySize(Array))
276
277
  #define RG_OFFSET_OF(Type, Member) ((Size)__builtin_offsetof(Type, Member))
277
278
 
@@ -1856,7 +1857,7 @@ public:
1856
1857
  typedef Iterator<Bitset> iterator_type;
1857
1858
 
1858
1859
  static constexpr Size Bits = N;
1859
- size_t data[(N + RG_SIZE(size_t) - 1) / RG_SIZE(size_t)] = {};
1860
+ size_t data[(N + RG_BITS(size_t) - 1) / RG_BITS(size_t)] = {};
1860
1861
 
1861
1862
  void Clear()
1862
1863
  {
@@ -3828,10 +3829,12 @@ static inline Size DecodeUtf8(Span<const char> str, Size offset, int32_t *out_c)
3828
3829
  #ifdef _WIN32
3829
3830
  #define RG_PATH_SEPARATORS "\\/"
3830
3831
  #define RG_PATH_DELIMITER ';'
3832
+ #define RG_EXECUTABLE_EXTENSION ".exe"
3831
3833
  #define RG_SHARED_LIBRARY_EXTENSION ".dll"
3832
3834
  #else
3833
3835
  #define RG_PATH_SEPARATORS "/"
3834
3836
  #define RG_PATH_DELIMITER ':'
3837
+ #define RG_EXECUTABLE_EXTENSION ""
3835
3838
  #define RG_SHARED_LIBRARY_EXTENSION ".so"
3836
3839
  #endif
3837
3840
 
package/src/index.js CHANGED
@@ -47,13 +47,13 @@ try {
47
47
  switch (triplet) {
48
48
  case 'darwin_arm64': { native = require('../build/koffi/darwin_arm64/koffi.node'); } break;
49
49
  case 'darwin_x64': { native = require('../build/koffi/darwin_x64/koffi.node'); } break;
50
- case 'freebsd_arm46': { native = require('../build/koffi/freebsd_arm46/koffi.node'); } break;
50
+ case 'freebsd_arm64': { native = require('../build/koffi/freebsd_arm64/koffi.node'); } break;
51
51
  case 'freebsd_ia32': { native = require('../build/koffi/freebsd_ia32/koffi.node'); } break;
52
52
  case 'freebsd_x64': { native = require('../build/koffi/freebsd_x64/koffi.node'); } break;
53
53
  case 'linux_arm32hf': { native = require('../build/koffi/linux_arm32hf/koffi.node'); } break;
54
54
  case 'linux_arm64': { native = require('../build/koffi/linux_arm64/koffi.node'); } break;
55
55
  case 'linux_ia32': { native = require('../build/koffi/linux_ia32/koffi.node'); } break;
56
- case 'linux_risc64hf64': { native = require('../build/koffi/linux_risc64hf64/koffi.node'); } break;
56
+ case 'linux_riscv64hf64': { native = require('../build/koffi/linux_riscv64hf64/koffi.node'); } break;
57
57
  case 'linux_x64': { native = require('../build/koffi/linux_x64/koffi.node'); } break;
58
58
  case 'openbsd_ia32': { native = require('../build/koffi/openbsd_ia32/koffi.node'); } break;
59
59
  case 'openbsd_x64': { native = require('../build/koffi/openbsd_x64/koffi.node'); } break;
@@ -81,7 +81,7 @@ class alignas(8) CallData {
81
81
  uint8_t *return_ptr = nullptr;
82
82
 
83
83
  LocalArray<int16_t, 16> used_trampolines;
84
- LocalArray<OutArgument, MaxParameters> out_arguments;
84
+ HeapArray<OutArgument> out_arguments;
85
85
 
86
86
  BlockAllocator call_alloc;
87
87
 
@@ -233,7 +233,7 @@ static Napi::Value CreateStructType(const Napi::CallbackInfo &info, bool pad)
233
233
  Napi::Array keys = obj.GetPropertyNames();
234
234
 
235
235
  type->name = named ? DuplicateString(name.Utf8Value().c_str(), &instance->str_alloc).ptr
236
- : Fmt(&instance->str_alloc, "<type_%1>", instance->types.len).ptr;
236
+ : Fmt(&instance->str_alloc, "<anonymous_%1>", instance->types.len).ptr;
237
237
 
238
238
  type->primitive = PrimitiveKind::Record;
239
239
  type->align = 1;
@@ -362,7 +362,7 @@ static Napi::Value CreateUnionType(const Napi::CallbackInfo &info)
362
362
  Napi::Array keys = obj.GetPropertyNames();
363
363
 
364
364
  type->name = named ? DuplicateString(name.Utf8Value().c_str(), &instance->str_alloc).ptr
365
- : Fmt(&instance->str_alloc, "<type_%1>", instance->types.len).ptr;
365
+ : Fmt(&instance->str_alloc, "<anonymous_%1>", instance->types.len).ptr;
366
366
 
367
367
  type->primitive = PrimitiveKind::Union;
368
368
  type->align = 1;
@@ -493,7 +493,7 @@ static Napi::Value CreateOpaqueType(const Napi::CallbackInfo &info)
493
493
  RG_DEFER_N(err_guard) { instance->types.RemoveLast(1); };
494
494
 
495
495
  type->name = named ? DuplicateString(name.Utf8Value().c_str(), &instance->str_alloc).ptr
496
- : Fmt(&instance->str_alloc, "<type_%1>", instance->types.len).ptr;
496
+ : Fmt(&instance->str_alloc, "<anonymous_%1>", instance->types.len).ptr;
497
497
 
498
498
  type->primitive = PrimitiveKind::Void;
499
499
  type->size = 0;
@@ -699,7 +699,7 @@ static Napi::Value CreateDisposableType(const Napi::CallbackInfo &info)
699
699
  type->members.allocator = GetNullAllocator();
700
700
 
701
701
  type->name = named ? DuplicateString(name.Utf8Value().c_str(), &instance->str_alloc).ptr
702
- : Fmt(&instance->str_alloc, "<type_%1>", instance->types.len).ptr;
702
+ : Fmt(&instance->str_alloc, "<anonymous_%1>", instance->types.len).ptr;
703
703
 
704
704
  type->dispose = dispose;
705
705
  type->dispose_ref = Napi::Persistent(dispose_func);
@@ -36,7 +36,7 @@ static const int DefaultMaxAsyncCalls = 64;
36
36
  static const Size DefaultMaxTypeSize = Mebibytes(64);
37
37
 
38
38
  static const int MaxAsyncCalls = 256;
39
- static const Size MaxParameters = 32;
39
+ static const Size MaxParameters = 64;
40
40
  static const Size MaxTrampolines = 8192;
41
41
 
42
42
  enum class PrimitiveKind {
@@ -243,7 +243,7 @@ const TypeInfo *ResolveType(Napi::Env env, Span<const char> str, int *out_direct
243
243
  TypeInfo *copy = instance->types.AppendDefault();
244
244
 
245
245
  memcpy((void *)copy, (const void *)type, RG_SIZE(*type));
246
- copy->name = Fmt(&instance->str_alloc, "<type_%1>", instance->types.len).ptr;
246
+ copy->name = Fmt(&instance->str_alloc, "<anonymous_%1>", instance->types.len).ptr;
247
247
  copy->members.allocator = GetNullAllocator();
248
248
 
249
249
  copy->dispose = [](Napi::Env env, const TypeInfo *, const void *ptr) {