koffi 3.0.2 → 3.1.0
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/CHANGELOG.md +25 -7
- package/cnoke.cjs +9 -9
- package/doc/benchmarks.md +2 -2
- package/doc/callbacks.md +7 -26
- package/doc/{input.md → composites.md} +161 -147
- package/doc/contribute.md +2 -1
- package/doc/index.md +0 -14
- package/doc/{functions.md → load.md} +54 -113
- package/doc/migration.md +4 -7
- package/doc/misc.md +0 -103
- package/doc/output.md +5 -11
- package/doc/pointers.md +76 -17
- package/doc/primitives.md +151 -0
- package/doc/start.md +3 -13
- package/doc/types.md +88 -0
- package/doc/unions.md +0 -186
- package/doc/values.md +134 -0
- package/index.d.ts +23 -4
- package/lib/native/base/base.cc +66 -24
- package/lib/native/base/base.hh +55 -153
- package/package.json +15 -15
- package/src/koffi/CMakeLists.txt +19 -17
- package/src/koffi/index.cjs +15 -10
- package/src/koffi/index.js +6 -6
- package/src/koffi/indirect.cjs +15 -10
- package/src/koffi/indirect.js +6 -6
- package/src/koffi/src/abi/arm64.cc +47 -62
- package/src/koffi/src/abi/riscv64.cc +38 -57
- package/src/koffi/src/abi/x64sysv.cc +38 -57
- package/src/koffi/src/abi/x64win.cc +47 -65
- package/src/koffi/src/abi/x86.cc +46 -59
- package/src/koffi/src/call.cc +239 -133
- package/src/koffi/src/call.hh +5 -10
- package/src/koffi/src/ffi.cc +211 -90
- package/src/koffi/src/ffi.hh +36 -16
- package/src/koffi/src/parser.cc +3 -3
- package/src/koffi/src/parser.hh +2 -2
- package/src/koffi/src/static.js +3 -0
- package/src/koffi/src/type.cc +43 -33
- package/src/koffi/src/type.hh +1 -1
- package/src/koffi/src/util.cc +73 -173
- package/src/koffi/src/util.hh +84 -43
- package/src/koffi/src/uv.cc +1 -1
- package/vendor/node-addon-api/README.md +1 -1
- package/vendor/node-addon-api/napi-inl.h +213 -35
- package/vendor/node-addon-api/napi.h +118 -7
- package/doc/variables.md +0 -102
package/src/koffi/index.cjs
CHANGED
|
@@ -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
|
-
|
|
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)
|
|
@@ -29,7 +34,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
29
34
|
));
|
|
30
35
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
31
36
|
|
|
32
|
-
//
|
|
37
|
+
// ../cnoke/src/abi.js
|
|
33
38
|
function determineAbi() {
|
|
34
39
|
let abi = process.arch.toString();
|
|
35
40
|
if (abi == "riscv32" || abi == "riscv64") {
|
|
@@ -119,20 +124,20 @@ function decodeElfHeader(buf) {
|
|
|
119
124
|
}
|
|
120
125
|
var import_node_fs;
|
|
121
126
|
var init_abi = __esm({
|
|
122
|
-
"
|
|
127
|
+
"../cnoke/src/abi.js"() {
|
|
123
128
|
import_node_fs = __toESM(require("node:fs"), 1);
|
|
124
129
|
}
|
|
125
130
|
});
|
|
126
131
|
|
|
127
|
-
//
|
|
132
|
+
// package.json
|
|
128
133
|
var package_default;
|
|
129
134
|
var init_package = __esm({
|
|
130
|
-
"
|
|
131
|
-
package_default = { name: "koffi", version: "3.0
|
|
135
|
+
"package.json"() {
|
|
136
|
+
package_default = { name: "koffi", version: "3.1.0", cnoke: { api: "../../vendor/node-api-headers", output: "../../bin/Koffi/{{ toolchain }}", node: 16, napi: 8 } };
|
|
132
137
|
}
|
|
133
138
|
});
|
|
134
139
|
|
|
135
|
-
// src/
|
|
140
|
+
// src/init.js
|
|
136
141
|
var init_exports = {};
|
|
137
142
|
__export(init_exports, {
|
|
138
143
|
detectPlatform: () => detectPlatform,
|
|
@@ -228,7 +233,7 @@ function wrapNative(native2, version2) {
|
|
|
228
233
|
}
|
|
229
234
|
var import_node_util, import_node_fs2, import_node_module, require2;
|
|
230
235
|
var init_init = __esm({
|
|
231
|
-
"src/
|
|
236
|
+
"src/init.js"() {
|
|
232
237
|
import_node_util = __toESM(require("node:util"));
|
|
233
238
|
import_node_fs2 = __toESM(require("node:fs"));
|
|
234
239
|
import_node_module = require("node:module");
|
|
@@ -238,7 +243,7 @@ var init_init = __esm({
|
|
|
238
243
|
}
|
|
239
244
|
});
|
|
240
245
|
|
|
241
|
-
//
|
|
246
|
+
// index.cjs
|
|
242
247
|
var { detectPlatform: detectPlatform2, loadDynamic: loadDynamic2, wrapNative: wrapNative2 } = (init_init(), __toCommonJS(init_exports));
|
|
243
248
|
var { loadStatic } = require("./src/static.cjs");
|
|
244
249
|
var [version, pkg, triplets] = detectPlatform2();
|
package/src/koffi/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
// src/
|
|
1
|
+
// src/init.js
|
|
2
2
|
import util from "node:util";
|
|
3
3
|
import fs2 from "node:fs";
|
|
4
4
|
import { createRequire } from "node:module";
|
|
5
5
|
|
|
6
|
-
//
|
|
6
|
+
// ../cnoke/src/abi.js
|
|
7
7
|
import fs from "node:fs";
|
|
8
8
|
function determineAbi() {
|
|
9
9
|
let abi = process.arch.toString();
|
|
@@ -93,10 +93,10 @@ function decodeElfHeader(buf) {
|
|
|
93
93
|
return header;
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
-
//
|
|
97
|
-
var package_default = { name: "koffi", version: "3.0
|
|
96
|
+
// package.json
|
|
97
|
+
var package_default = { name: "koffi", version: "3.1.0", cnoke: { api: "../../vendor/node-api-headers", output: "../../bin/Koffi/{{ toolchain }}", node: 16, napi: 8 } };
|
|
98
98
|
|
|
99
|
-
// src/
|
|
99
|
+
// src/init.js
|
|
100
100
|
var require2 = createRequire(import.meta.url);
|
|
101
101
|
function detectPlatform() {
|
|
102
102
|
if (process.versions.napi == null || process.versions.napi < package_default.cnoke.napi) {
|
|
@@ -186,7 +186,7 @@ function wrapNative(native2, version2) {
|
|
|
186
186
|
}
|
|
187
187
|
}
|
|
188
188
|
|
|
189
|
-
//
|
|
189
|
+
// index.js
|
|
190
190
|
import { loadStatic } from "./src/static.js";
|
|
191
191
|
var [version, pkg, triplets] = detectPlatform();
|
|
192
192
|
var native = loadStatic(pkg) ?? loadDynamic(import.meta.dirname, pkg, triplets);
|
package/src/koffi/indirect.cjs
CHANGED
|
@@ -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
|
-
|
|
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)
|
|
@@ -29,7 +34,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
29
34
|
));
|
|
30
35
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
31
36
|
|
|
32
|
-
//
|
|
37
|
+
// ../cnoke/src/abi.js
|
|
33
38
|
function determineAbi() {
|
|
34
39
|
let abi = process.arch.toString();
|
|
35
40
|
if (abi == "riscv32" || abi == "riscv64") {
|
|
@@ -119,20 +124,20 @@ function decodeElfHeader(buf) {
|
|
|
119
124
|
}
|
|
120
125
|
var import_node_fs;
|
|
121
126
|
var init_abi = __esm({
|
|
122
|
-
"
|
|
127
|
+
"../cnoke/src/abi.js"() {
|
|
123
128
|
import_node_fs = __toESM(require("node:fs"), 1);
|
|
124
129
|
}
|
|
125
130
|
});
|
|
126
131
|
|
|
127
|
-
//
|
|
132
|
+
// package.json
|
|
128
133
|
var package_default;
|
|
129
134
|
var init_package = __esm({
|
|
130
|
-
"
|
|
131
|
-
package_default = { name: "koffi", version: "3.0
|
|
135
|
+
"package.json"() {
|
|
136
|
+
package_default = { name: "koffi", version: "3.1.0", cnoke: { api: "../../vendor/node-api-headers", output: "../../bin/Koffi/{{ toolchain }}", node: 16, napi: 8 } };
|
|
132
137
|
}
|
|
133
138
|
});
|
|
134
139
|
|
|
135
|
-
// src/
|
|
140
|
+
// src/init.js
|
|
136
141
|
var init_exports = {};
|
|
137
142
|
__export(init_exports, {
|
|
138
143
|
detectPlatform: () => detectPlatform,
|
|
@@ -228,7 +233,7 @@ function wrapNative(native2, version2) {
|
|
|
228
233
|
}
|
|
229
234
|
var import_node_util, import_node_fs2, import_node_module, require2;
|
|
230
235
|
var init_init = __esm({
|
|
231
|
-
"src/
|
|
236
|
+
"src/init.js"() {
|
|
232
237
|
import_node_util = __toESM(require("node:util"));
|
|
233
238
|
import_node_fs2 = __toESM(require("node:fs"));
|
|
234
239
|
import_node_module = require("node:module");
|
|
@@ -238,7 +243,7 @@ var init_init = __esm({
|
|
|
238
243
|
}
|
|
239
244
|
});
|
|
240
245
|
|
|
241
|
-
//
|
|
246
|
+
// indirect.cjs
|
|
242
247
|
var { detectPlatform: detectPlatform2, loadDynamic: loadDynamic2, wrapNative: wrapNative2 } = (init_init(), __toCommonJS(init_exports));
|
|
243
248
|
var [version, pkg, triplets] = detectPlatform2();
|
|
244
249
|
var native = loadDynamic2(__dirname, pkg, triplets);
|
package/src/koffi/indirect.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
// src/
|
|
1
|
+
// src/init.js
|
|
2
2
|
import util from "node:util";
|
|
3
3
|
import fs2 from "node:fs";
|
|
4
4
|
import { createRequire } from "node:module";
|
|
5
5
|
|
|
6
|
-
//
|
|
6
|
+
// ../cnoke/src/abi.js
|
|
7
7
|
import fs from "node:fs";
|
|
8
8
|
function determineAbi() {
|
|
9
9
|
let abi = process.arch.toString();
|
|
@@ -93,10 +93,10 @@ function decodeElfHeader(buf) {
|
|
|
93
93
|
return header;
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
-
//
|
|
97
|
-
var package_default = { name: "koffi", version: "3.0
|
|
96
|
+
// package.json
|
|
97
|
+
var package_default = { name: "koffi", version: "3.1.0", cnoke: { api: "../../vendor/node-api-headers", output: "../../bin/Koffi/{{ toolchain }}", node: 16, napi: 8 } };
|
|
98
98
|
|
|
99
|
-
// src/
|
|
99
|
+
// src/init.js
|
|
100
100
|
var require2 = createRequire(import.meta.url);
|
|
101
101
|
function detectPlatform() {
|
|
102
102
|
if (process.versions.napi == null || process.versions.napi < package_default.cnoke.napi) {
|
|
@@ -186,7 +186,7 @@ function wrapNative(native2, version2) {
|
|
|
186
186
|
}
|
|
187
187
|
}
|
|
188
188
|
|
|
189
|
-
//
|
|
189
|
+
// indirect.js
|
|
190
190
|
var [version, pkg, triplets] = detectPlatform();
|
|
191
191
|
var native = loadDynamic(import.meta.dirname, pkg, triplets);
|
|
192
192
|
wrapNative(native, version);
|
|
@@ -133,9 +133,9 @@ static HfaInfo IsHFA(const TypeInfo *type)
|
|
|
133
133
|
|
|
134
134
|
bool AnalyseFunction(Napi::Env, InstanceData *instance, FunctionInfo *func)
|
|
135
135
|
{
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
136
|
+
int gpr_index = 0;
|
|
137
|
+
int vec_index = 0;
|
|
138
|
+
int stack_offset = 0;
|
|
139
139
|
|
|
140
140
|
#if defined(_M_ARM64EC)
|
|
141
141
|
int gpr_max = func->variadic ? 4 : 8;
|
|
@@ -542,8 +542,10 @@ bool AnalyseFunction(Napi::Env, InstanceData *instance, FunctionInfo *func)
|
|
|
542
542
|
return true;
|
|
543
543
|
}
|
|
544
544
|
|
|
545
|
-
#
|
|
546
|
-
#pragma GCC diagnostic
|
|
545
|
+
#if defined(__GNUC__) || defined(__clang__)
|
|
546
|
+
#pragma GCC diagnostic push
|
|
547
|
+
#pragma GCC diagnostic ignored "-Wunused-parameter"
|
|
548
|
+
#endif
|
|
547
549
|
|
|
548
550
|
namespace {
|
|
549
551
|
#if defined(MUST_TAIL)
|
|
@@ -705,14 +707,9 @@ namespace {
|
|
|
705
707
|
OP(PushAggregateReg) {
|
|
706
708
|
napi_value arg = args[inst->a];
|
|
707
709
|
|
|
708
|
-
if (!IsObject(call->env, arg)) [[unlikely]] {
|
|
709
|
-
ThrowError<Napi::TypeError>(call->env, "Unexpected %1 value, expected object", GetValueType(call->instance, arg));
|
|
710
|
-
return call->env.Null();
|
|
711
|
-
}
|
|
712
|
-
|
|
713
710
|
uint8_t *ptr = base + inst->b1;
|
|
714
711
|
|
|
715
|
-
if (!call->PushObject(arg, inst->type, ptr))
|
|
712
|
+
if (!call->PushObject(arg, inst->type, ptr)) [[unlikely]]
|
|
716
713
|
return call->env.Null();
|
|
717
714
|
|
|
718
715
|
NEXT();
|
|
@@ -720,15 +717,10 @@ namespace {
|
|
|
720
717
|
OP(PushAggregateMem) {
|
|
721
718
|
napi_value arg = args[inst->a];
|
|
722
719
|
|
|
723
|
-
if (!IsObject(call->env, arg)) [[unlikely]] {
|
|
724
|
-
ThrowError<Napi::TypeError>(call->env, "Unexpected %1 value, expected object", GetValueType(call->instance, arg));
|
|
725
|
-
return call->env.Null();
|
|
726
|
-
}
|
|
727
|
-
|
|
728
720
|
uint8_t *ptr = call->AllocHeap(inst->type->size);
|
|
729
721
|
*(uint8_t **)(base + inst->b1) = ptr;
|
|
730
722
|
|
|
731
|
-
if (!call->PushObject(arg, inst->type, ptr))
|
|
723
|
+
if (!call->PushObject(arg, inst->type, ptr)) [[unlikely]]
|
|
732
724
|
return call->env.Null();
|
|
733
725
|
|
|
734
726
|
NEXT();
|
|
@@ -750,7 +742,7 @@ namespace {
|
|
|
750
742
|
#define DISPOSE(Ptr) \
|
|
751
743
|
do { \
|
|
752
744
|
if (inst->type->dispose) { \
|
|
753
|
-
inst->type->dispose(call->
|
|
745
|
+
inst->type->dispose(call->instance, inst->type, (Ptr)); \
|
|
754
746
|
} \
|
|
755
747
|
} while (false)
|
|
756
748
|
|
|
@@ -778,42 +770,42 @@ namespace {
|
|
|
778
770
|
OP(RunUInt64S) { INTEGER_SWAP(GG, uint64_t); }
|
|
779
771
|
OP(RunString) {
|
|
780
772
|
uint64_t x0 = WRAP(ForwardCallGG(call->native, base, &call->saved_sp)).x0;
|
|
781
|
-
napi_value value =
|
|
773
|
+
napi_value value = NewString(call->env, (const char *)x0);
|
|
782
774
|
DISPOSE((void *)x0);
|
|
783
775
|
return value;
|
|
784
776
|
}
|
|
785
777
|
OP(RunString16) {
|
|
786
778
|
uint64_t x0 = WRAP(ForwardCallGG(call->native, base, &call->saved_sp)).x0;
|
|
787
|
-
napi_value value =
|
|
779
|
+
napi_value value = NewString(call->env, (const char16_t *)x0);
|
|
788
780
|
DISPOSE((void *)x0);
|
|
789
781
|
return value;
|
|
790
782
|
}
|
|
791
783
|
OP(RunString32) {
|
|
792
784
|
uint64_t x0 = WRAP(ForwardCallGG(call->native, base, &call->saved_sp)).x0;
|
|
793
|
-
napi_value value =
|
|
785
|
+
napi_value value = NewString(call->env, (const char32_t *)x0);
|
|
794
786
|
DISPOSE((void *)x0);
|
|
795
787
|
return value;
|
|
796
788
|
}
|
|
797
789
|
OP(RunPointer) {
|
|
798
790
|
uint64_t x0 = WRAP(ForwardCallGG(call->native, base, &call->saved_sp)).x0;
|
|
799
|
-
napi_value value =
|
|
791
|
+
napi_value value = WrapPointer(call->env, inst->type, (void *)x0);
|
|
800
792
|
DISPOSE((void *)x0);
|
|
801
793
|
return value;
|
|
802
794
|
}
|
|
803
795
|
OP(RunCallback) {
|
|
804
796
|
uint64_t x0 = WRAP(ForwardCallGG(call->native, base, &call->saved_sp)).x0;
|
|
805
|
-
return
|
|
797
|
+
return WrapPointer(call->env, inst->type, (void *)x0);
|
|
806
798
|
}
|
|
807
799
|
OP(RunRecord) { K_UNREACHABLE(); return call->env.Null(); }
|
|
808
800
|
OP(RunUnion) { K_UNREACHABLE(); return call->env.Null(); }
|
|
809
801
|
OP(RunArray) { K_UNREACHABLE(); return call->env.Null(); }
|
|
810
802
|
OP(RunFloat32) {
|
|
811
803
|
float f = WRAP(ForwardCallF(call->native, base, &call->saved_sp));
|
|
812
|
-
return
|
|
804
|
+
return NewFloat(call->env, f);
|
|
813
805
|
}
|
|
814
806
|
OP(RunFloat64) {
|
|
815
807
|
double d = WRAP(ForwardCallDDDD(call->native, base, &call->saved_sp)).d0;
|
|
816
|
-
return
|
|
808
|
+
return NewFloat(call->env, d);
|
|
817
809
|
}
|
|
818
810
|
OP(RunPrototype) { K_UNREACHABLE(); return call->env.Null(); }
|
|
819
811
|
OP(RunAggregateGG) {
|
|
@@ -854,42 +846,42 @@ namespace {
|
|
|
854
846
|
OP(RunUInt64SX) { INTEGER_SWAP(GGX, uint64_t); }
|
|
855
847
|
OP(RunStringX) {
|
|
856
848
|
uint64_t x0 = WRAP(ForwardCallGGX(call->native, base, &call->saved_sp)).x0;
|
|
857
|
-
napi_value value =
|
|
849
|
+
napi_value value = NewString(call->env, (const char *)x0);
|
|
858
850
|
DISPOSE((void *)x0);
|
|
859
851
|
return value;
|
|
860
852
|
}
|
|
861
853
|
OP(RunString16X) {
|
|
862
854
|
uint64_t x0 = WRAP(ForwardCallGGX(call->native, base, &call->saved_sp)).x0;
|
|
863
|
-
napi_value value =
|
|
855
|
+
napi_value value = NewString(call->env, (const char16_t *)x0);
|
|
864
856
|
DISPOSE((void *)x0);
|
|
865
857
|
return value;
|
|
866
858
|
}
|
|
867
859
|
OP(RunString32X) {
|
|
868
860
|
uint64_t x0 = WRAP(ForwardCallGGX(call->native, base, &call->saved_sp)).x0;
|
|
869
|
-
napi_value value =
|
|
861
|
+
napi_value value = NewString(call->env, (const char32_t *)x0);
|
|
870
862
|
DISPOSE((void *)x0);
|
|
871
863
|
return value;
|
|
872
864
|
}
|
|
873
865
|
OP(RunPointerX) {
|
|
874
866
|
uint64_t x0 = WRAP(ForwardCallGGX(call->native, base, &call->saved_sp)).x0;
|
|
875
|
-
napi_value value =
|
|
867
|
+
napi_value value = WrapPointer(call->env, inst->type, (void *)x0);
|
|
876
868
|
DISPOSE((void *)x0);
|
|
877
869
|
return value;
|
|
878
870
|
}
|
|
879
871
|
OP(RunCallbackX) {
|
|
880
872
|
uint64_t x0 = WRAP(ForwardCallGGX(call->native, base, &call->saved_sp)).x0;
|
|
881
|
-
return
|
|
873
|
+
return WrapPointer(call->env, inst->type, (void *)x0);
|
|
882
874
|
}
|
|
883
875
|
OP(RunRecordX) { K_UNREACHABLE(); return call->env.Null(); }
|
|
884
876
|
OP(RunUnionX) { K_UNREACHABLE(); return call->env.Null(); }
|
|
885
877
|
OP(RunArrayX) { K_UNREACHABLE(); return call->env.Null(); }
|
|
886
878
|
OP(RunFloat32X) {
|
|
887
879
|
float f = WRAP(ForwardCallFX(call->native, base, &call->saved_sp));
|
|
888
|
-
return
|
|
880
|
+
return NewFloat(call->env, f);
|
|
889
881
|
}
|
|
890
882
|
OP(RunFloat64X) {
|
|
891
883
|
double d = WRAP(ForwardCallDDDDX(call->native, base, &call->saved_sp)).d0;
|
|
892
|
-
return
|
|
884
|
+
return NewFloat(call->env, d);
|
|
893
885
|
}
|
|
894
886
|
OP(RunPrototypeX) { K_UNREACHABLE(); return call->env.Null(); }
|
|
895
887
|
OP(RunAggregateGGX) {
|
|
@@ -920,7 +912,7 @@ namespace {
|
|
|
920
912
|
do { \
|
|
921
913
|
if (inst->type->dispose) { \
|
|
922
914
|
void *ptr = *(void **)base; \
|
|
923
|
-
inst->type->dispose(call->
|
|
915
|
+
inst->type->dispose(call->instance, inst->type, ptr); \
|
|
924
916
|
} \
|
|
925
917
|
} while (false)
|
|
926
918
|
#define INTEGER(CType) \
|
|
@@ -989,42 +981,42 @@ namespace {
|
|
|
989
981
|
OP(ReturnUInt64S) { INTEGER_SWAP(uint64_t); }
|
|
990
982
|
OP(ReturnString) {
|
|
991
983
|
uint64_t x0 = *(uint64_t *)base;
|
|
992
|
-
napi_value value =
|
|
984
|
+
napi_value value = NewString(call->env, (const char *)x0);
|
|
993
985
|
DISPOSE();
|
|
994
986
|
return value;
|
|
995
987
|
}
|
|
996
988
|
OP(ReturnString16) {
|
|
997
989
|
uint64_t x0 = *(uint64_t *)base;
|
|
998
|
-
napi_value value =
|
|
990
|
+
napi_value value = NewString(call->env, (const char16_t *)x0);
|
|
999
991
|
DISPOSE();
|
|
1000
992
|
return value;
|
|
1001
993
|
}
|
|
1002
994
|
OP(ReturnString32) {
|
|
1003
995
|
uint64_t x0 = *(uint64_t *)base;
|
|
1004
|
-
napi_value value =
|
|
996
|
+
napi_value value = NewString(call->env, (const char32_t *)x0);
|
|
1005
997
|
DISPOSE();
|
|
1006
998
|
return value;
|
|
1007
999
|
}
|
|
1008
1000
|
OP(ReturnPointer) {
|
|
1009
1001
|
uint64_t x0 = *(uint64_t *)base;
|
|
1010
|
-
napi_value value =
|
|
1002
|
+
napi_value value = WrapPointer(call->env, inst->type, (void *)x0);
|
|
1011
1003
|
DISPOSE();
|
|
1012
1004
|
return value;
|
|
1013
1005
|
}
|
|
1014
1006
|
OP(ReturnCallback) {
|
|
1015
1007
|
uint64_t x0 = *(uint64_t *)base;
|
|
1016
|
-
return
|
|
1008
|
+
return WrapPointer(call->env, inst->type, (void *)x0);
|
|
1017
1009
|
}
|
|
1018
1010
|
OP(ReturnRecord) { K_UNREACHABLE(); return call->env.Null(); }
|
|
1019
1011
|
OP(ReturnUnion) { K_UNREACHABLE(); return call->env.Null(); }
|
|
1020
1012
|
OP(ReturnArray) { K_UNREACHABLE(); return call->env.Null(); }
|
|
1021
1013
|
OP(ReturnFloat32) {
|
|
1022
1014
|
float f = *(float *)base;
|
|
1023
|
-
return
|
|
1015
|
+
return NewFloat(call->env, f);
|
|
1024
1016
|
}
|
|
1025
1017
|
OP(ReturnFloat64) {
|
|
1026
1018
|
double d = *(double *)base;
|
|
1027
|
-
return
|
|
1019
|
+
return NewFloat(call->env, d);
|
|
1028
1020
|
}
|
|
1029
1021
|
OP(ReturnPrototype) { K_UNREACHABLE(); return call->env.Null(); }
|
|
1030
1022
|
OP(ReturnAggregateReg) { return DecodeObject(call->instance, base, inst->type); }
|
|
@@ -1101,7 +1093,9 @@ namespace {
|
|
|
1101
1093
|
#undef OP
|
|
1102
1094
|
}
|
|
1103
1095
|
|
|
1104
|
-
#
|
|
1096
|
+
#if defined(__GNUC__) || defined(__clang__)
|
|
1097
|
+
#pragma GCC diagnostic pop
|
|
1098
|
+
#endif
|
|
1105
1099
|
|
|
1106
1100
|
napi_value CallData::Run(const FunctionInfo *func, napi_value *args)
|
|
1107
1101
|
{
|
|
@@ -1200,30 +1194,30 @@ void CallData::Relay(Size idx, uint8_t *sp)
|
|
|
1200
1194
|
const uint8_t *src = in_ptr + param.abi.offset;
|
|
1201
1195
|
const char *str = *(const char **)src;
|
|
1202
1196
|
|
|
1203
|
-
arguments[i] =
|
|
1197
|
+
arguments[i] = NewString(env, str);
|
|
1204
1198
|
|
|
1205
1199
|
if (param.type->dispose) {
|
|
1206
|
-
param.type->dispose(
|
|
1200
|
+
param.type->dispose(instance, param.type, str);
|
|
1207
1201
|
}
|
|
1208
1202
|
} break;
|
|
1209
1203
|
case PrimitiveKind::String16: {
|
|
1210
1204
|
const uint8_t *src = in_ptr + param.abi.offset;
|
|
1211
1205
|
const char16_t *str16 = *(const char16_t **)src;
|
|
1212
1206
|
|
|
1213
|
-
arguments[i] =
|
|
1207
|
+
arguments[i] = NewString(env, str16);
|
|
1214
1208
|
|
|
1215
1209
|
if (param.type->dispose) {
|
|
1216
|
-
param.type->dispose(
|
|
1210
|
+
param.type->dispose(instance, param.type, str16);
|
|
1217
1211
|
}
|
|
1218
1212
|
} break;
|
|
1219
1213
|
case PrimitiveKind::String32: {
|
|
1220
1214
|
const uint8_t *src = in_ptr + param.abi.offset;
|
|
1221
1215
|
const char32_t *str32 = *(const char32_t **)src;
|
|
1222
1216
|
|
|
1223
|
-
arguments[i] =
|
|
1217
|
+
arguments[i] = NewString(env, str32);
|
|
1224
1218
|
|
|
1225
1219
|
if (param.type->dispose) {
|
|
1226
|
-
param.type->dispose(
|
|
1220
|
+
param.type->dispose(instance, param.type, str32);
|
|
1227
1221
|
}
|
|
1228
1222
|
} break;
|
|
1229
1223
|
|
|
@@ -1231,10 +1225,10 @@ void CallData::Relay(Size idx, uint8_t *sp)
|
|
|
1231
1225
|
const uint8_t *src = in_ptr + param.abi.offset;
|
|
1232
1226
|
void *ptr2 = *(void **)src;
|
|
1233
1227
|
|
|
1234
|
-
arguments[i] =
|
|
1228
|
+
arguments[i] = WrapPointer(env, param.type->ref.type, ptr2);
|
|
1235
1229
|
|
|
1236
1230
|
if (param.type->dispose) {
|
|
1237
|
-
param.type->dispose(
|
|
1231
|
+
param.type->dispose(instance, param.type, ptr2);
|
|
1238
1232
|
}
|
|
1239
1233
|
} break;
|
|
1240
1234
|
|
|
@@ -1251,24 +1245,20 @@ void CallData::Relay(Size idx, uint8_t *sp)
|
|
|
1251
1245
|
const uint8_t *src = in_ptr + param.abi.offset;
|
|
1252
1246
|
float f = *(float *)src;
|
|
1253
1247
|
|
|
1254
|
-
arguments[i] =
|
|
1248
|
+
arguments[i] = NewFloat(env, f);
|
|
1255
1249
|
} break;
|
|
1256
1250
|
case PrimitiveKind::Float64: {
|
|
1257
1251
|
const uint8_t *src = in_ptr + param.abi.offset;
|
|
1258
1252
|
double d = *(double *)src;
|
|
1259
1253
|
|
|
1260
|
-
arguments[i] =
|
|
1254
|
+
arguments[i] = NewFloat(env, d);
|
|
1261
1255
|
} break;
|
|
1262
1256
|
|
|
1263
1257
|
case PrimitiveKind::Callback: {
|
|
1264
1258
|
const uint8_t *src = in_ptr + param.abi.offset;
|
|
1265
1259
|
void *ptr2 = *(void **)src;
|
|
1266
1260
|
|
|
1267
|
-
arguments[i] =
|
|
1268
|
-
|
|
1269
|
-
if (param.type->dispose) {
|
|
1270
|
-
param.type->dispose(env, param.type, ptr2);
|
|
1271
|
-
}
|
|
1261
|
+
arguments[i] = WrapPointer(env, param.type->ref.type, ptr2);
|
|
1272
1262
|
} break;
|
|
1273
1263
|
|
|
1274
1264
|
case PrimitiveKind::Prototype: { K_UNREACHABLE(); } break;
|
|
@@ -1368,15 +1358,10 @@ void CallData::Relay(Size idx, uint8_t *sp)
|
|
|
1368
1358
|
|
|
1369
1359
|
case PrimitiveKind::Record:
|
|
1370
1360
|
case PrimitiveKind::Union: {
|
|
1371
|
-
if (!IsObject(env, value)) [[unlikely]] {
|
|
1372
|
-
ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected object", GetValueType(instance, value));
|
|
1373
|
-
return;
|
|
1374
|
-
}
|
|
1375
|
-
|
|
1376
1361
|
uint64_t *gpr_ptr = (uint64_t *)in_ptr;
|
|
1377
1362
|
uint8_t *dest = proto->ret.abi.regular ? (uint8_t *)&out_reg + proto->ret.abi.offset : (uint8_t *)gpr_ptr[8]; // x8
|
|
1378
1363
|
|
|
1379
|
-
if (!PushObject(value, type, dest))
|
|
1364
|
+
if (!PushObject(value, type, dest)) [[unlikely]]
|
|
1380
1365
|
return;
|
|
1381
1366
|
} break;
|
|
1382
1367
|
case PrimitiveKind::Array: { K_UNREACHABLE(); } break;
|