koffi 3.0.1 → 3.0.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 +11 -0
- package/cnoke.cjs +7 -7
- package/doc/benchmarks.md +1 -1
- package/doc/contribute.md +1 -1
- package/index.d.ts +356 -308
- package/package.json +16 -16
- package/src/koffi/CMakeLists.txt +1 -0
- package/src/koffi/index.cjs +30 -116
- package/src/koffi/index.js +27 -101
- package/src/koffi/indirect.cjs +29 -115
- package/src/koffi/indirect.js +28 -28
- package/src/koffi/src/abi/arm64.cc +1 -0
- package/src/koffi/src/abi/riscv64.cc +1 -0
- package/src/koffi/src/abi/x64sysv.cc +1 -0
- package/src/koffi/src/abi/x64win.cc +1 -0
- package/src/koffi/src/abi/x86.cc +1 -0
- package/src/koffi/src/call.cc +208 -97
- package/src/koffi/src/call.hh +2 -1
- package/src/koffi/src/ffi.cc +347 -237
- package/src/koffi/src/ffi.hh +37 -1
- package/src/koffi/src/parser.cc +3 -1
- package/src/koffi/src/static.cjs +122 -0
- package/src/koffi/src/static.js +122 -0
- package/src/koffi/src/type.cc +715 -0
- package/src/koffi/src/type.hh +71 -0
- package/src/koffi/src/util.cc +56 -1041
- package/src/koffi/src/util.hh +80 -119
- package/src/koffi/src/uv.cc +16 -10
- package/src/koffi/src/uv.hh +2 -1
- package/indirect.d.ts +0 -322
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
// SPDX-FileCopyrightText: 2026 Niels Martignène <niels.martignene@protonmail.com>
|
|
3
|
+
|
|
4
|
+
#pragma once
|
|
5
|
+
|
|
6
|
+
#include "lib/native/base/base.hh"
|
|
7
|
+
#include "ffi.hh"
|
|
8
|
+
|
|
9
|
+
#include <napi.h>
|
|
10
|
+
|
|
11
|
+
namespace K {
|
|
12
|
+
|
|
13
|
+
#if !defined(EXTERNAL_TYPES)
|
|
14
|
+
|
|
15
|
+
class TypeObject: public Napi::ObjectWrap<TypeObject> {
|
|
16
|
+
const TypeInfo *type;
|
|
17
|
+
|
|
18
|
+
mutable Napi::Object members;
|
|
19
|
+
|
|
20
|
+
public:
|
|
21
|
+
static Napi::Function InitClass(InstanceData *instance);
|
|
22
|
+
|
|
23
|
+
TypeObject(const Napi::CallbackInfo &info);
|
|
24
|
+
|
|
25
|
+
void Finalize(Napi::BasicEnv env) override;
|
|
26
|
+
|
|
27
|
+
const TypeInfo *GetType() { return type; }
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
#endif
|
|
31
|
+
|
|
32
|
+
static FORCE_INLINE bool IsInteger(const TypeInfo *type)
|
|
33
|
+
{
|
|
34
|
+
bool integer = ((int)type->primitive >= (int)PrimitiveKind::Int8 &&
|
|
35
|
+
(int)type->primitive <= (int)PrimitiveKind::UInt64);
|
|
36
|
+
return integer;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
static FORCE_INLINE bool IsFloat(const TypeInfo *type)
|
|
40
|
+
{
|
|
41
|
+
bool fp = (type->primitive == PrimitiveKind::Float32 ||
|
|
42
|
+
type->primitive == PrimitiveKind::Float64);
|
|
43
|
+
return fp;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
static FORCE_INLINE bool IsRegularSize(Size size, Size max)
|
|
47
|
+
{
|
|
48
|
+
bool regular = (size <= max && !(size & (size - 1)));
|
|
49
|
+
return regular;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
int ResolveDirections(Span<const char> str);
|
|
53
|
+
const TypeInfo *ResolveType(InstanceData *instance, napi_value value, int *out_directions = nullptr);
|
|
54
|
+
const TypeInfo *ResolveType(InstanceData *instance, Span<const char> str);
|
|
55
|
+
|
|
56
|
+
TypeInfo *MakePointerType(InstanceData *instance, const TypeInfo *ref, int count = 1);
|
|
57
|
+
TypeInfo *MakeArrayType(InstanceData *instance, const TypeInfo *ref, Size len);
|
|
58
|
+
TypeInfo *MakeArrayType(InstanceData *instance, const TypeInfo *ref, Size len, ArrayHint hint);
|
|
59
|
+
|
|
60
|
+
napi_value WrapType(Napi::Env env, const TypeInfo *type, bool freeze = true);
|
|
61
|
+
|
|
62
|
+
const TypeInfo *ReshapeType(InstanceData *instance, const TypeInfo *type, int32_t stride, uint16_t flags);
|
|
63
|
+
|
|
64
|
+
bool CanPassType(const TypeInfo *type, int directions);
|
|
65
|
+
bool CanReturnType(const TypeInfo *type);
|
|
66
|
+
bool CanStoreType(const TypeInfo *type);
|
|
67
|
+
|
|
68
|
+
// Can be slow, only use for error messages
|
|
69
|
+
const char *GetValueType(const InstanceData *instance, napi_value value);
|
|
70
|
+
|
|
71
|
+
}
|