koffi 2.3.19 → 2.3.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 -0
- package/build/2.3.20/koffi_darwin_arm64/koffi.node +0 -0
- package/build/2.3.20/koffi_darwin_x64/koffi.node +0 -0
- package/build/2.3.20/koffi_freebsd_arm64/koffi.node +0 -0
- package/build/2.3.20/koffi_freebsd_ia32/koffi.node +0 -0
- package/build/2.3.20/koffi_freebsd_x64/koffi.node +0 -0
- package/build/2.3.20/koffi_linux_arm32hf/koffi.node +0 -0
- package/build/2.3.20/koffi_linux_arm64/koffi.node +0 -0
- package/build/2.3.20/koffi_linux_ia32/koffi.node +0 -0
- package/build/2.3.20/koffi_linux_riscv64hf64/koffi.node +0 -0
- package/build/{2.3.19 → 2.3.20}/koffi_linux_x64/koffi.node +0 -0
- package/build/2.3.20/koffi_openbsd_ia32/koffi.node +0 -0
- package/build/2.3.20/koffi_openbsd_x64/koffi.node +0 -0
- package/build/2.3.20/koffi_win32_arm64/koffi.node +0 -0
- package/build/{2.3.19 → 2.3.20}/koffi_win32_ia32/koffi.node +0 -0
- package/build/2.3.20/koffi_win32_x64/koffi.node +0 -0
- package/doc/functions.md +19 -7
- package/package.json +2 -2
- package/src/koffi/src/ffi.cc +15 -1
- package/src/koffi/src/ffi.hh +3 -1
- package/build/2.3.19/koffi_darwin_arm64/koffi.node +0 -0
- package/build/2.3.19/koffi_darwin_x64/koffi.node +0 -0
- package/build/2.3.19/koffi_freebsd_arm64/koffi.node +0 -0
- package/build/2.3.19/koffi_freebsd_ia32/koffi.node +0 -0
- package/build/2.3.19/koffi_freebsd_x64/koffi.node +0 -0
- package/build/2.3.19/koffi_linux_arm32hf/koffi.node +0 -0
- package/build/2.3.19/koffi_linux_arm64/koffi.node +0 -0
- package/build/2.3.19/koffi_linux_ia32/koffi.node +0 -0
- package/build/2.3.19/koffi_linux_riscv64hf64/koffi.node +0 -0
- package/build/2.3.19/koffi_openbsd_ia32/koffi.node +0 -0
- package/build/2.3.19/koffi_openbsd_x64/koffi.node +0 -0
- package/build/2.3.19/koffi_win32_arm64/koffi.node +0 -0
- package/build/2.3.19/koffi_win32_x64/koffi.node +0 -0
- /package/build/{2.3.19 → 2.3.20}/koffi_win32_arm64/koffi.exp +0 -0
- /package/build/{2.3.19 → 2.3.20}/koffi_win32_arm64/koffi.lib +0 -0
- /package/build/{2.3.19 → 2.3.20}/koffi_win32_ia32/koffi.exp +0 -0
- /package/build/{2.3.19 → 2.3.20}/koffi_win32_ia32/koffi.lib +0 -0
- /package/build/{2.3.19 → 2.3.20}/koffi_win32_x64/koffi.exp +0 -0
- /package/build/{2.3.19 → 2.3.20}/koffi_win32_x64/koffi.lib +0 -0
package/CHANGELOG.md
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/doc/functions.md
CHANGED
|
@@ -1,20 +1,32 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Library functions
|
|
2
2
|
|
|
3
|
-
##
|
|
3
|
+
## Loading libraries
|
|
4
4
|
|
|
5
5
|
To declare functions, start by loading the shared library with `koffi.load(filename)`.
|
|
6
6
|
|
|
7
7
|
```js
|
|
8
8
|
const koffi = require('koffi');
|
|
9
9
|
const lib = koffi.load('/path/to/shared/library'); // File extension depends on platforms: .so, .dll, .dylib, etc.
|
|
10
|
+
````
|
|
11
|
+
|
|
12
|
+
This library will be automatically unloaded once all references to it (including all the functions that use it, as described below).
|
|
13
|
+
|
|
14
|
+
Starting with *Koffi 2.3.20*, you can explicitly unload a library by calling `lib.unload()`. Any attempt to find or call a function from this library after unloading it will crash.
|
|
15
|
+
|
|
16
|
+
```{note}
|
|
17
|
+
On some platforms (such as with the [musl C library on Linux](https://wiki.musl-libc.org/functional-differences-from-glibc.html#Unloading-libraries)), shared libraries cannot be unloaded, so the library will remain loaded and memory mapped after the call to `lib.unload()`.
|
|
10
18
|
```
|
|
11
19
|
|
|
12
|
-
|
|
20
|
+
## Function definitions
|
|
21
|
+
|
|
22
|
+
### Definition syntax
|
|
23
|
+
|
|
24
|
+
Use the object returned by `koffi.load()` to load C functions from the library. To do so, you can use two syntaxes:
|
|
13
25
|
|
|
14
26
|
- The classic syntax, inspired by node-ffi
|
|
15
27
|
- C-like prototypes
|
|
16
28
|
|
|
17
|
-
|
|
29
|
+
#### Classic syntax
|
|
18
30
|
|
|
19
31
|
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
32
|
|
|
@@ -25,7 +37,7 @@ const atoi = lib.func('atoi', 'int', ['str']);
|
|
|
25
37
|
|
|
26
38
|
Koffi automatically tries mangled names for non-standard x86 calling conventions. See the section on [calling conventions](#calling-conventions) for more information on this subject.
|
|
27
39
|
|
|
28
|
-
|
|
40
|
+
#### C-like prototypes
|
|
29
41
|
|
|
30
42
|
If you prefer, you can declare functions using simple C-like prototype strings, as shown below:
|
|
31
43
|
|
|
@@ -36,7 +48,7 @@ const atoi = lib.func('int atoi(str)'); // The parameter name is not used by Kof
|
|
|
36
48
|
|
|
37
49
|
You can use `()` or `(void)` for functions that take no argument.
|
|
38
50
|
|
|
39
|
-
|
|
51
|
+
### Variadic functions
|
|
40
52
|
|
|
41
53
|
Variadic functions are declared with an ellipsis as the last argument.
|
|
42
54
|
|
|
@@ -51,7 +63,7 @@ printf('Integer %d, double %g, str %s', 'int', 6, 'double', 8.5, 'str', 'THE END
|
|
|
51
63
|
|
|
52
64
|
On x86 platforms, only the Cdecl convention can be used for variadic functions.
|
|
53
65
|
|
|
54
|
-
|
|
66
|
+
### Calling conventions
|
|
55
67
|
|
|
56
68
|
By default, calling a C function happens synchronously.
|
|
57
69
|
|
package/package.json
CHANGED
package/src/koffi/src/ffi.cc
CHANGED
|
@@ -1532,6 +1532,16 @@ static Napi::Value FindLibraryFunction(const Napi::CallbackInfo &info, CallConve
|
|
|
1532
1532
|
return wrapper;
|
|
1533
1533
|
}
|
|
1534
1534
|
|
|
1535
|
+
static Napi::Value UnloadLibrary(const Napi::CallbackInfo &info)
|
|
1536
|
+
{
|
|
1537
|
+
Napi::Env env = info.Env();
|
|
1538
|
+
LibraryHolder *lib = (LibraryHolder *)info.Data();
|
|
1539
|
+
|
|
1540
|
+
lib->Unload();
|
|
1541
|
+
|
|
1542
|
+
return env.Undefined();
|
|
1543
|
+
}
|
|
1544
|
+
|
|
1535
1545
|
static Napi::Value LoadSharedLibrary(const Napi::CallbackInfo &info)
|
|
1536
1546
|
{
|
|
1537
1547
|
Napi::Env env = info.Env();
|
|
@@ -1610,6 +1620,8 @@ static Napi::Value LoadSharedLibrary(const Napi::CallbackInfo &info)
|
|
|
1610
1620
|
|
|
1611
1621
|
#undef ADD_CONVENTION
|
|
1612
1622
|
|
|
1623
|
+
obj.Set("unload", Napi::Function::New(env, UnloadLibrary, "unload", (void *)lib->Ref()));
|
|
1624
|
+
|
|
1613
1625
|
return obj;
|
|
1614
1626
|
}
|
|
1615
1627
|
|
|
@@ -1721,7 +1733,7 @@ static Napi::Value UnregisterCallback(const Napi::CallbackInfo &info)
|
|
|
1721
1733
|
return env.Undefined();
|
|
1722
1734
|
}
|
|
1723
1735
|
|
|
1724
|
-
LibraryHolder
|
|
1736
|
+
void LibraryHolder::Unload()
|
|
1725
1737
|
{
|
|
1726
1738
|
#ifdef _WIN32
|
|
1727
1739
|
if (module && module != GetModuleHandle(nullptr)) {
|
|
@@ -1732,6 +1744,8 @@ LibraryHolder::~LibraryHolder()
|
|
|
1732
1744
|
dlclose(module);
|
|
1733
1745
|
}
|
|
1734
1746
|
#endif
|
|
1747
|
+
|
|
1748
|
+
module = nullptr;
|
|
1735
1749
|
}
|
|
1736
1750
|
|
|
1737
1751
|
const LibraryHolder *LibraryHolder::Ref() const
|
package/src/koffi/src/ffi.hh
CHANGED
|
@@ -155,7 +155,9 @@ struct LibraryHolder {
|
|
|
155
155
|
mutable std::atomic_int refcount { 1 };
|
|
156
156
|
|
|
157
157
|
LibraryHolder(void *module) : module(module) {}
|
|
158
|
-
~LibraryHolder();
|
|
158
|
+
~LibraryHolder() { Unload(); }
|
|
159
|
+
|
|
160
|
+
void Unload();
|
|
159
161
|
|
|
160
162
|
const LibraryHolder *Ref() const;
|
|
161
163
|
void Unref() const;
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|