koffi 1.3.1 → 1.3.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.
Files changed (52) hide show
  1. package/CMakeLists.txt +6 -2
  2. package/ChangeLog.md +65 -0
  3. package/build/qemu/1.3.2/koffi_darwin_arm64.tar.gz +0 -0
  4. package/build/qemu/1.3.2/koffi_darwin_x64.tar.gz +0 -0
  5. package/build/qemu/1.3.2/koffi_freebsd_arm64.tar.gz +0 -0
  6. package/build/qemu/1.3.2/koffi_freebsd_ia32.tar.gz +0 -0
  7. package/build/qemu/1.3.2/koffi_freebsd_x64.tar.gz +0 -0
  8. package/build/qemu/1.3.2/koffi_linux_arm32hf.tar.gz +0 -0
  9. package/build/qemu/1.3.2/koffi_linux_arm64.tar.gz +0 -0
  10. package/build/qemu/1.3.2/koffi_linux_ia32.tar.gz +0 -0
  11. package/build/qemu/1.3.2/koffi_linux_riscv64hf64.tar.gz +0 -0
  12. package/build/qemu/1.3.2/koffi_linux_x64.tar.gz +0 -0
  13. package/build/qemu/1.3.2/koffi_openbsd_ia32.tar.gz +0 -0
  14. package/build/qemu/1.3.2/koffi_openbsd_x64.tar.gz +0 -0
  15. package/build/qemu/1.3.2/koffi_win32_arm64.tar.gz +0 -0
  16. package/build/qemu/1.3.2/koffi_win32_ia32.tar.gz +0 -0
  17. package/build/qemu/1.3.2/koffi_win32_x64.tar.gz +0 -0
  18. package/doc/conf.py +2 -2
  19. package/doc/dist/doctrees/environment.pickle +0 -0
  20. package/doc/dist/doctrees/index.doctree +0 -0
  21. package/doc/dist/html/_static/pygments.css +54 -54
  22. package/doc/dist/html/functions.html +66 -66
  23. package/doc/dist/html/index.html +2 -2
  24. package/doc/dist/html/memory.html +2 -2
  25. package/doc/dist/html/objects.inv +0 -0
  26. package/doc/dist/html/platforms.html +1 -1
  27. package/doc/dist/html/searchindex.js +1 -1
  28. package/doc/dist/html/start.html +45 -45
  29. package/doc/dist/html/types.html +152 -152
  30. package/package.json +3 -2
  31. package/qemu/qemu.js +1 -1
  32. package/src/abi_x64_sysv_fwd.S +14 -4
  33. package/src/abi_x86_fwd.S +6 -4
  34. package/src/call.cc +4 -4
  35. package/test/CMakeLists.txt +1 -1
  36. package/vendor/libcc/libcc.cc +17 -5
  37. package/vendor/libcc/libcc.hh +32 -0
  38. package/build/qemu/1.3.1/koffi_darwin_arm64.tar.gz +0 -0
  39. package/build/qemu/1.3.1/koffi_darwin_x64.tar.gz +0 -0
  40. package/build/qemu/1.3.1/koffi_freebsd_arm64.tar.gz +0 -0
  41. package/build/qemu/1.3.1/koffi_freebsd_ia32.tar.gz +0 -0
  42. package/build/qemu/1.3.1/koffi_freebsd_x64.tar.gz +0 -0
  43. package/build/qemu/1.3.1/koffi_linux_arm32hf.tar.gz +0 -0
  44. package/build/qemu/1.3.1/koffi_linux_arm64.tar.gz +0 -0
  45. package/build/qemu/1.3.1/koffi_linux_ia32.tar.gz +0 -0
  46. package/build/qemu/1.3.1/koffi_linux_riscv64hf64.tar.gz +0 -0
  47. package/build/qemu/1.3.1/koffi_linux_x64.tar.gz +0 -0
  48. package/build/qemu/1.3.1/koffi_openbsd_ia32.tar.gz +0 -0
  49. package/build/qemu/1.3.1/koffi_openbsd_x64.tar.gz +0 -0
  50. package/build/qemu/1.3.1/koffi_win32_arm64.tar.gz +0 -0
  51. package/build/qemu/1.3.1/koffi_win32_ia32.tar.gz +0 -0
  52. package/build/qemu/1.3.1/koffi_win32_x64.tar.gz +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "koffi",
3
- "version": "1.3.1",
3
+ "version": "1.3.2",
4
4
  "description": "Fast and simple C FFI (foreign function interface) for Node.js",
5
5
  "keywords": [
6
6
  "foreign",
@@ -25,7 +25,7 @@
25
25
  },
26
26
  "license": "AGPL-3.0",
27
27
  "dependencies": {
28
- "cnoke": "^2.0.2"
28
+ "cnoke": "^2.0.3"
29
29
  },
30
30
  "devDependencies": {
31
31
  "chalk": "^4.1.2",
@@ -56,6 +56,7 @@
56
56
  "vendor",
57
57
  "LICENSE.txt",
58
58
  "README.md",
59
+ "ChangeLog.md",
59
60
  "CMakeLists.txt",
60
61
  "build/qemu/*/*.tar.gz"
61
62
  ]
package/qemu/qemu.js CHANGED
@@ -249,7 +249,7 @@ async function start(detach = true) {
249
249
  let version = fs.existsSync(filename) ? parseInt(fs.readFileSync(filename).toString(), 10) : 0;
250
250
 
251
251
  if (version != machine.qemu.version) {
252
- log(machine, 'Download newer machine', chalk.bold.gray('[ignore]'));
252
+ log(machine, 'Machine version mismatch', chalk.bold.gray('[ignore]'));
253
253
 
254
254
  ignore.add(machine);
255
255
  missing++;
@@ -35,13 +35,15 @@
35
35
  .global SYMBOL(ForwardCallXGD)
36
36
  .global SYMBOL(ForwardCallXDD)
37
37
 
38
+ #define ENDBR64 .byte 0xf3, 0x0f, 0x1e, 0xfa
39
+
38
40
  # Copy function pointer to R11, in order to save it through argument forwarding.
39
41
  # Also make a copy of the SP to CallData::old_sp because the callback system might need it.
40
42
  # Save RSP in RBX (non-volatile), and use carefully assembled stack provided by caller.
41
43
  .macro prologue
42
44
  .cfi_startproc
43
45
  .cfi_def_cfa rsp, 8
44
- endbr64
46
+ ENDBR64
45
47
  movq %rdi, %r11
46
48
  pushq %rbx
47
49
  .cfi_def_cfa rsp, 16
@@ -196,7 +198,7 @@ SYMBOL(ForwardCallXDD):
196
198
  .macro trampoline id
197
199
  .cfi_startproc
198
200
  .cfi_def_cfa rsp, 8
199
- endbr64
201
+ ENDBR64
200
202
  subq $152, %rsp
201
203
  .cfi_def_cfa rsp, 160
202
204
  movq %rdi, 0(%rsp)
@@ -209,7 +211,11 @@ SYMBOL(ForwardCallXDD):
209
211
  movq %rsp, %rsi
210
212
  leaq 160(%rsp), %rdx
211
213
  leaq 112(%rsp), %rcx
214
+ #ifdef __linux__
215
+ call *RelayCallback@GOTPCREL(%rip)
216
+ #else
212
217
  call SYMBOL(RelayCallback)
218
+ #endif
213
219
  movq 112(%rsp), %rax
214
220
  movq 120(%rsp), %rdx
215
221
  addq $152, %rsp
@@ -222,7 +228,7 @@ SYMBOL(ForwardCallXDD):
222
228
  .macro trampoline_xmm id
223
229
  .cfi_startproc
224
230
  .cfi_def_cfa rsp, 8
225
- endbr64
231
+ ENDBR64
226
232
  subq $152, %rsp
227
233
  .cfi_def_cfa rsp, 160
228
234
  movq %rdi, 0(%rsp)
@@ -243,7 +249,11 @@ SYMBOL(ForwardCallXDD):
243
249
  movq %rsp, %rsi
244
250
  leaq 160(%rsp), %rdx
245
251
  leaq 112(%rsp), %rcx
252
+ #ifdef __linux__
253
+ call *RelayCallback@GOTPCREL(%rip)
254
+ #else
246
255
  call SYMBOL(RelayCallback)
256
+ #endif
247
257
  movq 112(%rsp), %rax
248
258
  movq 120(%rsp), %rdx
249
259
  movsd 128(%rsp), %xmm0
@@ -328,7 +338,7 @@ SYMBOL(TrampolineX15):
328
338
  SYMBOL(CallSwitchStack):
329
339
  .cfi_startproc
330
340
  .cfi_def_cfa rsp, 8
331
- endbr64
341
+ ENDBR64
332
342
  push %rbx
333
343
  .cfi_def_cfa rsp, 16
334
344
  movq %rsp, %rbx
package/src/abi_x86_fwd.S CHANGED
@@ -18,13 +18,15 @@
18
18
  .global ForwardCallRF
19
19
  .global ForwardCallRD
20
20
 
21
+ #define ENDBR32 .byte 0xf3, 0x0f, 0x1e, 0xfb
22
+
21
23
  # Copy function pointer to EAX, in order to save it through argument forwarding.
22
24
  # Also make a copy of the SP to CallData::old_sp because the callback system might need it.
23
25
  # Save ESP in EBX (non-volatile), and use carefully assembled stack provided by caller.
24
26
  .macro prologue
25
27
  .cfi_startproc
26
28
  .cfi_def_cfa esp, 4
27
- endbr32
29
+ ENDBR32
28
30
  push %ebx
29
31
  .cfi_def_cfa esp, 8
30
32
  movl %esp, %ebx
@@ -125,7 +127,7 @@ ForwardCallRD:
125
127
  .macro trampoline id
126
128
  .cfi_startproc
127
129
  .cfi_def_cfa esp, 4
128
- endbr32
130
+ ENDBR32
129
131
  sub $44, %esp
130
132
  .cfi_def_cfa esp, 48
131
133
  movl $\id, 0(%esp)
@@ -153,7 +155,7 @@ ForwardCallRD:
153
155
  .macro trampoline_x87 id
154
156
  .cfi_startproc
155
157
  .cfi_def_cfa esp, 4
156
- endbr32
158
+ ENDBR32
157
159
  sub $44, %esp
158
160
  .cfi_def_cfa esp, 48
159
161
  movl $\id, 0(%esp)
@@ -260,7 +262,7 @@ TrampolineX15:
260
262
  CallSwitchStack:
261
263
  .cfi_startproc
262
264
  .cfi_def_cfa esp, 4
263
- endbr32
265
+ ENDBR32
264
266
  push %ebx
265
267
  .cfi_def_cfa esp, 8
266
268
  movl %esp, %ebx
package/src/call.cc CHANGED
@@ -248,7 +248,7 @@ bool CallData::PushObject(Napi::Object obj, const TypeInfo *type, uint8_t *origi
248
248
  } break;
249
249
  case PrimitiveKind::Pointer: {
250
250
  if (CheckValueTag(instance, value, member.type)) {
251
- Napi::External external = value.As<Napi::External<void>>();
251
+ Napi::External<void> external = value.As<Napi::External<void>>();
252
252
  void *ptr = external.Data();
253
253
  *(void **)dest = ptr;
254
254
  } else if (IsNullOrUndefined(value)) {
@@ -317,7 +317,7 @@ bool CallData::PushObject(Napi::Object obj, const TypeInfo *type, uint8_t *origi
317
317
  if (RG_UNLIKELY(!ptr))
318
318
  return false;
319
319
  } else if (CheckValueTag(instance, value, member.type)) {
320
- Napi::External external = value.As<Napi::External<void>>();
320
+ Napi::External<void> external = value.As<Napi::External<void>>();
321
321
  ptr = external.Data();
322
322
  } else if (IsNullOrUndefined(value)) {
323
323
  ptr = nullptr;
@@ -452,7 +452,7 @@ bool CallData::PushNormalArray(Napi::Array array, Size len, const TypeInfo *ref,
452
452
  case PrimitiveKind::Pointer: {
453
453
  PUSH_ARRAY(CheckValueTag(instance, value, ref) || IsNullOrUndefined(value), ref->name, {
454
454
  if (!IsNullOrUndefined(value)) {
455
- Napi::External external = value.As<Napi::External<void>>();
455
+ Napi::External<void> external = value.As<Napi::External<void>>();
456
456
  *(void **)dest = external.Data();
457
457
  } else {
458
458
  *(void **)dest = nullptr;
@@ -528,7 +528,7 @@ bool CallData::PushNormalArray(Napi::Array array, Size len, const TypeInfo *ref,
528
528
  if (RG_UNLIKELY(!ptr))
529
529
  return false;
530
530
  } else if (CheckValueTag(instance, value, ref)) {
531
- Napi::External external = value.As<Napi::External<void>>();
531
+ Napi::External<void> external = value.As<Napi::External<void>>();
532
532
  ptr = external.Data();
533
533
  } else if (IsNullOrUndefined(value)) {
534
534
  ptr = nullptr;
@@ -11,7 +11,7 @@
11
11
  # You should have received a copy of the GNU Affero General Public License
12
12
  # along with this program. If not, see https://www.gnu.org/licenses/.
13
13
 
14
- cmake_minimum_required(VERSION 3.12)
14
+ cmake_minimum_required(VERSION 3.6)
15
15
  project(koffi_test C CXX)
16
16
 
17
17
  if(NOT TARGET koffi)
@@ -20,7 +20,7 @@
20
20
  #include "vendor/brotli/c/include/brotli/decode.h"
21
21
  #include "vendor/brotli/c/include/brotli/encode.h"
22
22
  #endif
23
- #if __has_include("vendor/dragonbox/include/dragonbox/dragonbox.h")
23
+ #if __has_include("vendor/dragonbox/include/dragonbox/dragonbox.h") && __cplusplus >= 201703L
24
24
  #include "vendor/dragonbox/include/dragonbox/dragonbox.h"
25
25
  #endif
26
26
 
@@ -81,6 +81,9 @@
81
81
 
82
82
  extern char **environ;
83
83
  #endif
84
+ #ifdef __linux__
85
+ #include <sys/syscall.h>
86
+ #endif
84
87
  #ifdef __APPLE__
85
88
  #include <sys/random.h>
86
89
  #include <mach-o/dyld.h>
@@ -3741,8 +3744,8 @@ bool ExecuteCommandLine(const char *cmd_line, FunctionRef<Span<const uint8_t>()>
3741
3744
  #if defined(__OpenBSD__) || defined(__FreeBSD__)
3742
3745
  static const pthread_t main_thread = pthread_self();
3743
3746
  #endif
3744
- static std::atomic_bool flag_interrupt = false;
3745
- static std::atomic_bool explicit_interrupt = false;
3747
+ static std::atomic_bool flag_interrupt {false};
3748
+ static std::atomic_bool explicit_interrupt {false};
3746
3749
  static int interrupt_pfd[2] = {-1, -1};
3747
3750
 
3748
3751
  void SetSignalHandler(int signal, void (*func)(int), struct sigaction *prev)
@@ -4165,7 +4168,7 @@ void WaitDelay(int64_t delay)
4165
4168
 
4166
4169
  WaitForResult WaitForInterrupt(int64_t timeout)
4167
4170
  {
4168
- static std::atomic_bool message = false;
4171
+ static std::atomic_bool message {false};
4169
4172
 
4170
4173
  flag_interrupt = true;
4171
4174
  SetSignalHandler(SIGUSR1, [](int) { message = true; });
@@ -4755,8 +4758,17 @@ void FillRandomSafe(void *out_buf, Size len)
4755
4758
  struct { uint32_t key[8]; uint32_t iv[2]; } buf;
4756
4759
 
4757
4760
  memset(rnd_state, 0, RG_SIZE(rnd_state));
4758
- #ifdef _WIN32
4761
+ #if defined(_WIN32)
4759
4762
  RG_CRITICAL(RtlGenRandom(&buf, RG_SIZE(buf)), "RtlGenRandom() failed: %s", GetWin32ErrorString());
4763
+ #elif defined(__linux__)
4764
+ {
4765
+ restart:
4766
+ int ret = syscall(SYS_getrandom, &buf, RG_SIZE(buf), 0);
4767
+ RG_CRITICAL(ret >= 0, "getentropy() failed: %s", strerror(errno));
4768
+
4769
+ if (ret < RG_SIZE(buf))
4770
+ goto restart;
4771
+ }
4760
4772
  #else
4761
4773
  RG_CRITICAL(getentropy(&buf, RG_SIZE(buf)) == 0, "getentropy() failed: %s", strerror(errno));
4762
4774
  #endif
@@ -1204,7 +1204,11 @@ public:
1204
1204
  {
1205
1205
  RemoveFrom(0);
1206
1206
  Grow(other.capacity);
1207
+ #if __cplusplus >= 201703L
1207
1208
  if constexpr(!std::is_trivial<T>::value) {
1209
+ #else
1210
+ if (true) {
1211
+ #endif
1208
1212
  for (Size i = 0; i < other.len; i++) {
1209
1213
  ptr[i] = other.ptr[i];
1210
1214
  }
@@ -1308,7 +1312,11 @@ public:
1308
1312
  Grow(count);
1309
1313
 
1310
1314
  T *first = ptr + len;
1315
+ #if __cplusplus >= 201703L
1311
1316
  if constexpr(!std::is_trivial<T>::value) {
1317
+ #else
1318
+ if (true) {
1319
+ #endif
1312
1320
  for (Size i = 0; i < count; i++) {
1313
1321
  new (ptr + len) T();
1314
1322
  len++;
@@ -1325,7 +1333,11 @@ public:
1325
1333
  Grow();
1326
1334
 
1327
1335
  T *first = ptr + len;
1336
+ #if __cplusplus >= 201703L
1328
1337
  if constexpr(!std::is_trivial<T>::value) {
1338
+ #else
1339
+ if (true) {
1340
+ #endif
1329
1341
  new (ptr + len) T;
1330
1342
  }
1331
1343
  ptr[len++] = value;
@@ -1337,7 +1349,11 @@ public:
1337
1349
 
1338
1350
  T *first = ptr + len;
1339
1351
  for (const T &value: values) {
1352
+ #if __cplusplus >= 201703L
1340
1353
  if constexpr(!std::is_trivial<T>::value) {
1354
+ #else
1355
+ if (true) {
1356
+ #endif
1341
1357
  new (ptr + len) T;
1342
1358
  }
1343
1359
  ptr[len++] = value;
@@ -1349,7 +1365,11 @@ public:
1349
1365
  {
1350
1366
  RG_ASSERT(first >= 0 && first <= len);
1351
1367
 
1368
+ #if __cplusplus >= 201703L
1352
1369
  if constexpr(!std::is_trivial<T>::value) {
1370
+ #else
1371
+ if (true) {
1372
+ #endif
1353
1373
  for (Size i = first; i < len; i++) {
1354
1374
  ptr[i].~T();
1355
1375
  }
@@ -1655,7 +1675,11 @@ private:
1655
1675
  void DeleteValues([[maybe_unused]] iterator_type begin,
1656
1676
  [[maybe_unused]] iterator_type end)
1657
1677
  {
1678
+ #if __cplusplus >= 201703L
1658
1679
  if constexpr(!std::is_trivial<T>::value) {
1680
+ #else
1681
+ if (true) {
1682
+ #endif
1659
1683
  for (iterator_type it = begin; it != end; ++it) {
1660
1684
  it->~T();
1661
1685
  }
@@ -1932,7 +1956,11 @@ public:
1932
1956
  }
1933
1957
  ~HashTable()
1934
1958
  {
1959
+ #if __cplusplus >= 201703L
1935
1960
  if constexpr(std::is_trivial<ValueType>::value) {
1961
+ #else
1962
+ if (false) {
1963
+ #endif
1936
1964
  count = 0;
1937
1965
  Rehash(0);
1938
1966
  } else {
@@ -2102,7 +2130,11 @@ private:
2102
2130
  { return (ValueType *)((const HashTable *)this)->Find(idx, key); }
2103
2131
  const ValueType *Find(Size *idx, const KeyType &key) const
2104
2132
  {
2133
+ #if __cplusplus >= 201703L
2105
2134
  if constexpr(std::is_pointer<ValueType>::value) {
2135
+ #else
2136
+ if (false) {
2137
+ #endif
2106
2138
  while (data[*idx]) {
2107
2139
  const KeyType &it_key = Handler::GetKey(data[*idx]);
2108
2140
  if (Handler::TestKeys(it_key, key))