koffi 2.0.1 → 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 (78) hide show
  1. package/CMakeLists.txt +1 -8
  2. package/benchmark/atoi_koffi.js +12 -8
  3. package/benchmark/atoi_napi.js +12 -8
  4. package/benchmark/atoi_node_ffi.js +11 -10
  5. package/benchmark/raylib_cc.cc +12 -9
  6. package/benchmark/raylib_koffi.js +15 -13
  7. package/benchmark/raylib_node_ffi.js +15 -13
  8. package/benchmark/raylib_node_raylib.js +14 -11
  9. package/build/qemu/2.1.0-beta.1/koffi_darwin_arm64.tar.gz +0 -0
  10. package/build/qemu/2.1.0-beta.1/koffi_darwin_x64.tar.gz +0 -0
  11. package/build/qemu/2.1.0-beta.1/koffi_freebsd_arm64.tar.gz +0 -0
  12. package/build/qemu/2.1.0-beta.1/koffi_freebsd_ia32.tar.gz +0 -0
  13. package/build/qemu/2.1.0-beta.1/koffi_freebsd_x64.tar.gz +0 -0
  14. package/build/qemu/2.1.0-beta.1/koffi_linux_arm32hf.tar.gz +0 -0
  15. package/build/qemu/2.1.0-beta.1/koffi_linux_arm64.tar.gz +0 -0
  16. package/build/qemu/2.1.0-beta.1/koffi_linux_ia32.tar.gz +0 -0
  17. package/build/qemu/2.1.0-beta.1/koffi_linux_riscv64hf64.tar.gz +0 -0
  18. package/build/qemu/2.1.0-beta.1/koffi_linux_x64.tar.gz +0 -0
  19. package/build/qemu/2.1.0-beta.1/koffi_openbsd_ia32.tar.gz +0 -0
  20. package/build/qemu/2.1.0-beta.1/koffi_openbsd_x64.tar.gz +0 -0
  21. package/build/qemu/2.1.0-beta.1/koffi_win32_arm64.tar.gz +0 -0
  22. package/build/qemu/2.1.0-beta.1/koffi_win32_ia32.tar.gz +0 -0
  23. package/build/qemu/2.1.0-beta.1/koffi_win32_x64.tar.gz +0 -0
  24. package/doc/changes.md +12 -8
  25. package/doc/dist/doctrees/changes.doctree +0 -0
  26. package/doc/dist/doctrees/environment.pickle +0 -0
  27. package/doc/dist/doctrees/functions.doctree +0 -0
  28. package/doc/dist/doctrees/index.doctree +0 -0
  29. package/doc/dist/doctrees/types.doctree +0 -0
  30. package/doc/dist/html/_sources/changes.md.txt +12 -8
  31. package/doc/dist/html/_sources/functions.md.txt +4 -4
  32. package/doc/dist/html/_sources/types.md.txt +69 -34
  33. package/doc/dist/html/benchmarks.html +1 -1
  34. package/doc/dist/html/changes.html +44 -33
  35. package/doc/dist/html/contribute.html +1 -1
  36. package/doc/dist/html/functions.html +7 -7
  37. package/doc/dist/html/genindex.html +1 -1
  38. package/doc/dist/html/index.html +3 -3
  39. package/doc/dist/html/memory.html +1 -1
  40. package/doc/dist/html/objects.inv +0 -0
  41. package/doc/dist/html/platforms.html +2 -2
  42. package/doc/dist/html/search.html +1 -1
  43. package/doc/dist/html/searchindex.js +1 -1
  44. package/doc/dist/html/start.html +1 -1
  45. package/doc/dist/html/types.html +77 -40
  46. package/doc/functions.md +4 -4
  47. package/doc/types.md +68 -33
  48. package/package.json +2 -2
  49. package/qemu/qemu.js +1 -1
  50. package/src/call.cc +42 -26
  51. package/src/call.hh +15 -3
  52. package/src/ffi.cc +70 -13
  53. package/src/ffi.hh +7 -0
  54. package/src/index.js +4 -2
  55. package/src/parser.cc +3 -5
  56. package/src/util.cc +44 -1
  57. package/src/util.hh +4 -0
  58. package/test/async.js +1 -2
  59. package/test/callbacks.js +2 -3
  60. package/test/misc.c +21 -1
  61. package/test/raylib.js +1 -1
  62. package/test/sqlite.js +3 -3
  63. package/test/sync.js +27 -3
  64. package/build/qemu/2.0.1/koffi_darwin_arm64.tar.gz +0 -0
  65. package/build/qemu/2.0.1/koffi_darwin_x64.tar.gz +0 -0
  66. package/build/qemu/2.0.1/koffi_freebsd_arm64.tar.gz +0 -0
  67. package/build/qemu/2.0.1/koffi_freebsd_ia32.tar.gz +0 -0
  68. package/build/qemu/2.0.1/koffi_freebsd_x64.tar.gz +0 -0
  69. package/build/qemu/2.0.1/koffi_linux_arm32hf.tar.gz +0 -0
  70. package/build/qemu/2.0.1/koffi_linux_arm64.tar.gz +0 -0
  71. package/build/qemu/2.0.1/koffi_linux_ia32.tar.gz +0 -0
  72. package/build/qemu/2.0.1/koffi_linux_riscv64hf64.tar.gz +0 -0
  73. package/build/qemu/2.0.1/koffi_linux_x64.tar.gz +0 -0
  74. package/build/qemu/2.0.1/koffi_openbsd_ia32.tar.gz +0 -0
  75. package/build/qemu/2.0.1/koffi_openbsd_x64.tar.gz +0 -0
  76. package/build/qemu/2.0.1/koffi_win32_arm64.tar.gz +0 -0
  77. package/build/qemu/2.0.1/koffi_win32_ia32.tar.gz +0 -0
  78. package/build/qemu/2.0.1/koffi_win32_x64.tar.gz +0 -0
package/test/sync.js CHANGED
@@ -15,7 +15,6 @@
15
15
 
16
16
  const koffi = require('./build/koffi.node');
17
17
  const assert = require('assert');
18
- const path = require('path');
19
18
 
20
19
  const Pack1 = koffi.struct('Pack1', {
21
20
  a: 'int'
@@ -62,7 +61,7 @@ const IntFloat = koffi.struct('IntFloat', {
62
61
 
63
62
  const BFG = koffi.struct('BFG', {
64
63
  a: 'int8_t',
65
- b: 'int64_t',
64
+ b: [16, 'int64_t'],
66
65
  c: 'char',
67
66
  d: 'const char *',
68
67
  e: 'short',
@@ -128,7 +127,7 @@ async function main() {
128
127
  }
129
128
 
130
129
  async function test() {
131
- let lib_filename = path.dirname(__filename) + '/build/misc' + koffi.extension;
130
+ let lib_filename = __dirname + '/build/misc' + koffi.extension;
132
131
  let lib = koffi.load(lib_filename);
133
132
 
134
133
  const GetMinusOne1 = lib.func('int8_t GetMinusOne1(void)');
@@ -160,6 +159,7 @@ async function test() {
160
159
  const ConcatenateToStr8 = lib.func('ConcatenateToStr8', 'str', [...Array(8).fill('int64_t'), koffi.struct('IJK8', {i: 'int64_t', j: 'int64_t', k: 'int64_t'}), 'int64_t']);
161
160
  const MakeBFG = lib.func('BFG __stdcall MakeBFG(_Out_ BFG *p, int x, double y, const char *str)');
162
161
  const MakePackedBFG = lib.func('AliasBFG __fastcall MakePackedBFG(int x, double y, _Out_ PackedBFG *p, const char *str)');
162
+ const MakePolymorphBFG = lib.func('void MakePolymorphBFG(int type, int x, double y, const char *str, _Out_ void *p)');
163
163
  const ReturnBigString = process.platform == 'win32' ?
164
164
  lib.stdcall(1, koffi.disposable('str', koffi.free), ['str']) :
165
165
  lib.func('const char * __stdcall ReturnBigString(const char *str)');
@@ -186,6 +186,7 @@ async function test() {
186
186
  const MultiplyIntegers = lib.func('void MultiplyIntegers(int multiplier, _Inout_ int *values, int len)');
187
187
  const ThroughStr = lib.func('str ThroughStr(StrStruct s)');
188
188
  const ThroughStr16 = lib.func('str16 ThroughStr16(StrStruct s)');
189
+ const ReverseBytes = lib.func('void ReverseBytes(_Inout_ void *array, int len)');
189
190
 
190
191
  // Simple signed value returns
191
192
  assert.equal(GetMinusOne1(), -1);
@@ -295,6 +296,17 @@ async function test() {
295
296
  assert.deepEqual(out, bfg);
296
297
  }
297
298
 
299
+ // Polymorph pointer
300
+ {
301
+ let bfg = {};
302
+
303
+ MakePolymorphBFG(0, 2, 7, 'boo', koffi.as(bfg, 'BFG *'));
304
+ assert.deepEqual(bfg, { a: 2, b: 4, c: -25, d: 'X/boo/X', e: 54, inner: { f: 14, g: 5 }});
305
+
306
+ MakePolymorphBFG(1, 2, 7, 'bies', koffi.as(bfg, 'PackedBFG *'));
307
+ assert.deepEqual(bfg, { a: 2, b: 4, c: -25, d: 'X/bies/X', e: 54, inner: { f: 14, g: 5 }});
308
+ }
309
+
298
310
  // Big string
299
311
  {
300
312
  let str = 'fooBAR!'.repeat(1024 * 1024);
@@ -394,4 +406,16 @@ async function test() {
394
406
  assert.equal(ThroughStr16({ str: null, str16: 'World!' }), 'World!');
395
407
  assert.equal(ThroughStr16({ str: 'World!', str16: null }), null);
396
408
  }
409
+
410
+ // Transparent typed arrays for void pointers
411
+ {
412
+ let arr8 = Uint8Array.from([1, 2, 3, 4, 5]);
413
+ let arr16 = Int16Array.from([1, 2, 3, 4, 5]);
414
+
415
+ ReverseBytes(arr8, arr8.byteLength);
416
+ assert.deepEqual(arr8, Uint8Array.from([5, 4, 3, 2, 1]));
417
+
418
+ ReverseBytes(arr16, arr16.byteLength);
419
+ assert.deepEqual(arr16, Int16Array.from([1280, 1024, 768, 512, 256]));
420
+ }
397
421
  }