koffi 1.3.12 → 2.1.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 (104) hide show
  1. package/CMakeLists.txt +8 -10
  2. package/ChangeLog.md +48 -16
  3. package/README.md +6 -0
  4. package/benchmark/atoi_koffi.js +12 -8
  5. package/benchmark/atoi_napi.js +12 -8
  6. package/benchmark/atoi_node_ffi.js +11 -10
  7. package/benchmark/raylib_cc.cc +12 -9
  8. package/benchmark/raylib_koffi.js +15 -13
  9. package/benchmark/raylib_node_ffi.js +15 -13
  10. package/benchmark/raylib_node_raylib.js +14 -11
  11. package/build/qemu/2.1.0-beta.1/koffi_darwin_arm64.tar.gz +0 -0
  12. package/build/qemu/2.1.0-beta.1/koffi_darwin_x64.tar.gz +0 -0
  13. package/build/qemu/2.1.0-beta.1/koffi_freebsd_arm64.tar.gz +0 -0
  14. package/build/qemu/2.1.0-beta.1/koffi_freebsd_ia32.tar.gz +0 -0
  15. package/build/qemu/2.1.0-beta.1/koffi_freebsd_x64.tar.gz +0 -0
  16. package/build/qemu/2.1.0-beta.1/koffi_linux_arm32hf.tar.gz +0 -0
  17. package/build/qemu/2.1.0-beta.1/koffi_linux_arm64.tar.gz +0 -0
  18. package/build/qemu/2.1.0-beta.1/koffi_linux_ia32.tar.gz +0 -0
  19. package/build/qemu/2.1.0-beta.1/koffi_linux_riscv64hf64.tar.gz +0 -0
  20. package/build/qemu/2.1.0-beta.1/koffi_linux_x64.tar.gz +0 -0
  21. package/build/qemu/2.1.0-beta.1/koffi_openbsd_ia32.tar.gz +0 -0
  22. package/build/qemu/2.1.0-beta.1/koffi_openbsd_x64.tar.gz +0 -0
  23. package/build/qemu/2.1.0-beta.1/koffi_win32_arm64.tar.gz +0 -0
  24. package/build/qemu/2.1.0-beta.1/koffi_win32_ia32.tar.gz +0 -0
  25. package/build/qemu/2.1.0-beta.1/koffi_win32_x64.tar.gz +0 -0
  26. package/doc/changes.md +160 -1
  27. package/doc/conf.py +14 -1
  28. package/doc/contribute.md +0 -1
  29. package/doc/dist/doctrees/benchmarks.doctree +0 -0
  30. package/doc/dist/doctrees/changes.doctree +0 -0
  31. package/doc/dist/doctrees/environment.pickle +0 -0
  32. package/doc/dist/doctrees/functions.doctree +0 -0
  33. package/doc/dist/doctrees/index.doctree +0 -0
  34. package/doc/dist/doctrees/types.doctree +0 -0
  35. package/doc/dist/html/.buildinfo +1 -1
  36. package/doc/dist/html/_sources/benchmarks.md.txt +2 -2
  37. package/doc/dist/html/_sources/changes.md.txt +160 -1
  38. package/doc/dist/html/_sources/functions.md.txt +17 -13
  39. package/doc/dist/html/_sources/types.md.txt +87 -35
  40. package/doc/dist/html/benchmarks.html +7 -3
  41. package/doc/dist/html/changes.html +241 -14
  42. package/doc/dist/html/contribute.html +5 -1
  43. package/doc/dist/html/functions.html +30 -23
  44. package/doc/dist/html/genindex.html +5 -1
  45. package/doc/dist/html/index.html +13 -19
  46. package/doc/dist/html/memory.html +7 -3
  47. package/doc/dist/html/objects.inv +0 -0
  48. package/doc/dist/html/platforms.html +6 -2
  49. package/doc/dist/html/search.html +5 -1
  50. package/doc/dist/html/searchindex.js +1 -1
  51. package/doc/dist/html/start.html +5 -1
  52. package/doc/dist/html/types.html +104 -43
  53. package/doc/functions.md +139 -15
  54. package/doc/templates/badges.html +5 -0
  55. package/doc/types.md +108 -40
  56. package/package.json +2 -2
  57. package/qemu/qemu.js +1 -1
  58. package/qemu/registry/machines.json +5 -5
  59. package/qemu/registry/sha256sum.txt +16 -16
  60. package/src/abi_arm32.cc +91 -19
  61. package/src/abi_arm32_fwd.S +121 -57
  62. package/src/abi_arm64.cc +91 -19
  63. package/src/abi_arm64_fwd.S +96 -0
  64. package/src/abi_arm64_fwd.asm +128 -0
  65. package/src/abi_riscv64.cc +89 -19
  66. package/src/abi_riscv64_fwd.S +96 -0
  67. package/src/abi_x64_sysv.cc +94 -22
  68. package/src/abi_x64_sysv_fwd.S +96 -0
  69. package/src/abi_x64_win.cc +89 -19
  70. package/src/abi_x64_win_fwd.asm +128 -0
  71. package/src/abi_x86.cc +94 -19
  72. package/src/abi_x86_fwd.S +96 -0
  73. package/src/abi_x86_fwd.asm +128 -0
  74. package/src/call.cc +128 -78
  75. package/src/call.hh +17 -4
  76. package/src/ffi.cc +514 -145
  77. package/src/ffi.hh +30 -9
  78. package/src/index.js +4 -2
  79. package/src/parser.cc +19 -44
  80. package/src/util.cc +160 -27
  81. package/src/util.hh +7 -2
  82. package/test/async.js +1 -2
  83. package/test/callbacks.js +56 -11
  84. package/test/misc.c +50 -15
  85. package/test/raylib.js +2 -2
  86. package/test/sqlite.js +27 -19
  87. package/test/sync.js +71 -35
  88. package/vendor/libcc/libcc.cc +18 -5
  89. package/vendor/libcc/libcc.hh +70 -23
  90. package/build/qemu/1.3.12/koffi_darwin_arm64.tar.gz +0 -0
  91. package/build/qemu/1.3.12/koffi_darwin_x64.tar.gz +0 -0
  92. package/build/qemu/1.3.12/koffi_freebsd_arm64.tar.gz +0 -0
  93. package/build/qemu/1.3.12/koffi_freebsd_ia32.tar.gz +0 -0
  94. package/build/qemu/1.3.12/koffi_freebsd_x64.tar.gz +0 -0
  95. package/build/qemu/1.3.12/koffi_linux_arm32hf.tar.gz +0 -0
  96. package/build/qemu/1.3.12/koffi_linux_arm64.tar.gz +0 -0
  97. package/build/qemu/1.3.12/koffi_linux_ia32.tar.gz +0 -0
  98. package/build/qemu/1.3.12/koffi_linux_riscv64hf64.tar.gz +0 -0
  99. package/build/qemu/1.3.12/koffi_linux_x64.tar.gz +0 -0
  100. package/build/qemu/1.3.12/koffi_openbsd_ia32.tar.gz +0 -0
  101. package/build/qemu/1.3.12/koffi_openbsd_x64.tar.gz +0 -0
  102. package/build/qemu/1.3.12/koffi_win32_arm64.tar.gz +0 -0
  103. package/build/qemu/1.3.12/koffi_win32_ia32.tar.gz +0 -0
  104. package/build/qemu/1.3.12/koffi_win32_x64.tar.gz +0 -0
@@ -235,7 +235,7 @@ extern "C" void AssertMessage(const char *filename, int line, const char *cond);
235
235
  RG_DEBUG_BREAK(); \
236
236
  abort(); \
237
237
  } while (false)
238
- #elif defined(__GNUC__)
238
+ #elif defined(__GNUC__) || defined(__clang__)
239
239
  #define RG_UNREACHABLE() __builtin_unreachable()
240
240
  #else
241
241
  #define RG_UNREACHABLE() __assume(0)
@@ -622,6 +622,7 @@ struct Vec3 {
622
622
  class Allocator;
623
623
 
624
624
  Allocator *GetDefaultAllocator();
625
+ Allocator *GetNullAllocator();
625
626
 
626
627
  class Allocator {
627
628
  RG_DELETE_COPY(Allocator)
@@ -696,8 +697,8 @@ public:
696
697
  void ReleaseAll();
697
698
 
698
699
  protected:
699
- void *Allocate(Size size, unsigned int flags = 0) override;
700
- void Resize(void **ptr, Size old_size, Size new_size, unsigned int flags = 0) override;
700
+ void *Allocate(Size size, unsigned int flags) override;
701
+ void Resize(void **ptr, Size old_size, Size new_size, unsigned int flags) override;
701
702
  void Release(void *ptr, Size size) override;
702
703
 
703
704
  private:
@@ -724,8 +725,8 @@ public:
724
725
  }
725
726
 
726
727
  protected:
727
- void *Allocate(Size size, unsigned int flags = 0) override;
728
- void Resize(void **ptr, Size old_size, Size new_size, unsigned int flags = 0) override;
728
+ void *Allocate(Size size, unsigned int flags) override;
729
+ void Resize(void **ptr, Size old_size, Size new_size, unsigned int flags) override;
729
730
  void Release(void *ptr, Size size) override;
730
731
 
731
732
  void CopyFrom(BlockAllocatorBase *other);
@@ -2020,9 +2021,11 @@ public:
2020
2021
  Iterator<HashTable> end() { return Iterator<HashTable>(this, capacity); }
2021
2022
  Iterator<const HashTable> end() const { return Iterator<const HashTable>(this, capacity); }
2022
2023
 
2023
- ValueType *Find(const KeyType &key)
2024
+ template <typename T = KeyType>
2025
+ ValueType *Find(const T &key)
2024
2026
  { return (ValueType *)((const HashTable *)this)->Find(key); }
2025
- const ValueType *Find(const KeyType &key) const
2027
+ template <typename T = KeyType>
2028
+ const ValueType *Find(const T &key) const
2026
2029
  {
2027
2030
  if (!capacity)
2028
2031
  return nullptr;
@@ -2031,9 +2034,11 @@ public:
2031
2034
  Size idx = HashToIndex(hash);
2032
2035
  return Find(&idx, key);
2033
2036
  }
2034
- ValueType FindValue(const KeyType &key, const ValueType &default_value)
2037
+ template <typename T = KeyType>
2038
+ ValueType FindValue(const T &key, const ValueType &default_value)
2035
2039
  { return (ValueType)((const HashTable *)this)->FindValue(key, default_value); }
2036
- const ValueType FindValue(const KeyType &key, const ValueType &default_value) const
2040
+ template <typename T = KeyType>
2041
+ const ValueType FindValue(const T &key, const ValueType &default_value) const
2037
2042
  {
2038
2043
  const ValueType *it = Find(key);
2039
2044
  return it ? *it : default_value;
@@ -2104,7 +2109,8 @@ public:
2104
2109
  MarkEmpty(empty_idx);
2105
2110
  new (&data[empty_idx]) ValueType();
2106
2111
  }
2107
- void Remove(const KeyType &key) { Remove(Find(key)); }
2112
+ template <typename T = KeyType>
2113
+ void Remove(const T &key) { Remove(Find(key)); }
2108
2114
 
2109
2115
  void Trim()
2110
2116
  {
@@ -2126,9 +2132,11 @@ public:
2126
2132
  Size IsEmpty(Size idx) const { return IsEmpty(used, idx); }
2127
2133
 
2128
2134
  private:
2129
- ValueType *Find(Size *idx, const KeyType &key)
2135
+ template <typename T = KeyType>
2136
+ ValueType *Find(Size *idx, const T &key)
2130
2137
  { return (ValueType *)((const HashTable *)this)->Find(idx, key); }
2131
- const ValueType *Find(Size *idx, const KeyType &key) const
2138
+ template <typename T = KeyType>
2139
+ const ValueType *Find(Size *idx, const T &key) const
2132
2140
  {
2133
2141
  #if __cplusplus >= 201703L
2134
2142
  if constexpr(std::is_pointer<ValueType>::value) {
@@ -2341,6 +2349,16 @@ template <>
2341
2349
  class HashTraits<const char *> {
2342
2350
  public:
2343
2351
  // FNV-1a
2352
+ static uint64_t Hash(Span<const char> key)
2353
+ {
2354
+ uint64_t hash = 0xCBF29CE484222325ull;
2355
+ for (char c: key) {
2356
+ hash ^= (uint64_t)c;
2357
+ hash *= 0x100000001B3ull;
2358
+ }
2359
+
2360
+ return hash;
2361
+ }
2344
2362
  static uint64_t Hash(const char *key)
2345
2363
  {
2346
2364
  uint64_t hash = 0xCBF29CE484222325ull;
@@ -2353,6 +2371,7 @@ public:
2353
2371
  }
2354
2372
 
2355
2373
  static bool Test(const char *key1, const char *key2) { return !strcmp(key1, key2); }
2374
+ static bool Test(const char *key1, Span<const char> key2) { return key2 == key1; }
2356
2375
  };
2357
2376
 
2358
2377
  template <>
@@ -2369,6 +2388,16 @@ public:
2369
2388
 
2370
2389
  return hash;
2371
2390
  }
2391
+ static uint64_t Hash(const char *key)
2392
+ {
2393
+ uint64_t hash = 0xCBF29CE484222325ull;
2394
+ for (Size i = 0; key[i]; i++) {
2395
+ hash ^= (uint64_t)key[i];
2396
+ hash *= 0x100000001B3ull;
2397
+ }
2398
+
2399
+ return hash;
2400
+ }
2372
2401
 
2373
2402
  static bool Test(Span<const char> key1, Span<const char> key2) { return key1 == key2; }
2374
2403
  static bool Test(Span<const char> key1, const char * key2) { return key1 == key2; }
@@ -2381,9 +2410,11 @@ public:
2381
2410
  { return (KeyType)(value.KeyMember); } \
2382
2411
  static KeyType GetKey(const ValueType *value) \
2383
2412
  { return (KeyType)(value->KeyMember); } \
2384
- static uint64_t HashKey(KeyType key) \
2413
+ template <typename TestKey> \
2414
+ static uint64_t HashKey(TestKey key) \
2385
2415
  { return HashFunc(key); } \
2386
- static bool TestKeys(KeyType key1, KeyType key2) \
2416
+ template <typename TestKey> \
2417
+ static bool TestKeys(KeyType key1, TestKey key2) \
2387
2418
  { return TestFunc((key1), (key2)); } \
2388
2419
  }
2389
2420
  #define RG_HASHTABLE_HANDLER_EX(ValueType, KeyType, KeyMember, HashFunc, TestFunc) \
@@ -2420,16 +2451,20 @@ public:
2420
2451
  void Clear() { table.Clear(); }
2421
2452
  void RemoveAll() { table.RemoveAll(); }
2422
2453
 
2423
- ValueType *Find(const KeyType &key)
2454
+ template <typename T = KeyType>
2455
+ ValueType *Find(const T &key)
2424
2456
  { return (ValueType *)((const HashMap *)this)->Find(key); }
2425
- const ValueType *Find(const KeyType &key) const
2457
+ template <typename T = KeyType>
2458
+ const ValueType *Find(const T &key) const
2426
2459
  {
2427
2460
  const Bucket *table_it = table.Find(key);
2428
2461
  return table_it ? &table_it->value : nullptr;
2429
2462
  }
2430
- ValueType FindValue(const KeyType &key, const ValueType &default_value)
2463
+ template <typename T = KeyType>
2464
+ ValueType FindValue(const T &key, const ValueType &default_value)
2431
2465
  { return (ValueType)((const HashMap *)this)->FindValue(key, default_value); }
2432
- const ValueType FindValue(const KeyType &key, const ValueType &default_value) const
2466
+ template <typename T = KeyType>
2467
+ const ValueType FindValue(const T &key, const ValueType &default_value) const
2433
2468
  {
2434
2469
  const ValueType *it = Find(key);
2435
2470
  return it ? *it : default_value;
@@ -2462,6 +2497,7 @@ public:
2462
2497
  return;
2463
2498
  table.Remove((Bucket *)((uint8_t *)it - RG_OFFSET_OF(Bucket, value)));
2464
2499
  }
2500
+ template <typename T = KeyType>
2465
2501
  void Remove(const KeyType &key) { Remove(Find(key)); }
2466
2502
 
2467
2503
  void Trim() { table.Trim(); }
@@ -2493,18 +2529,23 @@ public:
2493
2529
  void Clear() { table.Clear(); }
2494
2530
  void RemoveAll() { table.RemoveAll(); }
2495
2531
 
2496
- ValueType *Find(const ValueType &value) { return table.Find(value); }
2497
- const ValueType *Find(const ValueType &value) const { return table.Find(value); }
2498
- ValueType FindValue(const ValueType &value, const ValueType &default_value)
2532
+ template <typename T = ValueType>
2533
+ ValueType *Find(const T &value) { return table.Find(value); }
2534
+ template <typename T = ValueType>
2535
+ const ValueType *Find(const T &value) const { return table.Find(value); }
2536
+ template <typename T = ValueType>
2537
+ ValueType FindValue(const T &value, const ValueType &default_value)
2499
2538
  { return table.FindValue(value, default_value); }
2500
- const ValueType FindValue(const ValueType &value, const ValueType &default_value) const
2539
+ template <typename T = ValueType>
2540
+ const ValueType FindValue(const T &value, const ValueType &default_value) const
2501
2541
  { return table.FindValue(value, default_value); }
2502
2542
 
2503
2543
  ValueType *Set(const ValueType &value) { return table.Set(value); }
2504
2544
  std::pair<ValueType *, bool> TrySet(const ValueType &value) { return table.TrySet(value); }
2505
2545
 
2506
2546
  void Remove(ValueType *it) { table.Remove(it); }
2507
- void Remove(const ValueType &value) { Remove(Find(value)); }
2547
+ template <typename T = ValueType>
2548
+ void Remove(const T &value) { Remove(Find(value)); }
2508
2549
 
2509
2550
  void Trim() { table.Trim(); }
2510
2551
  };
@@ -3363,6 +3404,8 @@ static inline bool TestStr(Span<const char> str1, const char *str2)
3363
3404
  }
3364
3405
  return (i == str1.len) && !str2[i];
3365
3406
  }
3407
+ static inline bool TestStr(const char *str1, Span<const char> str2)
3408
+ { return TestStr(str2, str1); }
3366
3409
  static inline bool TestStr(const char *str1, const char *str2)
3367
3410
  { return !strcmp(str1, str2); }
3368
3411
 
@@ -3392,6 +3435,8 @@ static inline bool TestStrI(Span<const char> str1, const char *str2)
3392
3435
  }
3393
3436
  return (i == str1.len) && !str2[i];
3394
3437
  }
3438
+ static inline bool TestStrI(const char *str1, Span<const char> str2)
3439
+ { return TestStr(str2, str1); }
3395
3440
  static inline bool TestStrI(const char *str1, const char *str2)
3396
3441
  {
3397
3442
  Size i = 0;
@@ -3431,6 +3476,8 @@ static inline int CmpStr(Span<const char> str1, const char *str2)
3431
3476
  return str1[i];
3432
3477
  }
3433
3478
  }
3479
+ static inline int CmpStr(const char *str1, Span<const char> str2)
3480
+ { return -CmpStr(str2, str1); }
3434
3481
  static inline int CmpStr(const char *str1, const char *str2)
3435
3482
  { return strcmp(str1, str2); }
3436
3483