koffi 2.2.2-beta.6 → 2.2.2
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 +14 -0
- package/doc/callbacks.md +9 -2
- package/package.json +2 -2
- package/src/koffi/build/2.2.2/koffi_darwin_arm64.tar.gz +0 -0
- package/src/koffi/build/2.2.2/koffi_darwin_x64.tar.gz +0 -0
- package/src/koffi/build/2.2.2/koffi_freebsd_arm64.tar.gz +0 -0
- package/src/koffi/build/2.2.2/koffi_freebsd_ia32.tar.gz +0 -0
- package/src/koffi/build/2.2.2/koffi_freebsd_x64.tar.gz +0 -0
- package/src/koffi/build/2.2.2/koffi_linux_arm32hf.tar.gz +0 -0
- package/src/koffi/build/2.2.2/koffi_linux_arm64.tar.gz +0 -0
- package/src/koffi/build/2.2.2/koffi_linux_ia32.tar.gz +0 -0
- package/src/koffi/build/2.2.2/koffi_linux_riscv64hf64.tar.gz +0 -0
- package/src/koffi/build/2.2.2/koffi_linux_x64.tar.gz +0 -0
- package/src/koffi/build/2.2.2/koffi_openbsd_ia32.tar.gz +0 -0
- package/src/koffi/build/2.2.2/koffi_openbsd_x64.tar.gz +0 -0
- package/src/koffi/build/2.2.2/koffi_win32_arm64.tar.gz +0 -0
- package/src/koffi/build/2.2.2/koffi_win32_ia32.tar.gz +0 -0
- package/src/koffi/build/2.2.2/koffi_win32_x64.tar.gz +0 -0
- package/src/koffi/src/call.cc +3 -0
- package/src/koffi/src/ffi.cc +4 -4
- package/src/koffi/build/2.2.2-beta.6/koffi_darwin_arm64.tar.gz +0 -0
- package/src/koffi/build/2.2.2-beta.6/koffi_darwin_x64.tar.gz +0 -0
- package/src/koffi/build/2.2.2-beta.6/koffi_freebsd_arm64.tar.gz +0 -0
- package/src/koffi/build/2.2.2-beta.6/koffi_freebsd_ia32.tar.gz +0 -0
- package/src/koffi/build/2.2.2-beta.6/koffi_freebsd_x64.tar.gz +0 -0
- package/src/koffi/build/2.2.2-beta.6/koffi_linux_arm32hf.tar.gz +0 -0
- package/src/koffi/build/2.2.2-beta.6/koffi_linux_arm64.tar.gz +0 -0
- package/src/koffi/build/2.2.2-beta.6/koffi_linux_ia32.tar.gz +0 -0
- package/src/koffi/build/2.2.2-beta.6/koffi_linux_riscv64hf64.tar.gz +0 -0
- package/src/koffi/build/2.2.2-beta.6/koffi_linux_x64.tar.gz +0 -0
- package/src/koffi/build/2.2.2-beta.6/koffi_openbsd_ia32.tar.gz +0 -0
- package/src/koffi/build/2.2.2-beta.6/koffi_openbsd_x64.tar.gz +0 -0
- package/src/koffi/build/2.2.2-beta.6/koffi_win32_arm64.tar.gz +0 -0
- package/src/koffi/build/2.2.2-beta.6/koffi_win32_ia32.tar.gz +0 -0
- package/src/koffi/build/2.2.2-beta.6/koffi_win32_x64.tar.gz +0 -0
package/ChangeLog.md
CHANGED
|
@@ -2,6 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
## History
|
|
4
4
|
|
|
5
|
+
### Koffi 2.2.2
|
|
6
|
+
|
|
7
|
+
**Main fixes:**
|
|
8
|
+
|
|
9
|
+
- Support transparent [asynchronous callbacks](callbacks.md#asynchronous-callbacks)
|
|
10
|
+
- Expand from a maximum of 16+16 to 1024 callbacks running in parallel
|
|
11
|
+
|
|
12
|
+
**Other fixes:**
|
|
13
|
+
|
|
14
|
+
- Fix bundler support by removing shebang from index.js
|
|
15
|
+
- Fix bugs when loading Koffi multiples times in same process (context aware module)
|
|
16
|
+
- Check N-API version when module is loaded
|
|
17
|
+
- Optimize callback unregistration
|
|
18
|
+
|
|
5
19
|
### Koffi 2.2.1
|
|
6
20
|
|
|
7
21
|
**Main fixes:**
|
package/doc/callbacks.md
CHANGED
|
@@ -172,9 +172,16 @@ console.log(array); // Prints ['123', 'bar', 'foo', 'foobar']
|
|
|
172
172
|
|
|
173
173
|
*New in Koffi 2.2.2*
|
|
174
174
|
|
|
175
|
-
|
|
175
|
+
JS execution is inherently single-threaded, so JS callbacks must run on the main thread. There are two ways you may want to call a callback function from another thread:
|
|
176
176
|
|
|
177
|
-
|
|
177
|
+
- Call the callback from an asynchronous FFI call (e.g. `waitpid.async`)
|
|
178
|
+
- Inside a synchronous FFI call, pass the callback to another thread
|
|
179
|
+
|
|
180
|
+
In both cases, Koffi will queue the call back to JS to run on the main thread, as soon as the JS event loop has a chance to run (for example when you await a promise).
|
|
181
|
+
|
|
182
|
+
```{warning}
|
|
183
|
+
Be careful, you can easily get into a deadlock situation if you call a callback from a secondary thread and your main thread never lets the JS event loop run (for example, if the main thread waits for the secondary thread to finish something itself).
|
|
184
|
+
```
|
|
178
185
|
|
|
179
186
|
## Handling of exceptions
|
|
180
187
|
|
package/package.json
CHANGED
|
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/src/koffi/src/call.cc
CHANGED
|
@@ -81,6 +81,9 @@ CallData::~CallData()
|
|
|
81
81
|
void CallData::RelaySafe(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegisters *out_reg)
|
|
82
82
|
{
|
|
83
83
|
if (std::this_thread::get_id() != instance->main_thread_id) {
|
|
84
|
+
// JS/V8 is single-threaded, and runs on main_thread_id. Forward the call
|
|
85
|
+
// to the JS event loop.
|
|
86
|
+
|
|
84
87
|
RelayContext ctx;
|
|
85
88
|
|
|
86
89
|
ctx.call = this;
|
package/src/koffi/src/ffi.cc
CHANGED
|
@@ -1065,9 +1065,6 @@ static Napi::Value TranslateNormalCall(const Napi::CallbackInfo &info)
|
|
|
1065
1065
|
InstanceMemory *mem = instance->memories[0];
|
|
1066
1066
|
CallData call(env, instance, mem);
|
|
1067
1067
|
|
|
1068
|
-
RG_DEFER_C(prev_call = exec_call) { exec_call = prev_call; };
|
|
1069
|
-
exec_call = &call;
|
|
1070
|
-
|
|
1071
1068
|
if (!RG_UNLIKELY(call.Prepare(func, info)))
|
|
1072
1069
|
return env.Null();
|
|
1073
1070
|
|
|
@@ -1113,7 +1110,7 @@ static Napi::Value TranslateVariadicCall(const Napi::CallbackInfo &info)
|
|
|
1113
1110
|
for (Size i = func.parameters.len; i < (Size)info.Length(); i += 2) {
|
|
1114
1111
|
ParameterInfo param = {};
|
|
1115
1112
|
|
|
1116
|
-
param.type = ResolveType(info[i], ¶m.directions);
|
|
1113
|
+
param.type = ResolveType(info[(uint32_t)i], ¶m.directions);
|
|
1117
1114
|
|
|
1118
1115
|
if (RG_UNLIKELY(!param.type))
|
|
1119
1116
|
return env.Null();
|
|
@@ -1893,6 +1890,9 @@ extern "C" void RelayCallback(Size idx, uint8_t *own_sp, uint8_t *caller_sp, Bac
|
|
|
1893
1890
|
if (RG_LIKELY(exec_call)) {
|
|
1894
1891
|
exec_call->RelaySafe(idx, own_sp, caller_sp, out_reg);
|
|
1895
1892
|
} else {
|
|
1893
|
+
// This happens if the callback pointer is called from a different thread
|
|
1894
|
+
// than the one that runs the FFI call (sync or async).
|
|
1895
|
+
|
|
1896
1896
|
TrampolineInfo *trampoline = &shared.trampolines[idx];
|
|
1897
1897
|
|
|
1898
1898
|
Napi::Env env = trampoline->func.Env();
|
|
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
|