koffi 1.3.6 → 1.3.7
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.
- package/ChangeLog.md +13 -0
- package/benchmark/atoi_koffi.js +1 -1
- package/benchmark/raylib_koffi.js +4 -4
- package/build/qemu/1.3.7/koffi_darwin_arm64.tar.gz +0 -0
- package/build/qemu/1.3.7/koffi_darwin_x64.tar.gz +0 -0
- package/build/qemu/1.3.7/koffi_freebsd_arm64.tar.gz +0 -0
- package/build/qemu/1.3.7/koffi_freebsd_ia32.tar.gz +0 -0
- package/build/qemu/1.3.7/koffi_freebsd_x64.tar.gz +0 -0
- package/build/qemu/1.3.7/koffi_linux_arm32hf.tar.gz +0 -0
- package/build/qemu/1.3.7/koffi_linux_arm64.tar.gz +0 -0
- package/build/qemu/1.3.7/koffi_linux_ia32.tar.gz +0 -0
- package/build/qemu/1.3.7/koffi_linux_riscv64hf64.tar.gz +0 -0
- package/build/qemu/1.3.7/koffi_linux_x64.tar.gz +0 -0
- package/build/qemu/1.3.7/koffi_openbsd_ia32.tar.gz +0 -0
- package/build/qemu/1.3.7/koffi_openbsd_x64.tar.gz +0 -0
- package/build/qemu/1.3.7/koffi_win32_arm64.tar.gz +0 -0
- package/build/qemu/1.3.7/koffi_win32_ia32.tar.gz +0 -0
- package/build/qemu/1.3.7/koffi_win32_x64.tar.gz +0 -0
- package/doc/_static/perf_linux_20220628.png +0 -0
- package/doc/benchmarks.xlsx +0 -0
- package/doc/contribute.md +3 -6
- package/doc/dist/doctrees/changes.doctree +0 -0
- package/doc/dist/doctrees/contribute.doctree +0 -0
- package/doc/dist/doctrees/environment.pickle +0 -0
- package/doc/dist/doctrees/functions.doctree +0 -0
- package/doc/dist/doctrees/index.doctree +0 -0
- package/doc/dist/doctrees/start.doctree +0 -0
- package/doc/dist/doctrees/types.doctree +0 -0
- package/doc/dist/html/_sources/contribute.md.txt +3 -6
- package/doc/dist/html/_sources/functions.md.txt +9 -8
- package/doc/dist/html/_sources/start.md.txt +2 -2
- package/doc/dist/html/_sources/types.md.txt +15 -11
- package/doc/dist/html/_static/basic.css +12 -14
- package/doc/dist/html/_static/perf_linux_20220628.png +0 -0
- package/doc/dist/html/benchmarks.html +1 -1
- package/doc/dist/html/changes.html +16 -1
- package/doc/dist/html/contribute.html +4 -7
- package/doc/dist/html/functions.html +18 -17
- package/doc/dist/html/genindex.html +1 -1
- package/doc/dist/html/index.html +4 -3
- package/doc/dist/html/memory.html +1 -1
- package/doc/dist/html/objects.inv +0 -0
- package/doc/dist/html/platforms.html +2 -2
- package/doc/dist/html/search.html +1 -1
- package/doc/dist/html/searchindex.js +1 -1
- package/doc/dist/html/start.html +3 -3
- package/doc/dist/html/types.html +30 -10
- package/doc/functions.md +9 -8
- package/doc/start.md +2 -2
- package/doc/types.md +15 -11
- package/package.json +1 -1
- package/qemu/qemu.js +12 -2
- package/src/call.cc +17 -9
- package/src/ffi.cc +14 -5
- package/src/ffi.hh +0 -1
- package/src/util.cc +1 -1
- package/test/async.js +1 -1
- package/test/callbacks.js +25 -2
- package/test/misc.c +52 -2
- package/test/raylib.js +4 -4
- package/test/sqlite.js +5 -5
- package/test/sync.js +22 -7
- package/build/qemu/1.3.6/koffi_darwin_arm64.tar.gz +0 -0
- package/build/qemu/1.3.6/koffi_darwin_x64.tar.gz +0 -0
- package/build/qemu/1.3.6/koffi_freebsd_arm64.tar.gz +0 -0
- package/build/qemu/1.3.6/koffi_freebsd_ia32.tar.gz +0 -0
- package/build/qemu/1.3.6/koffi_freebsd_x64.tar.gz +0 -0
- package/build/qemu/1.3.6/koffi_linux_arm32hf.tar.gz +0 -0
- package/build/qemu/1.3.6/koffi_linux_arm64.tar.gz +0 -0
- package/build/qemu/1.3.6/koffi_linux_ia32.tar.gz +0 -0
- package/build/qemu/1.3.6/koffi_linux_riscv64hf64.tar.gz +0 -0
- package/build/qemu/1.3.6/koffi_linux_x64.tar.gz +0 -0
- package/build/qemu/1.3.6/koffi_openbsd_ia32.tar.gz +0 -0
- package/build/qemu/1.3.6/koffi_openbsd_x64.tar.gz +0 -0
- package/build/qemu/1.3.6/koffi_win32_arm64.tar.gz +0 -0
- package/build/qemu/1.3.6/koffi_win32_ia32.tar.gz +0 -0
- package/build/qemu/1.3.6/koffi_win32_x64.tar.gz +0 -0
package/ChangeLog.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## Koffi 1.3.7
|
|
4
|
+
|
|
5
|
+
**Main fixes:**
|
|
6
|
+
|
|
7
|
+
- Fix crash when using callbacks inside structs
|
|
8
|
+
- Support for null strings in record members
|
|
9
|
+
|
|
10
|
+
**Other changes:**
|
|
11
|
+
|
|
12
|
+
- Add intptr_t and uintptr_t primitive types
|
|
13
|
+
- Add str/str16 type aliases for string/string16
|
|
14
|
+
- Various documentation fixes and improvements
|
|
15
|
+
|
|
3
16
|
## Koffi 1.3.6
|
|
4
17
|
|
|
5
18
|
**Main fixes:**
|
package/benchmark/atoi_koffi.js
CHANGED
|
@@ -84,15 +84,15 @@ function main() {
|
|
|
84
84
|
let lib_filename = path.dirname(__filename) + '/build/raylib' + koffi.extension;
|
|
85
85
|
let lib = koffi.load(lib_filename);
|
|
86
86
|
|
|
87
|
-
const InitWindow = lib.cdecl('InitWindow', 'void', ['int', 'int', '
|
|
87
|
+
const InitWindow = lib.cdecl('InitWindow', 'void', ['int', 'int', 'str']);
|
|
88
88
|
const SetTraceLogLevel = lib.cdecl('SetTraceLogLevel', 'void', ['int']);
|
|
89
89
|
const SetWindowState = lib.cdecl('SetWindowState', 'void', ['uint']);
|
|
90
90
|
const GenImageColor = lib.cdecl('GenImageColor', Image, ['int', 'int', Color]);
|
|
91
91
|
const GetFontDefault = lib.cdecl('GetFontDefault', Font, []);
|
|
92
|
-
const MeasureTextEx = lib.cdecl('MeasureTextEx', Vector2, [Font, '
|
|
92
|
+
const MeasureTextEx = lib.cdecl('MeasureTextEx', Vector2, [Font, 'str', 'float', 'float']);
|
|
93
93
|
const ImageClearBackground = lib.cdecl('ImageClearBackground', 'void', [koffi.pointer(Image), Color]);
|
|
94
|
-
const ImageDrawTextEx = lib.cdecl('ImageDrawTextEx', 'void', [koffi.pointer(Image), Font, '
|
|
95
|
-
const ExportImage = lib.cdecl('ExportImage', 'bool', [Image, '
|
|
94
|
+
const ImageDrawTextEx = lib.cdecl('ImageDrawTextEx', 'void', [koffi.pointer(Image), Font, 'str', Vector2, 'float', 'float', Color]);
|
|
95
|
+
const ExportImage = lib.cdecl('ExportImage', 'bool', [Image, 'str']);
|
|
96
96
|
|
|
97
97
|
// We need to call InitWindow before using anything else (such as fonts)
|
|
98
98
|
SetTraceLogLevel(4); // Warnings
|
|
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/doc/benchmarks.xlsx
CHANGED
|
Binary file
|
package/doc/contribute.md
CHANGED
|
@@ -109,15 +109,12 @@ node qemu.js info debian_x64
|
|
|
109
109
|
|
|
110
110
|
## Todo list
|
|
111
111
|
|
|
112
|
-
|
|
112
|
+
The following features and improvements are planned, not necessarily in that order:
|
|
113
113
|
|
|
114
|
-
- Optimize passing of structs and arrays (avoid setting named properties one by one? separate HFA-specific helper functions?)
|
|
115
114
|
- Provide better ways to automatically deal with caller/heap-allocated memory (strings, etc.)
|
|
116
|
-
|
|
117
|
-
The following features are also planned eventually, not necessarily in that order:
|
|
118
|
-
|
|
115
|
+
- Optimize passing of structs and arrays (avoid setting named properties one by one? separate HFA-specific helper functions?)
|
|
119
116
|
- Automate Windows/AArch64 (qemu) and macOS/AArch64 (how? ... thanks Apple) tests
|
|
120
|
-
- Create a real-world example, using several libraries (Raylib, SQLite, libsodium) to illustrate
|
|
117
|
+
- Create a real-world example, using several libraries (Raylib, SQLite, libsodium) to illustrate various C API styles
|
|
121
118
|
- Add simple struct type parser
|
|
122
119
|
- Add more ways to manually encode and decode various types to and from byte arrays
|
|
123
120
|
- Add support for unions
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -109,15 +109,12 @@ node qemu.js info debian_x64
|
|
|
109
109
|
|
|
110
110
|
## Todo list
|
|
111
111
|
|
|
112
|
-
|
|
112
|
+
The following features and improvements are planned, not necessarily in that order:
|
|
113
113
|
|
|
114
|
-
- Optimize passing of structs and arrays (avoid setting named properties one by one? separate HFA-specific helper functions?)
|
|
115
114
|
- Provide better ways to automatically deal with caller/heap-allocated memory (strings, etc.)
|
|
116
|
-
|
|
117
|
-
The following features are also planned eventually, not necessarily in that order:
|
|
118
|
-
|
|
115
|
+
- Optimize passing of structs and arrays (avoid setting named properties one by one? separate HFA-specific helper functions?)
|
|
119
116
|
- Automate Windows/AArch64 (qemu) and macOS/AArch64 (how? ... thanks Apple) tests
|
|
120
|
-
- Create a real-world example, using several libraries (Raylib, SQLite, libsodium) to illustrate
|
|
117
|
+
- Create a real-world example, using several libraries (Raylib, SQLite, libsodium) to illustrate various C API styles
|
|
121
118
|
- Add simple struct type parser
|
|
122
119
|
- Add more ways to manually encode and decode various types to and from byte arrays
|
|
123
120
|
- Add support for unions
|
|
@@ -19,8 +19,8 @@ You can use the returned object to load C functions from the library. To do so,
|
|
|
19
19
|
To declare a function, you need to specify its non-mangled name, its return type, and its parameters. Use an ellipsis as the last parameter for variadic functions.
|
|
20
20
|
|
|
21
21
|
```js
|
|
22
|
-
const printf = lib.func('printf', 'int', ['
|
|
23
|
-
const atoi = lib.func('atoi', 'int', ['
|
|
22
|
+
const printf = lib.func('printf', 'int', ['str', '...']);
|
|
23
|
+
const atoi = lib.func('atoi', 'int', ['str']);
|
|
24
24
|
```
|
|
25
25
|
|
|
26
26
|
Koffi automatically tries mangled names for non-standard x86 calling conventions. See the section [on standard calls](#synchronous-calls) for more information on this subject.
|
|
@@ -31,7 +31,7 @@ If you prefer, you can declare functions using simple C-like prototype strings,
|
|
|
31
31
|
|
|
32
32
|
```js
|
|
33
33
|
const printf = lib.func('int printf(const char *fmt, ...)');
|
|
34
|
-
const atoi = lib.func('int atoi(
|
|
34
|
+
const atoi = lib.func('int atoi(str)'); // The parameter name is not used by Koffi, and optional
|
|
35
35
|
```
|
|
36
36
|
|
|
37
37
|
You can use `()` or `(void)` for functions that take no argument.
|
|
@@ -58,8 +58,8 @@ const koffi = require('koffi');
|
|
|
58
58
|
const lib = koffi.load('user32.dll');
|
|
59
59
|
|
|
60
60
|
// The following two declarations are equivalent, and use Stdcall
|
|
61
|
-
const MessageBoxA_1 = lib.stdcall('MessageBoxA', 'int', ['void *', '
|
|
62
|
-
const MessageBoxA_2 = lib.func('int __stdcall MessageBoxA(void *hwnd,
|
|
61
|
+
const MessageBoxA_1 = lib.stdcall('MessageBoxA', 'int', ['void *', 'str', 'str', 'uint']);
|
|
62
|
+
const MessageBoxA_2 = lib.func('int __stdcall MessageBoxA(void *hwnd, str text, str caption, uint type)');
|
|
63
63
|
```
|
|
64
64
|
|
|
65
65
|
## Asynchronous calls
|
|
@@ -95,10 +95,10 @@ Variadic functions are declared with an ellipsis as the last argument.
|
|
|
95
95
|
In order to call a variadic function, you must provide two Javascript arguments for each additional C parameter, the first one is the expected type and the second one is the value.
|
|
96
96
|
|
|
97
97
|
```js
|
|
98
|
-
const printf = lib.func('printf', 'int', ['
|
|
98
|
+
const printf = lib.func('printf', 'int', ['str', '...']);
|
|
99
99
|
|
|
100
100
|
// The variadic arguments are: 6 (int), 8.5 (double), 'THE END' (const char *)
|
|
101
|
-
printf('Integer %d, double %g,
|
|
101
|
+
printf('Integer %d, double %g, str %s', 'int', 6, 'double', 8.5, 'str', 'THE END');
|
|
102
102
|
```
|
|
103
103
|
|
|
104
104
|
On x86 platforms, only the Cdecl convention can be used for variadic functions.
|
|
@@ -159,7 +159,8 @@ const lib = koffi.load('sqlite.so');
|
|
|
159
159
|
const sqlite3_db = koffi.handle('sqlite3_db');
|
|
160
160
|
|
|
161
161
|
// Use koffi.out() on a pointer to copy out (from C to JS) after the call
|
|
162
|
-
const sqlite3_open_v2 = lib.func('sqlite3_open_v2', 'int', ['
|
|
162
|
+
const sqlite3_open_v2 = lib.func('sqlite3_open_v2', 'int', ['str', koffi.out(koffi.pointer(sqlite3_db)), 'int', 'str']);
|
|
163
|
+
const sqlite3_close_v2 = lib.func('sqlite3_close_v2', 'int', [sqlite3_db]);
|
|
163
164
|
|
|
164
165
|
const SQLITE_OPEN_READWRITE = 0x2;
|
|
165
166
|
const SQLITE_OPEN_CREATE = 0x4;
|
|
@@ -91,8 +91,8 @@ const IDYES = 6;
|
|
|
91
91
|
const IDNO = 7;
|
|
92
92
|
|
|
93
93
|
// Find functions
|
|
94
|
-
const MessageBoxA = lib.stdcall('MessageBoxA', 'int', ['void *', '
|
|
95
|
-
const MessageBoxW = lib.stdcall('MessageBoxW', 'int', ['void *', '
|
|
94
|
+
const MessageBoxA = lib.stdcall('MessageBoxA', 'int', ['void *', 'str', 'str', 'uint']);
|
|
95
|
+
const MessageBoxW = lib.stdcall('MessageBoxW', 'int', ['void *', 'str16', 'str16', 'uint']);
|
|
96
96
|
|
|
97
97
|
let ret = MessageBoxA(null, 'Do you want another message box?', 'Koffi', MB_YESNO | MB_ICONQUESTION);
|
|
98
98
|
if (ret == IDYES)
|
|
@@ -46,14 +46,18 @@ Koffi also accepts BigInt values when converting from JS to C integers. If the v
|
|
|
46
46
|
|
|
47
47
|
Koffi defines a few more types that can change size depending on the OS and the architecture:
|
|
48
48
|
|
|
49
|
-
JS type | C type
|
|
50
|
-
---------------- |
|
|
51
|
-
Boolean | bool
|
|
52
|
-
Number (integer) | long
|
|
53
|
-
Number (integer) | ulong
|
|
54
|
-
Number (integer) | unsigned long
|
|
55
|
-
|
|
56
|
-
|
|
49
|
+
JS type | C type | Signedness | Note
|
|
50
|
+
---------------- | ---------------- | ---------- | ------------------------------------------------
|
|
51
|
+
Boolean | bool | | Usually one byte
|
|
52
|
+
Number (integer) | long | Signed | 4 or 8 bytes depending on platform (LP64, LLP64)
|
|
53
|
+
Number (integer) | ulong | Unsigned | 4 or 8 bytes depending on platform (LP64, LLP64)
|
|
54
|
+
Number (integer) | unsigned long | Unsigned | 4 or 8 bytes depending on platform (LP64, LLP64)
|
|
55
|
+
Number (integer) | intptr | Signed | 4 or 8 bytes depending on register width
|
|
56
|
+
Number (integer) | intptr_t | Signed | 4 or 8 bytes depending on register width
|
|
57
|
+
Number (integer) | uintptr | Unsigned | 4 or 8 bytes depending on register width
|
|
58
|
+
Number (integer) | uintptr_t | Unsigned | 4 or 8 bytes depending on register width
|
|
59
|
+
String | str (string) | | JS strings are converted to and from UTF-8
|
|
60
|
+
String | str16 (string16) | | JS strings are converted to and from UTF-16 (LE)
|
|
57
61
|
|
|
58
62
|
Primitive types can be specified by name (in a string) or through `koffi.types`:
|
|
59
63
|
|
|
@@ -87,7 +91,7 @@ typedef struct A {
|
|
|
87
91
|
const A = koffi.struct('A', {
|
|
88
92
|
a: 'int',
|
|
89
93
|
b: 'char',
|
|
90
|
-
c: '
|
|
94
|
+
c: 'str',
|
|
91
95
|
d: koffi.struct({
|
|
92
96
|
d1: 'double',
|
|
93
97
|
d2: 'double'
|
|
@@ -270,11 +274,11 @@ const koffi = require('koffi');
|
|
|
270
274
|
const lib = koffi.load('./handles.so');
|
|
271
275
|
|
|
272
276
|
const Concat = koffi.handle('Concat');
|
|
273
|
-
const ConcatNewOut = lib.func('bool ConcatNewOut(Concat *out)');
|
|
274
277
|
const ConcatNew = lib.func('Concat ConcatNew()');
|
|
275
278
|
const ConcatFree = lib.func('void ConcatFree(Concat c)');
|
|
276
279
|
const ConcatAppend = lib.func('bool ConcatAppend(Concat c, const char *frag)');
|
|
277
280
|
const ConcatBuild = lib.func('const char *ConcatBuild(Concat c)');
|
|
281
|
+
const ConcatNewOut = lib.func('bool ConcatNewOut(_Out_ Concat out)');
|
|
278
282
|
|
|
279
283
|
let c = ConcatNew();
|
|
280
284
|
if (!c) {
|
|
@@ -385,7 +389,7 @@ const WIN32_FIND_DATA = koffi.struct('WIN32_FIND_DATA', {
|
|
|
385
389
|
wFinderFlags: 'ushort' // Obsolete. Do not use
|
|
386
390
|
});
|
|
387
391
|
|
|
388
|
-
const FindFirstFile = lib.func('HANDLE __stdcall FindFirstFileW(
|
|
392
|
+
const FindFirstFile = lib.func('HANDLE __stdcall FindFirstFileW(str16 path, _Out_ WIN32_FIND_DATA *data)');
|
|
389
393
|
const FindNextFile = lib.func('bool __stdcall FindNextFileW(HANDLE h, _Out_ WIN32_FIND_DATA *data)');
|
|
390
394
|
const FindClose = lib.func('bool __stdcall FindClose(HANDLE h)');
|
|
391
395
|
const GetLastError = lib.func('uint GetLastError()');
|
|
@@ -237,16 +237,6 @@ a.headerlink {
|
|
|
237
237
|
visibility: hidden;
|
|
238
238
|
}
|
|
239
239
|
|
|
240
|
-
a.brackets:before,
|
|
241
|
-
span.brackets > a:before{
|
|
242
|
-
content: "[";
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
a.brackets:after,
|
|
246
|
-
span.brackets > a:after {
|
|
247
|
-
content: "]";
|
|
248
|
-
}
|
|
249
|
-
|
|
250
240
|
h1:hover > a.headerlink,
|
|
251
241
|
h2:hover > a.headerlink,
|
|
252
242
|
h3:hover > a.headerlink,
|
|
@@ -334,14 +324,18 @@ aside.sidebar {
|
|
|
334
324
|
p.sidebar-title {
|
|
335
325
|
font-weight: bold;
|
|
336
326
|
}
|
|
327
|
+
nav.contents,
|
|
328
|
+
aside.topic,
|
|
337
329
|
|
|
338
|
-
div.admonition, div.topic,
|
|
330
|
+
div.admonition, div.topic, blockquote {
|
|
339
331
|
clear: left;
|
|
340
332
|
}
|
|
341
333
|
|
|
342
334
|
/* -- topics ---------------------------------------------------------------- */
|
|
335
|
+
nav.contents,
|
|
336
|
+
aside.topic,
|
|
343
337
|
|
|
344
|
-
div.topic
|
|
338
|
+
div.topic {
|
|
345
339
|
border: 1px solid #ccc;
|
|
346
340
|
padding: 7px;
|
|
347
341
|
margin: 10px 0 10px 0;
|
|
@@ -379,16 +373,20 @@ div.body p.centered {
|
|
|
379
373
|
|
|
380
374
|
div.sidebar > :last-child,
|
|
381
375
|
aside.sidebar > :last-child,
|
|
382
|
-
|
|
376
|
+
nav.contents > :last-child,
|
|
383
377
|
aside.topic > :last-child,
|
|
378
|
+
|
|
379
|
+
div.topic > :last-child,
|
|
384
380
|
div.admonition > :last-child {
|
|
385
381
|
margin-bottom: 0;
|
|
386
382
|
}
|
|
387
383
|
|
|
388
384
|
div.sidebar::after,
|
|
389
385
|
aside.sidebar::after,
|
|
390
|
-
|
|
386
|
+
nav.contents::after,
|
|
391
387
|
aside.topic::after,
|
|
388
|
+
|
|
389
|
+
div.topic::after,
|
|
392
390
|
div.admonition::after,
|
|
393
391
|
blockquote::after {
|
|
394
392
|
display: block;
|
|
Binary file
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
<meta name="color-scheme" content="light dark"><meta name="generator" content="Docutils 0.18.1: http://docutils.sourceforge.net/" />
|
|
6
6
|
<link rel="index" title="Index" href="genindex" /><link rel="search" title="Search" href="search" /><link rel="next" title="Contributing" href="contribute" /><link rel="prev" title="Memory usage" href="memory" />
|
|
7
7
|
|
|
8
|
-
<meta name="generator" content="sphinx-5.0.
|
|
8
|
+
<meta name="generator" content="sphinx-5.0.2, furo 2022.06.21"/>
|
|
9
9
|
<title>Benchmarks - Koffi</title>
|
|
10
10
|
<link rel="stylesheet" type="text/css" href="_static/pygments.css" />
|
|
11
11
|
<link rel="stylesheet" type="text/css" href="_static/styles/furo.css?digest=40978830699223671f4072448e654b5958f38b89" />
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
<meta name="color-scheme" content="light dark"><meta name="generator" content="Docutils 0.18.1: http://docutils.sourceforge.net/" />
|
|
6
6
|
<link rel="index" title="Index" href="genindex" /><link rel="search" title="Search" href="search" /><link rel="prev" title="Contributing" href="contribute" />
|
|
7
7
|
|
|
8
|
-
<meta name="generator" content="sphinx-5.0.
|
|
8
|
+
<meta name="generator" content="sphinx-5.0.2, furo 2022.06.21"/>
|
|
9
9
|
<title>Changelog - Koffi</title>
|
|
10
10
|
<link rel="stylesheet" type="text/css" href="_static/pygments.css" />
|
|
11
11
|
<link rel="stylesheet" type="text/css" href="_static/styles/furo.css?digest=40978830699223671f4072448e654b5958f38b89" />
|
|
@@ -205,6 +205,20 @@
|
|
|
205
205
|
<article role="main">
|
|
206
206
|
<section id="changelog">
|
|
207
207
|
<h1>Changelog<a class="headerlink" href="#changelog" title="Permalink to this heading">#</a></h1>
|
|
208
|
+
<section id="koffi-1-3-7">
|
|
209
|
+
<h2>Koffi 1.3.7<a class="headerlink" href="#koffi-1-3-7" title="Permalink to this heading">#</a></h2>
|
|
210
|
+
<p><strong>Main fixes:</strong></p>
|
|
211
|
+
<ul class="simple">
|
|
212
|
+
<li><p>Fix crash when using callbacks inside structs</p></li>
|
|
213
|
+
<li><p>Support for null strings in record members</p></li>
|
|
214
|
+
</ul>
|
|
215
|
+
<p><strong>Other changes:</strong></p>
|
|
216
|
+
<ul class="simple">
|
|
217
|
+
<li><p>Add intptr_t and uintptr_t primitive types</p></li>
|
|
218
|
+
<li><p>Add str/str16 type aliases for string/string16</p></li>
|
|
219
|
+
<li><p>Various documentation fixes and improvements</p></li>
|
|
220
|
+
</ul>
|
|
221
|
+
</section>
|
|
208
222
|
<section id="koffi-1-3-6">
|
|
209
223
|
<h2>Koffi 1.3.6<a class="headerlink" href="#koffi-1-3-6" title="Permalink to this heading">#</a></h2>
|
|
210
224
|
<p><strong>Main fixes:</strong></p>
|
|
@@ -374,6 +388,7 @@
|
|
|
374
388
|
<div class="toc-tree">
|
|
375
389
|
<ul>
|
|
376
390
|
<li><a class="reference internal" href="#">Changelog</a><ul>
|
|
391
|
+
<li><a class="reference internal" href="#koffi-1-3-7">Koffi 1.3.7</a></li>
|
|
377
392
|
<li><a class="reference internal" href="#koffi-1-3-6">Koffi 1.3.6</a></li>
|
|
378
393
|
<li><a class="reference internal" href="#koffi-1-3-5">Koffi 1.3.5</a></li>
|
|
379
394
|
<li><a class="reference internal" href="#koffi-1-3-4">Koffi 1.3.4</a></li>
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
<meta name="color-scheme" content="light dark"><meta name="generator" content="Docutils 0.18.1: http://docutils.sourceforge.net/" />
|
|
6
6
|
<link rel="index" title="Index" href="genindex" /><link rel="search" title="Search" href="search" /><link rel="next" title="Changelog" href="changes" /><link rel="prev" title="Benchmarks" href="benchmarks" />
|
|
7
7
|
|
|
8
|
-
<meta name="generator" content="sphinx-5.0.
|
|
8
|
+
<meta name="generator" content="sphinx-5.0.2, furo 2022.06.21"/>
|
|
9
9
|
<title>Contributing - Koffi</title>
|
|
10
10
|
<link rel="stylesheet" type="text/css" href="_static/pygments.css" />
|
|
11
11
|
<link rel="stylesheet" type="text/css" href="_static/styles/furo.css?digest=40978830699223671f4072448e654b5958f38b89" />
|
|
@@ -293,15 +293,12 @@
|
|
|
293
293
|
</section>
|
|
294
294
|
<section id="todo-list">
|
|
295
295
|
<h2>Todo list<a class="headerlink" href="#todo-list" title="Permalink to this heading">#</a></h2>
|
|
296
|
-
<p>
|
|
296
|
+
<p>The following features and improvements are planned, not necessarily in that order:</p>
|
|
297
297
|
<ul class="simple">
|
|
298
|
-
<li><p>Optimize passing of structs and arrays (avoid setting named properties one by one? separate HFA-specific helper functions?)</p></li>
|
|
299
298
|
<li><p>Provide better ways to automatically deal with caller/heap-allocated memory (strings, etc.)</p></li>
|
|
300
|
-
</
|
|
301
|
-
<p>The following features are also planned eventually, not necessarily in that order:</p>
|
|
302
|
-
<ul class="simple">
|
|
299
|
+
<li><p>Optimize passing of structs and arrays (avoid setting named properties one by one? separate HFA-specific helper functions?)</p></li>
|
|
303
300
|
<li><p>Automate Windows/AArch64 (qemu) and macOS/AArch64 (how? … thanks Apple) tests</p></li>
|
|
304
|
-
<li><p>Create a real-world example, using several libraries (Raylib, SQLite, libsodium) to illustrate
|
|
301
|
+
<li><p>Create a real-world example, using several libraries (Raylib, SQLite, libsodium) to illustrate various C API styles</p></li>
|
|
305
302
|
<li><p>Add simple struct type parser</p></li>
|
|
306
303
|
<li><p>Add more ways to manually encode and decode various types to and from byte arrays</p></li>
|
|
307
304
|
<li><p>Add support for unions</p></li>
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
<meta name="color-scheme" content="light dark"><meta name="generator" content="Docutils 0.18.1: http://docutils.sourceforge.net/" />
|
|
6
6
|
<link rel="index" title="Index" href="genindex" /><link rel="search" title="Search" href="search" /><link rel="next" title="Memory usage" href="memory" /><link rel="prev" title="Data types" href="types" />
|
|
7
7
|
|
|
8
|
-
<meta name="generator" content="sphinx-5.0.
|
|
8
|
+
<meta name="generator" content="sphinx-5.0.2, furo 2022.06.21"/>
|
|
9
9
|
<title>Function calls - Koffi</title>
|
|
10
10
|
<link rel="stylesheet" type="text/css" href="_static/pygments.css" />
|
|
11
11
|
<link rel="stylesheet" type="text/css" href="_static/styles/furo.css?digest=40978830699223671f4072448e654b5958f38b89" />
|
|
@@ -220,8 +220,8 @@
|
|
|
220
220
|
<section id="classic-syntax">
|
|
221
221
|
<h3>Classic syntax<a class="headerlink" href="#classic-syntax" title="Permalink to this heading">#</a></h3>
|
|
222
222
|
<p>To declare a function, you need to specify its non-mangled name, its return type, and its parameters. Use an ellipsis as the last parameter for variadic functions.</p>
|
|
223
|
-
<div class="highlight-js notranslate"><div class="highlight"><pre><span></span><span class="linenos">1</span><span class="kd">const</span><span class="w"> </span><span class="nx">printf</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nx">lib</span><span class="p">.</span><span class="nx">func</span><span class="p">(</span><span class="s1">'printf'</span><span class="p">,</span><span class="w"> </span><span class="s1">'int'</span><span class="p">,</span><span class="w"> </span><span class="p">[</span><span class="s1">'
|
|
224
|
-
<span class="linenos">2</span><span class="kd">const</span><span class="w"> </span><span class="nx">atoi</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nx">lib</span><span class="p">.</span><span class="nx">func</span><span class="p">(</span><span class="s1">'atoi'</span><span class="p">,</span><span class="w"> </span><span class="s1">'int'</span><span class="p">,</span><span class="w"> </span><span class="p">[</span><span class="s1">'
|
|
223
|
+
<div class="highlight-js notranslate"><div class="highlight"><pre><span></span><span class="linenos">1</span><span class="kd">const</span><span class="w"> </span><span class="nx">printf</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nx">lib</span><span class="p">.</span><span class="nx">func</span><span class="p">(</span><span class="s1">'printf'</span><span class="p">,</span><span class="w"> </span><span class="s1">'int'</span><span class="p">,</span><span class="w"> </span><span class="p">[</span><span class="s1">'str'</span><span class="p">,</span><span class="w"> </span><span class="s1">'...'</span><span class="p">]);</span><span class="w"></span>
|
|
224
|
+
<span class="linenos">2</span><span class="kd">const</span><span class="w"> </span><span class="nx">atoi</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nx">lib</span><span class="p">.</span><span class="nx">func</span><span class="p">(</span><span class="s1">'atoi'</span><span class="p">,</span><span class="w"> </span><span class="s1">'int'</span><span class="p">,</span><span class="w"> </span><span class="p">[</span><span class="s1">'str'</span><span class="p">]);</span><span class="w"></span>
|
|
225
225
|
</pre></div>
|
|
226
226
|
</div>
|
|
227
227
|
<p>Koffi automatically tries mangled names for non-standard x86 calling conventions. See the section <a class="reference internal" href="#synchronous-calls"><span class="std std-doc">on standard calls</span></a> for more information on this subject.</p>
|
|
@@ -230,7 +230,7 @@
|
|
|
230
230
|
<h3>C-like prototypes<a class="headerlink" href="#c-like-prototypes" title="Permalink to this heading">#</a></h3>
|
|
231
231
|
<p>If you prefer, you can declare functions using simple C-like prototype strings, as shown below:</p>
|
|
232
232
|
<div class="highlight-js notranslate"><div class="highlight"><pre><span></span><span class="linenos">1</span><span class="kd">const</span><span class="w"> </span><span class="nx">printf</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nx">lib</span><span class="p">.</span><span class="nx">func</span><span class="p">(</span><span class="s1">'int printf(const char *fmt, ...)'</span><span class="p">);</span><span class="w"></span>
|
|
233
|
-
<span class="linenos">2</span><span class="kd">const</span><span class="w"> </span><span class="nx">atoi</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nx">lib</span><span class="p">.</span><span class="nx">func</span><span class="p">(</span><span class="s1">'int atoi(
|
|
233
|
+
<span class="linenos">2</span><span class="kd">const</span><span class="w"> </span><span class="nx">atoi</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nx">lib</span><span class="p">.</span><span class="nx">func</span><span class="p">(</span><span class="s1">'int atoi(str)'</span><span class="p">);</span><span class="w"> </span><span class="c1">// The parameter name is not used by Koffi, and optional</span><span class="w"></span>
|
|
234
234
|
</pre></div>
|
|
235
235
|
</div>
|
|
236
236
|
<p>You can use <code class="docutils literal notranslate"><span class="pre">()</span></code> or <code class="docutils literal notranslate"><span class="pre">(void)</span></code> for functions that take no argument.</p>
|
|
@@ -279,8 +279,8 @@
|
|
|
279
279
|
<span class="linenos">2</span><span class="kd">const</span><span class="w"> </span><span class="nx">lib</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nx">koffi</span><span class="p">.</span><span class="nx">load</span><span class="p">(</span><span class="s1">'user32.dll'</span><span class="p">);</span><span class="w"></span>
|
|
280
280
|
<span class="linenos">3</span>
|
|
281
281
|
<span class="linenos">4</span><span class="c1">// The following two declarations are equivalent, and use Stdcall</span><span class="w"></span>
|
|
282
|
-
<span class="linenos">5</span><span class="kd">const</span><span class="w"> </span><span class="nx">MessageBoxA_1</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nx">lib</span><span class="p">.</span><span class="nx">stdcall</span><span class="p">(</span><span class="s1">'MessageBoxA'</span><span class="p">,</span><span class="w"> </span><span class="s1">'int'</span><span class="p">,</span><span class="w"> </span><span class="p">[</span><span class="s1">'void *'</span><span class="p">,</span><span class="w"> </span><span class="s1">'
|
|
283
|
-
<span class="linenos">6</span><span class="kd">const</span><span class="w"> </span><span class="nx">MessageBoxA_2</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nx">lib</span><span class="p">.</span><span class="nx">func</span><span class="p">(</span><span class="s1">'int __stdcall MessageBoxA(void *hwnd,
|
|
282
|
+
<span class="linenos">5</span><span class="kd">const</span><span class="w"> </span><span class="nx">MessageBoxA_1</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nx">lib</span><span class="p">.</span><span class="nx">stdcall</span><span class="p">(</span><span class="s1">'MessageBoxA'</span><span class="p">,</span><span class="w"> </span><span class="s1">'int'</span><span class="p">,</span><span class="w"> </span><span class="p">[</span><span class="s1">'void *'</span><span class="p">,</span><span class="w"> </span><span class="s1">'str'</span><span class="p">,</span><span class="w"> </span><span class="s1">'str'</span><span class="p">,</span><span class="w"> </span><span class="s1">'uint'</span><span class="p">]);</span><span class="w"></span>
|
|
283
|
+
<span class="linenos">6</span><span class="kd">const</span><span class="w"> </span><span class="nx">MessageBoxA_2</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nx">lib</span><span class="p">.</span><span class="nx">func</span><span class="p">(</span><span class="s1">'int __stdcall MessageBoxA(void *hwnd, str text, str caption, uint type)'</span><span class="p">);</span><span class="w"></span>
|
|
284
284
|
</pre></div>
|
|
285
285
|
</div>
|
|
286
286
|
</section>
|
|
@@ -310,10 +310,10 @@
|
|
|
310
310
|
<h2>Variadic functions<a class="headerlink" href="#variadic-functions" title="Permalink to this heading">#</a></h2>
|
|
311
311
|
<p>Variadic functions are declared with an ellipsis as the last argument.</p>
|
|
312
312
|
<p>In order to call a variadic function, you must provide two Javascript arguments for each additional C parameter, the first one is the expected type and the second one is the value.</p>
|
|
313
|
-
<div class="highlight-js notranslate"><div class="highlight"><pre><span></span><span class="linenos">1</span><span class="kd">const</span><span class="w"> </span><span class="nx">printf</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nx">lib</span><span class="p">.</span><span class="nx">func</span><span class="p">(</span><span class="s1">'printf'</span><span class="p">,</span><span class="w"> </span><span class="s1">'int'</span><span class="p">,</span><span class="w"> </span><span class="p">[</span><span class="s1">'
|
|
313
|
+
<div class="highlight-js notranslate"><div class="highlight"><pre><span></span><span class="linenos">1</span><span class="kd">const</span><span class="w"> </span><span class="nx">printf</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nx">lib</span><span class="p">.</span><span class="nx">func</span><span class="p">(</span><span class="s1">'printf'</span><span class="p">,</span><span class="w"> </span><span class="s1">'int'</span><span class="p">,</span><span class="w"> </span><span class="p">[</span><span class="s1">'str'</span><span class="p">,</span><span class="w"> </span><span class="s1">'...'</span><span class="p">]);</span><span class="w"></span>
|
|
314
314
|
<span class="linenos">2</span>
|
|
315
315
|
<span class="linenos">3</span><span class="c1">// The variadic arguments are: 6 (int), 8.5 (double), 'THE END' (const char *)</span><span class="w"></span>
|
|
316
|
-
<span class="linenos">4</span><span class="nx">printf</span><span class="p">(</span><span class="s1">'Integer %d, double %g,
|
|
316
|
+
<span class="linenos">4</span><span class="nx">printf</span><span class="p">(</span><span class="s1">'Integer %d, double %g, str %s'</span><span class="p">,</span><span class="w"> </span><span class="s1">'int'</span><span class="p">,</span><span class="w"> </span><span class="mf">6</span><span class="p">,</span><span class="w"> </span><span class="s1">'double'</span><span class="p">,</span><span class="w"> </span><span class="mf">8.5</span><span class="p">,</span><span class="w"> </span><span class="s1">'str'</span><span class="p">,</span><span class="w"> </span><span class="s1">'THE END'</span><span class="p">);</span><span class="w"></span>
|
|
317
317
|
</pre></div>
|
|
318
318
|
</div>
|
|
319
319
|
<p>On x86 platforms, only the Cdecl convention can be used for variadic functions.</p>
|
|
@@ -370,15 +370,16 @@
|
|
|
370
370
|
<span class="linenos"> 4</span><span class="kd">const</span><span class="w"> </span><span class="nx">sqlite3_db</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nx">koffi</span><span class="p">.</span><span class="nx">handle</span><span class="p">(</span><span class="s1">'sqlite3_db'</span><span class="p">);</span><span class="w"></span>
|
|
371
371
|
<span class="linenos"> 5</span>
|
|
372
372
|
<span class="linenos"> 6</span><span class="c1">// Use koffi.out() on a pointer to copy out (from C to JS) after the call</span><span class="w"></span>
|
|
373
|
-
<span class="linenos"> 7</span><span class="kd">const</span><span class="w"> </span><span class="nx">sqlite3_open_v2</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nx">lib</span><span class="p">.</span><span class="nx">func</span><span class="p">(</span><span class="s1">'sqlite3_open_v2'</span><span class="p">,</span><span class="w"> </span><span class="s1">'int'</span><span class="p">,</span><span class="w"> </span><span class="p">[</span><span class="s1">'
|
|
374
|
-
<span class="linenos"> 8</span>
|
|
375
|
-
<span class="linenos"> 9</span
|
|
376
|
-
<span class="linenos">10</span><span class="kd">const</span><span class="w"> </span><span class="nx">
|
|
377
|
-
<span class="linenos">11</span>
|
|
378
|
-
<span class="linenos">12</span
|
|
379
|
-
<span class="linenos">13</span><span class="
|
|
380
|
-
<span class="linenos">14</span><span class="w">
|
|
381
|
-
<span class="linenos">15</span><span class="
|
|
373
|
+
<span class="linenos"> 7</span><span class="kd">const</span><span class="w"> </span><span class="nx">sqlite3_open_v2</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nx">lib</span><span class="p">.</span><span class="nx">func</span><span class="p">(</span><span class="s1">'sqlite3_open_v2'</span><span class="p">,</span><span class="w"> </span><span class="s1">'int'</span><span class="p">,</span><span class="w"> </span><span class="p">[</span><span class="s1">'str'</span><span class="p">,</span><span class="w"> </span><span class="nx">koffi</span><span class="p">.</span><span class="nx">out</span><span class="p">(</span><span class="nx">koffi</span><span class="p">.</span><span class="nx">pointer</span><span class="p">(</span><span class="nx">sqlite3_db</span><span class="p">)),</span><span class="w"> </span><span class="s1">'int'</span><span class="p">,</span><span class="w"> </span><span class="s1">'str'</span><span class="p">]);</span><span class="w"></span>
|
|
374
|
+
<span class="linenos"> 8</span><span class="kd">const</span><span class="w"> </span><span class="nx">sqlite3_close_v2</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nx">lib</span><span class="p">.</span><span class="nx">func</span><span class="p">(</span><span class="s1">'sqlite3_close_v2'</span><span class="p">,</span><span class="w"> </span><span class="s1">'int'</span><span class="p">,</span><span class="w"> </span><span class="p">[</span><span class="nx">sqlite3_db</span><span class="p">]);</span><span class="w"></span>
|
|
375
|
+
<span class="linenos"> 9</span>
|
|
376
|
+
<span class="linenos">10</span><span class="kd">const</span><span class="w"> </span><span class="nx">SQLITE_OPEN_READWRITE</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mh">0x2</span><span class="p">;</span><span class="w"></span>
|
|
377
|
+
<span class="linenos">11</span><span class="kd">const</span><span class="w"> </span><span class="nx">SQLITE_OPEN_CREATE</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mh">0x4</span><span class="p">;</span><span class="w"></span>
|
|
378
|
+
<span class="linenos">12</span>
|
|
379
|
+
<span class="linenos">13</span><span class="kd">let</span><span class="w"> </span><span class="nx">db</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">{};</span><span class="w"></span>
|
|
380
|
+
<span class="linenos">14</span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="nx">sqlite3_open_v2</span><span class="p">(</span><span class="s1">':memory:'</span><span class="p">,</span><span class="w"> </span><span class="nx">db</span><span class="p">,</span><span class="w"> </span><span class="nx">SQLITE_OPEN_READWRITE</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="nx">SQLITE_OPEN_CREATE</span><span class="p">,</span><span class="w"> </span><span class="kc">null</span><span class="p">)</span><span class="w"> </span><span class="o">!=</span><span class="w"> </span><span class="mf">0</span><span class="p">)</span><span class="w"></span>
|
|
381
|
+
<span class="linenos">15</span><span class="w"> </span><span class="k">throw</span><span class="w"> </span><span class="ow">new</span><span class="w"> </span><span class="ne">Error</span><span class="p">(</span><span class="s1">'Failed to open database'</span><span class="p">);</span><span class="w"></span>
|
|
382
|
+
<span class="linenos">16</span><span class="nx">sqlite3_close_v2</span><span class="p">(</span><span class="nx">db</span><span class="p">);</span><span class="w"></span>
|
|
382
383
|
</pre></div>
|
|
383
384
|
</div>
|
|
384
385
|
</section>
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
<meta name="viewport" content="width=device-width,initial-scale=1"/>
|
|
5
5
|
<meta name="color-scheme" content="light dark"><link rel="index" title="Index" href="#" /><link rel="search" title="Search" href="search" />
|
|
6
6
|
|
|
7
|
-
<meta name="generator" content="sphinx-5.0.
|
|
7
|
+
<meta name="generator" content="sphinx-5.0.2, furo 2022.06.21"/><title>Index - Koffi</title>
|
|
8
8
|
<link rel="stylesheet" type="text/css" href="_static/pygments.css" />
|
|
9
9
|
<link rel="stylesheet" type="text/css" href="_static/styles/furo.css?digest=40978830699223671f4072448e654b5958f38b89" />
|
|
10
10
|
<link rel="stylesheet" type="text/css" href="_static/styles/furo-extensions.css?digest=30d1aed668e5c3a91c3e3bf6a60b675221979f0e" />
|