1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 15:24:46 -05:00

fix(ext/ffi): Fix pointer types (#15730)

This commit is contained in:
Aapo Alasuutari 2022-09-01 20:31:05 +03:00 committed by GitHub
parent 3a601e56f4
commit 778eb1da24
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 20 deletions

View file

@ -421,7 +421,7 @@ declare namespace Deno {
& Record<NativeBigIntType, PointerValue> & Record<NativeBigIntType, PointerValue>
& Record<NativePointerType, PointerValue | null> & Record<NativePointerType, PointerValue | null>
& Record<NativeFunctionType, PointerValue | null> & Record<NativeFunctionType, PointerValue | null>
& Record<NativeBufferType, TypedArray>; & Record<NativeBufferType, TypedArray | null>;
/** Type conversion for foreign symbol parameters and unsafe callback return /** Type conversion for foreign symbol parameters and unsafe callback return
* types. * types.
@ -633,12 +633,12 @@ declare namespace Deno {
/** Gets a C string (null terminated string) at the specified byte offset from the pointer. */ /** Gets a C string (null terminated string) at the specified byte offset from the pointer. */
getCString(offset?: number): string; getCString(offset?: number): string;
/** Gets a C string (null terminated string) at the specified byte offset from the specified pointer. */ /** Gets a C string (null terminated string) at the specified byte offset from the specified pointer. */
static getCString(pointer: BigInt, offset?: number): string; static getCString(pointer: PointerValue, offset?: number): string;
/** Gets an ArrayBuffer of length `byteLength` at the specified byte offset from the pointer. */ /** Gets an ArrayBuffer of length `byteLength` at the specified byte offset from the pointer. */
getArrayBuffer(byteLength: number, offset?: number): ArrayBuffer; getArrayBuffer(byteLength: number, offset?: number): ArrayBuffer;
/** Gets an ArrayBuffer of length `byteLength` at the specified byte offset from the specified pointer. */ /** Gets an ArrayBuffer of length `byteLength` at the specified byte offset from the specified pointer. */
static getArrayBuffer( static getArrayBuffer(
pointer: BigInt, pointer: PointerValue,
byteLength: number, byteLength: number,
offset?: number, offset?: number,
): ArrayBuffer; ): ArrayBuffer;
@ -646,7 +646,7 @@ declare namespace Deno {
copyInto(destination: TypedArray, offset?: number): void; copyInto(destination: TypedArray, offset?: number): void;
/** Copies the memory of the specified pointer into a typed array. Length is determined from the typed array's `byteLength`. Also takes optional byte offset from the pointer. */ /** Copies the memory of the specified pointer into a typed array. Length is determined from the typed array's `byteLength`. Also takes optional byte offset from the pointer. */
static copyInto( static copyInto(
pointer: BigInt, pointer: PointerValue,
destination: TypedArray, destination: TypedArray,
offset?: number, offset?: number,
): void; ): void;

View file

@ -143,12 +143,12 @@ remote.symbols.method15(0n);
const result = remote.symbols.method16(); const result = remote.symbols.method16();
// @ts-expect-error: Invalid argument // @ts-expect-error: Invalid argument
let r_0: string = result; let r_0: string = result;
let r_1: number | bigint = result; let r_1: Deno.PointerValue = result;
const result2 = remote.symbols.method17(); const result2 = remote.symbols.method17();
// @ts-expect-error: Invalid argument // @ts-expect-error: Invalid argument
result2.then((_0: string) => {}); result2.then((_0: string) => {});
result2.then((_1: number | bigint) => {}); result2.then((_1: Deno.PointerValue) => {});
const result3 = remote.symbols.method18(); const result3 = remote.symbols.method18();
// @ts-expect-error: Invalid argument // @ts-expect-error: Invalid argument
@ -200,7 +200,7 @@ const unsafe_callback_wrong4 = new Deno.UnsafeCallback(
parameters: ["u64"], parameters: ["u64"],
result: "void", result: "void",
} as const, } as const,
// @ts-expect-error: Callback's 64bit parameters are always called as bigint // @ts-expect-error: Callback's 64bit parameters are either number or bigint
(_: number) => {}, (_: number) => {},
); );
const unsafe_callback_right1 = new Deno.UnsafeCallback( const unsafe_callback_right1 = new Deno.UnsafeCallback(
@ -208,7 +208,7 @@ const unsafe_callback_right1 = new Deno.UnsafeCallback(
parameters: ["u8", "u32", "pointer"], parameters: ["u8", "u32", "pointer"],
result: "void", result: "void",
} as const, } as const,
(_1: number, _2: number, _3: Deno.UnsafePointer) => {}, (_1: number, _2: number, _3: Deno.PointerValue) => {},
); );
const unsafe_callback_right2 = new Deno.UnsafeCallback( const unsafe_callback_right2 = new Deno.UnsafeCallback(
{ {
@ -230,14 +230,14 @@ const unsafe_callback_right4 = new Deno.UnsafeCallback(
parameters: ["u8", "u32", "pointer"], parameters: ["u8", "u32", "pointer"],
result: "u8", result: "u8",
} as const, } as const,
(_1: number, _2: number, _3: Deno.UnsafePointer) => 3, (_1: number, _2: number, _3: Deno.PointerValue) => 3,
); );
const unsafe_callback_right5 = new Deno.UnsafeCallback( const unsafe_callback_right5 = new Deno.UnsafeCallback(
{ {
parameters: ["u8", "i32", "pointer"], parameters: ["u8", "i32", "pointer"],
result: "void", result: "void",
} as const, } as const,
(_1: number, _2: number, _3: Deno.UnsafePointer) => {}, (_1: number, _2: number, _3: Deno.PointerValue) => {},
); );
// @ts-expect-error: Must pass callback // @ts-expect-error: Must pass callback
@ -256,7 +256,6 @@ remote.symbols.method23(new Uint8Array(1));
remote.symbols.method23(0); remote.symbols.method23(0);
// @ts-expect-error: Cannot pass pointer values as buffer. // @ts-expect-error: Cannot pass pointer values as buffer.
remote.symbols.method23(0n); remote.symbols.method23(0n);
// @ts-expect-error: Cannot pass pointer values as buffer.
remote.symbols.method23(null); remote.symbols.method23(null);
// @ts-expect-error: Invalid member type // @ts-expect-error: Invalid member type
@ -348,9 +347,9 @@ type __Tests__ = [
{ {
symbols: { symbols: {
pushBuf: ( pushBuf: (
buf: TypedArray, buf: TypedArray | null,
ptr: number | bigint | null, ptr: Deno.PointerValue | null,
func: number | bigint | null, func: Deno.PointerValue | null,
) => void; ) => void;
}; };
close(): void; close(): void;
@ -368,10 +367,10 @@ type __Tests__ = [
{ {
symbols: { symbols: {
pushBuf: ( pushBuf: (
buf: TypedArray, buf: TypedArray | null,
ptr: number | bigint | null, ptr: Deno.PointerValue | null,
func: number | bigint | null, func: Deno.PointerValue | null,
) => number | bigint; ) => Deno.PointerValue;
}; };
close(): void; close(): void;
}, },
@ -388,8 +387,8 @@ type __Tests__ = [
{ {
symbols: { symbols: {
foo: ( foo: (
...args: (number | bigint | null)[] ...args: (Deno.PointerValue | null)[]
) => number | bigint; ) => Deno.PointerValue;
}; };
close(): void; close(): void;
}, },