koffi 2.3.11 → 2.3.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.
- package/CHANGELOG.md +13 -0
- package/build/2.3.13/koffi_darwin_arm64/koffi.node +0 -0
- package/build/2.3.13/koffi_darwin_x64/koffi.node +0 -0
- package/build/2.3.13/koffi_freebsd_arm64/koffi.node +0 -0
- package/build/2.3.13/koffi_freebsd_ia32/koffi.node +0 -0
- package/build/2.3.13/koffi_freebsd_x64/koffi.node +0 -0
- package/build/2.3.13/koffi_linux_arm32hf/koffi.node +0 -0
- package/build/{2.3.11 → 2.3.13}/koffi_linux_arm64/koffi.node +0 -0
- package/build/2.3.13/koffi_linux_ia32/koffi.node +0 -0
- package/build/2.3.13/koffi_linux_riscv64hf64/koffi.node +0 -0
- package/build/{2.3.11 → 2.3.13}/koffi_linux_x64/koffi.node +0 -0
- package/build/2.3.13/koffi_openbsd_ia32/koffi.node +0 -0
- package/build/2.3.13/koffi_openbsd_x64/koffi.node +0 -0
- package/build/2.3.13/koffi_win32_arm64/koffi.node +0 -0
- package/build/2.3.13/koffi_win32_ia32/koffi.node +0 -0
- package/build/{2.3.11 → 2.3.13}/koffi_win32_x64/koffi.node +0 -0
- package/doc/pointers.md +4 -0
- package/package.json +2 -2
- package/src/index.d.ts +9 -6
- package/src/koffi/src/ffi.cc +36 -4
- package/build/2.3.11/koffi_darwin_arm64/koffi.node +0 -0
- package/build/2.3.11/koffi_darwin_x64/koffi.node +0 -0
- package/build/2.3.11/koffi_freebsd_arm64/koffi.node +0 -0
- package/build/2.3.11/koffi_freebsd_ia32/koffi.node +0 -0
- package/build/2.3.11/koffi_freebsd_x64/koffi.node +0 -0
- package/build/2.3.11/koffi_linux_arm32hf/koffi.node +0 -0
- package/build/2.3.11/koffi_linux_ia32/koffi.node +0 -0
- package/build/2.3.11/koffi_linux_riscv64hf64/koffi.node +0 -0
- package/build/2.3.11/koffi_openbsd_ia32/koffi.node +0 -0
- package/build/2.3.11/koffi_openbsd_x64/koffi.node +0 -0
- package/build/2.3.11/koffi_win32_arm64/koffi.node +0 -0
- package/build/2.3.11/koffi_win32_ia32/koffi.node +0 -0
- /package/build/{2.3.11 → 2.3.13}/koffi_win32_arm64/koffi.exp +0 -0
- /package/build/{2.3.11 → 2.3.13}/koffi_win32_arm64/koffi.lib +0 -0
- /package/build/{2.3.11 → 2.3.13}/koffi_win32_ia32/koffi.exp +0 -0
- /package/build/{2.3.11 → 2.3.13}/koffi_win32_ia32/koffi.lib +0 -0
- /package/build/{2.3.11 → 2.3.13}/koffi_win32_x64/koffi.exp +0 -0
- /package/build/{2.3.11 → 2.3.13}/koffi_win32_x64/koffi.lib +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,19 @@
|
|
|
4
4
|
|
|
5
5
|
### Koffi 2.3
|
|
6
6
|
|
|
7
|
+
#### Koffi 2.3.13
|
|
8
|
+
|
|
9
|
+
**Main changes:**
|
|
10
|
+
|
|
11
|
+
- Add `koffi.address()` to get the raw value of a wrapper pointer
|
|
12
|
+
|
|
13
|
+
#### Koffi 2.3.12
|
|
14
|
+
|
|
15
|
+
**Main fixes:**
|
|
16
|
+
|
|
17
|
+
- Fix broken syntax in TS definition file
|
|
18
|
+
- Add missing exported properties in TS file
|
|
19
|
+
|
|
7
20
|
#### Koffi 2.3.11
|
|
8
21
|
|
|
9
22
|
**Main changes:**
|
|
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/pointers.md
CHANGED
|
@@ -133,3 +133,7 @@ By default, just like for objects, array arguments are copied from JS to C but n
|
|
|
133
133
|
Disposable types allow you to register a function that will automatically called after each C to JS conversion performed by Koffi. This can be used to avoid leaking heap-allocated strings, for example.
|
|
134
134
|
|
|
135
135
|
Read the documentation for [disposable types](calls.md#heap-allocated-values) on the page about function calls.
|
|
136
|
+
|
|
137
|
+
## Unwrap pointers
|
|
138
|
+
|
|
139
|
+
You can use `koffi.address(ptr)` on a pointer to get the numeric value as a [BigInt object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt).
|
package/package.json
CHANGED
package/src/index.d.ts
CHANGED
|
@@ -22,9 +22,9 @@
|
|
|
22
22
|
declare module 'koffi' {
|
|
23
23
|
export function load(path: string): IKoffiLib;
|
|
24
24
|
|
|
25
|
-
interface IKoffiCType { __brand: 'IKoffiCType' }
|
|
26
|
-
interface IKoffiPointerCast { __brand: 'IKoffiPointerCast' }
|
|
27
|
-
interface IKoffiRegisteredCallback { __brand: 'IKoffiRegisteredCallback' }
|
|
25
|
+
interface IKoffiCType { __brand: 'IKoffiCType' }
|
|
26
|
+
interface IKoffiPointerCast { __brand: 'IKoffiPointerCast' }
|
|
27
|
+
interface IKoffiRegisteredCallback { __brand: 'IKoffiRegisteredCallback' }
|
|
28
28
|
|
|
29
29
|
type PrimitiveKind = 'Void' | 'Bool' | 'Int8' | 'UInt8' | 'Int16' | 'Int16S' | 'UInt16' | 'UInt16S' |
|
|
30
30
|
'Int32' | 'Int32S' | 'UInt32' | 'UInt32S' | 'Int64' | 'Int64S' | 'UInt64' | 'UInt64S' |
|
|
@@ -79,7 +79,7 @@ declare module 'koffi' {
|
|
|
79
79
|
|
|
80
80
|
thiscall(definition: string): KoffiFunction;
|
|
81
81
|
thiscall(name: string, result: TypeSpec, arguments: TypeSpec[]): KoffiFunction;
|
|
82
|
-
}
|
|
82
|
+
}
|
|
83
83
|
|
|
84
84
|
export function struct(name: string, def: Record<string, TypeSpecWithAlignment>): IKoffiCType;
|
|
85
85
|
export function struct(def: Record<string, TypeSpecWithAlignment>): IKoffiCType;
|
|
@@ -101,8 +101,6 @@ declare module 'koffi' {
|
|
|
101
101
|
export function out(value: TypeSpec): IKoffiCType;
|
|
102
102
|
export function inout(value: TypeSpec): IKoffiCType;
|
|
103
103
|
|
|
104
|
-
export function as(value: any, type: TypeSpec): IKoffiPointerCast;
|
|
105
|
-
|
|
106
104
|
export function disposable(type: TypeSpec): IKoffiCType;
|
|
107
105
|
export function disposable(name: string, type: TypeSpec): IKoffiCType;
|
|
108
106
|
export function disposable(name: string, type: TypeSpec, freeFunction: Function): IKoffiCType;
|
|
@@ -114,10 +112,12 @@ declare module 'koffi' {
|
|
|
114
112
|
export function register(thisValue: any, callback: Function, type: TypeSpec): IKoffiRegisteredCallback;
|
|
115
113
|
export function unregister(callback: IKoffiRegisteredCallback): void;
|
|
116
114
|
|
|
115
|
+
export function as(value: any, type: TypeSpec): IKoffiPointerCast;
|
|
117
116
|
export function decode(value: any, type: TypeSpec): any;
|
|
118
117
|
export function decode(value: any, type: TypeSpec, len: number): any;
|
|
119
118
|
export function decode(value: any, offset: number, type: TypeSpec): any;
|
|
120
119
|
export function decode(value: any, offset: number, type: TypeSpec, len: number): any;
|
|
120
|
+
export function address(value: any): bigint;
|
|
121
121
|
|
|
122
122
|
export function sizeof(type: TypeSpec): number;
|
|
123
123
|
export function alignof(type: TypeSpec): number;
|
|
@@ -130,4 +130,7 @@ declare module 'koffi' {
|
|
|
130
130
|
export function config(): Record<string, unknown>;
|
|
131
131
|
export function config(cfg: Record<string, unknown>): Record<string, unknown>;
|
|
132
132
|
export function stats(): Record<string, unknown>;
|
|
133
|
+
|
|
134
|
+
export let internal: Boolean;
|
|
135
|
+
export let extension: String;
|
|
133
136
|
}
|
package/src/koffi/src/ffi.cc
CHANGED
|
@@ -722,19 +722,30 @@ static Napi::Value CreateDisposableType(const Napi::CallbackInfo &info)
|
|
|
722
722
|
return WrapType(env, instance, type);
|
|
723
723
|
}
|
|
724
724
|
|
|
725
|
+
static inline bool CheckExternalPointer(Napi::Env env, Napi::Value value)
|
|
726
|
+
{
|
|
727
|
+
InstanceData *instance = env.GetInstanceData<InstanceData>();
|
|
728
|
+
|
|
729
|
+
if (!value.IsExternal() || CheckValueTag(instance, value, &TypeInfoMarker) ||
|
|
730
|
+
CheckValueTag(instance, value, &CastMarker) ||
|
|
731
|
+
CheckValueTag(instance, value, &MagicUnionMarker)) {
|
|
732
|
+
ThrowError<Napi::TypeError>(env, "Unexpected %1 value for ptr, expected external pointer", GetValueType(instance, value));
|
|
733
|
+
return false;
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
return true;
|
|
737
|
+
}
|
|
738
|
+
|
|
725
739
|
static Napi::Value CallFree(const Napi::CallbackInfo &info)
|
|
726
740
|
{
|
|
727
741
|
Napi::Env env = info.Env();
|
|
728
|
-
InstanceData *instance = env.GetInstanceData<InstanceData>();
|
|
729
742
|
|
|
730
743
|
if (info.Length() < 1) {
|
|
731
744
|
ThrowError<Napi::TypeError>(env, "Expected 1 argument, got %1", info.Length());
|
|
732
745
|
return env.Null();
|
|
733
746
|
}
|
|
734
|
-
if (!
|
|
735
|
-
ThrowError<Napi::TypeError>(env, "Unexpected %1 value for ptr, expected external", GetValueType(instance, info[0]));
|
|
747
|
+
if (!CheckExternalPointer(env, info[0]))
|
|
736
748
|
return env.Null();
|
|
737
|
-
}
|
|
738
749
|
|
|
739
750
|
Napi::External<void> external = info[0].As<Napi::External<void>>();
|
|
740
751
|
void *ptr = external.Data();
|
|
@@ -1973,6 +1984,26 @@ static Napi::Value DecodeValue(const Napi::CallbackInfo &info)
|
|
|
1973
1984
|
return ret;
|
|
1974
1985
|
}
|
|
1975
1986
|
|
|
1987
|
+
static Napi::Value GetPointerAddress(const Napi::CallbackInfo &info)
|
|
1988
|
+
{
|
|
1989
|
+
Napi::Env env = info.Env();
|
|
1990
|
+
|
|
1991
|
+
if (info.Length() < 1) {
|
|
1992
|
+
ThrowError<Napi::TypeError>(env, "Expected 1 argument, got %1", info.Length());
|
|
1993
|
+
return env.Null();
|
|
1994
|
+
}
|
|
1995
|
+
if (!CheckExternalPointer(env, info[0]))
|
|
1996
|
+
return env.Null();
|
|
1997
|
+
|
|
1998
|
+
Napi::External<void> external = info[0].As<Napi::External<void>>();
|
|
1999
|
+
void *ptr = external.Data();
|
|
2000
|
+
|
|
2001
|
+
uint64_t ptr64 = (uint64_t)(uintptr_t)ptr;
|
|
2002
|
+
Napi::BigInt bigint = Napi::BigInt::New(env, ptr64);
|
|
2003
|
+
|
|
2004
|
+
return bigint;
|
|
2005
|
+
}
|
|
2006
|
+
|
|
1976
2007
|
extern "C" void RelayCallback(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegisters *out_reg)
|
|
1977
2008
|
{
|
|
1978
2009
|
if (RG_LIKELY(exec_call)) {
|
|
@@ -2038,6 +2069,7 @@ static void SetExports(Napi::Env env, Func func)
|
|
|
2038
2069
|
|
|
2039
2070
|
func("as", Napi::Function::New(env, CastValue));
|
|
2040
2071
|
func("decode", Napi::Function::New(env, DecodeValue));
|
|
2072
|
+
func("address", Napi::Function::New(env, GetPointerAddress));
|
|
2041
2073
|
|
|
2042
2074
|
#if defined(_WIN32)
|
|
2043
2075
|
func("extension", Napi::String::New(env, ".dll"));
|
|
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
|