diff --git a/pkg/front_end/testcases/general/ffi_sample.dart.weak.expect b/pkg/front_end/testcases/general/ffi_sample.dart.weak.expect index d92782a30a51..269de2851d77 100644 --- a/pkg/front_end/testcases/general/ffi_sample.dart.weak.expect +++ b/pkg/front_end/testcases/general/ffi_sample.dart.weak.expect @@ -40,7 +40,7 @@ constants { Constructor coverage from constants: org-dartlang-testcase:///ffi_sample.dart: -- Double. (from org-dartlang-sdk:///sdk/lib/ffi/native_type.dart:114:9) -- _NativeDouble. (from org-dartlang-sdk:///sdk/lib/ffi/native_type.dart:34:9) +- Double. (from org-dartlang-sdk:///sdk/lib/ffi/native_type.dart:115:9) +- _NativeDouble. (from org-dartlang-sdk:///sdk/lib/ffi/native_type.dart:35:9) - NativeType. (from org-dartlang-sdk:///sdk/lib/ffi/native_type.dart:12:9) - Object. (from org-dartlang-sdk:///sdk/lib/core/object.dart:25:9) diff --git a/pkg/front_end/testcases/general/ffi_sample.dart.weak.modular.expect b/pkg/front_end/testcases/general/ffi_sample.dart.weak.modular.expect index d92782a30a51..269de2851d77 100644 --- a/pkg/front_end/testcases/general/ffi_sample.dart.weak.modular.expect +++ b/pkg/front_end/testcases/general/ffi_sample.dart.weak.modular.expect @@ -40,7 +40,7 @@ constants { Constructor coverage from constants: org-dartlang-testcase:///ffi_sample.dart: -- Double. (from org-dartlang-sdk:///sdk/lib/ffi/native_type.dart:114:9) -- _NativeDouble. (from org-dartlang-sdk:///sdk/lib/ffi/native_type.dart:34:9) +- Double. (from org-dartlang-sdk:///sdk/lib/ffi/native_type.dart:115:9) +- _NativeDouble. (from org-dartlang-sdk:///sdk/lib/ffi/native_type.dart:35:9) - NativeType. (from org-dartlang-sdk:///sdk/lib/ffi/native_type.dart:12:9) - Object. (from org-dartlang-sdk:///sdk/lib/core/object.dart:25:9) diff --git a/pkg/front_end/testcases/general/ffi_sample.dart.weak.transformed.expect b/pkg/front_end/testcases/general/ffi_sample.dart.weak.transformed.expect index 0765c4c028cc..15587c98a7ee 100644 --- a/pkg/front_end/testcases/general/ffi_sample.dart.weak.transformed.expect +++ b/pkg/front_end/testcases/general/ffi_sample.dart.weak.transformed.expect @@ -74,7 +74,7 @@ constants { Constructor coverage from constants: org-dartlang-testcase:///ffi_sample.dart: -- Double. (from org-dartlang-sdk:///sdk/lib/ffi/native_type.dart:114:9) -- _NativeDouble. (from org-dartlang-sdk:///sdk/lib/ffi/native_type.dart:34:9) +- Double. (from org-dartlang-sdk:///sdk/lib/ffi/native_type.dart:115:9) +- _NativeDouble. (from org-dartlang-sdk:///sdk/lib/ffi/native_type.dart:35:9) - NativeType. (from org-dartlang-sdk:///sdk/lib/ffi/native_type.dart:12:9) - Object. (from org-dartlang-sdk:///sdk/lib/core/object.dart:25:9) diff --git a/pkg/front_end/testcases/nnbd/ffi_sample.dart.strong.expect b/pkg/front_end/testcases/nnbd/ffi_sample.dart.strong.expect index b190b3a9c292..b376ba2c5873 100644 --- a/pkg/front_end/testcases/nnbd/ffi_sample.dart.strong.expect +++ b/pkg/front_end/testcases/nnbd/ffi_sample.dart.strong.expect @@ -34,7 +34,7 @@ constants { Constructor coverage from constants: org-dartlang-testcase:///ffi_sample.dart: -- Double. (from org-dartlang-sdk:///sdk/lib/ffi/native_type.dart:114:9) -- _NativeDouble. (from org-dartlang-sdk:///sdk/lib/ffi/native_type.dart:34:9) +- Double. (from org-dartlang-sdk:///sdk/lib/ffi/native_type.dart:115:9) +- _NativeDouble. (from org-dartlang-sdk:///sdk/lib/ffi/native_type.dart:35:9) - NativeType. (from org-dartlang-sdk:///sdk/lib/ffi/native_type.dart:12:9) - Object. (from org-dartlang-sdk:///sdk/lib/core/object.dart:25:9) diff --git a/pkg/front_end/testcases/nnbd/ffi_sample.dart.strong.transformed.expect b/pkg/front_end/testcases/nnbd/ffi_sample.dart.strong.transformed.expect index fccf63463e32..2b681fae1d35 100644 --- a/pkg/front_end/testcases/nnbd/ffi_sample.dart.strong.transformed.expect +++ b/pkg/front_end/testcases/nnbd/ffi_sample.dart.strong.transformed.expect @@ -65,7 +65,7 @@ constants { Constructor coverage from constants: org-dartlang-testcase:///ffi_sample.dart: -- Double. (from org-dartlang-sdk:///sdk/lib/ffi/native_type.dart:114:9) -- _NativeDouble. (from org-dartlang-sdk:///sdk/lib/ffi/native_type.dart:34:9) +- Double. (from org-dartlang-sdk:///sdk/lib/ffi/native_type.dart:115:9) +- _NativeDouble. (from org-dartlang-sdk:///sdk/lib/ffi/native_type.dart:35:9) - NativeType. (from org-dartlang-sdk:///sdk/lib/ffi/native_type.dart:12:9) - Object. (from org-dartlang-sdk:///sdk/lib/core/object.dart:25:9) diff --git a/pkg/front_end/testcases/nnbd/ffi_sample.dart.weak.expect b/pkg/front_end/testcases/nnbd/ffi_sample.dart.weak.expect index b190b3a9c292..b376ba2c5873 100644 --- a/pkg/front_end/testcases/nnbd/ffi_sample.dart.weak.expect +++ b/pkg/front_end/testcases/nnbd/ffi_sample.dart.weak.expect @@ -34,7 +34,7 @@ constants { Constructor coverage from constants: org-dartlang-testcase:///ffi_sample.dart: -- Double. (from org-dartlang-sdk:///sdk/lib/ffi/native_type.dart:114:9) -- _NativeDouble. (from org-dartlang-sdk:///sdk/lib/ffi/native_type.dart:34:9) +- Double. (from org-dartlang-sdk:///sdk/lib/ffi/native_type.dart:115:9) +- _NativeDouble. (from org-dartlang-sdk:///sdk/lib/ffi/native_type.dart:35:9) - NativeType. (from org-dartlang-sdk:///sdk/lib/ffi/native_type.dart:12:9) - Object. (from org-dartlang-sdk:///sdk/lib/core/object.dart:25:9) diff --git a/pkg/front_end/testcases/nnbd/ffi_sample.dart.weak.modular.expect b/pkg/front_end/testcases/nnbd/ffi_sample.dart.weak.modular.expect index b190b3a9c292..b376ba2c5873 100644 --- a/pkg/front_end/testcases/nnbd/ffi_sample.dart.weak.modular.expect +++ b/pkg/front_end/testcases/nnbd/ffi_sample.dart.weak.modular.expect @@ -34,7 +34,7 @@ constants { Constructor coverage from constants: org-dartlang-testcase:///ffi_sample.dart: -- Double. (from org-dartlang-sdk:///sdk/lib/ffi/native_type.dart:114:9) -- _NativeDouble. (from org-dartlang-sdk:///sdk/lib/ffi/native_type.dart:34:9) +- Double. (from org-dartlang-sdk:///sdk/lib/ffi/native_type.dart:115:9) +- _NativeDouble. (from org-dartlang-sdk:///sdk/lib/ffi/native_type.dart:35:9) - NativeType. (from org-dartlang-sdk:///sdk/lib/ffi/native_type.dart:12:9) - Object. (from org-dartlang-sdk:///sdk/lib/core/object.dart:25:9) diff --git a/pkg/front_end/testcases/nnbd/ffi_sample.dart.weak.transformed.expect b/pkg/front_end/testcases/nnbd/ffi_sample.dart.weak.transformed.expect index fccf63463e32..2b681fae1d35 100644 --- a/pkg/front_end/testcases/nnbd/ffi_sample.dart.weak.transformed.expect +++ b/pkg/front_end/testcases/nnbd/ffi_sample.dart.weak.transformed.expect @@ -65,7 +65,7 @@ constants { Constructor coverage from constants: org-dartlang-testcase:///ffi_sample.dart: -- Double. (from org-dartlang-sdk:///sdk/lib/ffi/native_type.dart:114:9) -- _NativeDouble. (from org-dartlang-sdk:///sdk/lib/ffi/native_type.dart:34:9) +- Double. (from org-dartlang-sdk:///sdk/lib/ffi/native_type.dart:115:9) +- _NativeDouble. (from org-dartlang-sdk:///sdk/lib/ffi/native_type.dart:35:9) - NativeType. (from org-dartlang-sdk:///sdk/lib/ffi/native_type.dart:12:9) - Object. (from org-dartlang-sdk:///sdk/lib/core/object.dart:25:9) diff --git a/runtime/tools/ffi/sdk_lib_ffi_generator.dart b/runtime/tools/ffi/sdk_lib_ffi_generator.dart index d32b0a11427d..64b985a61344 100644 --- a/runtime/tools/ffi/sdk_lib_ffi_generator.dart +++ b/runtime/tools/ffi/sdk_lib_ffi_generator.dart @@ -24,12 +24,13 @@ const configuration = [ Config("Uint16", "int", "Uint16List", 2), Config("Uint32", "int", "Uint32List", 4), Config("Uint64", "int", "Uint64List", 8), - Config("IntPtr", "int", kDoNotEmit, kIntPtrElementSize), Config("Float", "double", "Float32List", 4), Config("Double", "double", "Float64List", 8), - Config("Bool", "bool", kDoNotEmit, 1), + Config("Bool", "bool", kDoNotEmit, 1, since: Version(2, 15)), ]; +const arrayVersion = Version(2, 13); + // // Generator. // @@ -81,8 +82,6 @@ void generatePublicExtension( final elementSize = config.elementSize; final bits = sizeOfBits(elementSize); - // final sizeInBytes = - // "${sizeOf(elementSize)} byte${elementSize != 1 ? "s" : ""}"; String property; if (_isInt(nativeType)) { @@ -178,9 +177,10 @@ $alignment external $typedListType asTypedList(int length); """; if (container == "Pointer") { + final since = config.since?.sinceAnnotation ?? ''; buffer.write(""" /// Extension on [Pointer] specialized for the type argument [$nativeType]. -extension ${nativeType}Pointer on Pointer<$nativeType> { +$since extension ${nativeType}Pointer on Pointer<$nativeType> { /// The $property at [address]. $platform$truncate$alignment external $dartType get value; @@ -197,9 +197,11 @@ $asTypedList """); } else { + final since = + Version.latest(config.since, arrayVersion)?.sinceAnnotation ?? ''; buffer.write(""" /// Bounds checking indexing methods on [Array]s of [$nativeType]. -extension ${nativeType}Array on Array<$nativeType> { +$since extension ${nativeType}Array on Array<$nativeType> { external $dartType operator [](int index); external void operator []=(int index, $dartType value); @@ -288,32 +290,11 @@ void generateFooter(StringBuffer buffer) { bool _isInt(String type) => type.startsWith("Int") || type.startsWith("Uint"); bool _isSigned(String type) => type.startsWith("Int"); -String sizeOf(int size) { - switch (size) { - case kIntPtrElementSize: - return "4 or 8"; - default: - return "$size"; - } -} +String sizeOf(int size) => "$size"; -String sizeOfBits(int size) { - switch (size) { - case kIntPtrElementSize: - return "32 or 64"; - default: - return "${size * 8}"; - } -} +String sizeOfBits(int size) => "${size * 8}"; -String sizeOfIntPtrSize(int size) { - switch (size) { - case kIntPtrElementSize: - return "_intPtrSize"; - default: - return "$size"; - } -} +String sizeOfIntPtrSize(int size) => "$size"; String bracketOr(String input) { if (input.contains("or")) { @@ -348,9 +329,32 @@ class Config { final String dartType; final String typedListType; final int elementSize; + final Version? since; const Config( - this.nativeType, this.dartType, this.typedListType, this.elementSize); + this.nativeType, this.dartType, this.typedListType, this.elementSize, + {Version? since}) + : since = since; } const String kDoNotEmit = "donotemit"; -const int kIntPtrElementSize = -1; + +class Version { + final int major; + final int minor; + + const Version(this.major, this.minor); + + @override + String toString() => '$major.$minor'; + + static Version? latest(Version? a, Version? b) { + if (a == null) return b; + if (b == null) return a; + if (a.major > b.major) return a; + if (b.major > a.major) return b; + if (a.minor > b.minor) return a; + return b; + } + + String get sinceAnnotation => "@Since('$this')"; +} diff --git a/sdk/lib/ffi/abi.dart b/sdk/lib/ffi/abi.dart index 1efe4a55cf06..e6f08b37d25c 100644 --- a/sdk/lib/ffi/abi.dart +++ b/sdk/lib/ffi/abi.dart @@ -14,6 +14,7 @@ part of dart.ffi; /// The Dart VM can run on a variety of operating systems and architectures. /// Supported ABIs are represented by `Abi` objects. /// See [values] for all the supported ABIs. +@Since('2.16') class Abi { /// The application binary interface for Android on the Arm architecture. static const androidArm = _androidArm; diff --git a/sdk/lib/ffi/abi_specific.dart b/sdk/lib/ffi/abi_specific.dart index a41308c44bec..61eb867be177 100644 --- a/sdk/lib/ffi/abi_specific.dart +++ b/sdk/lib/ffi/abi_specific.dart @@ -43,6 +43,7 @@ part of dart.ffi; /// const UintPtr(); /// } /// ``` +@Since('2.16') class AbiSpecificInteger extends NativeType { const AbiSpecificInteger(); } @@ -50,6 +51,7 @@ class AbiSpecificInteger extends NativeType { /// Mapping for a subtype of [AbiSpecificInteger]. /// /// See documentation on [AbiSpecificInteger]. +@Since('2.16') class AbiSpecificIntegerMapping { final Map mapping; diff --git a/sdk/lib/ffi/allocation.dart b/sdk/lib/ffi/allocation.dart index fc5fce402787..45673ccc63ee 100644 --- a/sdk/lib/ffi/allocation.dart +++ b/sdk/lib/ffi/allocation.dart @@ -5,6 +5,7 @@ part of dart.ffi; /// Manages memory on the native heap. +@Since('2.12') abstract class Allocator { /// This interface is meant to be implemented, not extended or mixed in. Allocator._() { @@ -28,6 +29,7 @@ abstract class Allocator { } /// Extension on [Allocator] to provide allocation with [NativeType]. +@Since('2.12') extension AllocatorAlloc on Allocator { /// Allocates `sizeOf() * count` bytes of memory using /// `allocator.allocate`. diff --git a/sdk/lib/ffi/c_type.dart b/sdk/lib/ffi/c_type.dart index cb9d386342f8..ee358c2f79d1 100644 --- a/sdk/lib/ffi/c_type.dart +++ b/sdk/lib/ffi/c_type.dart @@ -21,6 +21,7 @@ part of dart.ffi; /// Dart code. /// It occurs only in native type signatures and as annotation on [Struct] and /// [Union] fields. +@Since('2.17') @AbiSpecificIntegerMapping({ Abi.androidArm: Uint8(), Abi.androidArm64: Uint8(), @@ -57,6 +58,7 @@ class Char extends AbiSpecificInteger { /// Dart code. /// It occurs only in native type signatures and as annotation on [Struct] and /// [Union] fields. +@Since('2.17') @AbiSpecificIntegerMapping({ Abi.androidArm: Int8(), Abi.androidArm64: Int8(), @@ -93,6 +95,7 @@ class SignedChar extends AbiSpecificInteger { /// Dart code. /// It occurs only in native type signatures and as annotation on [Struct] and /// [Union] fields. +@Since('2.17') @AbiSpecificIntegerMapping({ Abi.androidArm: Uint8(), Abi.androidArm64: Uint8(), @@ -129,6 +132,7 @@ class UnsignedChar extends AbiSpecificInteger { /// Dart code. /// It occurs only in native type signatures and as annotation on [Struct] and /// [Union] fields. +@Since('2.17') @AbiSpecificIntegerMapping({ Abi.androidArm: Int16(), Abi.androidArm64: Int16(), @@ -165,6 +169,7 @@ class Short extends AbiSpecificInteger { /// Dart code. /// It occurs only in native type signatures and as annotation on [Struct] and /// [Union] fields. +@Since('2.17') @AbiSpecificIntegerMapping({ Abi.androidArm: Uint16(), Abi.androidArm64: Uint16(), @@ -201,6 +206,7 @@ class UnsignedShort extends AbiSpecificInteger { /// Dart code. /// It occurs only in native type signatures and as annotation on [Struct] and /// [Union] fields. +@Since('2.17') @AbiSpecificIntegerMapping({ Abi.androidArm: Int32(), Abi.androidArm64: Int32(), @@ -237,6 +243,7 @@ class Int extends AbiSpecificInteger { /// Dart code. /// It occurs only in native type signatures and as annotation on [Struct] and /// [Union] fields. +@Since('2.17') @AbiSpecificIntegerMapping({ Abi.androidArm: Uint32(), Abi.androidArm64: Uint32(), @@ -274,6 +281,7 @@ class UnsignedInt extends AbiSpecificInteger { /// Dart code. /// It occurs only in native type signatures and as annotation on [Struct] and /// [Union] fields. +@Since('2.17') @AbiSpecificIntegerMapping({ Abi.androidArm: Int32(), Abi.androidArm64: Int64(), @@ -311,6 +319,7 @@ class Long extends AbiSpecificInteger { /// Dart code. /// It occurs only in native type signatures and as annotation on [Struct] and /// [Union] fields. +@Since('2.17') @AbiSpecificIntegerMapping({ Abi.androidArm: Uint32(), Abi.androidArm64: Uint64(), @@ -347,6 +356,7 @@ class UnsignedLong extends AbiSpecificInteger { /// Dart code. /// It occurs only in native type signatures and as annotation on [Struct] and /// [Union] fields. +@Since('2.17') @AbiSpecificIntegerMapping({ Abi.androidArm: Int64(), Abi.androidArm64: Int64(), @@ -383,6 +393,7 @@ class LongLong extends AbiSpecificInteger { /// in Dart code. /// It occurs only in native type signatures and as annotation on [Struct] and /// [Union] fields. +@Since('2.17') @AbiSpecificIntegerMapping({ Abi.androidArm: Uint64(), Abi.androidArm64: Uint64(), @@ -447,6 +458,7 @@ class IntPtr extends AbiSpecificInteger { /// Dart code. /// It occurs only in native type signatures and as annotation on [Struct] and /// [Union] fields. +@Since('2.17') @AbiSpecificIntegerMapping({ Abi.androidArm: Uint32(), Abi.androidArm64: Uint64(), @@ -479,6 +491,7 @@ class UintPtr extends AbiSpecificInteger { /// Dart code. /// It occurs only in native type signatures and as annotation on [Struct] and /// [Union] fields. +@Since('2.17') @AbiSpecificIntegerMapping({ Abi.androidArm: Uint32(), Abi.androidArm64: Uint64(), @@ -514,6 +527,7 @@ class Size extends AbiSpecificInteger { /// Dart code. /// It occurs only in native type signatures and as annotation on [Struct] and /// [Union] fields. +@Since('2.17') @AbiSpecificIntegerMapping({ Abi.androidArm: Uint32(), Abi.androidArm64: Uint32(), diff --git a/sdk/lib/ffi/ffi.dart b/sdk/lib/ffi/ffi.dart index 0d4d5b71619e..8311238b93a0 100644 --- a/sdk/lib/ffi/ffi.dart +++ b/sdk/lib/ffi/ffi.dart @@ -2,13 +2,12 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file -/** - * Foreign Function Interface for interoperability with the C programming language. - * - * For further details, please see: https://dart.dev/server/c-interop - * - * {@category VM} - */ +/// Foreign Function Interface for interoperability with the C programming language. +/// +/// For further details, please see: https://dart.dev/server/c-interop. +/// +/// {@category VM} +@Since('2.6') library dart.ffi; import 'dart:_internal' show Since; @@ -93,6 +92,7 @@ class Pointer extends NativeType { } /// A fixed-sized array of [T]s. +@Since('2.13') class Array extends NativeType { /// Const constructor to specify [Array] dimensions in [Struct]s. /// @@ -523,6 +523,7 @@ extension DoublePointer on Pointer { } /// Extension on [Pointer] specialized for the type argument [Bool]. +@Since('2.15') extension BoolPointer on Pointer { /// The bool at [address]. external bool get value; @@ -537,6 +538,7 @@ extension BoolPointer on Pointer { } /// Bounds checking indexing methods on [Array]s of [Int8]. +@Since('2.13') extension Int8Array on Array { external int operator [](int index); @@ -544,6 +546,7 @@ extension Int8Array on Array { } /// Bounds checking indexing methods on [Array]s of [Int16]. +@Since('2.13') extension Int16Array on Array { external int operator [](int index); @@ -551,6 +554,7 @@ extension Int16Array on Array { } /// Bounds checking indexing methods on [Array]s of [Int32]. +@Since('2.13') extension Int32Array on Array { external int operator [](int index); @@ -558,6 +562,7 @@ extension Int32Array on Array { } /// Bounds checking indexing methods on [Array]s of [Int64]. +@Since('2.13') extension Int64Array on Array { external int operator [](int index); @@ -565,6 +570,7 @@ extension Int64Array on Array { } /// Bounds checking indexing methods on [Array]s of [Uint8]. +@Since('2.13') extension Uint8Array on Array { external int operator [](int index); @@ -572,6 +578,7 @@ extension Uint8Array on Array { } /// Bounds checking indexing methods on [Array]s of [Uint16]. +@Since('2.13') extension Uint16Array on Array { external int operator [](int index); @@ -579,6 +586,7 @@ extension Uint16Array on Array { } /// Bounds checking indexing methods on [Array]s of [Uint32]. +@Since('2.13') extension Uint32Array on Array { external int operator [](int index); @@ -586,6 +594,7 @@ extension Uint32Array on Array { } /// Bounds checking indexing methods on [Array]s of [Uint64]. +@Since('2.13') extension Uint64Array on Array { external int operator [](int index); @@ -593,6 +602,7 @@ extension Uint64Array on Array { } /// Bounds checking indexing methods on [Array]s of [Float]. +@Since('2.13') extension FloatArray on Array { external double operator [](int index); @@ -600,6 +610,7 @@ extension FloatArray on Array { } /// Bounds checking indexing methods on [Array]s of [Double]. +@Since('2.13') extension DoubleArray on Array { external double operator [](int index); @@ -607,6 +618,7 @@ extension DoubleArray on Array { } /// Bounds checking indexing methods on [Array]s of [Bool]. +@Since('2.15') extension BoolArray on Array { external bool operator [](int index); @@ -642,7 +654,7 @@ extension PointerPointer on Pointer> { /// Store a Dart value into this location offset by [index]. /// /// A [Pointer] is unboxed before being stored (as if by `.address`), and the - /// pointer is boxed (as if by `Pointer.fromAddress`) when loaded. + /// pointer is boxed (as if by [Pointer.fromAddress]) when loaded. /// /// On 32-bit platforms the [address] must be 4-byte aligned, and on 64-bit /// platforms the [address] must be 8-byte aligned. @@ -650,6 +662,7 @@ extension PointerPointer on Pointer> { } /// Extension on [Pointer] specialized for the type argument [Struct]. +@Since('2.12') extension StructPointer on Pointer { /// A Dart view of the struct referenced by this pointer. /// @@ -685,6 +698,7 @@ extension StructPointer on Pointer { } /// Extension on [Pointer] specialized for the type argument [Union]. +@Since('2.14') extension UnionPointer on Pointer { /// A Dart view of the union referenced by this pointer. /// @@ -721,6 +735,7 @@ extension UnionPointer on Pointer { /// Extension on [Pointer] specialized for the type argument /// [AbiSpecificInteger]. +@Since('2.16') extension AbiSpecificIntegerPointer on Pointer { /// The integer at [address]. @@ -736,6 +751,7 @@ extension AbiSpecificIntegerPointer } /// Bounds checking indexing methods on [Array]s of [Pointer]. +@Since('2.13') extension PointerArray on Array> { external Pointer operator [](int index); @@ -743,6 +759,7 @@ extension PointerArray on Array> { } /// Bounds checking indexing methods on [Array]s of [Struct]. +@Since('2.13') extension StructArray on Array { /// This extension method must be invoked on a receiver of type `Pointer` /// where `T` is a compile-time constant type. @@ -750,6 +767,7 @@ extension StructArray on Array { } /// Bounds checking indexing methods on [Array]s of [Union]. +@Since('2.14') extension UnionArray on Array { /// This extension method must be invoked on a receiver of type `Pointer` /// where `T` is a compile-time constant type. @@ -757,6 +775,7 @@ extension UnionArray on Array { } /// Bounds checking indexing methods on [Array]s of [Array]. +@Since('2.13') extension ArrayArray on Array> { external Array operator [](int index); @@ -764,6 +783,7 @@ extension ArrayArray on Array> { } /// Bounds checking indexing methods on [Array]s of [AbiSpecificInteger]. +@Since('2.16') extension AbiSpecificIntegerArray on Array { external int operator [](int index); @@ -771,31 +791,40 @@ extension AbiSpecificIntegerArray on Array { } /// Extension to retrieve the native `Dart_Port` from a [SendPort]. +@Since('2.7') extension NativePort on SendPort { /// The native port of this [SendPort]. /// /// The returned native port can for example be used by C code to post /// messages to the connected [ReceivePort] via `Dart_PostCObject()` - see /// `dart_native_api.h`. + /// + /// Only the send ports from the platform classes [ReceivePort] and + /// [RawReceivePort] are supported. User-defined implementations of + /// [SendPort] are not supported. external int get nativePort; } /// Opaque, not exposing it's members. +@Since('2.8') class Dart_CObject extends Opaque {} typedef Dart_NativeMessageHandler = Void Function(Int64, Pointer); /// Utilities for accessing the Dart VM API from Dart code or /// from C code via `dart_api_dl.h`. +@Since('2.8') abstract class NativeApi { /// On breaking changes the major version is increased. /// /// The versioning covers the API surface in `dart_api_dl.h`. + @Since('2.9') external static int get majorVersion; /// On backwards compatible changes the minor version is increased. /// /// The versioning covers the API surface in `dart_api_dl.h`. + @Since('2.9') external static int get minorVersion; /// A function pointer to @@ -827,6 +856,7 @@ abstract class NativeApi { /// Pass this to `Dart_InitializeApiDL` in your native code to enable using the /// symbols in `dart_api_dl.h`. + @Since('2.9') external static Pointer get initializeApiDLData; } @@ -843,6 +873,7 @@ abstract class NativeApi { /// See `Dart_SetFfiNativeResolver` in `dart_api.h` /// /// NOTE: This is an experimental feature and may change in the future. +@Since('2.14') class FfiNative { final String nativeName; final bool isLeaf; diff --git a/sdk/lib/ffi/native_finalizer.dart b/sdk/lib/ffi/native_finalizer.dart index 14074cf6cae5..fcc44377a660 100644 --- a/sdk/lib/ffi/native_finalizer.dart +++ b/sdk/lib/ffi/native_finalizer.dart @@ -218,6 +218,7 @@ part of dart.ffi; /// ``` // TODO(http://dartbug.com/44395): Add implicit await to Dart implementation. // This will fix `useAsync2` above. +@Since('2.17') abstract class Finalizable { factory Finalizable._() => throw UnsupportedError(""); } @@ -246,6 +247,7 @@ typedef NativeFinalizerFunction /// attached finalizers are definitely called at least once before the program /// ends, and the callbacks are called as soon as possible after an object /// is recognized as inaccessible. +@Since('2.17') abstract class NativeFinalizer { /// Creates a finalizer with the given finalization callback. /// diff --git a/sdk/lib/ffi/native_type.dart b/sdk/lib/ffi/native_type.dart index 55a9f6d52463..62db0d59a41d 100644 --- a/sdk/lib/ffi/native_type.dart +++ b/sdk/lib/ffi/native_type.dart @@ -16,6 +16,7 @@ abstract class NativeType { /// /// [Opaque]'s subtypes are not constructible in the Dart code and serve purely /// as markers in type signatures. +@Since('2.12') abstract class Opaque extends NativeType {} /// [_NativeInteger]'s subtypes represent a native integer in C. @@ -118,6 +119,7 @@ class Double extends _NativeDouble { /// /// [Bool] is not constructible in the Dart code and serves purely as marker /// in type signatures. +@Since('2.15') class Bool extends NativeType { const Bool(); } @@ -133,6 +135,7 @@ abstract class Void extends NativeType {} /// /// [Handle] is not constructible in the Dart code and serves purely as marker in /// type signatures. +@Since('2.9') abstract class Handle extends NativeType {} /// Represents a function type in C. diff --git a/sdk/lib/ffi/struct.dart b/sdk/lib/ffi/struct.dart index c02a0599be34..3f84c42e3826 100644 --- a/sdk/lib/ffi/struct.dart +++ b/sdk/lib/ffi/struct.dart @@ -61,6 +61,7 @@ abstract class _Compound extends NativeType { /// by native memory or typed data. They may allocated via allocation or loaded /// from a [Pointer] or created by ffi calls or callbacks. They cannot be /// created by a generative constructor. +@Since('2.12') abstract class Struct extends _Compound { /// Construct a reference to the [nullptr]. /// @@ -76,6 +77,7 @@ abstract class Struct extends _Compound { /// need to be packed. /// /// Valid values for [memberAlignment] are 1, 2, 4, 8, and 16. +@Since('2.13') class Packed { final int memberAlignment; diff --git a/sdk/lib/ffi/union.dart b/sdk/lib/ffi/union.dart index 60242fed984b..8d2ee9ebd977 100644 --- a/sdk/lib/ffi/union.dart +++ b/sdk/lib/ffi/union.dart @@ -46,6 +46,7 @@ part of dart.ffi; /// Instances of a subclass of [Union] have reference semantics and are backed /// by native memory. The may allocated via allocation or loaded from a /// [Pointer], but cannot be created by a generative constructor. +@Since('2.14') abstract class Union extends _Compound { /// Construct a reference to the [nullptr]. ///