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/CHANGELOG.md CHANGED
@@ -4,16 +4,26 @@
4
4
 
5
5
  ### Koffi 2.5
6
6
 
7
- #### Koffi 2.5.11
7
+ #### Koffi 2.5.13 (2023-08-23)
8
8
 
9
- - Support casting function pointers with [koffi.as()](parameters.md#input-polymorphism)
9
+ - Fix DLL error when using Koffi from NW.js on Windows
10
+ - Simplify NW.js Koffi example
11
+
12
+ #### Koffi 2.5.12 (2023-08-21)
13
+
14
+ - Fix native module bundling for FreeBSD ARM64 and Linux RISC-V 64
15
+ - Increase maximum number of parameters to 64
16
+
17
+ #### Koffi 2.5.11 (2023-08-03)
18
+
19
+ - Support casting function pointers with [koffi.as()](polymorphism.md#input-polymorphism)
10
20
  - Build in C++20 mode
11
21
 
12
- #### Koffi 2.5.10
22
+ #### Koffi 2.5.10 (2023-08-01)
13
23
 
14
24
  - Fix CMake regression when client has to build Koffi
15
25
 
16
- #### Koffi 2.5.9
26
+ #### Koffi 2.5.9 (2023-07-28)
17
27
 
18
28
  **Main changes:**
19
29
 
@@ -25,43 +35,43 @@
25
35
  - Add missing unload() export to TS file
26
36
  - Add export for koffi.types in TS file
27
37
 
28
- #### Koffi 2.5.8
38
+ #### Koffi 2.5.8 (2023-07-26)
29
39
 
30
40
  - Add more search paths for native Koffi modules
31
41
  - Add section [about bundling](start.md#bundling-koffi) to documentation
32
42
 
33
- #### Koffi 2.5.7
43
+ #### Koffi 2.5.7 (2023-07-19)
34
44
 
35
45
  - Point package to new repository
36
46
 
37
- #### Koffi 2.5.6
47
+ #### Koffi 2.5.6 (2023-07-19)
38
48
 
39
49
  - Increase limit of output parameters from 16 to 32
40
50
 
41
- #### Koffi 2.5.5
51
+ #### Koffi 2.5.5 (2023-07-17)
42
52
 
43
53
  - Support decoding non-char null-terminated arrays
44
54
 
45
- #### Koffi 2.5.4
55
+ #### Koffi 2.5.4 (2023-07-14)
46
56
 
47
57
  - Fix `koffi.pointer()` not accepting disposable types
48
58
  - Fix potential issues when making pointers to anonymous types
49
59
 
50
- #### Koffi 2.5.3
60
+ #### Koffi 2.5.3 (2023-07-05)
51
61
 
52
62
  - Add missing union exports in TS definition file
53
63
  - Fix some parameter names in TS definition file
54
64
 
55
- #### Koffi 2.5.2
65
+ #### Koffi 2.5.2 (2023-07-04)
56
66
 
57
67
  - Default initialize unset object/struct members
58
68
 
59
- #### Koffi 2.5.1
69
+ #### Koffi 2.5.1 (2023-06-20)
60
70
 
61
71
  - Fix crash with some struct types in System V 64 ABI
62
72
  - Always use direct passthrough for buffer arguments
63
73
 
64
- #### Koffi 2.5.0
74
+ #### Koffi 2.5.0 (2023-06-20)
65
75
 
66
76
  **New features:**
67
77
 
@@ -74,12 +84,12 @@
74
84
 
75
85
  ### Koffi 2.4
76
86
 
77
- #### Koffi 2.4.2
87
+ #### Koffi 2.4.2 (2023-06-04)
78
88
 
79
89
  - Support calling variadic function pointers
80
90
  - Add documentation for function pointers
81
91
 
82
- #### Koffi 2.4.1
92
+ #### Koffi 2.4.1 (2023-06-03)
83
93
 
84
94
  **Main changes:**
85
95
 
@@ -96,49 +106,49 @@
96
106
 
97
107
  ### Koffi 2.3
98
108
 
99
- #### Koffi 2.3.20
109
+ #### Koffi 2.3.20 (2023-05-15)
100
110
 
101
111
  - Support explicit library unloading with `lib.unload()`
102
112
 
103
- #### Koffi 2.3.19
113
+ #### Koffi 2.3.19 (2023-04-21)
104
114
 
105
115
  - Actually allow non-ambiguous [string] values for `void *` arguments
106
116
 
107
- #### Koffi 2.3.18
117
+ #### Koffi 2.3.18 (2023-04-21)
108
118
 
109
119
  - Fix possible crash on exit caused by unregistered callbacks
110
120
 
111
- #### Koffi 2.3.17
121
+ #### Koffi 2.3.17 (2023-04-20)
112
122
 
113
123
  - Allow strings for input `void *`, `int8_t *` and `int16_t *` pointer arguments
114
124
  - Support using `[string]` (single-element string arrays) for polymorphic input/output arguments
115
125
 
116
- #### Koffi 2.3.16
126
+ #### Koffi 2.3.16 (2023-04-11)
117
127
 
118
128
  - Fix Windows ARM64 build to work with official Node.js version
119
129
  - Compile Windows builds with Visual Studio 2022 17.5.3
120
130
  - Support null in `koffi.free()` and `koffi.address()`
121
131
 
122
- #### Koffi 2.3.15
132
+ #### Koffi 2.3.15 (2023-04-10)
123
133
 
124
134
  - Improve manual decoding of 0-terminated strings
125
135
  - Add checks around array conversion hints
126
136
 
127
- #### Koffi 2.3.14
137
+ #### Koffi 2.3.14 (2023-04-05)
128
138
 
129
139
  - Add `koffi.errno()` function to get and set current errno value
130
140
  - Add `koffi.os.errno` object with valid errno codes
131
141
 
132
- #### Koffi 2.3.13
142
+ #### Koffi 2.3.13 (2023-03-30)
133
143
 
134
144
  - Add `koffi.address()` to get the raw value of a wrapper pointer
135
145
 
136
- #### Koffi 2.3.12
146
+ #### Koffi 2.3.12 (2023-03-30)
137
147
 
138
148
  - Fix broken syntax in TS definition file
139
149
  - Add missing exported properties in TS file
140
150
 
141
- #### Koffi 2.3.11
151
+ #### Koffi 2.3.11 (2023-03-30)
142
152
 
143
153
  **Main changes:**
144
154
 
@@ -150,27 +160,27 @@
150
160
  - Avoid using `statx()` to allow compilation with glibc < 2.28
151
161
  - Reorganize NPM package files to be less convoluted
152
162
 
153
- #### Koffi 2.3.9
163
+ #### Koffi 2.3.9 (2023-03-10)
154
164
 
155
165
  - Relicense under MIT license
156
166
 
157
- #### Koffi 2.3.8
167
+ #### Koffi 2.3.8 (2023-02-28)
158
168
 
159
169
  - Disable non-ready union support
160
170
  - Simplify Windows stack allocation and drop NOACCESS and GUARD pages
161
171
  - Adjust Windows TEB SEH chain and GuaranteedStackBytes for Koffi calls
162
172
 
163
- #### Koffi 2.3.7
173
+ #### Koffi 2.3.7 (2023-02-27)
164
174
 
165
175
  - Fix missing require in index.js ([@gastonFrecceroNapse](https://github.com/gastonFrecceroNapse))
166
176
  - Reduce NPM package bloat (from 65 MB to 20 MB) caused by changes in 2.3.6
167
177
 
168
- #### Koffi 2.3.6
178
+ #### Koffi 2.3.6 (2023-02-26)
169
179
 
170
180
  - Fix broken TS definition file
171
181
  - Keep all prebuilt binaries and load correct one at runtime
172
182
 
173
- #### Koffi 2.3.5
183
+ #### Koffi 2.3.5 (2023-02-24)
174
184
 
175
185
  **Main fixes:**
176
186
 
@@ -186,15 +196,15 @@
186
196
  - Mark optional properties in TS TypeInfo class
187
197
  - Minor performance improvements
188
198
 
189
- #### Koffi 2.3.4
199
+ #### Koffi 2.3.4 (2023-01-31)
190
200
 
191
201
  - Fix error when installing Koffi on Windows (2.3.2)
192
202
 
193
- #### Koffi 2.3.2
203
+ #### Koffi 2.3.2 (2023-01-30)
194
204
 
195
205
  **Main changes:**
196
206
 
197
- - Fix type parser issues (such as ignoring some [disposable qualifiers](parameters.md#heap-allocated-values))
207
+ - Fix type parser issues (such as ignoring some [disposable qualifiers](pointers.md#disposable-types))
198
208
  - Fix crash when using disposable types in output parameters
199
209
  - Add basic [koffi.stats()](misc.md#usage-statistics) interface
200
210
 
@@ -203,18 +213,18 @@
203
213
  - Avoid CNoke dependency
204
214
  - Clear out development dependencies from package.json
205
215
 
206
- #### Koffi 2.3.1
216
+ #### Koffi 2.3.1 (2023-01-3O)
207
217
 
208
218
  - Error out when trying to use ambiguous `void *` arguments (input and/or output)
209
219
  - Adjust TypeScript definitions ([@insraq](https://github.com/insraq))
210
220
  - Fix possible crash when parsing invalid prototype
211
221
 
212
- #### Koffi 2.3.0
222
+ #### Koffi 2.3.0 (2023-01-25)
213
223
 
214
224
  **Main changes:**
215
225
 
216
226
  - Allow buffers (TypedArray or ArrayBuffer) values for input and/or output pointer arguments (for polymorphic arguments)
217
- - Support opaque buffers (TypedArray or ArrayBuffer) values in `koffi.decode()` to [decode output buffers](parameters.md#output-buffers)
227
+ - Support opaque buffers (TypedArray or ArrayBuffer) values in `koffi.decode()` to [decode output buffers](polymorphism.md#output-buffers)
218
228
  - Decode non-string types as arrays when an [explicit length is passed to koffi.decode()](callbacks.md#decoding-pointer-arguments)
219
229
 
220
230
  **Other changes:**
@@ -228,21 +238,21 @@
228
238
 
229
239
  ### Koffi 2.2
230
240
 
231
- #### Koffi 2.2.5
241
+ #### Koffi 2.2.5 (2023-01-23)
232
242
 
233
243
  - Relicense Koffi under LGPL 3.0
234
244
 
235
- #### Koffi 2.2.4
245
+ #### Koffi 2.2.4 (2023-01-19)
236
246
 
237
247
  - Fix memory leak on Windows (in Koffi 2.2.3) when running many async calls
238
248
  - Reorganize documentation pages
239
249
 
240
- #### Koffi 2.2.3
250
+ #### Koffi 2.2.3 (2023-01-17)
241
251
 
242
252
  - Support native code that uses [Structured Exception Handling (SEH)](https://learn.microsoft.com/en-us/cpp/cpp/structured-exception-handling-c-cpp) on Windows (x86, x64 and ARM64)
243
253
  - Try to use ebp/rbp as frame pointer in x86/x64 ASM code
244
254
 
245
- #### Koffi 2.2.2
255
+ #### Koffi 2.2.2 (2023-01-14)
246
256
 
247
257
  **Main fixes:**
248
258
 
@@ -256,16 +266,16 @@
256
266
  - Check N-API version when module is loaded
257
267
  - Optimize callback unregistration
258
268
 
259
- #### Koffi 2.2.1
269
+ #### Koffi 2.2.1 (2022-12-21)
260
270
 
261
271
  - Fix crash when [calling callback again after FFI call inside previous callback](https://github.com/Koromix/rygel/issues/15)
262
272
 
263
- #### Koffi 2.2.0
273
+ #### Koffi 2.2.0 (2022-12-20)
264
274
 
265
275
  **New features:**
266
276
 
267
277
  - Add [koffi.decode()](callbacks.md#decoding-pointer-arguments) for callback pointer arguments
268
- - Support transparent [output string parameters](parameters.md#output-parameters)
278
+ - Support transparent [output string parameters](output.md#string-buffer-example)
269
279
  - Add `koffi.offsetof()` utility function
270
280
  - Support optional *this* binding in `koffi.register()`
271
281
 
@@ -276,11 +286,11 @@
276
286
 
277
287
  ### Koffi 2.1
278
288
 
279
- #### Koffi 2.1.5
289
+ #### Koffi 2.1.5 (2022-11-27)
280
290
 
281
291
  - Add missing README.md file to NPM package
282
292
 
283
- #### Koffi 2.1.4
293
+ #### Koffi 2.1.4 (2022-11-25)
284
294
 
285
295
  **Main changes:**
286
296
 
@@ -291,24 +301,24 @@
291
301
 
292
302
  - Moved Koffi to a new repository: https://github.com/Koromix/rygel/
293
303
 
294
- #### Koffi 2.1.3
304
+ #### Koffi 2.1.3 (2022-10-31)
295
305
 
296
306
  - Support up to 16 output parameters (instead of 8)
297
307
 
298
- #### Koffi 2.1.2
308
+ #### Koffi 2.1.2 (2022-10-31)
299
309
 
300
310
  - Support up to 8 output parameters (instead of 4)
301
311
 
302
- #### Koffi 2.1.1
312
+ #### Koffi 2.1.1 (2022-08-16)
303
313
 
304
314
  - Fix potential memory allocation bugs
305
315
 
306
- #### Koffi 2.1.0
316
+ #### Koffi 2.1.0 (2022-08-13)
307
317
 
308
318
  **Main changes:**
309
319
 
310
- - Add [koffi.as()](parameters.md#polymorphic-parameters) to support polymorphic APIs based on `void *` parameters
311
- - Add [endian-sensitive integer types](types.md#endian-sensitive-types): `intX_le_t`, `intX_be_t`, `uintX_le_t`, `uintX_be_t`
320
+ - Add [koffi.as()](polymorphism.md#input-polymorphism) to support polymorphic APIs based on `void *` parameters
321
+ - Add [endian-sensitive integer types](input.md#endian-sensitive-types): `intX_le_t`, `intX_be_t`, `uintX_le_t`, `uintX_be_t`
312
322
  - Accept typed arrays for `void *` parameters
313
323
  - Introduce `koffi.opaque()` to replace `koffi.handle()` (which remains supported until Koffi 3.0)
314
324
  - Support JS Array and TypedArray to fill struct and array pointer members
@@ -323,15 +333,15 @@
323
333
 
324
334
  ### Koffi 2.0
325
335
 
326
- #### Koffi 2.0.1
336
+ #### Koffi 2.0.1 (2022-07-30)
327
337
 
328
338
  - Return `undefined` (instead of null) for `void` functions
329
339
 
330
- #### Koffi 2.0.0
340
+ #### Koffi 2.0.0 (2022-07-29)
331
341
 
332
342
  **Major new features:**
333
343
 
334
- - Add [disposable types](parameters.md#heap-allocated-values) for automatic disposal of C values (such as heap-allocated strings)
344
+ - Add [disposable types](pointers.md#disposable-types) for automatic disposal of C values (such as heap-allocated strings)
335
345
  - Add support for [registered callbacks](callbacks.md#registered-callbacks), that can be called after the initial FFI call
336
346
  - Support named pointer types
337
347
  - Support complex type specifications outside of prototype parser
@@ -353,15 +363,15 @@ Consult the [migration guide](migration.md) for more information.
353
363
 
354
364
  ### Koffi 1.3
355
365
 
356
- #### Koffi 1.3.12
366
+ #### Koffi 1.3.12 (2022-07-27)
357
367
 
358
368
  - Fix support for Yarn package manager
359
369
 
360
- #### Koffi 1.3.11
370
+ #### Koffi 1.3.11 (2022-07-26)
361
371
 
362
372
  - Fix broken parsing of `void *` when used for first parameter
363
373
 
364
- #### Koffi 1.3.10
374
+ #### Koffi 1.3.10 (2022-07-25)
365
375
 
366
376
  **Main fixes:**
367
377
 
@@ -373,11 +383,11 @@ Consult the [migration guide](migration.md) for more information.
373
383
 
374
384
  - Various documentation fixes and improvements
375
385
 
376
- #### Koffi 1.3.9
386
+ #### Koffi 1.3.9 (2022-07-15)
377
387
 
378
388
  - Fix prebuild compatibility with Electron on Windows x64
379
389
 
380
- #### Koffi 1.3.8
390
+ #### Koffi 1.3.8 (2022-07-12)
381
391
 
382
392
  **Main changes:**
383
393
 
@@ -388,7 +398,7 @@ Consult the [migration guide](migration.md) for more information.
388
398
 
389
399
  - Fix and harmonize a few error messages
390
400
 
391
- #### Koffi 1.3.7
401
+ #### Koffi 1.3.7 (2022-07-07)
392
402
 
393
403
  **Main fixes:**
394
404
 
@@ -401,7 +411,7 @@ Consult the [migration guide](migration.md) for more information.
401
411
  - Add str/str16 type aliases for string/string16
402
412
  - Various documentation fixes and improvements
403
413
 
404
- #### Koffi 1.3.6
414
+ #### Koffi 1.3.6 (2022-07-01)
405
415
 
406
416
  **Main fixes:**
407
417
 
@@ -413,7 +423,7 @@ Consult the [migration guide](migration.md) for more information.
413
423
  - Prebuild with Clang for Windows x64 and Linux x64 binaries
414
424
  - Various documentation improvements
415
425
 
416
- #### Koffi 1.3.5
426
+ #### Koffi 1.3.5 (2022-06-25)
417
427
 
418
428
  **Main changes:**
419
429
 
@@ -425,11 +435,11 @@ Consult the [migration guide](migration.md) for more information.
425
435
  - Reduce default async memory stack and heap size
426
436
  - Various documentation improvements
427
437
 
428
- #### Koffi 1.3.4
438
+ #### Koffi 1.3.4 (2022-06-24)
429
439
 
430
440
  - Fix possible OpenBSD i386 crash with `(void)` functions
431
441
 
432
- #### Koffi 1.3.3
442
+ #### Koffi 1.3.3 (2022-06-24)
433
443
 
434
444
  **Main fixes:**
435
445
 
@@ -441,16 +451,16 @@ Consult the [migration guide](migration.md) for more information.
441
451
  - Disable unsafe compiler optimizations
442
452
  - Various documentation improvements
443
453
 
444
- #### Koffi 1.3.2
454
+ #### Koffi 1.3.2 (2022-06-23)
445
455
 
446
456
  - Support compilation in C++14 mode (graceful degradation)
447
457
  - Support older toolchains on Linux (tested on Debian 9)
448
458
 
449
- #### Koffi 1.3.1
459
+ #### Koffi 1.3.1 (2022-06-22)
450
460
 
451
461
  - The prebuilt binary is tested when Koffi is installed, and a rebuild happens if it fails to load
452
462
 
453
- #### Koffi 1.3.0
463
+ #### Koffi 1.3.0 (2022-06-22)
454
464
 
455
465
  **Major changes:**
456
466
 
@@ -468,15 +478,15 @@ Consult the [migration guide](migration.md) for more information.
468
478
 
469
479
  ### Koffi 1.2
470
480
 
471
- #### Koffi 1.2.4
481
+ #### Koffi 1.2.4 (2022-06-12)
472
482
 
473
483
  - Windows ARM64 is now supported
474
484
 
475
- #### Koffi 1.2.3
485
+ #### Koffi 1.2.3 (2022-06-11)
476
486
 
477
487
  - A prebuilt binary for macOS ARM64 (M1) is now included
478
488
 
479
- #### Koffi 1.2.1
489
+ #### Koffi 1.2.1 (2022-06-11)
480
490
 
481
491
  This entry documents changes since version 1.1.0.
482
492
 
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/doc/callbacks.md CHANGED
@@ -1,4 +1,4 @@
1
- # Callbacks
1
+ # Javascript callbacks
2
2
 
3
3
  *Changed in Koffi 2.4*
4
4
 
package/doc/conf.py CHANGED
@@ -113,5 +113,6 @@ myst_number_code_blocks = ['c', 'js', 'sh', 'batch']
113
113
 
114
114
  rediraffe_redirects = {
115
115
  "changes.md": "changelog.md",
116
- "bundling.md": "packaging.md"
116
+ "bundling.md": "packaging.md",
117
+ "parameters.md": "input.md"
117
118
  }
package/doc/functions.md CHANGED
@@ -217,3 +217,14 @@ let delta = substract(100, 58);
217
217
 
218
218
  console.log(sum, delta); // Prints 9 and 42
219
219
  ```
220
+
221
+ ## Conversion of parameters
222
+
223
+ By default, Koffi will only forward and translate arguments from Javascript to C. However, many C functions use pointer arguments for output values, or input/output values.
224
+
225
+ Among other thing, in the the following pages you will learn more about:
226
+
227
+ - How Koffi translates [input parameters](input.md) to C
228
+ - How you can [define and use pointers](pointers.md)
229
+ - How to deal with [output parameters](output.md)
230
+ - How to handle [polymorphic API](polymorphism.md)
package/doc/index.rst CHANGED
@@ -15,6 +15,8 @@ Koffi requires a recent `Node.js <https://nodejs.org/>`_ version with N-API vers
15
15
 
16
16
  The source code is available here: https://github.com/Koromix/rygel/ (in the *src/koffi* subdirectory).
17
17
 
18
+ New releases are frequent, look at the :ref:`changelog<changelog>` for more information.
19
+
18
20
  Table of contents
19
21
  -----------------
20
22
 
@@ -24,10 +26,11 @@ Table of contents
24
26
  platforms
25
27
  start
26
28
  functions
27
- types
29
+ input
28
30
  pointers
31
+ output
32
+ polymorphism
29
33
  unions
30
- parameters
31
34
  callbacks
32
35
  misc
33
36
  packaging
@@ -1,4 +1,4 @@
1
- # Data types
1
+ # Input parameters
2
2
 
3
3
  ## Primitive types
4
4
 
@@ -6,47 +6,47 @@
6
6
 
7
7
  While the C standard allows for variation in the size of most integer types, Koffi enforces the same definition for most primitive types, listed below:
8
8
 
9
- JS type | C type | Bytes | Signedness | Note
10
- ---------------- | ----------------------------- | ----- | ---------- | ---------------------------
11
- Undefined | void | 0 | | Only valid as a return type
12
- Number (integer) | int8, int8_t | 1 | Signed |
13
- Number (integer) | uint8, uint8_t | 1 | Unsigned |
14
- Number (integer) | char | 1 | Signed |
15
- Number (integer) | uchar, unsigned char | 1 | Unsigned |
16
- Number (integer) | char16, char16_t | 2 | Signed |
17
- Number (integer) | int16, int16_t | 2 | Signed |
18
- Number (integer) | uint16, uint16_t | 2 | Unsigned |
19
- Number (integer) | short | 2 | Signed |
20
- Number (integer) | ushort, unsigned short | 2 | Unsigned |
21
- Number (integer) | int32, int32_t | 4 | Signed |
22
- Number (integer) | uint32, uint32_t | 4 | Unsigned |
23
- Number (integer) | int | 4 | Signed |
24
- Number (integer) | uint, unsigned int | 4 | Unsigned |
25
- Number (integer) | int64, int64_t | 8 | Signed |
26
- Number (integer) | uint64, uint64_t | 8 | Unsigned |
27
- Number (integer) | longlong, long long | 8 | Signed |
28
- Number (integer) | ulonglong, unsigned long long | 8 | Unsigned |
29
- Number (float) | float32 | 4 | |
30
- Number (float) | float64 | 8 | |
31
- Number (float) | float | 4 | |
32
- Number (float) | double | 8 | |
9
+ C type | JS type | Bytes | Signedness | Note
10
+ ----------------------------- | ---------------- | ----- | ---------- | ---------------------------
11
+ void | Undefined | 0 | | Only valid as a return type
12
+ int8, int8_t | Number (integer) | 1 | Signed |
13
+ uint8, uint8_t | Number (integer) | 1 | Unsigned |
14
+ char | Number (integer) | 1 | Signed |
15
+ uchar, unsigned char | Number (integer) | 1 | Unsigned |
16
+ char16, char16_t | Number (integer) | 2 | Signed |
17
+ int16, int16_t | Number (integer) | 2 | Signed |
18
+ uint16, uint16_t | Number (integer) | 2 | Unsigned |
19
+ short | Number (integer) | 2 | Signed |
20
+ ushort, unsigned short | Number (integer) | 2 | Unsigned |
21
+ int32, int32_t | Number (integer) | 4 | Signed |
22
+ uint32, uint32_t | Number (integer) | 4 | Unsigned |
23
+ int | Number (integer) | 4 | Signed |
24
+ uint, unsigned int | Number (integer) | 4 | Unsigned |
25
+ int64, int64_t | Number (integer) | 8 | Signed |
26
+ uint64, uint64_t | Number (integer) | 8 | Unsigned |
27
+ longlong, long long | Number (integer) | 8 | Signed |
28
+ ulonglong, unsigned long long | Number (integer) | 8 | Unsigned |
29
+ float32 | Number (float) | 4 | |
30
+ float64 | Number (float) | 8 | |
31
+ float | Number (float) | 4 | |
32
+ double | Number (float) | 8 | |
33
33
 
34
34
  Koffi also accepts BigInt values when converting from JS to C integers. If the value exceeds the range of the C type, Koffi will convert the number to an undefined value. In the reverse direction, BigInt values are automatically used when needed for big 64-bit integers.
35
35
 
36
36
  Koffi defines a few more types that can change size depending on the OS and the architecture:
37
37
 
38
- JS type | C type | Signedness | Note
38
+ C type | JS type | Signedness | Note
39
39
  ---------------- | ---------------- | ---------- | ------------------------------------------------
40
- Boolean | bool | | Usually one byte
41
- Number (integer) | long | Signed | 4 or 8 bytes depending on platform (LP64, LLP64)
42
- Number (integer) | ulong | Unsigned | 4 or 8 bytes depending on platform (LP64, LLP64)
43
- Number (integer) | unsigned long | Unsigned | 4 or 8 bytes depending on platform (LP64, LLP64)
44
- Number (integer) | intptr | Signed | 4 or 8 bytes depending on register width
45
- Number (integer) | intptr_t | Signed | 4 or 8 bytes depending on register width
46
- Number (integer) | uintptr | Unsigned | 4 or 8 bytes depending on register width
47
- Number (integer) | uintptr_t | Unsigned | 4 or 8 bytes depending on register width
48
- String | str, string | | JS strings are converted to and from UTF-8
49
- String | str16, string16 | | JS strings are converted to and from UTF-16 (LE)
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)
50
50
 
51
51
  Primitive types can be specified by name (in a string) or through `koffi.types`:
52
52
 
@@ -142,14 +142,14 @@ const Function2 = lib.func('Function', A, [A]);
142
142
 
143
143
  Many C libraries use some kind of object-oriented API, with a pair of functions dedicated to create and delete objects. An obvious example of this can be found in stdio.h, with the opaque `FILE *` pointer. You can open and close files with `fopen()` and `fclose()`, and manipule the opaque pointer with other functions such as `fread()` or `ftell()`.
144
144
 
145
- In Koffi, you can manage this with opaque types. Declare the opaque type with `koffi.opaque(name)`, and use a pointer to this type either as a return type or some kind of [output parameter](parameters.md#output-parameters) (with a double pointer).
145
+ In Koffi, you can manage this with opaque types. Declare the opaque type with `koffi.opaque(name)`, and use a pointer to this type either as a return type or some kind of [output parameter](output.md) (with a double pointer).
146
146
 
147
147
  ```{note}
148
148
  Opaque types **have changed in version 2.0, and again in version 2.1**.
149
149
 
150
150
  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.
151
151
 
152
- Now, you must use them through a pointer, and use an array for output parameters. This is shown in the example below (look for the call to `ConcatNewOut` in the JS part), and is described in the section on [output parameters](parameters.md#output-parameters).
152
+ Now, you must use them through a pointer, and use an array for output parameters. This is shown in the example below (look for the call to `ConcatNewOut` in the JS part), and is described in the section on [output parameters](output.md).
153
153
 
154
154
  In addition to this, you should use `koffi.opaque()` (introduced in Koffi 2.1) instead of `koffi.handle()` which is deprecated, and will be removed eventually in Koffi 3.0.
155
155
 
@@ -376,6 +376,10 @@ Koffi can also convert JS strings to fixed-sized arrays in the following cases:
376
376
 
377
377
  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')`).
378
378
 
379
- ### Array pointers (dynamic arrays)
379
+ ### Dynamic arrays (pointers)
380
380
 
381
381
  In C, dynamically-sized arrays are usually passed around as pointers. Read more about [array pointers](pointers.md#array-pointers-dynamic-arrays) in the relevant section.
382
+
383
+ ## Union types
384
+
385
+ The declaration and use of [unions types](unions.md) will be explained in a later section, they are only briefly mentioned here if you need them.