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.
- package/CMakeLists.txt +1 -8
- package/benchmark/atoi_koffi.js +12 -8
- package/benchmark/atoi_napi.js +12 -8
- package/benchmark/atoi_node_ffi.js +11 -10
- package/benchmark/raylib_cc.cc +12 -9
- package/benchmark/raylib_koffi.js +15 -13
- package/benchmark/raylib_node_ffi.js +15 -13
- package/benchmark/raylib_node_raylib.js +14 -11
- package/build/qemu/2.1.0-beta.1/koffi_darwin_arm64.tar.gz +0 -0
- package/build/qemu/2.1.0-beta.1/koffi_darwin_x64.tar.gz +0 -0
- package/build/qemu/2.1.0-beta.1/koffi_freebsd_arm64.tar.gz +0 -0
- package/build/qemu/2.1.0-beta.1/koffi_freebsd_ia32.tar.gz +0 -0
- package/build/qemu/2.1.0-beta.1/koffi_freebsd_x64.tar.gz +0 -0
- package/build/qemu/2.1.0-beta.1/koffi_linux_arm32hf.tar.gz +0 -0
- package/build/qemu/2.1.0-beta.1/koffi_linux_arm64.tar.gz +0 -0
- package/build/qemu/2.1.0-beta.1/koffi_linux_ia32.tar.gz +0 -0
- package/build/qemu/2.1.0-beta.1/koffi_linux_riscv64hf64.tar.gz +0 -0
- package/build/qemu/2.1.0-beta.1/koffi_linux_x64.tar.gz +0 -0
- package/build/qemu/2.1.0-beta.1/koffi_openbsd_ia32.tar.gz +0 -0
- package/build/qemu/2.1.0-beta.1/koffi_openbsd_x64.tar.gz +0 -0
- package/build/qemu/2.1.0-beta.1/koffi_win32_arm64.tar.gz +0 -0
- package/build/qemu/2.1.0-beta.1/koffi_win32_ia32.tar.gz +0 -0
- package/build/qemu/2.1.0-beta.1/koffi_win32_x64.tar.gz +0 -0
- package/doc/changes.md +12 -8
- package/doc/dist/doctrees/changes.doctree +0 -0
- package/doc/dist/doctrees/environment.pickle +0 -0
- package/doc/dist/doctrees/functions.doctree +0 -0
- package/doc/dist/doctrees/index.doctree +0 -0
- package/doc/dist/doctrees/types.doctree +0 -0
- package/doc/dist/html/_sources/changes.md.txt +12 -8
- package/doc/dist/html/_sources/functions.md.txt +4 -4
- package/doc/dist/html/_sources/types.md.txt +69 -34
- package/doc/dist/html/benchmarks.html +1 -1
- package/doc/dist/html/changes.html +44 -33
- package/doc/dist/html/contribute.html +1 -1
- package/doc/dist/html/functions.html +7 -7
- package/doc/dist/html/genindex.html +1 -1
- package/doc/dist/html/index.html +3 -3
- package/doc/dist/html/memory.html +1 -1
- package/doc/dist/html/objects.inv +0 -0
- package/doc/dist/html/platforms.html +2 -2
- package/doc/dist/html/search.html +1 -1
- package/doc/dist/html/searchindex.js +1 -1
- package/doc/dist/html/start.html +1 -1
- package/doc/dist/html/types.html +77 -40
- package/doc/functions.md +4 -4
- package/doc/types.md +68 -33
- package/package.json +2 -2
- package/qemu/qemu.js +1 -1
- package/src/call.cc +42 -26
- package/src/call.hh +15 -3
- package/src/ffi.cc +70 -13
- package/src/ffi.hh +7 -0
- package/src/index.js +4 -2
- package/src/parser.cc +3 -5
- package/src/util.cc +44 -1
- package/src/util.hh +4 -0
- package/test/async.js +1 -2
- package/test/callbacks.js +2 -3
- package/test/misc.c +21 -1
- package/test/raylib.js +1 -1
- package/test/sqlite.js +3 -3
- package/test/sync.js +27 -3
- package/build/qemu/2.0.1/koffi_darwin_arm64.tar.gz +0 -0
- package/build/qemu/2.0.1/koffi_darwin_x64.tar.gz +0 -0
- package/build/qemu/2.0.1/koffi_freebsd_arm64.tar.gz +0 -0
- package/build/qemu/2.0.1/koffi_freebsd_ia32.tar.gz +0 -0
- package/build/qemu/2.0.1/koffi_freebsd_x64.tar.gz +0 -0
- package/build/qemu/2.0.1/koffi_linux_arm32hf.tar.gz +0 -0
- package/build/qemu/2.0.1/koffi_linux_arm64.tar.gz +0 -0
- package/build/qemu/2.0.1/koffi_linux_ia32.tar.gz +0 -0
- package/build/qemu/2.0.1/koffi_linux_riscv64hf64.tar.gz +0 -0
- package/build/qemu/2.0.1/koffi_linux_x64.tar.gz +0 -0
- package/build/qemu/2.0.1/koffi_openbsd_ia32.tar.gz +0 -0
- package/build/qemu/2.0.1/koffi_openbsd_x64.tar.gz +0 -0
- package/build/qemu/2.0.1/koffi_win32_arm64.tar.gz +0 -0
- package/build/qemu/2.0.1/koffi_win32_ia32.tar.gz +0 -0
- package/build/qemu/2.0.1/koffi_win32_x64.tar.gz +0 -0
package/CMakeLists.txt
CHANGED
|
@@ -15,11 +15,6 @@ cmake_minimum_required(VERSION 3.6)
|
|
|
15
15
|
project(koffi C CXX ASM)
|
|
16
16
|
|
|
17
17
|
include(CheckCXXCompilerFlag)
|
|
18
|
-
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.9.0")
|
|
19
|
-
cmake_policy(SET CMP0069 NEW)
|
|
20
|
-
include(CheckIPOSupported)
|
|
21
|
-
check_ipo_supported(RESULT USE_LTO)
|
|
22
|
-
endif()
|
|
23
18
|
|
|
24
19
|
find_package(CNoke)
|
|
25
20
|
|
|
@@ -126,6 +121,4 @@ if(NOT MSVC OR CMAKE_C_COMPILER_ID MATCHES "[Cc]lang")
|
|
|
126
121
|
target_compile_options(koffi PRIVATE -fno-finite-loops)
|
|
127
122
|
endif()
|
|
128
123
|
endif()
|
|
129
|
-
|
|
130
|
-
set_target_properties(koffi PROPERTIES INTERPROCEDURAL_OPTIMIZATION TRUE)
|
|
131
|
-
endif()
|
|
124
|
+
enable_unity_build(koffi)
|
package/benchmark/atoi_koffi.js
CHANGED
|
@@ -26,14 +26,14 @@ let sum = 0;
|
|
|
26
26
|
main();
|
|
27
27
|
|
|
28
28
|
function main() {
|
|
29
|
-
let
|
|
29
|
+
let time = 5000;
|
|
30
30
|
|
|
31
31
|
if (process.argv.length >= 3) {
|
|
32
|
-
|
|
33
|
-
if (Number.isNaN(
|
|
32
|
+
time = parseFloat(process.argv[2]) * 1000;
|
|
33
|
+
if (Number.isNaN(time))
|
|
34
34
|
throw new Error('Not a valid number');
|
|
35
|
-
if (
|
|
36
|
-
throw new Error('
|
|
35
|
+
if (time < 0)
|
|
36
|
+
throw new Error('Time must be positive');
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
let lib = koffi.load(process.platform == 'win32' ? 'msvcrt.dll' : null);
|
|
@@ -41,11 +41,15 @@ function main() {
|
|
|
41
41
|
const atoi = lib.cdecl('atoi', 'int', ['str']);
|
|
42
42
|
|
|
43
43
|
let start = performance.now();
|
|
44
|
+
let iterations = 0;
|
|
44
45
|
|
|
45
|
-
|
|
46
|
-
|
|
46
|
+
while (performance.now() - start < time) {
|
|
47
|
+
for (let i = 0; i < 1000000; i++)
|
|
48
|
+
sum += atoi(strings[i % strings.length]);
|
|
49
|
+
|
|
50
|
+
iterations += 1000000;
|
|
47
51
|
}
|
|
48
52
|
|
|
49
|
-
|
|
53
|
+
time = performance.now() - start;
|
|
50
54
|
console.log(JSON.stringify({ iterations: iterations, time: Math.round(time) }));
|
|
51
55
|
}
|
package/benchmark/atoi_napi.js
CHANGED
|
@@ -26,22 +26,26 @@ let sum = 0;
|
|
|
26
26
|
main();
|
|
27
27
|
|
|
28
28
|
function main() {
|
|
29
|
-
let
|
|
29
|
+
let time = 5000;
|
|
30
30
|
|
|
31
31
|
if (process.argv.length >= 3) {
|
|
32
|
-
|
|
33
|
-
if (Number.isNaN(
|
|
32
|
+
time = parseFloat(process.argv[2]) * 1000;
|
|
33
|
+
if (Number.isNaN(time))
|
|
34
34
|
throw new Error('Not a valid number');
|
|
35
|
-
if (
|
|
36
|
-
throw new Error('
|
|
35
|
+
if (time < 0)
|
|
36
|
+
throw new Error('Time must be positive');
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
let start = performance.now();
|
|
40
|
+
let iterations = 0;
|
|
40
41
|
|
|
41
|
-
|
|
42
|
-
|
|
42
|
+
while (performance.now() - start < time) {
|
|
43
|
+
for (let i = 0; i < 1000000; i++)
|
|
44
|
+
sum += atoi.atoi(strings[i % strings.length]);
|
|
45
|
+
|
|
46
|
+
iterations += 1000000;
|
|
43
47
|
}
|
|
44
48
|
|
|
45
|
-
|
|
49
|
+
time = performance.now() - start;
|
|
46
50
|
console.log(JSON.stringify({ iterations: iterations, time: Math.round(time) }));
|
|
47
51
|
}
|
|
@@ -28,14 +28,14 @@ let sum = 0;
|
|
|
28
28
|
main();
|
|
29
29
|
|
|
30
30
|
async function main() {
|
|
31
|
-
let
|
|
31
|
+
let time = 5000;
|
|
32
32
|
|
|
33
33
|
if (process.argv.length >= 3) {
|
|
34
|
-
|
|
35
|
-
if (Number.isNaN(
|
|
34
|
+
time = parseFloat(process.argv[2]) * 1000;
|
|
35
|
+
if (Number.isNaN(time))
|
|
36
36
|
throw new Error('Not a valid number');
|
|
37
|
-
if (
|
|
38
|
-
throw new Error('
|
|
37
|
+
if (time < 0)
|
|
38
|
+
throw new Error('Time must be positive');
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
const lib = ffi.Library(process.platform == 'win32' ? 'msvcrt.dll' : null, {
|
|
@@ -43,14 +43,15 @@ async function main() {
|
|
|
43
43
|
});
|
|
44
44
|
|
|
45
45
|
let start = performance.now();
|
|
46
|
+
let iterations = 0;
|
|
46
47
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
while (performance.now() - start < time) {
|
|
49
|
+
for (let i = 0; i < 1000000; i++)
|
|
50
|
+
sum += lib.atoi(strings[i % strings.length]);
|
|
50
51
|
|
|
51
|
-
|
|
52
|
+
iterations += 1000000;
|
|
52
53
|
}
|
|
53
54
|
|
|
54
|
-
|
|
55
|
+
time = performance.now() - start;
|
|
55
56
|
console.log(JSON.stringify({ iterations: iterations, time: Math.round(time) }));
|
|
56
57
|
}
|
package/benchmark/raylib_cc.cc
CHANGED
|
@@ -18,10 +18,10 @@ namespace RG {
|
|
|
18
18
|
|
|
19
19
|
int Main(int argc, char **argv)
|
|
20
20
|
{
|
|
21
|
-
int
|
|
21
|
+
int time = 5000;
|
|
22
22
|
|
|
23
23
|
if (argc >= 2) {
|
|
24
|
-
if (!ParseInt(argv[1], &
|
|
24
|
+
if (!ParseInt(argv[1], &time))
|
|
25
25
|
return 1;
|
|
26
26
|
}
|
|
27
27
|
|
|
@@ -34,15 +34,16 @@ int Main(int argc, char **argv)
|
|
|
34
34
|
Font font = GetFontDefault();
|
|
35
35
|
|
|
36
36
|
int64_t start = GetMonotonicTime();
|
|
37
|
+
int64_t iterations = 0;
|
|
37
38
|
|
|
38
|
-
|
|
39
|
+
while (GetMonotonicTime() - start < time) {
|
|
39
40
|
ImageClearBackground(&img, Color { 0, 0, 0, 255 });
|
|
40
41
|
|
|
41
|
-
for (int
|
|
42
|
+
for (int i = 0; i < 3600; i++) {
|
|
42
43
|
const char *text = "Hello World!";
|
|
43
44
|
float text_width = MeasureTextEx(font, text, 10, 1).x;
|
|
44
45
|
|
|
45
|
-
double angle = (
|
|
46
|
+
double angle = (i * 7) * PI / 180;
|
|
46
47
|
Color color = {
|
|
47
48
|
(unsigned char)(127.5 + 127.5 * sin(angle)),
|
|
48
49
|
(unsigned char)(127.5 + 127.5 * sin(angle + PI / 2)),
|
|
@@ -50,16 +51,18 @@ int Main(int argc, char **argv)
|
|
|
50
51
|
255
|
|
51
52
|
};
|
|
52
53
|
Vector2 pos = {
|
|
53
|
-
(float)((img.width / 2 - text_width / 2) +
|
|
54
|
-
(float)((img.height / 2 - 16) +
|
|
54
|
+
(float)((img.width / 2 - text_width / 2) + i * 0.1 * cos(angle - PI / 2)),
|
|
55
|
+
(float)((img.height / 2 - 16) + i * 0.1 * sin(angle - PI / 2))
|
|
55
56
|
};
|
|
56
57
|
|
|
57
58
|
ImageDrawTextEx(&img, font, text, pos, 10, 1, color);
|
|
58
59
|
}
|
|
60
|
+
|
|
61
|
+
iterations += 3600;
|
|
59
62
|
}
|
|
60
63
|
|
|
61
|
-
|
|
62
|
-
PrintLn("{\"iterations\": %1
|
|
64
|
+
time = GetMonotonicTime() - start;
|
|
65
|
+
PrintLn("{\"iterations\": %1, \"time\": %2}", iterations, time);
|
|
63
66
|
|
|
64
67
|
return 0;
|
|
65
68
|
}
|
|
@@ -14,7 +14,6 @@
|
|
|
14
14
|
// along with this program. If not, see https://www.gnu.org/licenses/.
|
|
15
15
|
|
|
16
16
|
const koffi = require('./build/koffi.node');
|
|
17
|
-
const path = require('path');
|
|
18
17
|
|
|
19
18
|
const Color = koffi.struct('Color', {
|
|
20
19
|
r: 'uchar',
|
|
@@ -71,17 +70,17 @@ const Font = koffi.struct('Font', {
|
|
|
71
70
|
main();
|
|
72
71
|
|
|
73
72
|
function main() {
|
|
74
|
-
let
|
|
73
|
+
let time = 5000;
|
|
75
74
|
|
|
76
75
|
if (process.argv.length >= 3) {
|
|
77
|
-
|
|
78
|
-
if (Number.isNaN(
|
|
76
|
+
time = parseFloat(process.argv[2]) * 1000;
|
|
77
|
+
if (Number.isNaN(time))
|
|
79
78
|
throw new Error('Not a valid number');
|
|
80
|
-
if (
|
|
81
|
-
throw new Error('
|
|
79
|
+
if (time < 0)
|
|
80
|
+
throw new Error('Time must be positive');
|
|
82
81
|
}
|
|
83
82
|
|
|
84
|
-
let lib_filename =
|
|
83
|
+
let lib_filename = __dirname + '/build/raylib' + koffi.extension;
|
|
85
84
|
let lib = koffi.load(lib_filename);
|
|
86
85
|
|
|
87
86
|
const InitWindow = lib.cdecl('InitWindow', 'void', ['int', 'int', 'str']);
|
|
@@ -103,15 +102,16 @@ function main() {
|
|
|
103
102
|
let font = GetFontDefault();
|
|
104
103
|
|
|
105
104
|
let start = performance.now();
|
|
105
|
+
let iterations = 0;
|
|
106
106
|
|
|
107
|
-
|
|
107
|
+
while (performance.now() - start < time) {
|
|
108
108
|
ImageClearBackground(img, { r: 0, g: 0, b: 0, a: 255 });
|
|
109
109
|
|
|
110
|
-
for (let
|
|
110
|
+
for (let i = 0; i < 3600; i++) {
|
|
111
111
|
let text = 'Hello World!';
|
|
112
112
|
let text_width = MeasureTextEx(font, text, 10, 1).x;
|
|
113
113
|
|
|
114
|
-
let angle = (
|
|
114
|
+
let angle = (i * 7) * Math.PI / 180;
|
|
115
115
|
let color = {
|
|
116
116
|
r: 127.5 + 127.5 * Math.sin(angle),
|
|
117
117
|
g: 127.5 + 127.5 * Math.sin(angle + Math.PI / 2),
|
|
@@ -119,14 +119,16 @@ function main() {
|
|
|
119
119
|
a: 255
|
|
120
120
|
};
|
|
121
121
|
let pos = {
|
|
122
|
-
x: (img.width / 2 - text_width / 2) +
|
|
123
|
-
y: (img.height / 2 - 16) +
|
|
122
|
+
x: (img.width / 2 - text_width / 2) + i * 0.1 * Math.cos(angle - Math.PI / 2),
|
|
123
|
+
y: (img.height / 2 - 16) + i * 0.1 * Math.sin(angle - Math.PI / 2)
|
|
124
124
|
};
|
|
125
125
|
|
|
126
126
|
ImageDrawTextEx(img, font, text, pos, 10, 1, color);
|
|
127
127
|
}
|
|
128
|
+
|
|
129
|
+
iterations += 3600;
|
|
128
130
|
}
|
|
129
131
|
|
|
130
|
-
|
|
132
|
+
time = performance.now() - start;
|
|
131
133
|
console.log(JSON.stringify({ iterations: iterations, time: Math.round(time) }));
|
|
132
134
|
}
|
|
@@ -17,7 +17,6 @@ const ref = require('ref-napi');
|
|
|
17
17
|
const ffi = require('ffi-napi');
|
|
18
18
|
const struct = require('ref-struct-di')(ref);
|
|
19
19
|
const koffi = require('./build/koffi.node');
|
|
20
|
-
const path = require('path');
|
|
21
20
|
|
|
22
21
|
const Color = struct({
|
|
23
22
|
r: 'uchar',
|
|
@@ -87,17 +86,17 @@ const Font = struct({
|
|
|
87
86
|
main();
|
|
88
87
|
|
|
89
88
|
function main() {
|
|
90
|
-
let
|
|
89
|
+
let time = 5000;
|
|
91
90
|
|
|
92
91
|
if (process.argv.length >= 3) {
|
|
93
|
-
|
|
94
|
-
if (Number.isNaN(
|
|
92
|
+
time = parseFloat(process.argv[2]) * 1000;
|
|
93
|
+
if (Number.isNaN(time))
|
|
95
94
|
throw new Error('Not a valid number');
|
|
96
|
-
if (
|
|
97
|
-
throw new Error('
|
|
95
|
+
if (time < 0)
|
|
96
|
+
throw new Error('Time must be positive');
|
|
98
97
|
}
|
|
99
98
|
|
|
100
|
-
let lib_filename =
|
|
99
|
+
let lib_filename = __dirname + '/build/raylib' + koffi.extension;
|
|
101
100
|
|
|
102
101
|
const r = ffi.Library(lib_filename, {
|
|
103
102
|
InitWindow: ['void', ['int', 'int', 'string']],
|
|
@@ -121,15 +120,16 @@ function main() {
|
|
|
121
120
|
let font = r.GetFontDefault();
|
|
122
121
|
|
|
123
122
|
let start = performance.now();
|
|
123
|
+
let iterations = 0;
|
|
124
124
|
|
|
125
|
-
|
|
125
|
+
while (performance.now() - start < time) {
|
|
126
126
|
r.ImageClearBackground(imgp, new Color({ r: 0, g: 0, b: 0, a: 255 }));
|
|
127
127
|
|
|
128
|
-
for (let
|
|
128
|
+
for (let i = 0; i < 3600; i++) {
|
|
129
129
|
let text = 'Hello World!';
|
|
130
130
|
let text_width = r.MeasureTextEx(font, text, 10, 1).x;
|
|
131
131
|
|
|
132
|
-
let angle = (
|
|
132
|
+
let angle = (i * 7) * Math.PI / 180;
|
|
133
133
|
let color = new Color({
|
|
134
134
|
r: 127.5 + 127.5 * Math.sin(angle),
|
|
135
135
|
g: 127.5 + 127.5 * Math.sin(angle + Math.PI / 2),
|
|
@@ -137,14 +137,16 @@ function main() {
|
|
|
137
137
|
a: 255
|
|
138
138
|
});
|
|
139
139
|
let pos = new Vector2({
|
|
140
|
-
x: (img.width / 2 - text_width / 2) +
|
|
141
|
-
y: (img.height / 2 - 16) +
|
|
140
|
+
x: (img.width / 2 - text_width / 2) + i * 0.1 * Math.cos(angle - Math.PI / 2),
|
|
141
|
+
y: (img.height / 2 - 16) + i * 0.1 * Math.sin(angle - Math.PI / 2)
|
|
142
142
|
});
|
|
143
143
|
|
|
144
144
|
r.ImageDrawTextEx(imgp, font, text, pos, 10, 1, color);
|
|
145
145
|
}
|
|
146
|
+
|
|
147
|
+
iterations += 3600;
|
|
146
148
|
}
|
|
147
149
|
|
|
148
|
-
|
|
150
|
+
time = performance.now() - start;
|
|
149
151
|
console.log(JSON.stringify({ iterations: iterations, time: Math.round(time) }));
|
|
150
152
|
}
|
|
@@ -18,14 +18,14 @@ const r = require('raylib');
|
|
|
18
18
|
main();
|
|
19
19
|
|
|
20
20
|
function main() {
|
|
21
|
-
let
|
|
21
|
+
let time = 5000;
|
|
22
22
|
|
|
23
23
|
if (process.argv.length >= 3) {
|
|
24
|
-
|
|
25
|
-
if (Number.isNaN(
|
|
24
|
+
time = parseFloat(process.argv[2]) * 1000;
|
|
25
|
+
if (Number.isNaN(time))
|
|
26
26
|
throw new Error('Not a valid number');
|
|
27
|
-
if (
|
|
28
|
-
throw new Error('
|
|
27
|
+
if (time < 0)
|
|
28
|
+
throw new Error('Time must be positive');
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
// We need to call InitWindow before using anything else (such as fonts)
|
|
@@ -37,15 +37,16 @@ function main() {
|
|
|
37
37
|
let font = r.GetFontDefault();
|
|
38
38
|
|
|
39
39
|
let start = performance.now();
|
|
40
|
+
let iterations = 0;
|
|
40
41
|
|
|
41
|
-
|
|
42
|
+
while (performance.now() - start < time) {
|
|
42
43
|
r.ImageClearBackground(img, { r: 0, g: 0, b: 0, a: 255 });
|
|
43
44
|
|
|
44
|
-
for (let
|
|
45
|
+
for (let i = 0; i < 3600; i++) {
|
|
45
46
|
let text = 'Hello World!';
|
|
46
47
|
let text_width = r.MeasureTextEx(font, text, 10, 1).x;
|
|
47
48
|
|
|
48
|
-
let angle = (
|
|
49
|
+
let angle = (i * 7) * Math.PI / 180;
|
|
49
50
|
let color = {
|
|
50
51
|
r: 127.5 + 127.5 * Math.sin(angle),
|
|
51
52
|
g: 127.5 + 127.5 * Math.sin(angle + Math.PI / 2),
|
|
@@ -53,14 +54,16 @@ function main() {
|
|
|
53
54
|
a: 255
|
|
54
55
|
};
|
|
55
56
|
let pos = {
|
|
56
|
-
x: (img.width / 2 - text_width / 2) +
|
|
57
|
-
y: (img.height / 2 - 16) +
|
|
57
|
+
x: (img.width / 2 - text_width / 2) + i * 0.1 * Math.cos(angle - Math.PI / 2),
|
|
58
|
+
y: (img.height / 2 - 16) + i * 0.1 * Math.sin(angle - Math.PI / 2)
|
|
58
59
|
};
|
|
59
60
|
|
|
60
61
|
r.ImageDrawTextEx(img, font, text, pos, 10, 1, color);
|
|
61
62
|
}
|
|
63
|
+
|
|
64
|
+
iterations += 3600;
|
|
62
65
|
}
|
|
63
66
|
|
|
64
|
-
|
|
67
|
+
time = performance.now() - start;
|
|
65
68
|
console.log(JSON.stringify({ iterations: iterations, time: Math.round(time) }));
|
|
66
69
|
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/doc/changes.md
CHANGED
|
@@ -10,7 +10,7 @@ The API was changed in 2.x in a few ways, in order to reduce some excessively "m
|
|
|
10
10
|
You may need to change your code if you use:
|
|
11
11
|
|
|
12
12
|
- Callback functions
|
|
13
|
-
- Opaque
|
|
13
|
+
- Opaque types
|
|
14
14
|
- `koffi.introspect()`
|
|
15
15
|
|
|
16
16
|
#### Callback types
|
|
@@ -66,11 +66,13 @@ console.log(ret);
|
|
|
66
66
|
|
|
67
67
|
Koffi 1.x only supported [transient callbacks](functions.md#javascript-callbacks), you must use Koffi 2.x for registered callbacks.
|
|
68
68
|
|
|
69
|
-
#### Opaque
|
|
69
|
+
#### Opaque types
|
|
70
70
|
|
|
71
|
-
In Koffi 1.x, opaque handles were defined in a way that made them usable directly as parameter and return types, obscuring the underlying pointer. Now, you must use them through a pointer, and use an array for output parameters.
|
|
71
|
+
In Koffi 1.x, opaque handles were defined in a way that made them usable directly as parameter and return types, obscuring the underlying pointer. Now, in Koffi 2.0, you must use them through a pointer, and use an array for output parameters.
|
|
72
72
|
|
|
73
|
-
|
|
73
|
+
In addition to that, `koffi.handle()` has been deprecated in Koffi 2.1 and replaced with `koffi.opaque()`. They work the same but new code should use `koffi.opaque()`, the former one will eventually be removed in Koffi 3.0.
|
|
74
|
+
|
|
75
|
+
For functions that return opaque pointers or pass them by parameter:
|
|
74
76
|
|
|
75
77
|
```js
|
|
76
78
|
// Koffi 1.x
|
|
@@ -86,9 +88,10 @@ fclose(fp);
|
|
|
86
88
|
```
|
|
87
89
|
|
|
88
90
|
```js
|
|
89
|
-
// Koffi 2.
|
|
91
|
+
// Koffi 2.1
|
|
90
92
|
|
|
91
|
-
const FILE = koffi.handle('FILE');
|
|
93
|
+
// If you use Koffi 2.0: const FILE = koffi.handle('FILE');
|
|
94
|
+
const FILE = koffi.opaque('FILE');
|
|
92
95
|
const fopen = lib.func('fopen', 'FILE *', ['str', 'str']);
|
|
93
96
|
const fopen = lib.func('fclose', 'int', ['FILE *']);
|
|
94
97
|
|
|
@@ -120,9 +123,10 @@ sqlite3_close_v2(db);
|
|
|
120
123
|
```
|
|
121
124
|
|
|
122
125
|
```js
|
|
123
|
-
// Koffi 2.
|
|
126
|
+
// Koffi 2.1
|
|
124
127
|
|
|
125
|
-
const sqlite3 = koffi.handle('sqlite3');
|
|
128
|
+
// If you use Koffi 2.0: const sqlite3 = koffi.handle('sqlite3');
|
|
129
|
+
const sqlite3 = koffi.opaque('sqlite3');
|
|
126
130
|
|
|
127
131
|
const sqlite3_open_v2 = lib.func('int sqlite3_open_v2(const char *, _Out_ sqlite3 **db, int, const char *)');
|
|
128
132
|
const sqlite3_close_v2 = lib.func('int sqlite3_close_v2(sqlite3 *db)');
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -10,7 +10,7 @@ The API was changed in 2.x in a few ways, in order to reduce some excessively "m
|
|
|
10
10
|
You may need to change your code if you use:
|
|
11
11
|
|
|
12
12
|
- Callback functions
|
|
13
|
-
- Opaque
|
|
13
|
+
- Opaque types
|
|
14
14
|
- `koffi.introspect()`
|
|
15
15
|
|
|
16
16
|
#### Callback types
|
|
@@ -66,11 +66,13 @@ console.log(ret);
|
|
|
66
66
|
|
|
67
67
|
Koffi 1.x only supported [transient callbacks](functions.md#javascript-callbacks), you must use Koffi 2.x for registered callbacks.
|
|
68
68
|
|
|
69
|
-
#### Opaque
|
|
69
|
+
#### Opaque types
|
|
70
70
|
|
|
71
|
-
In Koffi 1.x, opaque handles were defined in a way that made them usable directly as parameter and return types, obscuring the underlying pointer. Now, you must use them through a pointer, and use an array for output parameters.
|
|
71
|
+
In Koffi 1.x, opaque handles were defined in a way that made them usable directly as parameter and return types, obscuring the underlying pointer. Now, in Koffi 2.0, you must use them through a pointer, and use an array for output parameters.
|
|
72
72
|
|
|
73
|
-
|
|
73
|
+
In addition to that, `koffi.handle()` has been deprecated in Koffi 2.1 and replaced with `koffi.opaque()`. They work the same but new code should use `koffi.opaque()`, the former one will eventually be removed in Koffi 3.0.
|
|
74
|
+
|
|
75
|
+
For functions that return opaque pointers or pass them by parameter:
|
|
74
76
|
|
|
75
77
|
```js
|
|
76
78
|
// Koffi 1.x
|
|
@@ -86,9 +88,10 @@ fclose(fp);
|
|
|
86
88
|
```
|
|
87
89
|
|
|
88
90
|
```js
|
|
89
|
-
// Koffi 2.
|
|
91
|
+
// Koffi 2.1
|
|
90
92
|
|
|
91
|
-
const FILE = koffi.handle('FILE');
|
|
93
|
+
// If you use Koffi 2.0: const FILE = koffi.handle('FILE');
|
|
94
|
+
const FILE = koffi.opaque('FILE');
|
|
92
95
|
const fopen = lib.func('fopen', 'FILE *', ['str', 'str']);
|
|
93
96
|
const fopen = lib.func('fclose', 'int', ['FILE *']);
|
|
94
97
|
|
|
@@ -120,9 +123,10 @@ sqlite3_close_v2(db);
|
|
|
120
123
|
```
|
|
121
124
|
|
|
122
125
|
```js
|
|
123
|
-
// Koffi 2.
|
|
126
|
+
// Koffi 2.1
|
|
124
127
|
|
|
125
|
-
const sqlite3 = koffi.handle('sqlite3');
|
|
128
|
+
// If you use Koffi 2.0: const sqlite3 = koffi.handle('sqlite3');
|
|
129
|
+
const sqlite3 = koffi.opaque('sqlite3');
|
|
126
130
|
|
|
127
131
|
const sqlite3_open_v2 = lib.func('int sqlite3_open_v2(const char *, _Out_ sqlite3 **db, int, const char *)');
|
|
128
132
|
const sqlite3_close_v2 = lib.func('int sqlite3_close_v2(sqlite3 *db)');
|
|
@@ -114,7 +114,7 @@ By default, Koffi will only forward arguments from Javascript to C. However, man
|
|
|
114
114
|
For simplicity, and because Javascript only has value semantics for primitive types, Koffi can marshal out (or in/out) two types of parameters:
|
|
115
115
|
|
|
116
116
|
- [Structs](types.md#struct-types) (to/from JS objects)
|
|
117
|
-
- [Opaque
|
|
117
|
+
- [Opaque types](types.md#opaque-types)
|
|
118
118
|
|
|
119
119
|
In order to change an argument from input-only to output or input/output, use the following functions:
|
|
120
120
|
|
|
@@ -152,7 +152,7 @@ gettimeofday(tv, null);
|
|
|
152
152
|
console.log(tv);
|
|
153
153
|
```
|
|
154
154
|
|
|
155
|
-
#### Opaque
|
|
155
|
+
#### Opaque type example
|
|
156
156
|
|
|
157
157
|
This example opens an in-memory SQLite database, and uses the node-ffi-style function declaration syntax.
|
|
158
158
|
|
|
@@ -160,7 +160,7 @@ This example opens an in-memory SQLite database, and uses the node-ffi-style fun
|
|
|
160
160
|
const koffi = require('koffi');
|
|
161
161
|
const lib = koffi.load('sqlite3.so');
|
|
162
162
|
|
|
163
|
-
const sqlite3 = koffi.
|
|
163
|
+
const sqlite3 = koffi.opaque('sqlite3');
|
|
164
164
|
|
|
165
165
|
// Use koffi.out() on a double pointer to copy out (from C to JS) after the call
|
|
166
166
|
const sqlite3_open_v2 = lib.func('sqlite3_open_v2', 'int', ['str', koffi.out(koffi.pointer(sqlite3, 2)), 'int', 'str']);
|
|
@@ -181,7 +181,7 @@ sqlite3_close_v2(db);
|
|
|
181
181
|
|
|
182
182
|
Some C functions return heap-allocated values directly or through output parameters. While Koffi automatically converts values from C to JS (to a string or an object), it does not know when something needs to be freed, or how.
|
|
183
183
|
|
|
184
|
-
For opaque
|
|
184
|
+
For opaque types, such as FILE, this does not matter because you will explicitly call `fclose()` on them. But some values (such as strings) get implicitly converted by Koffi, and you lose access to the original pointer. This creates a leak if the string is heap-allocated.
|
|
185
185
|
|
|
186
186
|
To avoid this, you can instruct Koffi to call a function on the original pointer once the conversion is done, by creating a **disposable type** with `koffi.dispose(name, type, func)`. This creates a type derived from another type, the only difference being that *func* gets called with the original pointer once the value has been converted and is not needed anymore.
|
|
187
187
|
|