mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 10:28:47 +00:00
Fix ffi uint64_t parameter (#1158)
This commit is contained in:
@@ -2023,7 +2023,7 @@ JSC__JSValue JSC__JSValue__fromUInt64NoTruncate(JSC__JSGlobalObject* globalObjec
|
||||
return JSC::JSValue::encode(JSC::JSValue(JSC::JSBigInt::createFrom(globalObject, val)));
|
||||
}
|
||||
|
||||
uint64_t JSC__JSValue__toUInt64NoTruncate(JSC__JSValue val)
|
||||
uint64_t JSC__JSValue__toUInt64NoTruncate(JSC__JSGlobalObject* arg0, JSC__JSValue val)
|
||||
{
|
||||
JSC::JSValue _val = JSC::JSValue::decode(val);
|
||||
|
||||
|
||||
@@ -546,7 +546,7 @@ CPP_DECL JSC__JSValue JSC__JSValue__toPropertyKeyValue(JSC__JSValue JSValue0, JS
|
||||
CPP_DECL JSC__JSString* JSC__JSValue__toString(JSC__JSValue JSValue0, JSC__JSGlobalObject* arg1);
|
||||
CPP_DECL JSC__JSString* JSC__JSValue__toString(JSC__JSValue JSValue0, JSC__JSGlobalObject* arg1);
|
||||
CPP_DECL JSC__JSString* JSC__JSValue__toStringOrNull(JSC__JSValue JSValue0, JSC__JSGlobalObject* arg1);
|
||||
CPP_DECL uint64_t JSC__JSValue__toUInt64NoTruncate(JSC__JSValue JSValue0);
|
||||
CPP_DECL uint64_t JSC__JSValue__toUInt64NoTruncate(JSC__JSGlobalObject* arg0, JSC__JSValue JSValue0);
|
||||
CPP_DECL bWTF__String JSC__JSValue__toWTFString(JSC__JSValue JSValue0, JSC__JSGlobalObject* arg1);
|
||||
CPP_DECL void JSC__JSValue__toZigException(JSC__JSValue JSValue0, JSC__JSGlobalObject* arg1, ZigException* arg2);
|
||||
CPP_DECL void JSC__JSValue__toZigString(JSC__JSValue JSValue0, ZigString* arg1, JSC__JSGlobalObject* arg2);
|
||||
|
||||
@@ -76,7 +76,7 @@ ffiWrappers[FFIType.uint32_t] = function uint32(val) {
|
||||
};
|
||||
ffiWrappers[FFIType.i64_fast] = function int64(val) {
|
||||
if (typeof val === "bigint") {
|
||||
if (val < BigInt(Number.MAX_VALUE)) {
|
||||
if (val <= BigInt(Number.MAX_SAFE_INTEGER) && val >= BigInt(-Number.MAX_SAFE_INTEGER)) {
|
||||
return Number(val).valueOf() || 0;
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ ffiWrappers[FFIType.i64_fast] = function int64(val) {
|
||||
|
||||
ffiWrappers[FFIType.u64_fast] = function u64_fast(val) {
|
||||
if (typeof val === "bigint") {
|
||||
if (val < BigInt(Number.MAX_VALUE) && val > 0) {
|
||||
if (val <= BigInt(Number.MAX_SAFE_INTEGER) && val >= 0) {
|
||||
return Number(val).valueOf() || 0;
|
||||
}
|
||||
|
||||
@@ -124,11 +124,9 @@ ffiWrappers[FFIType.uint64_t] = function uint64(val) {
|
||||
|
||||
ffiWrappers[FFIType.u64_fast] = function u64_fast(val) {
|
||||
if (typeof val === "bigint") {
|
||||
return val < BigInt(Number.MAX_VALUE)
|
||||
? val <= BigInt(0)
|
||||
? 0
|
||||
: Number(val)
|
||||
: val;
|
||||
if (val <= BigInt(Number.MAX_SAFE_INTEGER) && val >= BigInt(0))
|
||||
return Number(val);
|
||||
return val;
|
||||
}
|
||||
|
||||
return typeof val === "number" ? (val <= 0 ? 0 : +val || 0) : +val || 0;
|
||||
|
||||
@@ -297,7 +297,8 @@ function getTypes(fast) {
|
||||
};
|
||||
}
|
||||
|
||||
function ffiRunner(types) {
|
||||
function ffiRunner(fast) {
|
||||
const types = getTypes(fast)
|
||||
const {
|
||||
symbols: {
|
||||
returns_true,
|
||||
@@ -365,12 +366,10 @@ function ffiRunner(types) {
|
||||
expect(returns_false()).toBe(false);
|
||||
|
||||
expect(returns_42_char()).toBe(42);
|
||||
// console.log(
|
||||
// returns_42_uint64_t().valueOf(),
|
||||
// returns_42_uint64_t(),
|
||||
// returns_42_uint64_t().valueOf() === returns_42_uint64_t()
|
||||
// );
|
||||
// expect(returns_42_uint64_t().valueOf()).toBe(42);
|
||||
if (fast)
|
||||
expect(returns_42_uint64_t().valueOf()).toBe(42);
|
||||
else
|
||||
expect(returns_42_uint64_t().valueOf()).toBe(42n);
|
||||
Bun.gc(true);
|
||||
expect(Math.fround(returns_42_float())).toBe(Math.fround(42.41999804973602));
|
||||
expect(returns_42_double()).toBe(42.42);
|
||||
@@ -378,12 +377,18 @@ function ffiRunner(types) {
|
||||
expect(returns_neg_42_int8_t()).toBe(-42);
|
||||
expect(returns_42_uint16_t()).toBe(42);
|
||||
expect(returns_42_uint32_t()).toBe(42);
|
||||
// expect(returns_42_uint64_t()).toBe(42);
|
||||
if (fast)
|
||||
expect(returns_42_uint64_t()).toBe(42);
|
||||
else
|
||||
expect(returns_42_uint64_t()).toBe(42n);
|
||||
expect(returns_neg_42_int16_t()).toBe(-42);
|
||||
expect(returns_neg_42_int32_t()).toBe(-42);
|
||||
expect(identity_int32_t(10)).toBe(10);
|
||||
Bun.gc(true);
|
||||
// expect(returns_neg_42_int64_t()).toBe(-42);
|
||||
if (fast)
|
||||
expect(returns_neg_42_int64_t()).toBe(-42);
|
||||
else
|
||||
expect(returns_neg_42_int64_t()).toBe(-42n);
|
||||
|
||||
expect(identity_char(10)).toBe(10);
|
||||
|
||||
@@ -396,31 +401,49 @@ function ffiRunner(types) {
|
||||
|
||||
expect(identity_int8_t(10)).toBe(10);
|
||||
expect(identity_int16_t(10)).toBe(10);
|
||||
// expect(identity_int64_t(10)).toBe(10);
|
||||
if (fast)
|
||||
expect(identity_int64_t(10)).toBe(10);
|
||||
else
|
||||
expect(identity_int64_t(10)).toBe(10n);
|
||||
expect(identity_uint8_t(10)).toBe(10);
|
||||
expect(identity_uint16_t(10)).toBe(10);
|
||||
expect(identity_uint32_t(10)).toBe(10);
|
||||
// expect(identity_uint64_t(10)).toBe(10);
|
||||
if (fast)
|
||||
expect(identity_uint64_t(10)).toBe(10);
|
||||
else
|
||||
expect(identity_uint64_t(10)).toBe(10n);
|
||||
Bun.gc(true);
|
||||
var bigArray = new BigUint64Array(8);
|
||||
new Uint8Array(bigArray.buffer).fill(255);
|
||||
var bigIntArray = new BigInt64Array(bigArray.buffer);
|
||||
// expect(identity_uint64_t(bigArray[0])).toBe(bigArray[0]);
|
||||
// expect(identity_uint64_t(bigArray[0] - BigInt(1))).toBe(
|
||||
// bigArray[0] - BigInt(1)
|
||||
// );
|
||||
expect(identity_uint64_t(bigArray[0])).toBe(bigArray[0]);
|
||||
expect(identity_uint64_t(bigArray[0] - BigInt(1))).toBe(
|
||||
bigArray[0] - BigInt(1)
|
||||
);
|
||||
if (fast) {
|
||||
expect(add_uint64_t(BigInt(-1) * bigArray[0], bigArray[0])).toBe(0);
|
||||
expect(add_uint64_t(BigInt(-1) * bigArray[0] + BigInt(10), bigArray[0])).toBe(10);
|
||||
} else {
|
||||
expect(add_uint64_t(BigInt(-1) * bigArray[0], bigArray[0])).toBe(0n);
|
||||
expect(add_uint64_t(BigInt(-1) * bigArray[0] + BigInt(10), bigArray[0])).toBe(10n);
|
||||
}
|
||||
if (fast) {
|
||||
expect(identity_uint64_t(0)).toBe(0);
|
||||
expect(identity_uint64_t(100)).toBe(100);
|
||||
expect(identity_uint64_t(BigInt(100))).toBe(100);
|
||||
|
||||
// expect(add_uint64_t(BigInt(-1) * bigArray[0], bigArray[0])).toBe(0);
|
||||
// expect(add_uint64_t(BigInt(-1) * bigArray[0] + BigInt(10), bigArray[0])).toBe(
|
||||
// 10
|
||||
// );
|
||||
// expect(identity_uint64_t(0)).toBe(0);
|
||||
// expect(identity_uint64_t(100)).toBe(100);
|
||||
// expect(identity_uint64_t(BigInt(100))).toBe(100);
|
||||
// expect(identity_int64_t(bigIntArray[0])).toBe(bigIntArray[0]);
|
||||
// expect(identity_int64_t(bigIntArray[0] - BigInt(1))).toBe(
|
||||
// bigIntArray[0] - BigInt(1)
|
||||
// );
|
||||
expect(identity_int64_t(bigIntArray[0])).toBe(-1);
|
||||
expect(identity_int64_t(bigIntArray[0] - BigInt(1))).toBe(-2);
|
||||
} else {
|
||||
expect(identity_uint64_t(0)).toBe(0n);
|
||||
expect(identity_uint64_t(100)).toBe(100n);
|
||||
expect(identity_uint64_t(BigInt(100))).toBe(100n);
|
||||
|
||||
expect(identity_int64_t(bigIntArray[0])).toBe(bigIntArray[0]);
|
||||
expect(identity_int64_t(bigIntArray[0] - BigInt(1))).toBe(
|
||||
bigIntArray[0] - BigInt(1)
|
||||
);
|
||||
}
|
||||
Bun.gc(true);
|
||||
expect(add_char.native(1, 1)).toBe(2);
|
||||
|
||||
@@ -429,7 +452,10 @@ function ffiRunner(types) {
|
||||
expect(add_int8_t(1, 1)).toBe(2);
|
||||
expect(add_int16_t(1, 1)).toBe(2);
|
||||
expect(add_int32_t(1, 1)).toBe(2);
|
||||
// expect(add_int64_t(1, 1)).toBe(2);
|
||||
if (fast)
|
||||
expect(add_int64_t(1, 1)).toBe(2);
|
||||
else
|
||||
expect(add_int64_t(1n, 1n)).toBe(2n);
|
||||
expect(add_uint8_t(1, 1)).toBe(2);
|
||||
expect(add_uint16_t(1, 1)).toBe(2);
|
||||
expect(add_uint32_t(1, 1)).toBe(2);
|
||||
@@ -575,9 +601,9 @@ function ffiRunner(types) {
|
||||
}
|
||||
|
||||
it("run ffi fast", () => {
|
||||
ffiRunner(getTypes(true));
|
||||
ffiRunner(true);
|
||||
});
|
||||
|
||||
it("run ffi", () => {
|
||||
ffiRunner(getTypes(false));
|
||||
ffiRunner(false);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user