From b56b8c8a753442036ace3bb0f4403c952f18d408 Mon Sep 17 00:00:00 2001 From: Aapo Alasuutari Date: Wed, 22 Feb 2023 19:32:38 +0200 Subject: feat(ext/ffi): Replace pointer integers with v8::External objects (#16889) --- cli/tsc/dts/lib.deno.unstable.d.ts | 43 +++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 15 deletions(-) (limited to 'cli/tsc') diff --git a/cli/tsc/dts/lib.deno.unstable.d.ts b/cli/tsc/dts/lib.deno.unstable.d.ts index 0362b416d..a1584701f 100644 --- a/cli/tsc/dts/lib.deno.unstable.d.ts +++ b/cli/tsc/dts/lib.deno.unstable.d.ts @@ -131,10 +131,10 @@ declare namespace Deno { */ type ToNativeTypeMap = & Record - & Record + & Record & Record - & Record - & Record + & Record + & Record & Record; /** **UNSTABLE**: New API, yet to be vetted. @@ -191,7 +191,7 @@ declare namespace Deno { */ type FromNativeTypeMap = & Record - & Record + & Record & Record & Record & Record @@ -340,6 +340,9 @@ declare namespace Deno { [K in keyof T]: StaticForeignSymbol; }; + const brand: unique symbol; + type PointerObject = { [brand]: unknown }; + /** **UNSTABLE**: New API, yet to be vetted. * * Pointer type depends on the architecture and actual pointer value. @@ -350,7 +353,7 @@ declare namespace Deno { * * @category FFI */ - export type PointerValue = number | bigint; + export type PointerValue = null | PointerObject; /** **UNSTABLE**: New API, yet to be vetted. * @@ -360,8 +363,16 @@ declare namespace Deno { * @category FFI */ export class UnsafePointer { + /** Create a pointer from a numeric value. This is one is really dangerous! */ + static create(value: number | bigint): PointerValue; + /** Returns `true` if the two pointers point to the same address. */ + static equals(a: PointerValue, b: PointerValue): boolean; /** Return the direct memory pointer to the typed array in memory. */ static of(value: Deno.UnsafeCallback | BufferSource): PointerValue; + /** Return a new pointer offset from the original by `offset` bytes. */ + static offset(value: NonNullable, offset: number): PointerValue + /** Get the numeric value of a pointer */ + static value(value: PointerValue): number | bigint; } /** **UNSTABLE**: New API, yet to be vetted. @@ -374,9 +385,9 @@ declare namespace Deno { * @category FFI */ export class UnsafePointerView { - constructor(pointer: PointerValue); + constructor(pointer: NonNullable); - pointer: PointerValue; + pointer: NonNullable; /** Gets a boolean at the specified byte offset from the pointer. */ getBool(offset?: number): boolean; @@ -400,29 +411,31 @@ declare namespace Deno { getInt32(offset?: number): number; /** Gets an unsigned 64-bit integer at the specified byte offset from the * pointer. */ - getBigUint64(offset?: number): PointerValue; + getBigUint64(offset?: number): number | bigint; /** Gets a signed 64-bit integer at the specified byte offset from the * pointer. */ - getBigInt64(offset?: number): PointerValue; + getBigInt64(offset?: number): number | bigint; /** Gets a signed 32-bit float at the specified byte offset from the * pointer. */ getFloat32(offset?: number): number; /** Gets a signed 64-bit float at the specified byte offset from the * pointer. */ getFloat64(offset?: number): number; + /** Gets a pointer at the specified byte offset from the pointer */ + getPointer(offset?: number): PointerValue; /** Gets a C string (`null` terminated string) at the specified byte offset * from the pointer. */ getCString(offset?: number): string; /** Gets a C string (`null` terminated string) at the specified byte offset * from the specified pointer. */ - static getCString(pointer: PointerValue, offset?: number): string; + static getCString(pointer: NonNullable, offset?: number): string; /** Gets an `ArrayBuffer` of length `byteLength` at the specified byte * offset from the pointer. */ getArrayBuffer(byteLength: number, offset?: number): ArrayBuffer; /** Gets an `ArrayBuffer` of length `byteLength` at the specified byte * offset from the specified pointer. */ static getArrayBuffer( - pointer: PointerValue, + pointer: NonNullable, byteLength: number, offset?: number, ): ArrayBuffer; @@ -438,7 +451,7 @@ declare namespace Deno { * * Also takes optional byte offset from the pointer. */ static copyInto( - pointer: PointerValue, + pointer: NonNullable, destination: BufferSource, offset?: number, ): void; @@ -453,11 +466,11 @@ declare namespace Deno { */ export class UnsafeFnPointer { /** The pointer to the function. */ - pointer: PointerValue; + pointer: NonNullable; /** The definition of the function. */ definition: Fn; - constructor(pointer: PointerValue, definition: Const); + constructor(pointer: NonNullable, definition: Const); /** Call the foreign function. */ call: FromForeignFunction; @@ -516,7 +529,7 @@ declare namespace Deno { ); /** The pointer to the unsafe callback. */ - pointer: PointerValue; + pointer: NonNullable; /** The definition of the unsafe callback. */ definition: Definition; /** The callback function. */ -- cgit v1.2.3