koffi 3.0.2 → 3.1.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/CHANGELOG.md +32 -7
  2. package/cnoke.cjs +2 -2
  3. package/doc/benchmarks.md +2 -2
  4. package/doc/callbacks.md +8 -27
  5. package/doc/{input.md → composites.md} +161 -147
  6. package/doc/contribute.md +2 -1
  7. package/doc/index.md +0 -14
  8. package/doc/{functions.md → load.md} +54 -113
  9. package/doc/migration.md +4 -7
  10. package/doc/misc.md +0 -103
  11. package/doc/output.md +5 -11
  12. package/doc/pointers.md +76 -17
  13. package/doc/primitives.md +151 -0
  14. package/doc/start.md +3 -13
  15. package/doc/types.md +88 -0
  16. package/doc/unions.md +0 -186
  17. package/doc/values.md +134 -0
  18. package/index.d.ts +23 -4
  19. package/lib/native/base/base.cc +142 -90
  20. package/lib/native/base/base.hh +69 -165
  21. package/package.json +16 -15
  22. package/src/koffi/CMakeLists.txt +19 -17
  23. package/src/koffi/index.cjs +8 -3
  24. package/src/koffi/index.js +1 -1
  25. package/src/koffi/indirect.cjs +8 -3
  26. package/src/koffi/indirect.js +1 -1
  27. package/src/koffi/src/abi/arm64.cc +47 -62
  28. package/src/koffi/src/abi/riscv64.cc +38 -57
  29. package/src/koffi/src/abi/x64sysv.cc +38 -57
  30. package/src/koffi/src/abi/x64win.cc +47 -65
  31. package/src/koffi/src/abi/x86.cc +46 -59
  32. package/src/koffi/src/call.cc +239 -133
  33. package/src/koffi/src/call.hh +5 -10
  34. package/src/koffi/src/ffi.cc +211 -90
  35. package/src/koffi/src/ffi.hh +36 -16
  36. package/src/koffi/src/parser.cc +3 -3
  37. package/src/koffi/src/parser.hh +2 -2
  38. package/src/koffi/src/static.cjs +8 -0
  39. package/src/koffi/src/static.js +11 -0
  40. package/src/koffi/src/type.cc +43 -33
  41. package/src/koffi/src/type.hh +1 -1
  42. package/src/koffi/src/util.cc +73 -173
  43. package/src/koffi/src/util.hh +84 -43
  44. package/src/koffi/src/uv.cc +1 -1
  45. package/vendor/node-addon-api/README.md +1 -1
  46. package/vendor/node-addon-api/napi-inl.h +213 -35
  47. package/vendor/node-addon-api/napi.h +118 -7
  48. package/doc/variables.md +0 -102
@@ -467,21 +467,30 @@ constexpr T BigEndian(T v) { return ReverseBytes(v); }
467
467
 
468
468
  static inline Size AlignLen(Size len, Size align)
469
469
  {
470
- Size aligned = (len + align - 1) / align * align;
470
+ K_ASSERT(align >= 1 && !((align - 1) & align));
471
+
472
+ // Compilers can optimize x / align * align... for unsigned types.
473
+ // It's pessimized for signed types, to handle len < 0.
474
+
475
+ Size aligned = (len + align - 1) & ~(align - 1);
471
476
  return aligned;
472
477
  }
473
478
 
474
479
  template <typename T>
475
480
  static inline T *AlignUp(T *ptr, Size align)
476
481
  {
477
- uint8_t *aligned = (uint8_t *)(((uintptr_t)ptr + align - 1) / align * align);
482
+ K_ASSERT(align >= 1 && !((align - 1) & align));
483
+
484
+ uint8_t *aligned = (uint8_t *)(((uintptr_t)ptr + align - 1) & ~(align - 1));
478
485
  return (T *)aligned;
479
486
  }
480
487
 
481
488
  template <typename T>
482
489
  static inline T *AlignDown(T *ptr, Size align)
483
490
  {
484
- uint8_t *aligned = (uint8_t *)((uintptr_t)ptr / align * align);
491
+ K_ASSERT(align >= 1 && !((align - 1) & align));
492
+
493
+ uint8_t *aligned = (uint8_t *)((uintptr_t)ptr & ~(align - 1));
485
494
  return (T *)aligned;
486
495
  }
487
496
 
@@ -1157,15 +1166,11 @@ private:
1157
1166
  };
1158
1167
 
1159
1168
  class BlockAllocator final: public Allocator {
1160
- struct Bucket {
1161
- Size used;
1162
- uint8_t data[];
1163
- };
1164
-
1165
1169
  LinkedAllocator allocator;
1166
1170
  Size block_size;
1167
1171
 
1168
- Bucket *current_bucket = nullptr;
1172
+ uint8_t *bucket_ptr = nullptr;
1173
+ uint8_t *bucket_end = nullptr;
1169
1174
  uint8_t *last_alloc = nullptr;
1170
1175
 
1171
1176
  public:
@@ -1191,9 +1196,6 @@ public:
1191
1196
 
1192
1197
  void GiveTo(LinkedAllocator *alloc);
1193
1198
  void GiveTo(BlockAllocator *alloc) { GiveTo(&alloc->allocator); }
1194
-
1195
- private:
1196
- bool AllocateSeparately(Size aligned_size) const { return aligned_size > block_size / 2; }
1197
1199
  };
1198
1200
 
1199
1201
  static inline void *AllocateRaw(Allocator *alloc, Size size)
@@ -3074,8 +3076,8 @@ private:
3074
3076
  template <typename T>
3075
3077
  class HashTraits {
3076
3078
  public:
3077
- static constexpr uint64_t Hash(const T &key) { return key.Hash(); }
3078
- static constexpr bool Test(const T &key1, const T &key2) { return key1 == key2; }
3079
+ static uint64_t Hash(const T &key) { return key.Hash(); }
3080
+ static bool Test(const T &key1, const T &key2) { return key1 == key2; }
3079
3081
  };
3080
3082
 
3081
3083
  // Stole the Hash function from Thomas Wang (see here: https://gist.github.com/badboy/6267743)
@@ -3146,44 +3148,17 @@ DEFINE_INTEGER_HASH_TRAITS_64(unsigned long long, constexpr);
3146
3148
  #undef DEFINE_INTEGER_HASH_TRAITS_64
3147
3149
 
3148
3150
  // MurmurHash2
3149
- static constexpr inline uint64_t HashStr(Span<const char> str)
3151
+ static inline uint64_t HashStr(Span<const char> str)
3150
3152
  {
3151
3153
  const uint64_t Seed = 0;
3152
3154
  const uint64_t Mult = (((uint64_t)0xc6a4a793ull) << 32ull) + (uint64_t)0x5bd1e995ull;
3153
3155
 
3154
3156
  const auto unaligned_load =
3155
- #if __cplusplus >= 202002L && (__GNUC__ >= 12 || __clang_major__ >= 16)
3156
- !std::is_constant_evaluated() ?
3157
3157
  [](const char *p) {
3158
3158
  uint64_t result;
3159
- __builtin_memcpy(&result, p, sizeof(result));
3160
- return result;
3161
- } :
3162
- #endif
3163
- [](const char *p) {
3164
- #if defined(K_BIG_ENDIAN)
3165
- uint64_t result = ((uint64_t)p[0] << 56) |
3166
- ((uint64_t)p[1] << 48) |
3167
- ((uint64_t)p[2] << 40) |
3168
- ((uint64_t)p[3] << 32) |
3169
- ((uint64_t)p[4] << 24) |
3170
- ((uint64_t)p[5] << 16) |
3171
- ((uint64_t)p[6] << 8) |
3172
- ((uint64_t)p[7] << 0);
3173
- #else
3174
- uint64_t result = ((uint64_t)p[0] << 0) |
3175
- ((uint64_t)p[1] << 8) |
3176
- ((uint64_t)p[2] << 16) |
3177
- ((uint64_t)p[3] << 24) |
3178
- ((uint64_t)p[4] << 32) |
3179
- ((uint64_t)p[5] << 40) |
3180
- ((uint64_t)p[6] << 48) |
3181
- ((uint64_t)p[7] << 56);
3182
- #endif
3183
-
3159
+ memcpy(&result, p, sizeof(result));
3184
3160
  return result;
3185
3161
  };
3186
-
3187
3162
  const auto load_bytes = [](const char *p, int n) {
3188
3163
  uint64_t result = 0;
3189
3164
 
@@ -3216,7 +3191,7 @@ static constexpr inline uint64_t HashStr(Span<const char> str)
3216
3191
  return hash;
3217
3192
  }
3218
3193
 
3219
- static constexpr inline uint64_t HashStr(const char *str)
3194
+ static inline uint64_t HashStr(const char *str)
3220
3195
  {
3221
3196
  Span<const char> span = str;
3222
3197
  return HashStr(span);
@@ -3225,35 +3200,35 @@ static constexpr inline uint64_t HashStr(const char *str)
3225
3200
  template <>
3226
3201
  class HashTraits<const char *> {
3227
3202
  public:
3228
- static constexpr uint64_t Hash(Span<const char> key) { return HashStr(key); }
3229
- static constexpr uint64_t Hash(const char *key) { return HashStr(key); }
3203
+ static uint64_t Hash(Span<const char> key) { return HashStr(key); }
3204
+ static uint64_t Hash(const char *key) { return HashStr(key); }
3230
3205
 
3231
- static constexpr bool Test(const char *key1, const char *key2) { return TestStr(key1, key2); }
3232
- static constexpr bool Test(const char *key1, Span<const char> key2) { return key2 == key1; }
3206
+ static bool Test(const char *key1, const char *key2) { return TestStr(key1, key2); }
3207
+ static bool Test(const char *key1, Span<const char> key2) { return key2 == key1; }
3233
3208
  };
3234
3209
 
3235
3210
  template <>
3236
3211
  class HashTraits<Span<const char>> {
3237
3212
  public:
3238
- static constexpr uint64_t Hash(Span<const char> key) { return HashStr(key); }
3239
- static constexpr uint64_t Hash(const char *key) { return HashStr(key); }
3213
+ static uint64_t Hash(Span<const char> key) { return HashStr(key); }
3214
+ static uint64_t Hash(const char *key) { return HashStr(key); }
3240
3215
 
3241
- static constexpr bool Test(Span<const char> key1, Span<const char> key2) { return key1 == key2; }
3242
- static constexpr bool Test(Span<const char> key1, const char * key2) { return key1 == key2; }
3216
+ static bool Test(Span<const char> key1, Span<const char> key2) { return key1 == key2; }
3217
+ static bool Test(Span<const char> key1, const char * key2) { return key1 == key2; }
3243
3218
  };
3244
3219
 
3245
3220
  #define K_HASHTABLE_HANDLER_EX_N(Name, ValueType, KeyType, KeyMember, HashFunc, TestFunc) \
3246
3221
  class Name { \
3247
3222
  public: \
3248
- static constexpr KeyType GetKey(const ValueType &value) \
3223
+ static KeyType GetKey(const ValueType &value) \
3249
3224
  { return (KeyType)(value.KeyMember); } \
3250
- static constexpr KeyType GetKey(const ValueType *value) \
3225
+ static KeyType GetKey(const ValueType *value) \
3251
3226
  { return (KeyType)(value->KeyMember); } \
3252
3227
  template <typename TestKey> \
3253
- static constexpr uint64_t HashKey(TestKey key) \
3228
+ static uint64_t HashKey(TestKey key) \
3254
3229
  { return HashFunc(key); } \
3255
3230
  template <typename TestKey> \
3256
- static constexpr bool TestKeys(KeyType key1, TestKey key2) \
3231
+ static bool TestKeys(KeyType key1, TestKey key2) \
3257
3232
  { return TestFunc((key1), (key2)); } \
3258
3233
  }
3259
3234
  #define K_HASHTABLE_HANDLER_EX(ValueType, KeyType, KeyMember, HashFunc, TestFunc) \
@@ -3355,11 +3330,11 @@ template <typename ValueType>
3355
3330
  class HashSet {
3356
3331
  class Handler {
3357
3332
  public:
3358
- static constexpr ValueType GetKey(const ValueType &value) { return value; }
3359
- static constexpr ValueType GetKey(const ValueType *value) { return *value; }
3360
- static constexpr uint64_t HashKey(const ValueType &value)
3333
+ static ValueType GetKey(const ValueType &value) { return value; }
3334
+ static ValueType GetKey(const ValueType *value) { return *value; }
3335
+ static uint64_t HashKey(const ValueType &value)
3361
3336
  { return HashTraits<ValueType>::Hash(value); }
3362
- static constexpr bool TestKeys(const ValueType &value1, const ValueType &value2)
3337
+ static bool TestKeys(const ValueType &value1, const ValueType &value2)
3363
3338
  { return HashTraits<ValueType>::Test(value1, value2); }
3364
3339
  };
3365
3340
 
@@ -3403,101 +3378,6 @@ public:
3403
3378
  private:
3404
3379
  };
3405
3380
 
3406
- // XXX: Switch to perfect hashing later on
3407
- template <Size N, typename KeyType, typename ValueType>
3408
- class ConstMap {
3409
- public:
3410
- struct Bucket {
3411
- KeyType key;
3412
- ValueType value;
3413
- };
3414
-
3415
- size_t used[(N + (K_SIZE(size_t) * 8) - 1) / K_SIZE(size_t)] = {};
3416
- Bucket data[N] = {};
3417
- Size count = 0;
3418
-
3419
- constexpr ConstMap(std::initializer_list<Bucket> l)
3420
- {
3421
- K_CRITICAL(l.size() <= N, "ConstMap<%1> cannot store %2 values", N, l.size());
3422
-
3423
- for (const Bucket &it: l) {
3424
- Bucket *bucket = Insert(it.key);
3425
-
3426
- bucket->key = it.key;
3427
- bucket->value = it.value;
3428
- }
3429
- }
3430
-
3431
- template <typename T = KeyType>
3432
- ValueType *Find(const T &key)
3433
- { return (ValueType *)((const ConstMap *)this)->Find(key); }
3434
- template <typename T = KeyType>
3435
- const ValueType *Find(const T &key) const
3436
- {
3437
- uint64_t hash = HashTraits<KeyType>::Hash(key);
3438
- Size idx = HashToIndex(hash);
3439
-
3440
- const Bucket *bucket = Find(&idx, key);
3441
- return bucket ? &bucket->value : nullptr;
3442
- }
3443
-
3444
- template <typename T = KeyType>
3445
- ValueType FindValue(const T &key, const ValueType &default_value)
3446
- { return (ValueType)((const ConstMap *)this)->FindValue(key, default_value); }
3447
- template <typename T = KeyType>
3448
- const ValueType FindValue(const T &key, const ValueType &default_value) const
3449
- {
3450
- const ValueType *it = Find(key);
3451
- return it ? *it : default_value;
3452
- }
3453
-
3454
- private:
3455
- template <typename T = KeyType>
3456
- constexpr Bucket *Find(Size *idx, const T &key)
3457
- { return (Bucket *)((const ConstMap *)this)->Find(idx, key); }
3458
- template <typename T = KeyType>
3459
- constexpr const Bucket *Find(Size *idx, const T &key) const
3460
- {
3461
- while (!IsEmpty(*idx)) {
3462
- if (HashTraits<KeyType>::Test(data[*idx].key, key))
3463
- return &data[*idx];
3464
- *idx = (*idx + 1) & (N - 1);
3465
- }
3466
- return nullptr;
3467
- }
3468
-
3469
- constexpr Bucket *Insert(const KeyType &key)
3470
- {
3471
- uint64_t hash = HashTraits<KeyType>::Hash(key);
3472
- Size idx = HashToIndex(hash);
3473
- Bucket *it = Find(&idx, key);
3474
-
3475
- if (!it) {
3476
- count++;
3477
- MarkUsed(idx);
3478
-
3479
- return &data[idx];
3480
- } else {
3481
- return it;
3482
- }
3483
- }
3484
-
3485
- constexpr void MarkUsed(Size idx)
3486
- {
3487
- used[idx / (K_SIZE(size_t) * 8)] |= (1ull << (idx % (K_SIZE(size_t) * 8)));
3488
- }
3489
- constexpr bool IsEmpty(Size idx) const
3490
- {
3491
- bool empty = !(used[idx / (K_SIZE(size_t) * 8)] & (1ull << (idx % (K_SIZE(size_t) * 8))));
3492
- return empty;
3493
- }
3494
-
3495
- constexpr Size HashToIndex(uint64_t hash) const
3496
- {
3497
- return (Size)(hash & (uint64_t)(N - 1));
3498
- }
3499
- };
3500
-
3501
3381
  // ------------------------------------------------------------------------
3502
3382
  // Date
3503
3383
  // ------------------------------------------------------------------------
@@ -3683,7 +3563,8 @@ enum class FmtType {
3683
3563
  MemorySize,
3684
3564
  DiskSize,
3685
3565
  Date,
3686
- TimeISO,
3566
+ TimeBasic,
3567
+ TimeIso,
3687
3568
  TimeNice,
3688
3569
  List,
3689
3570
  FlagNames,
@@ -3938,10 +3819,19 @@ static inline FmtArg FmtDiskSize(int64_t size)
3938
3819
  return arg;
3939
3820
  }
3940
3821
 
3941
- static inline FmtArg FmtTimeISO(TimeSpec spec, bool ms = false)
3822
+ static inline FmtArg FmtTimeBasic(TimeSpec spec, bool ms = false)
3942
3823
  {
3943
3824
  FmtArg arg;
3944
- arg.type = FmtType::TimeISO;
3825
+ arg.type = FmtType::TimeBasic;
3826
+ arg.u.time.spec = spec;
3827
+ arg.u.time.ms = ms;
3828
+ return arg;
3829
+ }
3830
+
3831
+ static inline FmtArg FmtTimeIso(TimeSpec spec, bool ms = false)
3832
+ {
3833
+ FmtArg arg;
3834
+ arg.type = FmtType::TimeIso;
3945
3835
  arg.u.time.spec = spec;
3946
3836
  arg.u.time.ms = ms;
3947
3837
  return arg;
@@ -4060,11 +3950,11 @@ public:
4060
3950
  operator FmtArg() const { return FmtCustom(*this); }
4061
3951
  };
4062
3952
 
4063
- class FmtHtmlSafe {
3953
+ class FmtXmlSafe {
4064
3954
  Span<const char> str;
4065
3955
 
4066
3956
  public:
4067
- FmtHtmlSafe(Span<const char> str) : str(str) {}
3957
+ FmtXmlSafe(Span<const char> str) : str(str) {}
4068
3958
 
4069
3959
  void Format(FunctionRef<void(Span<const char>)> append) const;
4070
3960
  operator FmtArg() const { return FmtCustom(*this); }
@@ -4675,8 +4565,17 @@ static inline bool ExecuteCommandLine(const char *cmd_line, const ExecuteInfo &i
4675
4565
  (HeapArray<uint8_t> *)out_buf, out_code);
4676
4566
  }
4677
4567
 
4678
- Size ReadCommandOutput(const char *cmd_line, Span<char> out_output);
4679
- bool ReadCommandOutput(const char *cmd_line, HeapArray<char> *out_output);
4568
+ Size ReadCommandOutput(const char *cmd_line, Span<uint8_t> out_output);
4569
+ bool ReadCommandOutput(const char *cmd_line, HeapArray<uint8_t> *out_output);
4570
+
4571
+ // Char variants
4572
+ static inline Size ReadCommandOutput(const char *cmd_line, Span<char> out_output)
4573
+ { return ReadCommandOutput(cmd_line, out_output.As<uint8_t>()); }
4574
+ static inline bool ReadCommandOutput(const char *cmd_line, HeapArray<char> *out_output)
4575
+ {
4576
+ HeapArray<uint8_t> *out = (HeapArray<uint8_t> *)out_output;
4577
+ return ReadCommandOutput(cmd_line, out);
4578
+ }
4680
4579
 
4681
4580
  #endif
4682
4581
 
@@ -5034,6 +4933,10 @@ void CloseSocket(int fd);
5034
4933
  // Tasks
5035
4934
  // ------------------------------------------------------------------------
5036
4935
 
4936
+ enum class AsyncFlag {
4937
+ Selfish = 1 << 0
4938
+ };
4939
+
5037
4940
  class Async {
5038
4941
  K_DELETE_COPY(Async)
5039
4942
 
@@ -5042,20 +4945,21 @@ class Async {
5042
4945
  std::atomic_int remaining_tasks { 0 };
5043
4946
 
5044
4947
  class AsyncPool *pool;
4948
+
4949
+ Async *only = nullptr;
5045
4950
  #else
5046
4951
  bool success = true;
5047
4952
  #endif
5048
4953
 
5049
4954
  public:
5050
- Async(int threads = -1);
5051
- Async(Async *parent);
4955
+ Async(int threads = -1, unsigned int flags = 0);
4956
+ Async(Async *parent, unsigned int flags = 0);
5052
4957
  ~Async();
5053
4958
 
5054
4959
  void Run(const std::function<bool()> &f);
5055
4960
  void Run(int worker, const std::function<bool()> &f);
5056
4961
 
5057
4962
  bool Sync();
5058
- bool SyncSoon();
5059
4963
  bool Wait(int timeout);
5060
4964
  bool IsSuccess() const { return success; }
5061
4965
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "koffi",
3
- "version": "3.0.2",
3
+ "version": "3.1.1",
4
4
  "description": "Fast and easy-to-use dynamic C FFI (foreign function interface) for Node.js",
5
5
  "keywords": [
6
6
  "foreign",
@@ -33,20 +33,21 @@
33
33
  },
34
34
  "funding": "https://liberapay.com/Koromix",
35
35
  "optionalDependencies": {
36
- "@koromix/koffi-linux-arm64": "3.0.2",
37
- "@koromix/koffi-linux-ia32": "3.0.2",
38
- "@koromix/koffi-linux-x64": "3.0.2",
39
- "@koromix/koffi-linux-riscv64": "3.0.2",
40
- "@koromix/koffi-freebsd-ia32": "3.0.2",
41
- "@koromix/koffi-freebsd-x64": "3.0.2",
42
- "@koromix/koffi-freebsd-arm64": "3.0.2",
43
- "@koromix/koffi-openbsd-ia32": "3.0.2",
44
- "@koromix/koffi-openbsd-x64": "3.0.2",
45
- "@koromix/koffi-win32-ia32": "3.0.2",
46
- "@koromix/koffi-win32-x64": "3.0.2",
47
- "@koromix/koffi-darwin-x64": "3.0.2",
48
- "@koromix/koffi-darwin-arm64": "3.0.2",
49
- "@koromix/koffi-linux-loong64": "3.0.2"
36
+ "@koromix/koffi-linux-arm64": "3.1.1",
37
+ "@koromix/koffi-linux-ia32": "3.1.1",
38
+ "@koromix/koffi-linux-x64": "3.1.1",
39
+ "@koromix/koffi-linux-riscv64": "3.1.1",
40
+ "@koromix/koffi-freebsd-ia32": "3.1.1",
41
+ "@koromix/koffi-freebsd-x64": "3.1.1",
42
+ "@koromix/koffi-freebsd-arm64": "3.1.1",
43
+ "@koromix/koffi-openbsd-ia32": "3.1.1",
44
+ "@koromix/koffi-openbsd-x64": "3.1.1",
45
+ "@koromix/koffi-win32-ia32": "3.1.1",
46
+ "@koromix/koffi-win32-x64": "3.1.1",
47
+ "@koromix/koffi-win32-arm64": "3.1.1",
48
+ "@koromix/koffi-darwin-x64": "3.1.1",
49
+ "@koromix/koffi-darwin-arm64": "3.1.1",
50
+ "@koromix/koffi-linux-loong64": "3.1.1"
50
51
  },
51
52
  "type": "module",
52
53
  "main": "./index.cjs",
@@ -137,7 +137,8 @@ if(WIN32)
137
137
  target_link_libraries(koffi PRIVATE ${UV_LINK_LIB})
138
138
  endif()
139
139
 
140
- target_compile_definitions(koffi PRIVATE FELIX_TARGET=koffi NAPI_DISABLE_CPP_EXCEPTIONS NAPI_VERSION=NAPI_VERSION_EXPERIMENTAL)
140
+ target_compile_definitions(koffi PRIVATE FELIX_TARGET=koffi NAPI_VERSION=NAPI_VERSION_EXPERIMENTAL
141
+ NODE_ADDON_API_DISABLE_CPP_EXCEPTIONS NODE_ADDON_API_REQUIRE_BASIC_FINALIZERS)
141
142
 
142
143
  if(WIN32)
143
144
  target_compile_definitions(koffi PRIVATE _CRT_SECURE_NO_WARNINGS _CRT_NONSTDC_NO_DEPRECATE)
@@ -175,12 +176,11 @@ endif()
175
176
  if(NOT MSVC OR CMAKE_C_COMPILER_ID MATCHES "[Cc]lang")
176
177
  # Restore C/C++ compiler sanity
177
178
 
178
- target_compile_options(koffi PRIVATE $<$<COMPILE_LANGUAGE:CXX>:-fno-exceptions -fno-rtti -fno-strict-aliasing
179
- -fno-delete-null-pointer-checks>)
179
+ target_compile_options(koffi PRIVATE $<$<COMPILE_LANGUAGE:CXX>:-fno-strict-aliasing -fno-delete-null-pointer-checks>)
180
180
  if(MSVC)
181
- target_compile_options(koffi PRIVATE $<$<COMPILE_LANGUAGE:CXX>:/clang:-fwrapv>)
181
+ target_compile_options(koffi PRIVATE $<$<COMPILE_LANGUAGE:CXX>:/clang:-fwrapv /clang:-fno-exceptions /clang:-fno-rtti>)
182
182
  else()
183
- target_compile_options(koffi PRIVATE $<$<COMPILE_LANGUAGE:CXX>:-fwrapv>)
183
+ target_compile_options(koffi PRIVATE $<$<COMPILE_LANGUAGE:CXX>:-fwrapv -fno-exceptions -fno-rtti>)
184
184
  endif()
185
185
 
186
186
  check_cxx_compiler_flag(-fno-finite-loops use_no_finite_loops)
@@ -217,18 +217,20 @@ else()
217
217
  enable_unity_build(koffi)
218
218
  endif()
219
219
 
220
- if(APPLE)
221
- add_custom_command(
222
- TARGET koffi POST_BUILD
223
- COMMAND $<$<CONFIG:release>:${CMAKE_STRIP}>
224
- ARGS -x $<TARGET_FILE:koffi>
225
- )
226
- elseif(UNIX)
227
- add_custom_command(
228
- TARGET koffi POST_BUILD
229
- COMMAND $<$<CONFIG:release>:${CMAKE_STRIP}>
230
- ARGS $<TARGET_FILE:koffi>
231
- )
220
+ if(CMAKE_BUILD_TYPE STREQUAL "Release")
221
+ if(APPLE)
222
+ add_custom_command(
223
+ TARGET koffi POST_BUILD
224
+ COMMAND ${CMAKE_STRIP}
225
+ ARGS -x $<TARGET_FILE:koffi>
226
+ )
227
+ elseif(UNIX)
228
+ add_custom_command(
229
+ TARGET koffi POST_BUILD
230
+ COMMAND ${CMAKE_STRIP}
231
+ ARGS $<TARGET_FILE:koffi>
232
+ )
233
+ endif()
232
234
  endif()
233
235
 
234
236
  # ---- Debug ----
@@ -4,8 +4,13 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __getProtoOf = Object.getPrototypeOf;
6
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __esm = (fn, res) => function __init() {
8
- return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
7
+ var __esm = (fn, res, err) => function __init() {
8
+ if (err) throw err[0];
9
+ try {
10
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
11
+ } catch (e) {
12
+ throw err = [e], e;
13
+ }
9
14
  };
10
15
  var __export = (target, all) => {
11
16
  for (var name in all)
@@ -128,7 +133,7 @@ var init_abi = __esm({
128
133
  var package_default;
129
134
  var init_package = __esm({
130
135
  "src/koffi/package.json"() {
131
- package_default = { name: "koffi", version: "3.0.2", cnoke: { api: "../../vendor/node-api-headers", output: "../../bin/Koffi/{{ toolchain }}", node: 16, napi: 8 } };
136
+ package_default = { name: "koffi", version: "3.1.1", cnoke: { api: "../../vendor/node-api-headers", output: "../../bin/Koffi/{{ toolchain }}", node: 16, napi: 8 } };
132
137
  }
133
138
  });
134
139
 
@@ -94,7 +94,7 @@ function decodeElfHeader(buf) {
94
94
  }
95
95
 
96
96
  // src/koffi/package.json
97
- var package_default = { name: "koffi", version: "3.0.2", cnoke: { api: "../../vendor/node-api-headers", output: "../../bin/Koffi/{{ toolchain }}", node: 16, napi: 8 } };
97
+ var package_default = { name: "koffi", version: "3.1.1", cnoke: { api: "../../vendor/node-api-headers", output: "../../bin/Koffi/{{ toolchain }}", node: 16, napi: 8 } };
98
98
 
99
99
  // src/koffi/src/init.js
100
100
  var require2 = createRequire(import.meta.url);
@@ -4,8 +4,13 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __getProtoOf = Object.getPrototypeOf;
6
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __esm = (fn, res) => function __init() {
8
- return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
7
+ var __esm = (fn, res, err) => function __init() {
8
+ if (err) throw err[0];
9
+ try {
10
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
11
+ } catch (e) {
12
+ throw err = [e], e;
13
+ }
9
14
  };
10
15
  var __export = (target, all) => {
11
16
  for (var name in all)
@@ -128,7 +133,7 @@ var init_abi = __esm({
128
133
  var package_default;
129
134
  var init_package = __esm({
130
135
  "src/koffi/package.json"() {
131
- package_default = { name: "koffi", version: "3.0.2", cnoke: { api: "../../vendor/node-api-headers", output: "../../bin/Koffi/{{ toolchain }}", node: 16, napi: 8 } };
136
+ package_default = { name: "koffi", version: "3.1.1", cnoke: { api: "../../vendor/node-api-headers", output: "../../bin/Koffi/{{ toolchain }}", node: 16, napi: 8 } };
132
137
  }
133
138
  });
134
139
 
@@ -94,7 +94,7 @@ function decodeElfHeader(buf) {
94
94
  }
95
95
 
96
96
  // src/koffi/package.json
97
- var package_default = { name: "koffi", version: "3.0.2", cnoke: { api: "../../vendor/node-api-headers", output: "../../bin/Koffi/{{ toolchain }}", node: 16, napi: 8 } };
97
+ var package_default = { name: "koffi", version: "3.1.1", cnoke: { api: "../../vendor/node-api-headers", output: "../../bin/Koffi/{{ toolchain }}", node: 16, napi: 8 } };
98
98
 
99
99
  // src/koffi/src/init.js
100
100
  var require2 = createRequire(import.meta.url);