koffi 3.0.1 → 3.1.0
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 +32 -3
- package/cnoke.cjs +2 -2
- package/doc/benchmarks.md +1 -1
- package/doc/callbacks.md +7 -26
- package/doc/{input.md → composites.md} +161 -147
- package/doc/contribute.md +3 -2
- package/doc/index.md +0 -14
- package/doc/{functions.md → load.md} +54 -113
- package/doc/migration.md +4 -7
- package/doc/misc.md +0 -103
- package/doc/output.md +5 -11
- package/doc/pointers.md +76 -17
- package/doc/primitives.md +151 -0
- package/doc/start.md +3 -13
- package/doc/types.md +88 -0
- package/doc/unions.md +0 -186
- package/doc/values.md +134 -0
- package/index.d.ts +375 -308
- package/lib/native/base/base.cc +66 -24
- package/lib/native/base/base.hh +55 -153
- package/package.json +16 -16
- package/src/koffi/CMakeLists.txt +20 -17
- package/src/koffi/index.cjs +30 -111
- package/src/koffi/index.js +22 -96
- package/src/koffi/indirect.cjs +30 -111
- package/src/koffi/indirect.js +24 -24
- package/src/koffi/src/abi/arm64.cc +48 -62
- package/src/koffi/src/abi/riscv64.cc +39 -57
- package/src/koffi/src/abi/x64sysv.cc +39 -57
- package/src/koffi/src/abi/x64win.cc +48 -65
- package/src/koffi/src/abi/x86.cc +47 -59
- package/src/koffi/src/call.cc +426 -209
- package/src/koffi/src/call.hh +7 -11
- package/src/koffi/src/ffi.cc +534 -303
- package/src/koffi/src/ffi.hh +71 -15
- package/src/koffi/src/parser.cc +5 -3
- package/src/koffi/src/parser.hh +2 -2
- package/src/koffi/src/static.cjs +122 -0
- package/src/koffi/src/static.js +125 -0
- package/src/koffi/src/type.cc +725 -0
- package/src/koffi/src/type.hh +71 -0
- package/src/koffi/src/util.cc +117 -1202
- package/src/koffi/src/util.hh +158 -156
- package/src/koffi/src/uv.cc +17 -11
- package/src/koffi/src/uv.hh +2 -1
- package/vendor/node-addon-api/README.md +1 -1
- package/vendor/node-addon-api/napi-inl.h +213 -35
- package/vendor/node-addon-api/napi.h +118 -7
- package/doc/variables.md +0 -102
- package/indirect.d.ts +0 -322
package/src/koffi/src/util.hh
CHANGED
|
@@ -10,53 +10,6 @@
|
|
|
10
10
|
|
|
11
11
|
namespace K {
|
|
12
12
|
|
|
13
|
-
#if defined(_MSC_VER)
|
|
14
|
-
#define FORCE_INLINE __forceinline
|
|
15
|
-
#else
|
|
16
|
-
#define FORCE_INLINE __attribute__((always_inline)) inline
|
|
17
|
-
#endif
|
|
18
|
-
#if defined(UNITY_BUILD)
|
|
19
|
-
#define INLINE_UNITY FORCE_INLINE
|
|
20
|
-
#else
|
|
21
|
-
#define INLINE_UNITY
|
|
22
|
-
#endif
|
|
23
|
-
|
|
24
|
-
#if defined(__GNUC__) || defined(__clang__)
|
|
25
|
-
#if __has_attribute(musttail) && __has_attribute(preserve_none)
|
|
26
|
-
#define MUST_TAIL __attribute__((musttail))
|
|
27
|
-
#define PRESERVE_NONE __attribute__((preserve_none))
|
|
28
|
-
#elif __has_attribute(musttail) && !defined(__clang__)
|
|
29
|
-
// GCC regalloc seems better, so the generated code is not too bad even without preserve_none
|
|
30
|
-
#define MUST_TAIL __attribute__((musttail))
|
|
31
|
-
#define PRESERVE_NONE
|
|
32
|
-
#endif
|
|
33
|
-
#endif
|
|
34
|
-
|
|
35
|
-
extern const napi_type_tag LibraryHandleMarker;
|
|
36
|
-
extern const napi_type_tag TypeObjectMarker;
|
|
37
|
-
extern const napi_type_tag DirectionMarker;
|
|
38
|
-
extern const napi_type_tag UnionValueMarker;
|
|
39
|
-
extern const napi_type_tag CastMarker;
|
|
40
|
-
|
|
41
|
-
#if !defined(EXTERNAL_TYPES)
|
|
42
|
-
|
|
43
|
-
class TypeObject: public Napi::ObjectWrap<TypeObject> {
|
|
44
|
-
const TypeInfo *type;
|
|
45
|
-
|
|
46
|
-
mutable Napi::Object members;
|
|
47
|
-
|
|
48
|
-
public:
|
|
49
|
-
static Napi::Function InitClass(Napi::Env env);
|
|
50
|
-
|
|
51
|
-
TypeObject(const Napi::CallbackInfo &info);
|
|
52
|
-
|
|
53
|
-
void Finalize(Napi::BasicEnv env) override;
|
|
54
|
-
|
|
55
|
-
const TypeInfo *GetType() { return type; }
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
#endif
|
|
59
|
-
|
|
60
13
|
class UnionValue: public Napi::ObjectWrap<UnionValue> {
|
|
61
14
|
InstanceData *instance;
|
|
62
15
|
const TypeInfo *type;
|
|
@@ -66,7 +19,7 @@ class UnionValue: public Napi::ObjectWrap<UnionValue> {
|
|
|
66
19
|
HeapArray<uint8_t> raw;
|
|
67
20
|
|
|
68
21
|
public:
|
|
69
|
-
static Napi::Function InitClass(
|
|
22
|
+
static Napi::Function InitClass(InstanceData *instance, const TypeInfo *type);
|
|
70
23
|
|
|
71
24
|
UnionValue(const Napi::CallbackInfo &info);
|
|
72
25
|
|
|
@@ -93,63 +46,17 @@ void ThrowError(Napi::Env env, const char *msg, Args... args)
|
|
|
93
46
|
err.ThrowAsJavaScriptException();
|
|
94
47
|
}
|
|
95
48
|
|
|
96
|
-
static FORCE_INLINE bool IsInteger(const TypeInfo *type)
|
|
97
|
-
{
|
|
98
|
-
bool integer = ((int)type->primitive >= (int)PrimitiveKind::Int8 &&
|
|
99
|
-
(int)type->primitive <= (int)PrimitiveKind::UInt64);
|
|
100
|
-
return integer;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
static FORCE_INLINE bool IsFloat(const TypeInfo *type)
|
|
104
|
-
{
|
|
105
|
-
bool fp = (type->primitive == PrimitiveKind::Float32 ||
|
|
106
|
-
type->primitive == PrimitiveKind::Float64);
|
|
107
|
-
return fp;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
static FORCE_INLINE bool IsRegularSize(Size size, Size max)
|
|
111
|
-
{
|
|
112
|
-
bool regular = (size <= max && !(size & (size - 1)));
|
|
113
|
-
return regular;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
int ResolveDirections(Span<const char> str);
|
|
117
|
-
const TypeInfo *ResolveType(Napi::Value value, int *out_directions = nullptr);
|
|
118
|
-
const TypeInfo *ResolveType(Napi::Env env, Span<const char> str);
|
|
119
|
-
|
|
120
|
-
TypeInfo *MakePointerType(InstanceData *instance, const TypeInfo *ref, int count = 1);
|
|
121
|
-
TypeInfo *MakeArrayType(InstanceData *instance, const TypeInfo *ref, Size len);
|
|
122
|
-
TypeInfo *MakeArrayType(InstanceData *instance, const TypeInfo *ref, Size len, ArrayHint hint);
|
|
123
|
-
|
|
124
|
-
Napi::Value WrapType(Napi::Env env, const TypeInfo *type, bool freeze = true);
|
|
125
|
-
|
|
126
|
-
const TypeInfo *ReshapeType(InstanceData *instance, const TypeInfo *type, int32_t stride, uint16_t flags);
|
|
127
|
-
|
|
128
|
-
bool CanPassType(const TypeInfo *type, int directions);
|
|
129
|
-
bool CanReturnType(const TypeInfo *type);
|
|
130
|
-
bool CanStoreType(const TypeInfo *type);
|
|
131
|
-
|
|
132
49
|
static FORCE_INLINE napi_valuetype GetKindOf(napi_env env, napi_value value)
|
|
133
50
|
{
|
|
134
51
|
napi_valuetype kind = napi_undefined;
|
|
135
|
-
napi_typeof(env, value, &kind);
|
|
52
|
+
NAPI_OK(napi_typeof(env, value, &kind));
|
|
136
53
|
|
|
137
54
|
return kind;
|
|
138
55
|
}
|
|
139
56
|
|
|
140
|
-
static FORCE_INLINE napi_valuetype GetKindOf(Napi::Value value)
|
|
141
|
-
{
|
|
142
|
-
return GetKindOf(value.Env(), value);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
// Can be slow, only use for error messages
|
|
146
|
-
const char *GetValueType(const InstanceData *instance, napi_value value);
|
|
147
|
-
|
|
148
57
|
void SetValueTag(napi_env env, napi_value value, const void *marker);
|
|
149
58
|
bool CheckValueTag(napi_env env, napi_value value, const void *marker);
|
|
150
59
|
|
|
151
|
-
void DeleteReferenceSafe(napi_env env, napi_ref ref);
|
|
152
|
-
|
|
153
60
|
static FORCE_INLINE bool IsNullOrUndefined(napi_valuetype kind)
|
|
154
61
|
{
|
|
155
62
|
return kind == napi_null || kind == napi_undefined;
|
|
@@ -203,9 +110,7 @@ static FORCE_INLINE bool IsBuffer(napi_env env, napi_value value)
|
|
|
203
110
|
static FORCE_INLINE napi_value GetReferenceValue(napi_env env, napi_ref ref)
|
|
204
111
|
{
|
|
205
112
|
napi_value value;
|
|
206
|
-
|
|
207
|
-
napi_status status = napi_get_reference_value(env, ref, &value);
|
|
208
|
-
K_ASSERT(status == napi_ok);
|
|
113
|
+
NAPI_OK(napi_get_reference_value(env, ref, &value));
|
|
209
114
|
|
|
210
115
|
return value;
|
|
211
116
|
}
|
|
@@ -213,9 +118,7 @@ static FORCE_INLINE napi_value GetReferenceValue(napi_env env, napi_ref ref)
|
|
|
213
118
|
static FORCE_INLINE uint32_t GetArrayLength(napi_env env, napi_value array)
|
|
214
119
|
{
|
|
215
120
|
uint32_t length = 0;
|
|
216
|
-
|
|
217
|
-
napi_status status = napi_get_array_length(env, array, &length);
|
|
218
|
-
K_ASSERT(status == napi_ok);
|
|
121
|
+
NAPI_OK(napi_get_array_length(env, array, &length));
|
|
219
122
|
|
|
220
123
|
return length;
|
|
221
124
|
}
|
|
@@ -307,6 +210,62 @@ static FORCE_INLINE bool TryPointer(napi_env env, napi_value value, void **out_p
|
|
|
307
210
|
return false;
|
|
308
211
|
}
|
|
309
212
|
|
|
213
|
+
static FORCE_INLINE bool TryPointer(napi_env env, napi_value value, void **out_ptr, Size *out_len)
|
|
214
|
+
{
|
|
215
|
+
// Fast path for BigInt
|
|
216
|
+
{
|
|
217
|
+
uint64_t u64;
|
|
218
|
+
bool lossless;
|
|
219
|
+
napi_status status = napi_get_value_bigint_uint64(env, value, &u64, &lossless);
|
|
220
|
+
|
|
221
|
+
if (status == napi_ok) {
|
|
222
|
+
*out_ptr = (void *)(uintptr_t)u64;
|
|
223
|
+
*out_len = -1;
|
|
224
|
+
|
|
225
|
+
return true;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
if (size_t len = 0; node_api_get_buffer_info(env, value, out_ptr, &len) == napi_ok) {
|
|
230
|
+
*out_len = (Size)len;
|
|
231
|
+
return true;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
napi_valuetype kind = GetKindOf(env, value);
|
|
235
|
+
|
|
236
|
+
if (IsNullOrUndefined(kind)) {
|
|
237
|
+
*out_ptr = nullptr;
|
|
238
|
+
*out_len = -1;
|
|
239
|
+
|
|
240
|
+
return true;
|
|
241
|
+
} else if (kind == napi_number) {
|
|
242
|
+
int64_t i;
|
|
243
|
+
napi_status status = napi_get_value_int64(env, value, &i);
|
|
244
|
+
K_ASSERT(status == napi_ok);
|
|
245
|
+
|
|
246
|
+
*out_ptr = (void *)(uintptr_t)i;
|
|
247
|
+
*out_len = -1;
|
|
248
|
+
|
|
249
|
+
return true;
|
|
250
|
+
#if defined(EXTERNAL_POINTERS)
|
|
251
|
+
} else if (kind == napi_external) {
|
|
252
|
+
Napi::External<void> external = Napi::External<void>(env, value);
|
|
253
|
+
|
|
254
|
+
*out_ptr = (void *)external.Data();
|
|
255
|
+
*out_len = -1;
|
|
256
|
+
|
|
257
|
+
return true;
|
|
258
|
+
#endif
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
if (size_t len = 0; napi_get_arraybuffer_info(env, value, out_ptr, &len) == napi_ok) {
|
|
262
|
+
*out_len = (Size)len;
|
|
263
|
+
return true;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
return false;
|
|
267
|
+
}
|
|
268
|
+
|
|
310
269
|
static FORCE_INLINE bool TryPointer(napi_env env, napi_value value, void **out_ptr, napi_valuetype *out_kind)
|
|
311
270
|
{
|
|
312
271
|
// Fast path for BigInt
|
|
@@ -382,43 +341,6 @@ static FORCE_INLINE bool TryBuffer(napi_env env, napi_value value, Span<uint8_t>
|
|
|
382
341
|
|
|
383
342
|
int GetTypedArrayType(const TypeInfo *type);
|
|
384
343
|
|
|
385
|
-
template <typename T>
|
|
386
|
-
Size NullTerminatedLength(const T *ptr)
|
|
387
|
-
{
|
|
388
|
-
Size len = 0;
|
|
389
|
-
while (ptr[len]) {
|
|
390
|
-
len++;
|
|
391
|
-
}
|
|
392
|
-
return len;
|
|
393
|
-
}
|
|
394
|
-
template <typename T>
|
|
395
|
-
Size NullTerminatedLength(const T *ptr, Size max)
|
|
396
|
-
{
|
|
397
|
-
Size len = 0;
|
|
398
|
-
while (len < max && ptr[len]) {
|
|
399
|
-
len++;
|
|
400
|
-
}
|
|
401
|
-
return len;
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
Napi::String MakeStringFromUTF32(Napi::Env env, const char32_t *ptr, Size len);
|
|
405
|
-
static inline Napi::String MakeStringFromUTF32(Napi::Env env, const char32_t *ptr)
|
|
406
|
-
{ return MakeStringFromUTF32(env, ptr, NullTerminatedLength(ptr)); }
|
|
407
|
-
|
|
408
|
-
napi_value DecodeObject(InstanceData *instance, const uint8_t *origin, const TypeInfo *type);
|
|
409
|
-
void DecodeObject(InstanceData *instance, napi_value obj, const uint8_t *origin, const TypeInfo *type);
|
|
410
|
-
|
|
411
|
-
napi_value DecodeArray(InstanceData *instance, const uint8_t *origin, const TypeInfo *type);
|
|
412
|
-
napi_value DecodeArray(InstanceData *instance, const uint8_t *origin, const TypeInfo *type, uint32_t len);
|
|
413
|
-
void DecodeElements(InstanceData *instance, napi_value array, const uint8_t *origin, const TypeInfo *type, uint32_t len);
|
|
414
|
-
INLINE_UNITY void DecodeBuffer(Span<uint8_t> buffer, const uint8_t *origin, const TypeInfo *type);
|
|
415
|
-
|
|
416
|
-
napi_value Decode(Napi::Value value, Size offset, const TypeInfo *type, const Size *len = nullptr);
|
|
417
|
-
napi_value Decode(InstanceData *instance, const uint8_t *ptr, const TypeInfo *type, const Size *len = nullptr);
|
|
418
|
-
|
|
419
|
-
bool Encode(Napi::Value ref, Size offset, Napi::Value value, const TypeInfo *type, const Size *len = nullptr);
|
|
420
|
-
bool Encode(InstanceData *instance, uint8_t *ptr, Napi::Value value, const TypeInfo *type, const Size *len = nullptr);
|
|
421
|
-
|
|
422
344
|
static FORCE_INLINE napi_value NewInt(Napi::Env env, char i) { napi_value value; napi_create_int32(env, (int32_t)i, &value); return value; }
|
|
423
345
|
static FORCE_INLINE napi_value NewInt(Napi::Env env, signed char i) { napi_value value; napi_create_int32(env, (int32_t)i, &value); return value; }
|
|
424
346
|
static FORCE_INLINE napi_value NewInt(Napi::Env env, unsigned char i) { napi_value value; napi_create_uint32(env, (uint32_t)i, &value); return value; }
|
|
@@ -436,25 +358,104 @@ static FORCE_INLINE napi_value NewInt(Napi::Env env, T i)
|
|
|
436
358
|
{
|
|
437
359
|
static_assert(sizeof(T) == 8);
|
|
438
360
|
|
|
361
|
+
napi_value value;
|
|
362
|
+
|
|
439
363
|
if constexpr (std::is_signed_v<T>) {
|
|
440
364
|
if (i <= 9007199254740992ll && i >= -9007199254740992ll) {
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
return Napi::Value(env, value);
|
|
365
|
+
NAPI_OK(napi_create_int64(env, (int64_t)i, &value));
|
|
366
|
+
return value;
|
|
444
367
|
}
|
|
445
368
|
|
|
446
|
-
|
|
369
|
+
NAPI_OK(napi_create_bigint_int64(env, (int64_t)i, &value));
|
|
370
|
+
return value;
|
|
447
371
|
} else {
|
|
448
372
|
if (i <= 9007199254740992ull) {
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
return Napi::Value(env, value);
|
|
373
|
+
NAPI_OK(napi_create_int64(env, (int64_t)i, &value));
|
|
374
|
+
return value;
|
|
452
375
|
}
|
|
453
376
|
|
|
454
|
-
|
|
377
|
+
NAPI_OK(napi_create_bigint_uint64(env, (uint64_t)i, &value));
|
|
378
|
+
return value;
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
static FORCE_INLINE napi_value NewFloat(Napi::Env env, float f) { napi_value value; napi_create_double(env, (double)f, &value); return value; }
|
|
383
|
+
static FORCE_INLINE napi_value NewFloat(Napi::Env env, double d) { napi_value value; napi_create_double(env, d, &value); return value; }
|
|
384
|
+
|
|
385
|
+
template <typename T>
|
|
386
|
+
static FORCE_INLINE Size NullTerminatedLength(const T *ptr)
|
|
387
|
+
{
|
|
388
|
+
Size len = 0;
|
|
389
|
+
while (ptr[len]) {
|
|
390
|
+
len++;
|
|
391
|
+
}
|
|
392
|
+
return len;
|
|
393
|
+
}
|
|
394
|
+
template <typename T>
|
|
395
|
+
static FORCE_INLINE Size NullTerminatedLength(const T *ptr, Size max)
|
|
396
|
+
{
|
|
397
|
+
Size len = 0;
|
|
398
|
+
while (len < max && ptr[len]) {
|
|
399
|
+
len++;
|
|
400
|
+
}
|
|
401
|
+
return len;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
static FORCE_INLINE napi_value NewString(Napi::Env env, const char *ptr, Size len)
|
|
405
|
+
{
|
|
406
|
+
napi_value value;
|
|
407
|
+
if (ptr) {
|
|
408
|
+
NAPI_OK(napi_create_string_utf8(env, ptr, (size_t)len, &value));
|
|
409
|
+
} else {
|
|
410
|
+
NAPI_OK(napi_get_null(env, &value));
|
|
411
|
+
}
|
|
412
|
+
return value;
|
|
413
|
+
}
|
|
414
|
+
static FORCE_INLINE napi_value NewString(Napi::Env env, const char *ptr)
|
|
415
|
+
{
|
|
416
|
+
napi_value value;
|
|
417
|
+
if (ptr) {
|
|
418
|
+
NAPI_OK(napi_create_string_utf8(env, ptr, NAPI_AUTO_LENGTH, &value));
|
|
419
|
+
} else {
|
|
420
|
+
NAPI_OK(napi_get_null(env, &value));
|
|
421
|
+
}
|
|
422
|
+
return value;
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
static FORCE_INLINE napi_value NewString(Napi::Env env, const char16_t *ptr, Size len)
|
|
426
|
+
{
|
|
427
|
+
napi_value value;
|
|
428
|
+
if (ptr) {
|
|
429
|
+
NAPI_OK(napi_create_string_utf16(env, ptr, (size_t)len, &value));
|
|
430
|
+
} else {
|
|
431
|
+
NAPI_OK(napi_get_null(env, &value));
|
|
432
|
+
}
|
|
433
|
+
return value;
|
|
434
|
+
}
|
|
435
|
+
static FORCE_INLINE napi_value NewString(Napi::Env env, const char16_t *ptr)
|
|
436
|
+
{
|
|
437
|
+
napi_value value;
|
|
438
|
+
if (ptr) {
|
|
439
|
+
NAPI_OK(napi_create_string_utf16(env, ptr, NAPI_AUTO_LENGTH, &value));
|
|
440
|
+
} else {
|
|
441
|
+
NAPI_OK(napi_get_null(env, &value));
|
|
455
442
|
}
|
|
443
|
+
return value;
|
|
456
444
|
}
|
|
457
445
|
|
|
446
|
+
napi_value NewString(Napi::Env env, const char32_t *ptr, Size len);
|
|
447
|
+
napi_value NewString(Napi::Env env, const char32_t *ptr);
|
|
448
|
+
|
|
449
|
+
napi_value DecodeObject(InstanceData *instance, const uint8_t *origin, const TypeInfo *type);
|
|
450
|
+
void DecodeObject(InstanceData *instance, napi_value obj, const uint8_t *origin, const TypeInfo *type);
|
|
451
|
+
|
|
452
|
+
napi_value DecodeArray(InstanceData *instance, const uint8_t *origin, const TypeInfo *type);
|
|
453
|
+
napi_value DecodeArray(InstanceData *instance, const uint8_t *origin, const TypeInfo *type, uint32_t len);
|
|
454
|
+
void DecodeElements(InstanceData *instance, napi_value array, const uint8_t *origin, const TypeInfo *type, uint32_t len);
|
|
455
|
+
INLINE_UNITY void DecodeBuffer(Span<uint8_t> buffer, const uint8_t *origin, const TypeInfo *type);
|
|
456
|
+
|
|
457
|
+
napi_value Decode(InstanceData *instance, const uint8_t *ptr, const TypeInfo *type);
|
|
458
|
+
|
|
458
459
|
static FORCE_INLINE Napi::Array GetOwnPropertyNames(napi_env env, napi_value obj)
|
|
459
460
|
{
|
|
460
461
|
K_ASSERT(IsObject(env, obj));
|
|
@@ -468,21 +469,22 @@ static FORCE_INLINE Napi::Array GetOwnPropertyNames(napi_env env, napi_value obj
|
|
|
468
469
|
return Napi::Array(env, result);
|
|
469
470
|
}
|
|
470
471
|
|
|
471
|
-
|
|
472
|
-
Napi::Function WrapFunction(Napi::Env env, const FunctionInfo *func);
|
|
473
|
-
|
|
474
|
-
static FORCE_INLINE Napi::Value WrapPointer(Napi::Env env, const TypeInfo *ref, void *ptr)
|
|
472
|
+
static FORCE_INLINE napi_value WrapPointer(Napi::Env env, const TypeInfo *, void *ptr)
|
|
475
473
|
{
|
|
474
|
+
napi_value value;
|
|
475
|
+
|
|
476
|
+
if (ptr) {
|
|
476
477
|
#if defined(EXTERNAL_POINTERS)
|
|
477
|
-
|
|
478
|
-
return external;
|
|
478
|
+
NAPI_OK(napi_create_external(env, ptr, nullptr, nullptr, &value));
|
|
479
479
|
#else
|
|
480
|
-
|
|
481
|
-
return big;
|
|
480
|
+
NAPI_OK(napi_create_bigint_uint64(env, (uint64_t)(uintptr_t)ptr, &value));
|
|
482
481
|
#endif
|
|
483
|
-
}
|
|
482
|
+
} else {
|
|
483
|
+
NAPI_OK(napi_get_null(env, &value));
|
|
484
|
+
}
|
|
484
485
|
|
|
485
|
-
|
|
486
|
+
return value;
|
|
487
|
+
}
|
|
486
488
|
|
|
487
489
|
int AnalyseFlat(const TypeInfo *type, FunctionRef<void(const TypeInfo *type, int offset, int count)> func);
|
|
488
490
|
|
package/src/koffi/src/uv.cc
CHANGED
|
@@ -1,19 +1,25 @@
|
|
|
1
1
|
// SPDX-License-Identifier: MIT
|
|
2
2
|
|
|
3
|
-
#include "
|
|
3
|
+
#include "lib/native/base/base.hh"
|
|
4
|
+
#include "type.hh"
|
|
4
5
|
#include "util.hh"
|
|
6
|
+
#include "uv.hh"
|
|
7
|
+
|
|
8
|
+
#include <napi.h>
|
|
5
9
|
|
|
6
10
|
namespace K {
|
|
7
11
|
|
|
8
|
-
Napi::Function PollHandle::InitClass(
|
|
12
|
+
Napi::Function PollHandle::InitClass(InstanceData *instance)
|
|
9
13
|
{
|
|
14
|
+
Napi::Env env = instance->env;
|
|
15
|
+
|
|
10
16
|
// node-addon-api wants std::vector
|
|
11
17
|
std::vector<Napi::ClassPropertyDescriptor<PollHandle>> properties = {
|
|
12
|
-
InstanceMethod("start", &PollHandle::Start),
|
|
13
|
-
InstanceMethod("stop", &PollHandle::Stop),
|
|
14
|
-
InstanceMethod("close", &PollHandle::Close),
|
|
15
|
-
InstanceMethod("unref", &PollHandle::Unref),
|
|
16
|
-
InstanceMethod("ref", &PollHandle::Ref)
|
|
18
|
+
InstanceMethod("start", &PollHandle::Start, napi_default, instance),
|
|
19
|
+
InstanceMethod("stop", &PollHandle::Stop, napi_default, instance),
|
|
20
|
+
InstanceMethod("close", &PollHandle::Close, napi_default, instance),
|
|
21
|
+
InstanceMethod("unref", &PollHandle::Unref, napi_default, instance),
|
|
22
|
+
InstanceMethod("ref", &PollHandle::Ref, napi_default, instance)
|
|
17
23
|
};
|
|
18
24
|
|
|
19
25
|
if (Napi::Value dispose = env.RunScript("Symbol.dispose"); !IsNullOrUndefined(env, dispose)) {
|
|
@@ -21,7 +27,7 @@ Napi::Function PollHandle::InitClass(Napi::Env env)
|
|
|
21
27
|
properties.push_back(prop);
|
|
22
28
|
}
|
|
23
29
|
|
|
24
|
-
Napi::Function constructor = DefineClass(env, "PollHandle", properties);
|
|
30
|
+
Napi::Function constructor = DefineClass(env, "PollHandle", properties, instance);
|
|
25
31
|
return constructor;
|
|
26
32
|
}
|
|
27
33
|
|
|
@@ -62,7 +68,7 @@ PollHandle::PollHandle(const Napi::CallbackInfo &info)
|
|
|
62
68
|
|
|
63
69
|
void PollHandle::Start(const Napi::CallbackInfo &info)
|
|
64
70
|
{
|
|
65
|
-
InstanceData *instance =
|
|
71
|
+
InstanceData *instance = (InstanceData *)info.Data();
|
|
66
72
|
|
|
67
73
|
bool has_opts = (info.Length() >= 2 && info[0].IsObject());
|
|
68
74
|
|
|
@@ -98,7 +104,7 @@ void PollHandle::Start(const Napi::CallbackInfo &info)
|
|
|
98
104
|
|
|
99
105
|
void PollHandle::Finalize(Napi::BasicEnv env)
|
|
100
106
|
{
|
|
101
|
-
|
|
107
|
+
node_api_delete_reference(env, *this);
|
|
102
108
|
SuppressDestruct();
|
|
103
109
|
|
|
104
110
|
Close();
|
|
@@ -165,7 +171,7 @@ void PollHandle::OnPoll(uv_poll_t *h, int status, int events)
|
|
|
165
171
|
Napi::Value Poll(const Napi::CallbackInfo &info)
|
|
166
172
|
{
|
|
167
173
|
Napi::Env env = info.Env();
|
|
168
|
-
InstanceData *instance =
|
|
174
|
+
InstanceData *instance = (InstanceData *)info.Data();
|
|
169
175
|
|
|
170
176
|
bool has_opts = (info.Length() >= 3 && info[1].IsObject());
|
|
171
177
|
|
package/src/koffi/src/uv.hh
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
#pragma once
|
|
4
4
|
|
|
5
5
|
#include "lib/native/base/base.hh"
|
|
6
|
+
#include "ffi.hh"
|
|
6
7
|
|
|
7
8
|
#include <napi.h>
|
|
8
9
|
|
|
@@ -88,7 +89,7 @@ class PollHandle: public Napi::ObjectWrap<PollHandle> {
|
|
|
88
89
|
Napi::FunctionReference callback;
|
|
89
90
|
|
|
90
91
|
public:
|
|
91
|
-
static Napi::Function InitClass(
|
|
92
|
+
static Napi::Function InitClass(InstanceData *instance);
|
|
92
93
|
|
|
93
94
|
PollHandle(const Napi::CallbackInfo &info);
|
|
94
95
|
|
|
@@ -19,7 +19,7 @@ and exception handling semantics with low overhead.
|
|
|
19
19
|
API references are available in the [doc](doc/README.md) directory.
|
|
20
20
|
|
|
21
21
|
<!-- x-release-please-start-version -->
|
|
22
|
-
## Current version: 8.
|
|
22
|
+
## Current version: 8.9.0
|
|
23
23
|
<!-- x-release-please-end -->
|
|
24
24
|
|
|
25
25
|
(See [CHANGELOG.md](CHANGELOG.md) for complete Changelog)
|