koffi 2.5.19 → 2.5.20
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 +6 -1
- package/build/koffi/darwin_arm64/koffi.node +0 -0
- package/build/koffi/darwin_x64/koffi.node +0 -0
- package/build/koffi/freebsd_arm64/koffi.node +0 -0
- package/build/koffi/freebsd_ia32/koffi.node +0 -0
- package/build/koffi/freebsd_x64/koffi.node +0 -0
- package/build/koffi/linux_arm32hf/koffi.node +0 -0
- package/build/koffi/linux_arm64/koffi.node +0 -0
- package/build/koffi/linux_ia32/koffi.node +0 -0
- package/build/koffi/linux_riscv64hf64/koffi.node +0 -0
- package/build/koffi/linux_x64/koffi.node +0 -0
- package/build/koffi/openbsd_ia32/koffi.node +0 -0
- package/build/koffi/openbsd_x64/koffi.node +0 -0
- package/build/koffi/win32_arm64/koffi.node +0 -0
- package/build/koffi/win32_ia32/koffi.node +0 -0
- package/build/koffi/win32_x64/koffi.node +0 -0
- package/doc/callbacks.md +1 -1
- package/doc/contribute.md +26 -6
- package/doc/input.md +15 -15
- package/doc/misc.md +3 -3
- package/package.json +2 -2
- package/src/index.js +2 -2
- package/src/koffi/src/call.cc +2 -10
- package/src/koffi/src/ffi.cc +19 -0
- package/src/koffi/src/ffi.hh +2 -0
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,11 @@
|
|
|
4
4
|
|
|
5
5
|
### Koffi 2.5
|
|
6
6
|
|
|
7
|
+
#### Koffi 2.5.20 (2023-08-31)
|
|
8
|
+
|
|
9
|
+
- Fix possible crash with async registered callbacks introduced in Koffi 2.5.19
|
|
10
|
+
- Various documentation fixes and improvements
|
|
11
|
+
|
|
7
12
|
#### Koffi 2.5.19 (2023-08-29)
|
|
8
13
|
|
|
9
14
|
- Create thread-safe function broker lazily
|
|
@@ -332,7 +337,7 @@ Pre-built binaries don't work correctly in Koffi 2.5.13 to 2.5.15, skip those ve
|
|
|
332
337
|
**Main changes:**
|
|
333
338
|
|
|
334
339
|
- Add [koffi.as()](polymorphism.md#input-polymorphism) to support polymorphic APIs based on `void *` parameters
|
|
335
|
-
- Add [endian-sensitive integer types](input.md#endian-sensitive-
|
|
340
|
+
- Add [endian-sensitive integer types](input.md#endian-sensitive-integers): `intX_le_t`, `intX_be_t`, `uintX_le_t`, `uintX_be_t`
|
|
336
341
|
- Accept typed arrays for `void *` parameters
|
|
337
342
|
- Introduce `koffi.opaque()` to replace `koffi.handle()` (which remains supported until Koffi 3.0)
|
|
338
343
|
- Support JS Array and TypedArray to fill struct and array pointer members
|
|
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/callbacks.md
CHANGED
|
@@ -88,7 +88,7 @@ console.log(ret);
|
|
|
88
88
|
|
|
89
89
|
Use registered callbacks when the function needs to be called at a later time (e.g. log handler, event handler, `fopencookie/funopen`). Call `koffi.register(func, type)` to register a callback function, with two arguments: the JS function, and the callback type.
|
|
90
90
|
|
|
91
|
-
When you are done, call `koffi.unregister()` (with the value returned by `koffi.register()`) to release the slot. A maximum of
|
|
91
|
+
When you are done, call `koffi.unregister()` (with the value returned by `koffi.register()`) to release the slot. A maximum of 8192 callbacks can exist at the same time. Failure to do so will leak the slot, and subsequent registrations may fail (with an exception) once all slots are used.
|
|
92
92
|
|
|
93
93
|
The example below shows how to register and unregister delayed callbacks.
|
|
94
94
|
|
package/doc/contribute.md
CHANGED
|
@@ -14,7 +14,7 @@ Start by cloning the repository with [Git](https://git-scm.com/):
|
|
|
14
14
|
|
|
15
15
|
```sh
|
|
16
16
|
git clone https://github.com/Koromix/rygel
|
|
17
|
-
cd rygel
|
|
17
|
+
cd rygel
|
|
18
18
|
```
|
|
19
19
|
|
|
20
20
|
As said before, this is a monorepository containg multiple projects, hence the name.
|
|
@@ -30,8 +30,8 @@ First, make sure the following dependencies are met:
|
|
|
30
30
|
Once this is done, run this command _from the test or the benchmark directory_ (depending on what you want to build):
|
|
31
31
|
|
|
32
32
|
```sh
|
|
33
|
-
cd
|
|
34
|
-
node
|
|
33
|
+
cd src/koffi
|
|
34
|
+
node ../cnoke/cnoke.js
|
|
35
35
|
```
|
|
36
36
|
|
|
37
37
|
### Other platforms
|
|
@@ -46,11 +46,31 @@ Make sure the following dependencies are met:
|
|
|
46
46
|
Once this is done, run this command _from the test or the benchmark directory_ (depending on what you want to build):
|
|
47
47
|
|
|
48
48
|
```sh
|
|
49
|
-
cd
|
|
49
|
+
cd src/koffi
|
|
50
|
+
node ../cnoke/cnoke.js
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Run tests
|
|
54
|
+
|
|
55
|
+
### On your machine
|
|
56
|
+
|
|
57
|
+
Once Koffi is built, you can build the tests and run them with the following commands:
|
|
58
|
+
|
|
59
|
+
```sh
|
|
60
|
+
cd src/koffi/test
|
|
50
61
|
node ../../cnoke/cnoke.js
|
|
62
|
+
|
|
63
|
+
node sync.js # Run synchronous unit tests
|
|
64
|
+
node async.js # Run asynchronous unit tests
|
|
65
|
+
node callbacks.js # Run callback unit tests
|
|
66
|
+
node union.js # Run union unit tests
|
|
67
|
+
node win32.js # Run Windows-specific unit tests (only on Windows)
|
|
68
|
+
|
|
69
|
+
node sqlite.js # Run SQLite integration tests
|
|
70
|
+
node raylib.js # Run Raylib integration tests
|
|
51
71
|
```
|
|
52
72
|
|
|
53
|
-
|
|
73
|
+
### On virtual machines
|
|
54
74
|
|
|
55
75
|
Koffi is tested on multiple architectures using emulated (accelerated when possible) QEMU machines. First, you need to install qemu packages, such as `qemu-system` (or even `qemu-system-gui`) on Ubuntu.
|
|
56
76
|
|
|
@@ -59,7 +79,7 @@ These machines are not included directly in this repository (for license and siz
|
|
|
59
79
|
For example, if you want to run the tests on Debian ARM64, run the following commands:
|
|
60
80
|
|
|
61
81
|
```sh
|
|
62
|
-
cd
|
|
82
|
+
cd src/koffi/tools/
|
|
63
83
|
wget -q -O- https://koromix.dev/files/machines/qemu_debian_arm64.tar.zst | zstd -d | tar xv
|
|
64
84
|
sha256sum -c --ignore-missing registry/sha256sum.txt
|
|
65
85
|
```
|
package/doc/input.md
CHANGED
|
@@ -56,26 +56,26 @@ let struct1 = koffi.struct({ dummy: 'long' });
|
|
|
56
56
|
let struct2 = koffi.struct({ dummy: koffi.types.long });
|
|
57
57
|
```
|
|
58
58
|
|
|
59
|
-
### Endian-sensitive
|
|
59
|
+
### Endian-sensitive integers
|
|
60
60
|
|
|
61
61
|
*New in Koffi 2.1*
|
|
62
62
|
|
|
63
63
|
Koffi defines a bunch of endian-sensitive types, which can be used when dealing with binary data (network payloads, binary file formats, etc.).
|
|
64
64
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
65
|
+
C type | Bytes | Signedness | Endianness
|
|
66
|
+
---------------------- | ----- | ---------- | -------------
|
|
67
|
+
int16_le, int16_le_t | 2 | Signed | Little Endian
|
|
68
|
+
int16_be, int16_be_t | 2 | Signed | Big Endian
|
|
69
|
+
uint16_le, uint16_le_t | 2 | Unsigned | Little Endian
|
|
70
|
+
uint16_be, uint16_be_t | 2 | Unsigned | Big Endian
|
|
71
|
+
int32_le, int32_le_t | 4 | Signed | Little Endian
|
|
72
|
+
int32_be, int32_be_t | 4 | Signed | Big Endian
|
|
73
|
+
uint32_le, uint32_le_t | 4 | Unsigned | Little Endian
|
|
74
|
+
uint32_be, uint32_be_t | 4 | Unsigned | Big Endian
|
|
75
|
+
int64_le, int64_le_t | 8 | Signed | Little Endian
|
|
76
|
+
int64_be, int64_be_t | 8 | Signed | Big Endian
|
|
77
|
+
uint64_le, uint64_le_t | 8 | Unsigned | Little Endian
|
|
78
|
+
uint64_be, uint64_be_t | 8 | Unsigned | Big Endian
|
|
79
79
|
|
|
80
80
|
## Struct types
|
|
81
81
|
|
package/doc/misc.md
CHANGED
|
@@ -106,9 +106,9 @@ You can use `koffi.stats()` to get a few statistics related to Koffi.
|
|
|
106
106
|
|
|
107
107
|
*New in Koffi 2.3.14*
|
|
108
108
|
|
|
109
|
-
You can use `koffi.errno()` to the current errno value, and `koffi.errno(value)` to change it.
|
|
109
|
+
You can use `koffi.errno()` to get the current errno value, and `koffi.errno(value)` to change it.
|
|
110
110
|
|
|
111
|
-
The standard POSIX error codes are available in `koffi.os.errno`, as
|
|
111
|
+
The standard POSIX error codes are available in `koffi.os.errno`, as shown below:
|
|
112
112
|
|
|
113
113
|
```js
|
|
114
114
|
const assert = require('assert');
|
|
@@ -138,5 +138,5 @@ You can use `koffi.reset()` to clear some Koffi internal state such as:
|
|
|
138
138
|
This function is mainly intended for test code, when you execute the same code over and over and you need to reuse type names.
|
|
139
139
|
|
|
140
140
|
```{warning}
|
|
141
|
-
Trying to use a function or a type defined before the reset is undefined behavior and will likely lead to a crash!
|
|
141
|
+
Trying to use a function or a type that was initially defined before the reset is undefined behavior and will likely lead to a crash!
|
|
142
142
|
```
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -378,8 +378,8 @@ var require_package = __commonJS({
|
|
|
378
378
|
"build/dist/src/koffi/package.json"(exports2, module2) {
|
|
379
379
|
module2.exports = {
|
|
380
380
|
name: "koffi",
|
|
381
|
-
version: "2.5.
|
|
382
|
-
stable: "2.5.
|
|
381
|
+
version: "2.5.20",
|
|
382
|
+
stable: "2.5.20",
|
|
383
383
|
description: "Fast and simple C FFI (foreign function interface) for Node.js",
|
|
384
384
|
keywords: [
|
|
385
385
|
"foreign",
|
package/src/koffi/src/call.cc
CHANGED
|
@@ -1236,16 +1236,8 @@ void CallData::PopOutArguments()
|
|
|
1236
1236
|
|
|
1237
1237
|
void *CallData::ReserveTrampoline(const FunctionInfo *proto, Napi::Function func)
|
|
1238
1238
|
{
|
|
1239
|
-
if (!instance
|
|
1240
|
-
|
|
1241
|
-
Napi::String::New(env, "Koffi Async Callback Broker"),
|
|
1242
|
-
0, 1, nullptr, nullptr, nullptr,
|
|
1243
|
-
CallData::RelayAsync, &instance->broker) != napi_ok) {
|
|
1244
|
-
LogError("Failed to create async callback broker");
|
|
1245
|
-
return nullptr;
|
|
1246
|
-
}
|
|
1247
|
-
napi_unref_threadsafe_function(env, instance->broker);
|
|
1248
|
-
}
|
|
1239
|
+
if (!InitAsyncBroker(env, instance)) [[unlikely]]
|
|
1240
|
+
return nullptr;
|
|
1249
1241
|
|
|
1250
1242
|
int16_t idx;
|
|
1251
1243
|
{
|
package/src/koffi/src/ffi.cc
CHANGED
|
@@ -1656,6 +1656,9 @@ static Napi::Value RegisterCallback(const Napi::CallbackInfo &info)
|
|
|
1656
1656
|
Napi::Env env = info.Env();
|
|
1657
1657
|
InstanceData *instance = env.GetInstanceData<InstanceData>();
|
|
1658
1658
|
|
|
1659
|
+
if (!InitAsyncBroker(env, instance)) [[unlikely]]
|
|
1660
|
+
return env.Null();
|
|
1661
|
+
|
|
1659
1662
|
bool has_recv = (info.Length() >= 3 && info[1].IsFunction());
|
|
1660
1663
|
|
|
1661
1664
|
if (info.Length() < 2u + has_recv) {
|
|
@@ -1937,6 +1940,22 @@ InstanceMemory::~InstanceMemory()
|
|
|
1937
1940
|
#endif
|
|
1938
1941
|
}
|
|
1939
1942
|
|
|
1943
|
+
bool InitAsyncBroker(Napi::Env env, InstanceData *instance)
|
|
1944
|
+
{
|
|
1945
|
+
if (!instance->broker) {
|
|
1946
|
+
if (napi_create_threadsafe_function(env, nullptr, nullptr,
|
|
1947
|
+
Napi::String::New(env, "Koffi Async Callback Broker"),
|
|
1948
|
+
0, 1, nullptr, nullptr, nullptr,
|
|
1949
|
+
CallData::RelayAsync, &instance->broker) != napi_ok) {
|
|
1950
|
+
LogError("Failed to create async callback broker");
|
|
1951
|
+
return false;
|
|
1952
|
+
}
|
|
1953
|
+
napi_unref_threadsafe_function(env, instance->broker);
|
|
1954
|
+
}
|
|
1955
|
+
|
|
1956
|
+
return true;
|
|
1957
|
+
}
|
|
1958
|
+
|
|
1940
1959
|
static void RegisterPrimitiveType(Napi::Env env, Napi::Object map, std::initializer_list<const char *> names,
|
|
1941
1960
|
PrimitiveKind primitive, int32_t size, int16_t align, const char *ref = nullptr)
|
|
1942
1961
|
{
|
package/src/koffi/src/ffi.hh
CHANGED
|
@@ -341,4 +341,6 @@ Napi::Value TranslateNormalCall(const Napi::CallbackInfo &info);
|
|
|
341
341
|
Napi::Value TranslateVariadicCall(const Napi::CallbackInfo &info);
|
|
342
342
|
Napi::Value TranslateAsyncCall(const Napi::CallbackInfo &info);
|
|
343
343
|
|
|
344
|
+
bool InitAsyncBroker(Napi::Env env, InstanceData *instance);
|
|
345
|
+
|
|
344
346
|
}
|