koffi 2.4.2 → 2.5.0-beta.1

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.
Files changed (48) hide show
  1. package/build/2.5.0-beta.1/koffi_darwin_arm64/koffi.node +0 -0
  2. package/build/2.5.0-beta.1/koffi_darwin_x64/koffi.node +0 -0
  3. package/build/2.5.0-beta.1/koffi_freebsd_arm64/koffi.node +0 -0
  4. package/build/2.5.0-beta.1/koffi_freebsd_ia32/koffi.node +0 -0
  5. package/build/2.5.0-beta.1/koffi_freebsd_x64/koffi.node +0 -0
  6. package/build/2.5.0-beta.1/koffi_linux_arm32hf/koffi.node +0 -0
  7. package/build/2.5.0-beta.1/koffi_linux_arm64/koffi.node +0 -0
  8. package/build/2.5.0-beta.1/koffi_linux_ia32/koffi.node +0 -0
  9. package/build/2.5.0-beta.1/koffi_linux_riscv64hf64/koffi.node +0 -0
  10. package/build/2.5.0-beta.1/koffi_linux_x64/koffi.node +0 -0
  11. package/build/2.5.0-beta.1/koffi_openbsd_ia32/koffi.node +0 -0
  12. package/build/{2.4.2 → 2.5.0-beta.1}/koffi_openbsd_x64/koffi.node +0 -0
  13. package/build/2.5.0-beta.1/koffi_win32_arm64/koffi.node +0 -0
  14. package/build/{2.4.2 → 2.5.0-beta.1}/koffi_win32_ia32/koffi.node +0 -0
  15. package/build/{2.4.2 → 2.5.0-beta.1}/koffi_win32_x64/koffi.node +0 -0
  16. package/build/2.5.0-beta.1/koffi_win32_x64/koffi.pdb +0 -0
  17. package/doc/callbacks.md +1 -1
  18. package/doc/conf.py +1 -1
  19. package/doc/functions.md +1 -1
  20. package/doc/parameters.md +0 -1
  21. package/doc/pointers.md +1 -1
  22. package/package.json +1 -1
  23. package/src/core/libcc/libcc.cc +58 -54
  24. package/src/core/libcc/libcc.hh +33 -19
  25. package/src/koffi/src/abi_x86.cc +31 -4
  26. package/src/koffi/src/call.cc +37 -22
  27. package/src/koffi/src/ffi.cc +251 -303
  28. package/src/koffi/src/ffi.hh +3 -1
  29. package/src/koffi/src/util.cc +20 -13
  30. package/src/koffi/src/util.hh +4 -2
  31. package/build/2.4.2/koffi_darwin_arm64/koffi.node +0 -0
  32. package/build/2.4.2/koffi_darwin_x64/koffi.node +0 -0
  33. package/build/2.4.2/koffi_freebsd_arm64/koffi.node +0 -0
  34. package/build/2.4.2/koffi_freebsd_ia32/koffi.node +0 -0
  35. package/build/2.4.2/koffi_freebsd_x64/koffi.node +0 -0
  36. package/build/2.4.2/koffi_linux_arm32hf/koffi.node +0 -0
  37. package/build/2.4.2/koffi_linux_arm64/koffi.node +0 -0
  38. package/build/2.4.2/koffi_linux_ia32/koffi.node +0 -0
  39. package/build/2.4.2/koffi_linux_riscv64hf64/koffi.node +0 -0
  40. package/build/2.4.2/koffi_linux_x64/koffi.node +0 -0
  41. package/build/2.4.2/koffi_openbsd_ia32/koffi.node +0 -0
  42. package/build/2.4.2/koffi_win32_arm64/koffi.node +0 -0
  43. /package/build/{2.4.2 → 2.5.0-beta.1}/koffi_win32_arm64/koffi.exp +0 -0
  44. /package/build/{2.4.2 → 2.5.0-beta.1}/koffi_win32_arm64/koffi.lib +0 -0
  45. /package/build/{2.4.2 → 2.5.0-beta.1}/koffi_win32_ia32/koffi.exp +0 -0
  46. /package/build/{2.4.2 → 2.5.0-beta.1}/koffi_win32_ia32/koffi.lib +0 -0
  47. /package/build/{2.4.2 → 2.5.0-beta.1}/koffi_win32_x64/koffi.exp +0 -0
  48. /package/build/{2.4.2 → 2.5.0-beta.1}/koffi_win32_x64/koffi.lib +0 -0
@@ -58,14 +58,19 @@ Napi::Function MagicUnion::InitClass(Napi::Env env, const TypeInfo *type)
58
58
  MagicUnion::MagicUnion(const Napi::CallbackInfo &info)
59
59
  : Napi::ObjectWrap<MagicUnion>(info), type((const TypeInfo *)info.Data())
60
60
  {
61
+ Napi::Env env = info.Env();
62
+ InstanceData *instance = env.GetInstanceData<InstanceData>();
63
+
64
+ active_symbol = instance->active_symbol;
61
65
  }
62
66
 
63
67
  void MagicUnion::SetRaw(const uint8_t *ptr)
64
68
  {
65
- raw = ptr;
69
+ raw.RemoveFrom(0);
70
+ raw.Append(MakeSpan(ptr, type->size));
66
71
 
72
+ Value().Set(active_symbol, Env().Undefined());
67
73
  active_idx = -1;
68
- Value().Set("__active", Env().Undefined());
69
74
  }
70
75
 
71
76
  Napi::Value MagicUnion::Getter(const Napi::CallbackInfo &info)
@@ -76,18 +81,18 @@ Napi::Value MagicUnion::Getter(const Napi::CallbackInfo &info)
76
81
  Napi::Value value;
77
82
 
78
83
  if (idx == active_idx) {
79
- value = Value().Get("__active");
84
+ value = Value().Get(active_symbol);
80
85
  } else {
81
86
  Napi::Env env = info.Env();
82
87
 
83
- if (RG_UNLIKELY(!raw)) {
88
+ if (RG_UNLIKELY(!raw.len)) {
84
89
  ThrowError<Napi::Error>(env, "Cannont convert %1 union value", active_idx < 0 ? "empty" : "assigned");
85
90
  return env.Null();
86
91
  }
87
92
 
88
- value = Decode(env, raw, member.type);
93
+ value = Decode(env, raw.ptr, member.type);
89
94
 
90
- Value().Set("__active", value);
95
+ Value().Set(active_symbol, value);
91
96
  active_idx = idx;
92
97
  }
93
98
 
@@ -99,10 +104,10 @@ void MagicUnion::Setter(const Napi::CallbackInfo &info, const Napi::Value &value
99
104
  {
100
105
  Size idx = (Size)info.Data();
101
106
 
102
- Value().Set("__active", value);
107
+ Value().Set(active_symbol, value);
103
108
  active_idx = idx;
104
109
 
105
- raw = nullptr;
110
+ raw.Clear();
106
111
  }
107
112
 
108
113
  const TypeInfo *ResolveType(Napi::Value value, int *out_directions)
@@ -272,10 +277,11 @@ const TypeInfo *MakePointerType(InstanceData *instance, const TypeInfo *ref, int
272
277
  char name_buf[256];
273
278
  Fmt(name_buf, "%1%2*", ref->name, EndsWith(ref->name, "*") ? "" : " ");
274
279
 
275
- TypeInfo *type = (TypeInfo *)instance->types_map.FindValue(name_buf, nullptr);
280
+ bool inserted;
281
+ auto bucket = instance->types_map.TrySetDefault(name_buf, &inserted);
276
282
 
277
- if (!type) {
278
- type = instance->types.AppendDefault();
283
+ if (inserted) {
284
+ TypeInfo *type = instance->types.AppendDefault();
279
285
 
280
286
  type->name = DuplicateString(name_buf, &instance->str_alloc).ptr;
281
287
 
@@ -291,10 +297,11 @@ const TypeInfo *MakePointerType(InstanceData *instance, const TypeInfo *ref, int
291
297
  type->ref.proto = ref->ref.proto;
292
298
  }
293
299
 
294
- instance->types_map.Set(type->name, type);
300
+ bucket->key = type->name;
301
+ bucket->value = type;
295
302
  }
296
303
 
297
- ref = type;
304
+ ref = bucket->value;
298
305
  }
299
306
 
300
307
  return ref;
@@ -38,8 +38,10 @@ extern const int MagicUnionMarker;
38
38
  class MagicUnion: public Napi::ObjectWrap<MagicUnion> {
39
39
  const TypeInfo *type;
40
40
 
41
+ napi_value active_symbol;
41
42
  Size active_idx = -1;
42
- const uint8_t *raw = nullptr;
43
+
44
+ HeapArray<uint8_t> raw;
43
45
 
44
46
  public:
45
47
  static Napi::Function InitClass(Napi::Env env, const TypeInfo *type);
@@ -49,7 +51,7 @@ public:
49
51
  const RecordMember *GetMember() const { return (active_idx >= 0) ? &type->members[active_idx] : nullptr; }
50
52
 
51
53
  void SetRaw(const uint8_t *ptr);
52
- const uint8_t *GetRaw() const { return raw; }
54
+ const uint8_t *GetRaw() const { return raw.ptr; }
53
55
 
54
56
  private:
55
57
  Napi::Value Getter(const Napi::CallbackInfo &info);