Version 2.17.0-38.0.dev
Merge commit 'bab2d07b841809a0fa175f6440721723ee59fde3' into 'dev'
diff --git a/benchmarks/FfiMemory/dart/FfiMemory.dart b/benchmarks/FfiMemory/dart/FfiMemory.dart
index 881eff2..6178f24 100644
--- a/benchmarks/FfiMemory/dart/FfiMemory.dart
+++ b/benchmarks/FfiMemory/dart/FfiMemory.dart
@@ -15,36 +15,6 @@
import 'package:ffi/ffi.dart';
import 'package:benchmark_harness/benchmark_harness.dart';
-/// Represents a native unsigned pointer-sized integer in C.
-///
-/// [UintPtr] is not constructible in the Dart code and serves purely as marker in
-/// type signatures.
-@AbiSpecificIntegerMapping({
- Abi.androidArm: Uint32(),
- Abi.androidArm64: Uint64(),
- Abi.androidIA32: Uint32(),
- Abi.androidX64: Uint64(),
- Abi.fuchsiaArm64: Uint64(),
- Abi.fuchsiaX64: Uint64(),
- Abi.iosArm: Uint32(),
- Abi.iosArm64: Uint64(),
- Abi.iosX64: Uint64(),
- Abi.linuxArm: Uint32(),
- Abi.linuxArm64: Uint64(),
- Abi.linuxIA32: Uint32(),
- Abi.linuxX64: Uint64(),
- Abi.linuxRiscv32: Uint32(),
- Abi.linuxRiscv64: Uint64(),
- Abi.macosArm64: Uint64(),
- Abi.macosX64: Uint64(),
- Abi.windowsArm64: Uint64(),
- Abi.windowsIA32: Uint32(),
- Abi.windowsX64: Uint64(),
-})
-class UintPtr extends AbiSpecificInteger {
- const UintPtr();
-}
-
//
// Pointer store.
//
diff --git a/benchmarks/FfiMemory/dart2/FfiMemory.dart b/benchmarks/FfiMemory/dart2/FfiMemory.dart
index 86f7e1f..b3a6cf9 100644
--- a/benchmarks/FfiMemory/dart2/FfiMemory.dart
+++ b/benchmarks/FfiMemory/dart2/FfiMemory.dart
@@ -17,36 +17,6 @@
import 'package:ffi/ffi.dart';
import 'package:benchmark_harness/benchmark_harness.dart';
-/// Represents a native unsigned pointer-sized integer in C.
-///
-/// [UintPtr] is not constructible in the Dart code and serves purely as marker in
-/// type signatures.
-@AbiSpecificIntegerMapping({
- Abi.androidArm: Uint32(),
- Abi.androidArm64: Uint64(),
- Abi.androidIA32: Uint32(),
- Abi.androidX64: Uint64(),
- Abi.fuchsiaArm64: Uint64(),
- Abi.fuchsiaX64: Uint64(),
- Abi.iosArm: Uint32(),
- Abi.iosArm64: Uint64(),
- Abi.iosX64: Uint64(),
- Abi.linuxArm: Uint32(),
- Abi.linuxArm64: Uint64(),
- Abi.linuxIA32: Uint32(),
- Abi.linuxX64: Uint64(),
- Abi.linuxRiscv32: Uint32(),
- Abi.linuxRiscv64: Uint64(),
- Abi.macosArm64: Uint64(),
- Abi.macosX64: Uint64(),
- Abi.windowsArm64: Uint64(),
- Abi.windowsIA32: Uint32(),
- Abi.windowsX64: Uint64(),
-})
-class UintPtr extends AbiSpecificInteger {
- const UintPtr();
-}
-
//
// Pointer store.
//
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 8c513a4..d92782a 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 @@
Constructor coverage from constants:
org-dartlang-testcase:///ffi_sample.dart:
-- Double. (from org-dartlang-sdk:///sdk/lib/ffi/native_type.dart:144:9)
+- 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)
- 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 8c513a4..d92782a 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 @@
Constructor coverage from constants:
org-dartlang-testcase:///ffi_sample.dart:
-- Double. (from org-dartlang-sdk:///sdk/lib/ffi/native_type.dart:144:9)
+- 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)
- 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 ae497d5..0765c4c 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 @@
Constructor coverage from constants:
org-dartlang-testcase:///ffi_sample.dart:
-- Double. (from org-dartlang-sdk:///sdk/lib/ffi/native_type.dart:144:9)
+- 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)
- 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/incremental/no_outline_change_50_ffi.yaml.world.1.expect b/pkg/front_end/testcases/incremental/no_outline_change_50_ffi.yaml.world.1.expect
index 6c37a20d..7e198e7 100644
--- a/pkg/front_end/testcases/incremental/no_outline_change_50_ffi.yaml.world.1.expect
+++ b/pkg/front_end/testcases/incremental/no_outline_change_50_ffi.yaml.world.1.expect
@@ -51,6 +51,7 @@
ffi::Bool,
ffi::BoolArray,
ffi::BoolPointer,
+ ffi::Char,
ffi::DartRepresentationOf,
ffi::Dart_CObject,
ffi::Double,
@@ -63,6 +64,7 @@
ffi::FloatArray,
ffi::FloatPointer,
ffi::Handle,
+ ffi::Int,
ffi::Int16,
ffi::Int16Array,
ffi::Int16Pointer,
@@ -76,6 +78,8 @@
ffi::Int8Array,
ffi::Int8Pointer,
ffi::IntPtr,
+ ffi::Long,
+ ffi::LongLong,
ffi::NativeApi,
ffi::NativeFunction,
ffi::NativeFunctionPointer,
@@ -86,6 +90,9 @@
ffi::Pointer,
ffi::PointerArray,
ffi::PointerPointer,
+ ffi::Short,
+ ffi::SignedChar,
+ ffi::Size,
ffi::Struct,
ffi::StructArray,
ffi::StructPointer,
@@ -101,11 +108,18 @@
ffi::Uint8,
ffi::Uint8Array,
ffi::Uint8Pointer,
+ ffi::UintPtr,
ffi::Union,
ffi::UnionArray,
ffi::UnionPointer,
+ ffi::UnsignedChar,
+ ffi::UnsignedInt,
+ ffi::UnsignedLong,
+ ffi::UnsignedLongLong,
+ ffi::UnsignedShort,
ffi::Unsized,
- ffi::Void)
+ ffi::Void,
+ ffi::WChar)
export "org-dartlang-test:///lib3.dart";
@@ -127,6 +141,7 @@
ffi::Bool,
ffi::BoolArray,
ffi::BoolPointer,
+ ffi::Char,
ffi::DartRepresentationOf,
ffi::Dart_CObject,
ffi::Double,
@@ -139,6 +154,7 @@
ffi::FloatArray,
ffi::FloatPointer,
ffi::Handle,
+ ffi::Int,
ffi::Int16,
ffi::Int16Array,
ffi::Int16Pointer,
@@ -152,6 +168,8 @@
ffi::Int8Array,
ffi::Int8Pointer,
ffi::IntPtr,
+ ffi::Long,
+ ffi::LongLong,
ffi::NativeApi,
ffi::NativeFunction,
ffi::NativeFunctionPointer,
@@ -162,6 +180,9 @@
ffi::Pointer,
ffi::PointerArray,
ffi::PointerPointer,
+ ffi::Short,
+ ffi::SignedChar,
+ ffi::Size,
ffi::Struct,
ffi::StructArray,
ffi::StructPointer,
@@ -177,11 +198,18 @@
ffi::Uint8,
ffi::Uint8Array,
ffi::Uint8Pointer,
+ ffi::UintPtr,
ffi::Union,
ffi::UnionArray,
ffi::UnionPointer,
+ ffi::UnsignedChar,
+ ffi::UnsignedInt,
+ ffi::UnsignedLong,
+ ffi::UnsignedLongLong,
+ ffi::UnsignedShort,
ffi::Unsized,
- ffi::Void)
+ ffi::Void,
+ ffi::WChar)
export "dart:ffi";
diff --git a/pkg/front_end/testcases/incremental/no_outline_change_50_ffi.yaml.world.2.expect b/pkg/front_end/testcases/incremental/no_outline_change_50_ffi.yaml.world.2.expect
index e7c047a..934102e 100644
--- a/pkg/front_end/testcases/incremental/no_outline_change_50_ffi.yaml.world.2.expect
+++ b/pkg/front_end/testcases/incremental/no_outline_change_50_ffi.yaml.world.2.expect
@@ -51,6 +51,7 @@
ffi::Bool,
ffi::BoolArray,
ffi::BoolPointer,
+ ffi::Char,
ffi::DartRepresentationOf,
ffi::Dart_CObject,
ffi::Double,
@@ -63,6 +64,7 @@
ffi::FloatArray,
ffi::FloatPointer,
ffi::Handle,
+ ffi::Int,
ffi::Int16,
ffi::Int16Array,
ffi::Int16Pointer,
@@ -76,6 +78,8 @@
ffi::Int8Array,
ffi::Int8Pointer,
ffi::IntPtr,
+ ffi::Long,
+ ffi::LongLong,
ffi::NativeApi,
ffi::NativeFunction,
ffi::NativeFunctionPointer,
@@ -86,6 +90,9 @@
ffi::Pointer,
ffi::PointerArray,
ffi::PointerPointer,
+ ffi::Short,
+ ffi::SignedChar,
+ ffi::Size,
ffi::Struct,
ffi::StructArray,
ffi::StructPointer,
@@ -101,11 +108,18 @@
ffi::Uint8,
ffi::Uint8Array,
ffi::Uint8Pointer,
+ ffi::UintPtr,
ffi::Union,
ffi::UnionArray,
ffi::UnionPointer,
+ ffi::UnsignedChar,
+ ffi::UnsignedInt,
+ ffi::UnsignedLong,
+ ffi::UnsignedLongLong,
+ ffi::UnsignedShort,
ffi::Unsized,
- ffi::Void)
+ ffi::Void,
+ ffi::WChar)
export "org-dartlang-test:///lib3.dart";
@@ -127,6 +141,7 @@
ffi::Bool,
ffi::BoolArray,
ffi::BoolPointer,
+ ffi::Char,
ffi::DartRepresentationOf,
ffi::Dart_CObject,
ffi::Double,
@@ -139,6 +154,7 @@
ffi::FloatArray,
ffi::FloatPointer,
ffi::Handle,
+ ffi::Int,
ffi::Int16,
ffi::Int16Array,
ffi::Int16Pointer,
@@ -152,6 +168,8 @@
ffi::Int8Array,
ffi::Int8Pointer,
ffi::IntPtr,
+ ffi::Long,
+ ffi::LongLong,
ffi::NativeApi,
ffi::NativeFunction,
ffi::NativeFunctionPointer,
@@ -162,6 +180,9 @@
ffi::Pointer,
ffi::PointerArray,
ffi::PointerPointer,
+ ffi::Short,
+ ffi::SignedChar,
+ ffi::Size,
ffi::Struct,
ffi::StructArray,
ffi::StructPointer,
@@ -177,11 +198,18 @@
ffi::Uint8,
ffi::Uint8Array,
ffi::Uint8Pointer,
+ ffi::UintPtr,
ffi::Union,
ffi::UnionArray,
ffi::UnionPointer,
+ ffi::UnsignedChar,
+ ffi::UnsignedInt,
+ ffi::UnsignedLong,
+ ffi::UnsignedLongLong,
+ ffi::UnsignedShort,
ffi::Unsized,
- ffi::Void)
+ ffi::Void,
+ ffi::WChar)
export "dart:ffi";
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 35dda10..b190b3a 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 @@
Constructor coverage from constants:
org-dartlang-testcase:///ffi_sample.dart:
-- Double. (from org-dartlang-sdk:///sdk/lib/ffi/native_type.dart:144:9)
+- 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)
- 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 02dfd2a..fccf634 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 @@
Constructor coverage from constants:
org-dartlang-testcase:///ffi_sample.dart:
-- Double. (from org-dartlang-sdk:///sdk/lib/ffi/native_type.dart:144:9)
+- 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)
- 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 35dda10..b190b3a 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 @@
Constructor coverage from constants:
org-dartlang-testcase:///ffi_sample.dart:
-- Double. (from org-dartlang-sdk:///sdk/lib/ffi/native_type.dart:144:9)
+- 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)
- 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 35dda10..b190b3a 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 @@
Constructor coverage from constants:
org-dartlang-testcase:///ffi_sample.dart:
-- Double. (from org-dartlang-sdk:///sdk/lib/ffi/native_type.dart:144:9)
+- 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)
- 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 02dfd2a..fccf634 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 @@
Constructor coverage from constants:
org-dartlang-testcase:///ffi_sample.dart:
-- Double. (from org-dartlang-sdk:///sdk/lib/ffi/native_type.dart:144:9)
+- 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)
- 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_struct_inline_array.dart.strong.expect b/pkg/front_end/testcases/nnbd/ffi_struct_inline_array.dart.strong.expect
index 0db513d..4d771b3 100644
--- a/pkg/front_end/testcases/nnbd/ffi_struct_inline_array.dart.strong.expect
+++ b/pkg/front_end/testcases/nnbd/ffi_struct_inline_array.dart.strong.expect
@@ -25,5 +25,5 @@
Constructor coverage from constants:
org-dartlang-testcase:///ffi_struct_inline_array.dart:
-- _ArraySize. (from org-dartlang-sdk:///sdk/lib/ffi/ffi.dart:138:9)
+- _ArraySize. (from org-dartlang-sdk:///sdk/lib/ffi/ffi.dart:139:9)
- Object. (from org-dartlang-sdk:///sdk/lib/core/object.dart:25:9)
diff --git a/pkg/front_end/testcases/nnbd/ffi_struct_inline_array.dart.strong.transformed.expect b/pkg/front_end/testcases/nnbd/ffi_struct_inline_array.dart.strong.transformed.expect
index 525cfd9..f3903c0 100644
--- a/pkg/front_end/testcases/nnbd/ffi_struct_inline_array.dart.strong.transformed.expect
+++ b/pkg/front_end/testcases/nnbd/ffi_struct_inline_array.dart.strong.transformed.expect
@@ -52,5 +52,5 @@
Constructor coverage from constants:
org-dartlang-testcase:///ffi_struct_inline_array.dart:
-- _ArraySize. (from org-dartlang-sdk:///sdk/lib/ffi/ffi.dart:138:9)
+- _ArraySize. (from org-dartlang-sdk:///sdk/lib/ffi/ffi.dart:139:9)
- Object. (from org-dartlang-sdk:///sdk/lib/core/object.dart:25:9)
diff --git a/pkg/front_end/testcases/nnbd/ffi_struct_inline_array.dart.weak.expect b/pkg/front_end/testcases/nnbd/ffi_struct_inline_array.dart.weak.expect
index e6c0f95..e179ab5 100644
--- a/pkg/front_end/testcases/nnbd/ffi_struct_inline_array.dart.weak.expect
+++ b/pkg/front_end/testcases/nnbd/ffi_struct_inline_array.dart.weak.expect
@@ -25,5 +25,5 @@
Constructor coverage from constants:
org-dartlang-testcase:///ffi_struct_inline_array.dart:
-- _ArraySize. (from org-dartlang-sdk:///sdk/lib/ffi/ffi.dart:138:9)
+- _ArraySize. (from org-dartlang-sdk:///sdk/lib/ffi/ffi.dart:139:9)
- Object. (from org-dartlang-sdk:///sdk/lib/core/object.dart:25:9)
diff --git a/pkg/front_end/testcases/nnbd/ffi_struct_inline_array.dart.weak.modular.expect b/pkg/front_end/testcases/nnbd/ffi_struct_inline_array.dart.weak.modular.expect
index e6c0f95..e179ab5 100644
--- a/pkg/front_end/testcases/nnbd/ffi_struct_inline_array.dart.weak.modular.expect
+++ b/pkg/front_end/testcases/nnbd/ffi_struct_inline_array.dart.weak.modular.expect
@@ -25,5 +25,5 @@
Constructor coverage from constants:
org-dartlang-testcase:///ffi_struct_inline_array.dart:
-- _ArraySize. (from org-dartlang-sdk:///sdk/lib/ffi/ffi.dart:138:9)
+- _ArraySize. (from org-dartlang-sdk:///sdk/lib/ffi/ffi.dart:139:9)
- Object. (from org-dartlang-sdk:///sdk/lib/core/object.dart:25:9)
diff --git a/pkg/front_end/testcases/nnbd/ffi_struct_inline_array.dart.weak.transformed.expect b/pkg/front_end/testcases/nnbd/ffi_struct_inline_array.dart.weak.transformed.expect
index b38ad34..24cfa96 100644
--- a/pkg/front_end/testcases/nnbd/ffi_struct_inline_array.dart.weak.transformed.expect
+++ b/pkg/front_end/testcases/nnbd/ffi_struct_inline_array.dart.weak.transformed.expect
@@ -52,5 +52,5 @@
Constructor coverage from constants:
org-dartlang-testcase:///ffi_struct_inline_array.dart:
-- _ArraySize. (from org-dartlang-sdk:///sdk/lib/ffi/ffi.dart:138:9)
+- _ArraySize. (from org-dartlang-sdk:///sdk/lib/ffi/ffi.dart:139:9)
- Object. (from org-dartlang-sdk:///sdk/lib/core/object.dart:25:9)
diff --git a/pkg/front_end/testcases/nnbd/ffi_struct_inline_array_multi_dimensional.dart.strong.expect b/pkg/front_end/testcases/nnbd/ffi_struct_inline_array_multi_dimensional.dart.strong.expect
index 0e058b1..dd7fa30 100644
--- a/pkg/front_end/testcases/nnbd/ffi_struct_inline_array_multi_dimensional.dart.strong.expect
+++ b/pkg/front_end/testcases/nnbd/ffi_struct_inline_array_multi_dimensional.dart.strong.expect
@@ -33,5 +33,5 @@
Constructor coverage from constants:
org-dartlang-testcase:///ffi_struct_inline_array_multi_dimensional.dart:
-- _ArraySize. (from org-dartlang-sdk:///sdk/lib/ffi/ffi.dart:138:9)
+- _ArraySize. (from org-dartlang-sdk:///sdk/lib/ffi/ffi.dart:139:9)
- Object. (from org-dartlang-sdk:///sdk/lib/core/object.dart:25:9)
diff --git a/pkg/front_end/testcases/nnbd/ffi_struct_inline_array_multi_dimensional.dart.strong.transformed.expect b/pkg/front_end/testcases/nnbd/ffi_struct_inline_array_multi_dimensional.dart.strong.transformed.expect
index ecf21c0..a16945b 100644
--- a/pkg/front_end/testcases/nnbd/ffi_struct_inline_array_multi_dimensional.dart.strong.transformed.expect
+++ b/pkg/front_end/testcases/nnbd/ffi_struct_inline_array_multi_dimensional.dart.strong.transformed.expect
@@ -84,5 +84,5 @@
Constructor coverage from constants:
org-dartlang-testcase:///ffi_struct_inline_array_multi_dimensional.dart:
-- _ArraySize. (from org-dartlang-sdk:///sdk/lib/ffi/ffi.dart:138:9)
+- _ArraySize. (from org-dartlang-sdk:///sdk/lib/ffi/ffi.dart:139:9)
- Object. (from org-dartlang-sdk:///sdk/lib/core/object.dart:25:9)
diff --git a/pkg/front_end/testcases/nnbd/ffi_struct_inline_array_multi_dimensional.dart.weak.expect b/pkg/front_end/testcases/nnbd/ffi_struct_inline_array_multi_dimensional.dart.weak.expect
index 5e4b756..be09548 100644
--- a/pkg/front_end/testcases/nnbd/ffi_struct_inline_array_multi_dimensional.dart.weak.expect
+++ b/pkg/front_end/testcases/nnbd/ffi_struct_inline_array_multi_dimensional.dart.weak.expect
@@ -33,5 +33,5 @@
Constructor coverage from constants:
org-dartlang-testcase:///ffi_struct_inline_array_multi_dimensional.dart:
-- _ArraySize. (from org-dartlang-sdk:///sdk/lib/ffi/ffi.dart:138:9)
+- _ArraySize. (from org-dartlang-sdk:///sdk/lib/ffi/ffi.dart:139:9)
- Object. (from org-dartlang-sdk:///sdk/lib/core/object.dart:25:9)
diff --git a/pkg/front_end/testcases/nnbd/ffi_struct_inline_array_multi_dimensional.dart.weak.modular.expect b/pkg/front_end/testcases/nnbd/ffi_struct_inline_array_multi_dimensional.dart.weak.modular.expect
index 5e4b756..be09548 100644
--- a/pkg/front_end/testcases/nnbd/ffi_struct_inline_array_multi_dimensional.dart.weak.modular.expect
+++ b/pkg/front_end/testcases/nnbd/ffi_struct_inline_array_multi_dimensional.dart.weak.modular.expect
@@ -33,5 +33,5 @@
Constructor coverage from constants:
org-dartlang-testcase:///ffi_struct_inline_array_multi_dimensional.dart:
-- _ArraySize. (from org-dartlang-sdk:///sdk/lib/ffi/ffi.dart:138:9)
+- _ArraySize. (from org-dartlang-sdk:///sdk/lib/ffi/ffi.dart:139:9)
- Object. (from org-dartlang-sdk:///sdk/lib/core/object.dart:25:9)
diff --git a/pkg/front_end/testcases/nnbd/ffi_struct_inline_array_multi_dimensional.dart.weak.transformed.expect b/pkg/front_end/testcases/nnbd/ffi_struct_inline_array_multi_dimensional.dart.weak.transformed.expect
index a9ba39c..a83a86b 100644
--- a/pkg/front_end/testcases/nnbd/ffi_struct_inline_array_multi_dimensional.dart.weak.transformed.expect
+++ b/pkg/front_end/testcases/nnbd/ffi_struct_inline_array_multi_dimensional.dart.weak.transformed.expect
@@ -84,5 +84,5 @@
Constructor coverage from constants:
org-dartlang-testcase:///ffi_struct_inline_array_multi_dimensional.dart:
-- _ArraySize. (from org-dartlang-sdk:///sdk/lib/ffi/ffi.dart:138:9)
+- _ArraySize. (from org-dartlang-sdk:///sdk/lib/ffi/ffi.dart:139:9)
- Object. (from org-dartlang-sdk:///sdk/lib/core/object.dart:25:9)
diff --git a/runtime/bin/ffi_test/ffi_test_functions.cc b/runtime/bin/ffi_test/ffi_test_functions.cc
index dd5e41f..1545f8e 100644
--- a/runtime/bin/ffi_test/ffi_test_functions.cc
+++ b/runtime/bin/ffi_test/ffi_test_functions.cc
@@ -1138,27 +1138,36 @@
typedef intptr_t ssize_t;
#endif
-#define DEFINE_SIZE_OF(type_modifier, type) \
- DART_EXPORT uint64_t FfiSizeOf_##type_modifier##_##type() { \
- return sizeof(type_modifier type); \
+#define DEFINE_SIZE_OF_AND_SIGN_OF(type_modifier, type, type2) \
+ DART_EXPORT uint64_t FfiSizeOf_##type_modifier##_##type##_##type2() { \
+ return sizeof(type_modifier type type2); \
+ } \
+ \
+ DART_EXPORT uint64_t FfiSignOf_##type_modifier##_##type##_##type2() { \
+ return std::numeric_limits<type_modifier type type2>::is_signed; \
}
-#define SIZES(F) \
- F(, intptr_t) \
- F(, uintptr_t) \
- F(, int) \
- F(unsigned, int) \
- F(, long) /* NOLINT */ \
- F(unsigned, long) /* NOLINT */ \
- F(, wchar_t) \
- F(, size_t) \
- F(, ssize_t) \
- F(, off_t)
+#define TYPES(F) \
+ F(, char, ) /* NOLINT */ \
+ F(signed, char, ) /* NOLINT */ \
+ F(unsigned, char, ) /* NOLINT */ \
+ F(, short, ) /* NOLINT */ \
+ F(unsigned, short, ) /* NOLINT */ \
+ F(, int, ) /* NOLINT */ \
+ F(unsigned, int, ) /* NOLINT */ \
+ F(, long, ) /* NOLINT */ \
+ F(unsigned, long, ) /* NOLINT */ \
+ F(, long, long) /* NOLINT */ \
+ F(unsigned, long, long) /* NOLINT */ \
+ F(, intptr_t, ) /* NOLINT */ \
+ F(, uintptr_t, ) /* NOLINT */ \
+ F(, size_t, ) /* NOLINT */ \
+ F(, wchar_t, ) /* NOLINT */
-SIZES(DEFINE_SIZE_OF)
+TYPES(DEFINE_SIZE_OF_AND_SIGN_OF)
-#undef DEFINE_SIZE_OF
-#undef SIZES
+#undef DEFINE_SIZE_OF_AND_SIGN_OF
+#undef TYPES
DART_EXPORT int64_t WCharMinValue() {
return WCHAR_MIN;
diff --git a/sdk/lib/_internal/vm/lib/ffi_native_type_patch.dart b/sdk/lib/_internal/vm/lib/ffi_native_type_patch.dart
index 92e23c1..ca47a83 100644
--- a/sdk/lib/_internal/vm/lib/ffi_native_type_patch.dart
+++ b/sdk/lib/_internal/vm/lib/ffi_native_type_patch.dart
@@ -55,11 +55,6 @@
@pragma("vm:entry-point")
class Uint64 extends _NativeInteger {}
-// TODO(http://dartbug.com/47938): Implement as AbiSpecificInteger.
-@patch
-@pragma("vm:entry-point")
-class IntPtr extends _NativeInteger {}
-
@patch
@pragma("vm:entry-point")
class Float extends _NativeDouble {}
diff --git a/sdk/lib/async/stream.dart b/sdk/lib/async/stream.dart
index 679c4ef..509faf2 100644
--- a/sdk/lib/async/stream.dart
+++ b/sdk/lib/async/stream.dart
@@ -15,14 +15,14 @@
/// A Stream provides a way to receive a sequence of events.
/// Each event is either a data event, also called an *element* of the stream,
/// or an error event, which is a notification that something has failed.
-/// When a stream has emitted all its event,
-/// a single "done" event will notify the listener that the end has been reached.
+/// When a stream has emitted all its events,
+/// a single "done" event notifies the listener that the end has been reached.
///
/// You produce a stream by calling an `async*` function, which then returns
/// a stream. Consuming that stream will lead the function to emit events
/// until it ends, and the stream closes.
/// You consume a stream either using an `await for` loop, which is available
-/// inside an `async` or `async*` function, or forwards its events directly
+/// inside an `async` or `async*` function, or by forwarding its events directly
/// using `yield*` inside an `async*` function.
/// Example:
/// ```dart
@@ -55,7 +55,7 @@
/// then the `optionalMap` function body completes,
/// which closes the returned stream.
/// On an error event from the `source` stream,
-/// the `await for` that error is (re-)thrown which breaks the loop.
+/// the `await for` re-throws that error, which breaks the loop.
/// The error then reaches the end of the `optionalMap` function body,
/// since it's not caught.
/// That makes the error be emitted on the returned stream, which then closes.
@@ -71,7 +71,7 @@
///
/// The more low-level [listen] method is what every other method is based on.
/// You call `listen` on a stream to tell it that you want to receive
-/// events, and to registers the callbacks which will receive those events.
+/// events, and to register the callbacks which will receive those events.
/// When you call `listen`, you receive a [StreamSubscription] object
/// which is the active object providing the events,
/// and which can be used to stop listening again,
@@ -114,7 +114,7 @@
/// Listening on a broadcast stream can be treated as listening on a new stream
/// containing only the events that have not yet been emitted when the [listen]
/// call occurs.
-/// For example, the [first] getter listens to the stream, then returns the first
+/// For example the [first] getter listens to the stream, then returns the first
/// event that listener receives.
/// This is not necessarily the first even emitted by the stream, but the first
/// of the *remaining* events of the broadcast stream.
@@ -126,7 +126,7 @@
/// as possible.
///
/// Stream subscriptions always respect "pause" requests. If necessary they need
-/// to buffer their input, but often, and preferably, they can simply request
+/// to buffer their input, but often, and preferably they can simply request
/// their input to pause too.
///
/// The default implementation of [isBroadcast] returns false.
@@ -147,6 +147,19 @@
///
/// This is a stream which does nothing except sending a done event
/// when it's listened to.
+ ///
+ /// Example:
+ /// ```dart
+ /// const stream = Stream.empty();
+ /// stream.listen(
+ /// (value) {
+ /// throw "Unreachable";
+ /// },
+ /// onDone: () {
+ /// print('Done');
+ /// },
+ /// );
+ /// ```
const factory Stream.empty() = _EmptyStream<T>;
/// Creates a stream which emits a single data event before closing.
@@ -161,7 +174,7 @@
/// print(x);
/// }
/// }
- /// printThings(Stream<String>.value("ok")); // prints "ok".
+ /// printThings(Stream<String>.value('ok')); // prints "ok".
/// ```
///
/// The returned stream is effectively equivalent to one created by
@@ -183,13 +196,13 @@
/// Future<void> tryThings(Stream<int> data) async {
/// try {
/// await for (var x in data) {
- /// print("Data: $x");
+ /// print('Data: $x');
/// }
/// } catch (e) {
/// print(e);
/// }
/// }
- /// tryThings(Stream<int>.error("Error")); // prints "Error".
+ /// tryThings(Stream<int>.error('Error')); // prints "Error".
/// ```
/// The returned stream is effectively equivalent to one created by
/// `Future<T>.error(error, stackTrace).asStream()`, by or
@@ -209,6 +222,22 @@
///
/// When the future completes, the stream will fire one event, either
/// data or error, and then close with a done-event.
+ ///
+ /// Example:
+ /// ```dart
+ /// Future<String> futureTask() async {
+ /// await Future.delayed(const Duration(seconds: 5));
+ /// return 'Future complete';
+ /// }
+ ///
+ /// final stream = Stream<String>.fromFuture(futureTask());
+ /// stream.listen(print,
+ /// onDone: () => print('Done'), onError: print);
+ ///
+ /// // Outputs:
+ /// // "Future complete" after 'futureTask' finished.
+ /// // "Done" when stream completed.
+ /// ```
factory Stream.fromFuture(Future<T> future) {
// Use the controller's buffering to fill in the value even before
// the stream has a listener. For a single value, it's not worth it
@@ -238,6 +267,27 @@
/// When all futures have completed, the stream is closed.
///
/// If [futures] is empty, the stream closes as soon as possible.
+ ///
+ /// Example:
+ /// ```dart
+ /// Future<int> waitTask() async {
+ /// await Future.delayed(const Duration(seconds: 2));
+ /// return 10;
+ /// }
+ ///
+ /// Future<String> doneTask() async {
+ /// await Future.delayed(const Duration(seconds: 5));
+ /// return 'Future complete';
+ /// }
+ ///
+ /// final stream = Stream<Object>.fromFutures([doneTask(), waitTask()]);
+ /// stream.listen(print, onDone: () => print('Done'), onError: print);
+ ///
+ /// // Outputs:
+ /// // 10 after 'waitTask' finished.
+ /// // "Future complete" after 'doneTask' finished.
+ /// // "Done" when stream completed.
+ /// ```
factory Stream.fromFutures(Iterable<Future<T>> futures) {
_StreamController<T> controller =
new _SyncStreamController<T>(null, null, null, null);
@@ -282,6 +332,12 @@
/// the stream emits that error and then it closes.
/// If reading [Iterator.current] on `elements.iterator` throws,
/// the stream emits that error, but keeps iterating.
+ ///
+ /// Example:
+ /// ```dart
+ /// final numbers = [1, 2, 3, 5, 6, 7];
+ /// final stream = Stream.fromIterable(numbers);
+ /// ```
factory Stream.fromIterable(Iterable<T> elements) {
return new _GeneratedStreamImpl<T>(
() => new _IterablePendingEvents<T>(elements));
@@ -290,7 +346,7 @@
/// Creates a multi-subscription stream.
///
/// Each time the created stream is listened to,
- /// the [onListen] callback is invoked with a new [MultiStreamController]
+ /// the [onListen] callback is invoked with a new [MultiStreamController],
/// which forwards events to the [StreamSubscription]
/// returned by that [listen] call.
///
@@ -362,12 +418,21 @@
/// this callback is an integer that starts with 0 and is incremented for
/// every event.
///
- /// The [period] must a non-negative [Duration].
+ /// The [period] must be a non-negative [Duration].
///
- /// If [computation] is omitted the event values will all be `null`.
+ /// If [computation] is omitted, the event values will all be `null`.
///
/// The [computation] must not be omitted if the event type [T] does not
/// allow `null` as a value.
+ ///
+ /// Example:
+ /// ```dart
+ /// final stream =
+ /// Stream<int>.periodic(const Duration(
+ /// seconds: 1), (count) => count * count).take(5);
+ ///
+ /// stream.forEach(print); // Outputs event values 0,1,4,9,16.
+ /// ```
factory Stream.periodic(Duration period,
[T computation(int computationCount)?]) {
if (computation == null && !typeAcceptsNull<T>()) {
@@ -485,7 +550,7 @@
/// using [StreamSubscription.asFuture].
///
/// If [onCancel] is provided, it is called in a similar way to [onListen]
- /// when the returned stream stops having listener. If it later gets
+ /// when the returned stream stops having listeners. If it later gets
/// a new listener, the [onListen] function is called again.
///
/// Use the callbacks, for example, for pausing the underlying subscription
@@ -496,6 +561,51 @@
/// If the subscription passed to `onListen` or `onCancel` is cancelled,
/// then no further events are ever emitted by current subscriptions on
/// the returned broadcast stream, not even a done event.
+ ///
+ /// Example:
+ /// ```dart
+ /// final stream =
+ /// Stream<int>.periodic(const Duration(seconds: 1), (count) => count)
+ /// .take(10);
+ ///
+ /// final broadcastStream = stream.asBroadcastStream(
+ /// onCancel: (controller) {
+ /// print('Stream paused');
+ /// controller.pause();
+ /// },
+ /// onListen: (controller) async {
+ /// if (controller.isPaused) {
+ /// print('Stream resumed');
+ /// controller.resume();
+ /// }
+ /// },
+ /// );
+ ///
+ /// final oddNumberStream = broadcastStream.where((event) => event.isOdd);
+ /// final oddNumberListener = oddNumberStream.listen(
+ /// (event) {
+ /// print('Odd: $event');
+ /// },
+ /// onDone: () => print('Done'),
+ /// );
+ ///
+ /// final evenNumberStream = broadcastStream.where((event) => event.isEven);
+ /// final evenNumberListener = evenNumberStream.listen((event) {
+ /// print('Even: $event');
+ /// }, onDone: () => print('Done'));
+ ///
+ /// await Future.delayed(const Duration(milliseconds: 3500)); // 3.5 second
+ /// // Outputs:
+ /// // Even: 0
+ /// // Odd: 1
+ /// // Even: 2
+ /// oddNumberListener.cancel(); // Nothing printed.
+ /// evenNumberListener.cancel(); // "Stream paused"
+ /// await Future.delayed(const Duration(seconds: 2));
+ /// print(await broadcastStream.first); // "Stream resumed"
+ /// // Outputs:
+ /// // 3
+ /// ```
Stream<T> asBroadcastStream(
{void onListen(StreamSubscription<T> subscription)?,
void onCancel(StreamSubscription<T> subscription)?}) {
@@ -551,6 +661,16 @@
/// The returned stream is a broadcast stream if this stream is.
/// If a broadcast stream is listened to more than once, each subscription
/// will individually perform the `test`.
+ ///
+ /// Example:
+ /// ```dart
+ /// final stream =
+ /// Stream<int>.periodic(const Duration(seconds: 1), (count) => count)
+ /// .take(10);
+ ///
+ /// final customStream = stream.where((event) => event > 3 && event <= 6);
+ /// customStream.listen(print); // Outputs event values: 4,5,6.
+ /// ```
Stream<T> where(bool test(T event)) {
return new _WhereStream<T>(this, test);
}
@@ -579,6 +699,22 @@
/// if a surrogate pair, or a multibyte UTF-8 encoding, is split into
/// separate events, and those events are attempted encoded or decoded
/// independently.
+ ///
+ /// Example:
+ /// ```dart
+ /// final stream =
+ /// Stream<int>.periodic(const Duration(seconds: 1), (count) => count)
+ /// .take(5);
+ ///
+ /// final calculationStream =
+ /// stream.map<String>((event) => 'Square: ${event * event}');
+ /// calculationStream.forEach(print);
+ /// // Square: 0
+ /// // Square: 1
+ /// // Square: 4
+ /// // Square: 9
+ /// // Square: 16
+ /// ```
Stream<S> map<S>(S convert(T event)) {
return new _MapStream<T, S>(this, convert);
}
@@ -699,8 +835,8 @@
/// an error without a stack trace.
///
/// An asynchronous error `error` is matched by a test function if
- ///`test(error)` returns true. If [test] is omitted, every error is considered
- /// matching.
+ /// `test(error)` returns true. If [test] is omitted, every error is
+ /// considered matching.
///
/// If the error is intercepted, the [onError] function can decide what to do
/// with it. It can throw if it wants to raise a new (or the same) error,
@@ -716,6 +852,23 @@
/// The returned stream is a broadcast stream if this stream is.
/// If a broadcast stream is listened to more than once, each subscription
/// will individually perform the `test` and handle the error.
+ ///
+ /// Example:
+ /// ```dart
+ /// Stream.periodic(const Duration(seconds: 1), (count) {
+ /// if (count == 2) {
+ /// throw Exception('Exceptional event');
+ /// }
+ /// return count;
+ /// }).take(4).handleError(print).forEach(print);
+ ///
+ /// // Outputs:
+ /// // 0
+ /// // 1
+ /// // Exception: Exceptional event
+ /// // 3
+ /// // 4
+ /// ```
Stream<T> handleError(Function onError, {bool test(error)?}) {
if (onError is! void Function(Object, StackTrace) &&
onError is! void Function(Object)) {
@@ -813,6 +966,13 @@
/// If this stream emits an error, or the call to [combine] throws,
/// the returned future is completed with that error,
/// and processing is stopped.
+ ///
+ /// Example:
+ /// ```dart
+ /// final result = await Stream.fromIterable([2, 6, 10, 8, 2])
+ /// .reduce((previous, element) => previous + element);
+ /// print(result); // 28
+ /// ```
Future<T> reduce(T combine(T previous, T element)) {
_Future<T> result = new _Future<T>();
bool seenFirst = false;
@@ -860,6 +1020,13 @@
/// If this stream emits an error, or the call to [combine] throws,
/// the returned future is completed with that error,
/// and processing is stopped.
+ ///
+ /// Example:
+ /// ```dart
+ /// final result = await Stream.fromIterable([2, 6, 10, 8, 2])
+ /// .fold<int>(10, (previous, element) => previous + element);
+ /// print(result); // 38
+ /// ```
Future<S> fold<S>(S initialValue, S combine(S previous, T element)) {
_Future<S> result = new _Future<S>();
S value = initialValue;
@@ -887,6 +1054,13 @@
/// If this stream emits an error, or the call to [Object.toString] throws,
/// the returned future is completed with that error,
/// and processing stops.
+ ///
+ /// Example:
+ /// ```dart
+ /// final result = await Stream.fromIterable(['Mars', 'Venus', 'Earth'])
+ /// .join('--');
+ /// print(result); // 'Mars--Venus--Earth'
+ /// ```
Future<String> join([String separator = ""]) {
_Future<String> result = new _Future<String>();
StringBuffer buffer = new StringBuffer();
@@ -927,6 +1101,13 @@
/// If this stream emits an error, or the call to [Object.==] throws,
/// the returned future is completed with that error,
/// and processing stops.
+ ///
+ /// Example:
+ /// ```dart
+ /// final result = await Stream.fromIterable(['Year', 2021, 12, 24, 'Dart'])
+ /// .contains('Dart');
+ /// print(result); // true
+ /// ```
Future<bool> contains(Object? needle) {
_Future<bool> future = new _Future<bool>();
StreamSubscription<T> subscription =
@@ -976,6 +1157,15 @@
/// If this stream emits an error, or if the call to [test] throws,
/// the returned future is completed with that error,
/// and processing stops.
+ ///
+ /// Example:
+ /// ```dart
+ /// final result =
+ /// await Stream.periodic(const Duration(seconds: 1), (count) => count)
+ /// .take(15)
+ /// .every((x) => x <= 5);
+ /// print(result); // false
+ /// ```
Future<bool> every(bool test(T element)) {
_Future<bool> future = new _Future<bool>();
StreamSubscription<T> subscription =
@@ -1004,6 +1194,16 @@
/// If this stream emits an error, or if the call to [test] throws,
/// the returned future is completed with that error,
/// and processing stops.
+ ///
+ /// Example:
+ /// ```dart
+ /// final result =
+ /// await Stream.periodic(const Duration(seconds: 1), (count) => count)
+ /// .take(15)
+ /// .any((element) => element >= 5);
+ ///
+ /// print(result); // true
+ /// ```
Future<bool> any(bool test(T element)) {
_Future<bool> future = new _Future<bool>();
StreamSubscription<T> subscription =
@@ -1144,6 +1344,12 @@
/// [futureValue].
///
/// The [futureValue] must not be omitted if `null` is not assignable to [E].
+ ///
+ /// Example:
+ /// ```dart
+ /// final result = await Stream.fromIterable([1, 2, 3]).drain(100);
+ /// print(result); // Outputs: 100.
+ /// ```
Future<E> drain<E>([E? futureValue]) {
if (futureValue == null) {
futureValue = futureValue as E;
@@ -1170,6 +1376,14 @@
/// If this is a broadcast stream, the returned stream is a broadcast stream.
/// In that case, the events are only counted from the time
/// the returned stream is listened to.
+ ///
+ /// Example:
+ /// ```dart
+ /// final stream =
+ /// Stream<int>.periodic(const Duration(seconds: 1), (i) => i)
+ /// .take(60);
+ /// stream.forEach(print); // Outputs events: 0, ... 59.
+ /// ```
Stream<T> take(int count) {
return new _TakeStream<T>(this, count);
}
@@ -1194,6 +1408,13 @@
/// The returned stream is a broadcast stream if this stream is.
/// For a broadcast stream, the events are only tested from the time
/// the returned stream is listened to.
+ ///
+ /// Example:
+ /// ```dart
+ /// final stream = Stream<int>.periodic(const Duration(seconds: 1), (i) => i)
+ /// .takeWhile((event) => event < 6);
+ /// stream.forEach(print); // Outputs events: 0, ..., 5.
+ /// ```
Stream<T> takeWhile(bool test(T element)) {
return new _TakeWhileStream<T>(this, test);
}
@@ -1211,6 +1432,13 @@
/// The returned stream is a broadcast stream if this stream is.
/// For a broadcast stream, the events are only counted from the time
/// the returned stream is listened to.
+ ///
+ /// Example:
+ /// ```dart
+ /// final stream =
+ /// Stream<int>.periodic(const Duration(seconds: 1), (i) => i).skip(7);
+ /// stream.forEach(print); // Skips events 0, ..., 6. Outputs events: 7, ...
+ /// ```
Stream<T> skip(int count) {
return new _SkipStream<T>(this, count);
}
@@ -1231,6 +1459,14 @@
/// The returned stream is a broadcast stream if this stream is.
/// For a broadcast stream, the events are only tested from the time
/// the returned stream is listened to.
+ ///
+ /// Example:
+ /// ```dart
+ /// final stream = Stream<int>.periodic(const Duration(seconds: 1), (i) => i)
+ /// .take(10)
+ /// .skipWhile((x) => x < 5);
+ /// stream.forEach(print); // Outputs events: 5, ..., 9.
+ /// ```
Stream<T> skipWhile(bool test(T element)) {
return new _SkipWhileStream<T>(this, test);
}
@@ -1254,6 +1490,12 @@
/// The returned stream is a broadcast stream if this stream is.
/// If a broadcast stream is listened to more than once, each subscription
/// will individually perform the `equals` test.
+ ///
+ /// Example:
+ /// ```dart
+ /// final stream = Stream.fromIterable([2, 6, 6, 8, 12, 8, 8, 2]).distinct();
+ /// stream.forEach(print); // Outputs events: 2,6,8,12,8,2.
+ /// ```
Stream<T> distinct([bool equals(T previous, T next)?]) {
return new _DistinctStream<T>(this, equals);
}
@@ -1366,9 +1608,9 @@
/// Finds the first element of this stream matching [test].
///
/// Returns a future that is completed with the first element of this stream
- /// that [test] returns `true` for.
+ /// for which [test] returns `true`.
///
- /// If no such element is found before this stream is done, and a
+ /// If no such element is found before this stream is done, and an
/// [orElse] function is provided, the result of calling [orElse]
/// becomes the value of the future. If [orElse] throws, the returned
/// future is completed with that error.
@@ -1386,6 +1628,17 @@
/// If an error occurs, or if this stream ends without finding a match and
/// with no [orElse] function provided,
/// the returned future is completed with an error.
+ ///
+ /// Example:
+ /// ```dart
+ /// var result = await Stream.fromIterable([1, 3, 4, 9, 12])
+ /// .firstWhere((element) => element % 6 == 0, orElse: () => -1);
+ /// print(result); // 12
+ ///
+ /// result = await Stream.fromIterable([1, 2, 3, 4, 5])
+ /// .firstWhere((element) => element % 6 == 0, orElse: () => -1);
+ /// print(result); // -1
+ /// ```
Future<T> firstWhere(bool test(T element), {T orElse()?}) {
_Future<T> future = new _Future();
StreamSubscription<T> subscription =
@@ -1421,6 +1674,17 @@
/// instead of the first.
/// That means that a non-error result cannot be provided before this stream
/// is done.
+ ///
+ /// Example:
+ /// ```dart
+ /// var result = await Stream.fromIterable([1, 3, 4, 7, 12, 24, 32])
+ /// .lastWhere((element) => element % 6 == 0, orElse: () => -1);
+ /// print(result); // 24
+ ///
+ /// result = await Stream.fromIterable([1, 3, 4, 7, 12, 24, 32])
+ /// .lastWhere((element) => element % 10 == 0, orElse: () => -1);
+ /// print(result); // -1
+ /// ```
Future<T> lastWhere(bool test(T element), {T orElse()?}) {
_Future<T> future = new _Future();
late T result;
@@ -1457,6 +1721,21 @@
///
/// Like [lastWhere], except that it is an error if more than one
/// matching element occurs in this stream.
+ ///
+ /// Example:
+ /// ```dart
+ /// var result = await Stream.fromIterable([1, 2, 3, 6, 9, 12])
+ /// .singleWhere((element) => element % 4 == 0, orElse: () => -1);
+ /// print(result); // 12
+ ///
+ /// result = await Stream.fromIterable([2, 6, 8, 12, 24, 32])
+ /// .singleWhere((element) => element % 9 == 0, orElse: () => -1);
+ /// print(result); // -1
+ ///
+ /// result = await Stream.fromIterable([2, 6, 8, 12, 24, 32])
+ /// .singleWhere((element) => element % 6 == 0, orElse: () => -1);
+ /// // Throws.
+ /// ```
Future<T> singleWhere(bool test(T element), {T orElse()?}) {
_Future<T> future = new _Future<T>();
late T result;
@@ -1541,7 +1820,7 @@
/// the returned stream.
///
/// The countdown starts when the returned stream is listened to,
- /// and is restarted when an event from the this stream is emitted,
+ /// and is restarted when an event from this stream is emitted,
/// or when listening on the returned stream is paused and resumed.
/// The countdown is stopped when listening on the returned stream is
/// paused or cancelled.
@@ -1565,6 +1844,25 @@
/// If a broadcast stream is listened to more than once, each subscription
/// will have its individually timer that starts counting on listen,
/// and the subscriptions' timers can be paused individually.
+ ///
+ /// Example:
+ /// ```dart
+ /// Future<String> waitTask() async {
+ /// return await Future.delayed(
+ /// const Duration(seconds: 4), () => 'Complete');
+ /// }
+ /// final stream = Stream<String>.fromFuture(waitTask())
+ /// .timeout(const Duration(seconds: 2), onTimeout: (controller) {
+ /// print('TimeOut occurred');
+ /// controller.close();
+ /// });
+ ///
+ /// stream.listen(print, onDone: () => print('Done'));
+ ///
+ /// // Outputs:
+ /// // TimeOut occurred
+ /// // Done
+ /// ```
Stream<T> timeout(Duration timeLimit, {void onTimeout(EventSink<T> sink)?}) {
_StreamControllerBase<T> controller;
if (isBroadcast) {
@@ -1648,6 +1946,31 @@
/// and holds the callbacks used to handle the events.
/// The subscription can also be used to unsubscribe from the events,
/// or to temporarily pause the events from the stream.
+///
+/// Example:
+/// ```dart
+/// final stream = Stream.periodic(const Duration(seconds: 1), (i) => i * i)
+/// .take(10);
+///
+/// final subscription = stream.listen(print); // A StreamSubscription<int>.
+/// ```
+/// To pause the subscription, use [pause].
+/// ```dart continued
+/// // Do some work.
+/// subscription.pause();
+/// print(subscription.isPaused); // true
+/// ```
+/// To resume after the pause, use [resume].
+/// ```dart continued
+/// // Do some work.
+/// subscription.resume();
+/// print(subscription.isPaused); // false
+/// ```
+/// To cancel the subscription, use [cancel].
+/// ```dart continued
+/// // Do some work.
+/// subscription.cancel();
+/// ```
abstract class StreamSubscription<T> {
/// Cancels this subscription.
///
@@ -2223,7 +2546,7 @@
/// As with any synchronous event delivery, the sender should be very careful
/// to not deliver events at times when a new listener might not
/// be ready to receive them.
-/// That generally means only delivering events synchronously in response to other
+/// That usually means only delivering events synchronously in response to other
/// asynchronous events, because that is a time when an asynchronous event could
/// happen.
@Since("2.9")
diff --git a/sdk/lib/collection/collection.dart b/sdk/lib/collection/collection.dart
index ac592bd..499b781 100644
--- a/sdk/lib/collection/collection.dart
+++ b/sdk/lib/collection/collection.dart
@@ -8,6 +8,49 @@
/// ```dart
/// import 'dart:collection';
/// ```
+///
+/// ## Map
+/// A finite mapping from unique keys to their associated values.
+/// Allows efficient lookup of the value associated with a key, if any,
+/// and iterating through the individual keys and values of the map.
+/// The [Map] interface has a number of implementations, including the following:
+/// * [HashMap] is unordered, the order of iteration is not guaranteed.
+/// * [LinkedHashMap] iterates in key insertion order.
+/// * [SplayTreeMap] iterates the keys in sorted order.
+/// * [UnmodifiableMapView] is a wrapper, an unmodifiable [Map] view of another
+/// `Map`.
+///
+/// ## Set
+/// A collection of objects in which each object can occur only once.
+/// The [Set] interface has a number of implementations, including the following:
+/// * [HashSet] the order of the objects in the iterations is not guaranteed.
+/// * [LinkedHashSet] iterates the objects in insertion order.
+/// * [SplayTreeSet] iterates the objects in sorted order.
+/// * [UnmodifiableSetView] is a wrapper, an unmodifiable [Set] view of another
+/// `Set`.
+///
+/// ## Queue
+/// A queue is a sequence of elements that is intended to be modified,
+/// by adding or removing elements, only at its ends.
+/// Dart queues are *double ended* queues, which means that they can be
+/// accessed equally from either end, and can therefore be used
+/// to implement both stack and queue behavior.
+/// * [Queue] is the general interface for queues.
+/// * [ListQueue] is a list-based queue. Default implementation for [Queue].
+/// * [DoubleLinkedQueue] is a queue implementation based on a double-linked
+/// list.
+///
+/// ## List
+/// An indexable Sequence of objects. Objects can be accessed using their
+/// position, index, in the sequence. [List] is also called an "array" in other
+/// programming languages.
+/// * [UnmodifiableListView] is a wrapper, an unmodifiable [List] view of
+/// another `List`.
+///
+/// ## LinkedList
+/// [LinkedList] is a specialized double-linked list of elements that extends
+/// [LinkedListEntry]. Each element knows its own place in the linked list,
+/// as well as which list it is in.
/// {@category Core}
library dart.collection;
diff --git a/sdk/lib/core/function.dart b/sdk/lib/core/function.dart
index 1151354..ea2d614 100644
--- a/sdk/lib/core/function.dart
+++ b/sdk/lib/core/function.dart
@@ -20,16 +20,33 @@
///
/// Example:
/// ```dart
- /// Function.apply(foo, [1, 2, 3], {#f: 4, #g: 5});
- /// ```
+ /// void printWineDetails(int vintage, {String? country, String? name}) {
+ /// print('Name: $name, Country: $country, Vintage: $vintage');
+ /// }
///
- /// gives exactly the same result as
- /// ```dart
- /// foo(1, 2, 3, f: 4, g: 5).
+ /// void main() {
+ /// Function.apply(
+ /// printWineDetails, [2018], {#country: 'USA', #name: 'Dominus Estate'});
+ /// }
+ ///
+ /// // Output of the example is:
+ /// // Name: Dominus Estate, Country: USA, Vintage: 2018
/// ```
///
/// If [positionalArguments] is null, it's considered an empty list.
/// If [namedArguments] is omitted or null, it is considered an empty map.
+ ///
+ /// ```dart
+ /// void helloWorld() {
+ /// print('Hello world!');
+ /// }
+ ///
+ /// void main() {
+ /// Function.apply(helloWorld, null);
+ /// }
+ /// // Output of the example is:
+ /// // Hello world!
+ /// ```
external static apply(Function function, List<dynamic>? positionalArguments,
[Map<Symbol, dynamic>? namedArguments]);
diff --git a/sdk/lib/ffi/abi_specific.dart b/sdk/lib/ffi/abi_specific.dart
index d84f74e..a41308c 100644
--- a/sdk/lib/ffi/abi_specific.dart
+++ b/sdk/lib/ffi/abi_specific.dart
@@ -13,10 +13,12 @@
/// For example:
///
/// ```
-/// /// Represents a `uintptr_t` in C.
+/// /// The C `uintptr_t` type.
/// ///
-/// /// [UintPtr] is not constructible in the Dart code and serves purely as
-/// /// marker in type signatures.
+/// /// The [UintPtr] type is a native type, and should not be constructed in
+/// /// Dart code.
+/// /// It occurs only in native type signatures and as annotation on [Struct]
+/// /// and [Union] fields.
/// @AbiSpecificIntegerMapping({
/// Abi.androidArm: Uint32(),
/// Abi.androidArm64: Uint64(),
diff --git a/sdk/lib/ffi/c_type.dart b/sdk/lib/ffi/c_type.dart
new file mode 100644
index 0000000..9370fdc
--- /dev/null
+++ b/sdk/lib/ffi/c_type.dart
@@ -0,0 +1,541 @@
+// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
+// 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.
+
+/// This library defines [NativeType]s for common C types.
+///
+/// Many C types only define a minimal size in the C standard, but they are
+/// consistent per [Abi]. Therefore we use [AbiSpecificInteger]s to define
+/// these C types in this library.
+part of dart.ffi;
+
+/// The C `char` type.
+///
+/// Typically a signed or unsigned 8-bit integer.
+/// For a guaranteed 8-bit integer, use [Int8] with the C `int8_t` type
+/// or [Uint8] with the C `uint8_t` type.
+/// For a specifically `signed` or `unsigned` `char`, use [SignedChar] or
+/// [UnsignedChar].
+///
+/// The [Char] type is a native type, and should not be constructed in
+/// Dart code.
+/// It occurs only in native type signatures and as annotation on [Struct] and
+/// [Union] fields.
+@AbiSpecificIntegerMapping({
+ Abi.androidArm: Uint8(),
+ Abi.androidArm64: Uint8(),
+ Abi.androidIA32: Uint8(),
+ Abi.androidX64: Uint8(),
+ Abi.fuchsiaArm64: Int8(),
+ Abi.fuchsiaX64: Int8(),
+ Abi.iosArm: Uint8(),
+ Abi.iosArm64: Int8(),
+ Abi.iosX64: Int8(),
+ Abi.linuxArm: Uint8(),
+ Abi.linuxArm64: Int8(),
+ Abi.linuxIA32: Int8(),
+ Abi.linuxX64: Int8(),
+ Abi.linuxRiscv32: Int8(),
+ Abi.linuxRiscv64: Int8(),
+ Abi.macosArm64: Int8(),
+ Abi.macosX64: Int8(),
+ Abi.windowsArm64: Int8(),
+ Abi.windowsIA32: Int8(),
+ Abi.windowsX64: Int8(),
+})
+class Char extends AbiSpecificInteger {
+ const Char();
+}
+
+/// The C `signed char` type.
+///
+/// Typically a signed 8-bit integer.
+/// For a guaranteed 8-bit integer, use [Int8] with the C `int8_t` type.
+/// For an `unsigned char`, use [UnsignedChar].
+///
+/// The [SignedChar] type is a native type, and should not be constructed in
+/// Dart code.
+/// It occurs only in native type signatures and as annotation on [Struct] and
+/// [Union] fields.
+@AbiSpecificIntegerMapping({
+ Abi.androidArm: Int8(),
+ Abi.androidArm64: Int8(),
+ Abi.androidIA32: Int8(),
+ Abi.androidX64: Int8(),
+ Abi.fuchsiaArm64: Int8(),
+ Abi.fuchsiaX64: Int8(),
+ Abi.iosArm: Int8(),
+ Abi.iosArm64: Int8(),
+ Abi.iosX64: Int8(),
+ Abi.linuxArm: Int8(),
+ Abi.linuxArm64: Int8(),
+ Abi.linuxIA32: Int8(),
+ Abi.linuxX64: Int8(),
+ Abi.linuxRiscv32: Int8(),
+ Abi.linuxRiscv64: Int8(),
+ Abi.macosArm64: Int8(),
+ Abi.macosX64: Int8(),
+ Abi.windowsArm64: Int8(),
+ Abi.windowsIA32: Int8(),
+ Abi.windowsX64: Int8(),
+})
+class SignedChar extends AbiSpecificInteger {
+ const SignedChar();
+}
+
+/// The C `unsigned char` type.
+///
+/// Typically an unsigned 8-bit integer.
+/// For a guaranteed 8-bit integer, use [Uint8] with the C `uint8_t` type.
+/// For a `signed char`, use [Char].
+///
+/// The [UnsignedChar] type is a native type, and should not be constructed in
+/// Dart code.
+/// It occurs only in native type signatures and as annotation on [Struct] and
+/// [Union] fields.
+@AbiSpecificIntegerMapping({
+ Abi.androidArm: Uint8(),
+ Abi.androidArm64: Uint8(),
+ Abi.androidIA32: Uint8(),
+ Abi.androidX64: Uint8(),
+ Abi.fuchsiaArm64: Uint8(),
+ Abi.fuchsiaX64: Uint8(),
+ Abi.iosArm: Uint8(),
+ Abi.iosArm64: Uint8(),
+ Abi.iosX64: Uint8(),
+ Abi.linuxArm: Uint8(),
+ Abi.linuxArm64: Uint8(),
+ Abi.linuxIA32: Uint8(),
+ Abi.linuxX64: Uint8(),
+ Abi.linuxRiscv32: Uint8(),
+ Abi.linuxRiscv64: Uint8(),
+ Abi.macosArm64: Uint8(),
+ Abi.macosX64: Uint8(),
+ Abi.windowsArm64: Uint8(),
+ Abi.windowsIA32: Uint8(),
+ Abi.windowsX64: Uint8(),
+})
+class UnsignedChar extends AbiSpecificInteger {
+ const UnsignedChar();
+}
+
+/// The C `short` type.
+///
+/// Typically a signed 16-bit integer.
+/// For a guaranteed 16-bit integer, use [Int16] with the C `int16_t` type.
+/// For an `unsigned short`, use [UnsignedShort].
+///
+/// The [Short] type is a native type, and should not be constructed in
+/// Dart code.
+/// It occurs only in native type signatures and as annotation on [Struct] and
+/// [Union] fields.
+@AbiSpecificIntegerMapping({
+ Abi.androidArm: Int16(),
+ Abi.androidArm64: Int16(),
+ Abi.androidIA32: Int16(),
+ Abi.androidX64: Int16(),
+ Abi.fuchsiaArm64: Int16(),
+ Abi.fuchsiaX64: Int16(),
+ Abi.iosArm: Int16(),
+ Abi.iosArm64: Int16(),
+ Abi.iosX64: Int16(),
+ Abi.linuxArm: Int16(),
+ Abi.linuxArm64: Int16(),
+ Abi.linuxIA32: Int16(),
+ Abi.linuxX64: Int16(),
+ Abi.linuxRiscv32: Int16(),
+ Abi.linuxRiscv64: Int16(),
+ Abi.macosArm64: Int16(),
+ Abi.macosX64: Int16(),
+ Abi.windowsArm64: Int16(),
+ Abi.windowsIA32: Int16(),
+ Abi.windowsX64: Int16(),
+})
+class Short extends AbiSpecificInteger {
+ const Short();
+}
+
+/// The C `unsigned short` type.
+///
+/// Typically an unsigned 16-bit integer.
+/// For a guaranteed 16-bit integer, use [Uint16] with the C `uint16_t` type.
+/// For a signed `short`, use [Short].
+///
+/// The [UnsignedShort] type is a native type, and should not be constructed in
+/// Dart code.
+/// It occurs only in native type signatures and as annotation on [Struct] and
+/// [Union] fields.
+@AbiSpecificIntegerMapping({
+ Abi.androidArm: Uint16(),
+ Abi.androidArm64: Uint16(),
+ Abi.androidIA32: Uint16(),
+ Abi.androidX64: Uint16(),
+ Abi.fuchsiaArm64: Uint16(),
+ Abi.fuchsiaX64: Uint16(),
+ Abi.iosArm: Uint16(),
+ Abi.iosArm64: Uint16(),
+ Abi.iosX64: Uint16(),
+ Abi.linuxArm: Uint16(),
+ Abi.linuxArm64: Uint16(),
+ Abi.linuxIA32: Uint16(),
+ Abi.linuxX64: Uint16(),
+ Abi.linuxRiscv32: Uint16(),
+ Abi.linuxRiscv64: Uint16(),
+ Abi.macosArm64: Uint16(),
+ Abi.macosX64: Uint16(),
+ Abi.windowsArm64: Uint16(),
+ Abi.windowsIA32: Uint16(),
+ Abi.windowsX64: Uint16(),
+})
+class UnsignedShort extends AbiSpecificInteger {
+ const UnsignedShort();
+}
+
+/// The C `int` type.
+///
+/// Typically a signed 32-bit integer.
+/// For a guaranteed 32-bit integer, use [Int32] with the C `int32_t` type.
+/// For an `unsigned int`, use [UnsignedInt].
+///
+/// The [Int] type is a native type, and should not be constructed in
+/// Dart code.
+/// It occurs only in native type signatures and as annotation on [Struct] and
+/// [Union] fields.
+@AbiSpecificIntegerMapping({
+ Abi.androidArm: Int32(),
+ Abi.androidArm64: Int32(),
+ Abi.androidIA32: Int32(),
+ Abi.androidX64: Int32(),
+ Abi.fuchsiaArm64: Int32(),
+ Abi.fuchsiaX64: Int32(),
+ Abi.iosArm: Int32(),
+ Abi.iosArm64: Int32(),
+ Abi.iosX64: Int32(),
+ Abi.linuxArm: Int32(),
+ Abi.linuxArm64: Int32(),
+ Abi.linuxIA32: Int32(),
+ Abi.linuxX64: Int32(),
+ Abi.linuxRiscv32: Int32(),
+ Abi.linuxRiscv64: Int32(),
+ Abi.macosArm64: Int32(),
+ Abi.macosX64: Int32(),
+ Abi.windowsArm64: Int32(),
+ Abi.windowsIA32: Int32(),
+ Abi.windowsX64: Int32(),
+})
+class Int extends AbiSpecificInteger {
+ const Int();
+}
+
+/// The C `unsigned int` type.
+///
+/// Typically an unsigned 32-bit integer.
+/// For a guaranteed 32-bit integer, use [Uint32] with the C `uint32_t` type.
+/// For a signed `int`, use [Int].
+///
+/// The [UnsignedInt] type is a native type, and should not be constructed in
+/// Dart code.
+/// It occurs only in native type signatures and as annotation on [Struct] and
+/// [Union] fields.
+@AbiSpecificIntegerMapping({
+ Abi.androidArm: Uint32(),
+ Abi.androidArm64: Uint32(),
+ Abi.androidIA32: Uint32(),
+ Abi.androidX64: Uint32(),
+ Abi.fuchsiaArm64: Uint32(),
+ Abi.fuchsiaX64: Uint32(),
+ Abi.iosArm: Uint32(),
+ Abi.iosArm64: Uint32(),
+ Abi.iosX64: Uint32(),
+ Abi.linuxArm: Uint32(),
+ Abi.linuxArm64: Uint32(),
+ Abi.linuxIA32: Uint32(),
+ Abi.linuxX64: Uint32(),
+ Abi.linuxRiscv32: Uint32(),
+ Abi.linuxRiscv64: Uint32(),
+ Abi.macosArm64: Uint32(),
+ Abi.macosX64: Uint32(),
+ Abi.windowsArm64: Uint32(),
+ Abi.windowsIA32: Uint32(),
+ Abi.windowsX64: Uint32(),
+})
+class UnsignedInt extends AbiSpecificInteger {
+ const UnsignedInt();
+}
+
+/// The C `long int`, aka. `long`, type.
+///
+/// Typically a signed 32- or 64-bit integer.
+/// For a guaranteed 32-bit integer, use [Int32] with the C `int32_t` type.
+/// For a guaranteed 64-bit integer, use [Int64] with the C `int64_t` type.
+/// For an `unsigned long`, use [UnsignedLong].
+///
+/// The [Long] type is a native type, and should not be constructed in
+/// Dart code.
+/// It occurs only in native type signatures and as annotation on [Struct] and
+/// [Union] fields.
+@AbiSpecificIntegerMapping({
+ Abi.androidArm: Int32(),
+ Abi.androidArm64: Int64(),
+ Abi.androidIA32: Int32(),
+ Abi.androidX64: Int64(),
+ Abi.fuchsiaArm64: Int64(),
+ Abi.fuchsiaX64: Int64(),
+ Abi.iosArm: Int32(),
+ Abi.iosArm64: Int64(),
+ Abi.iosX64: Int64(),
+ Abi.linuxArm: Int32(),
+ Abi.linuxArm64: Int64(),
+ Abi.linuxIA32: Int32(),
+ Abi.linuxX64: Int64(),
+ Abi.linuxRiscv32: Int32(),
+ Abi.linuxRiscv64: Int64(),
+ Abi.macosArm64: Int64(),
+ Abi.macosX64: Int64(),
+ Abi.windowsArm64: Int32(),
+ Abi.windowsIA32: Int32(),
+ Abi.windowsX64: Int32(),
+})
+class Long extends AbiSpecificInteger {
+ const Long();
+}
+
+/// The C `unsigned long int`, aka. `unsigned long`, type.
+///
+/// Typically an unsigned 32- or 64-bit integer.
+/// For a guaranteed 32-bit integer, use [Uint32] with the C `uint32_t` type.
+/// For a guaranteed 64-bit integer, use [Uint64] with the C `uint64_t` type.
+/// For a signed `long`, use [Long].
+///
+/// The [UnsignedLong] type is a native type, and should not be constructed in
+/// Dart code.
+/// It occurs only in native type signatures and as annotation on [Struct] and
+/// [Union] fields.
+@AbiSpecificIntegerMapping({
+ Abi.androidArm: Uint32(),
+ Abi.androidArm64: Uint64(),
+ Abi.androidIA32: Uint32(),
+ Abi.androidX64: Uint64(),
+ Abi.fuchsiaArm64: Uint64(),
+ Abi.fuchsiaX64: Uint64(),
+ Abi.iosArm: Uint32(),
+ Abi.iosArm64: Uint64(),
+ Abi.iosX64: Uint64(),
+ Abi.linuxArm: Uint32(),
+ Abi.linuxArm64: Uint64(),
+ Abi.linuxIA32: Uint32(),
+ Abi.linuxX64: Uint64(),
+ Abi.linuxRiscv32: Uint32(),
+ Abi.linuxRiscv64: Uint64(),
+ Abi.macosArm64: Uint64(),
+ Abi.macosX64: Uint64(),
+ Abi.windowsArm64: Uint32(),
+ Abi.windowsIA32: Uint32(),
+ Abi.windowsX64: Uint32(),
+})
+class UnsignedLong extends AbiSpecificInteger {
+ const UnsignedLong();
+}
+
+/// The C `long long` type.
+///
+/// Typically a signed 64-bit integer.
+/// For a guaranteed 64-bit integer, use [Int64] with the C `int64_t` type.
+/// For an `unsigned long long`, use [UnsignedLongLong].
+///
+/// The [LongLong] type is a native type, and should not be constructed in
+/// Dart code.
+/// It occurs only in native type signatures and as annotation on [Struct] and
+/// [Union] fields.
+@AbiSpecificIntegerMapping({
+ Abi.androidArm: Int64(),
+ Abi.androidArm64: Int64(),
+ Abi.androidIA32: Int64(),
+ Abi.androidX64: Int64(),
+ Abi.fuchsiaArm64: Int64(),
+ Abi.fuchsiaX64: Int64(),
+ Abi.iosArm: Int64(),
+ Abi.iosArm64: Int64(),
+ Abi.iosX64: Int64(),
+ Abi.linuxArm: Int64(),
+ Abi.linuxArm64: Int64(),
+ Abi.linuxIA32: Int64(),
+ Abi.linuxX64: Int64(),
+ Abi.linuxRiscv32: Int64(),
+ Abi.linuxRiscv64: Int64(),
+ Abi.macosArm64: Int64(),
+ Abi.macosX64: Int64(),
+ Abi.windowsArm64: Int64(),
+ Abi.windowsIA32: Int64(),
+ Abi.windowsX64: Int64(),
+})
+class LongLong extends AbiSpecificInteger {
+ const LongLong();
+}
+
+/// The C `unsigned long long` type.
+///
+/// Typically an unsigned 64-bit integer.
+/// For a guaranteed 64-bit integer, use [Uint64] with the C `uint64_t` type.
+/// For a signed `long long`, use [LongLong].
+///
+/// The [UnsignedLongLong] type is a native type, and should not be constructed
+/// in Dart code.
+/// It occurs only in native type signatures and as annotation on [Struct] and
+/// [Union] fields.
+@AbiSpecificIntegerMapping({
+ Abi.androidArm: Uint64(),
+ Abi.androidArm64: Uint64(),
+ Abi.androidIA32: Uint64(),
+ Abi.androidX64: Uint64(),
+ Abi.fuchsiaArm64: Uint64(),
+ Abi.fuchsiaX64: Uint64(),
+ Abi.iosArm: Uint64(),
+ Abi.iosArm64: Uint64(),
+ Abi.iosX64: Uint64(),
+ Abi.linuxArm: Uint64(),
+ Abi.linuxArm64: Uint64(),
+ Abi.linuxIA32: Uint64(),
+ Abi.linuxX64: Uint64(),
+ Abi.linuxRiscv32: Uint64(),
+ Abi.linuxRiscv64: Uint64(),
+ Abi.macosArm64: Uint64(),
+ Abi.macosX64: Uint64(),
+ Abi.windowsArm64: Uint64(),
+ Abi.windowsIA32: Uint64(),
+ Abi.windowsX64: Uint64(),
+})
+class UnsignedLongLong extends AbiSpecificInteger {
+ const UnsignedLongLong();
+}
+
+/// The C `intptr_t` type.
+///
+/// The [IntPtr] type is a native type, and should not be constructed in
+/// Dart code.
+/// It occurs only in native type signatures and as annotation on [Struct] and
+/// [Union] fields.
+@AbiSpecificIntegerMapping({
+ Abi.androidArm: Int32(),
+ Abi.androidArm64: Int64(),
+ Abi.androidIA32: Int32(),
+ Abi.androidX64: Int64(),
+ Abi.fuchsiaArm64: Int64(),
+ Abi.fuchsiaX64: Int64(),
+ Abi.iosArm: Int32(),
+ Abi.iosArm64: Int64(),
+ Abi.iosX64: Int64(),
+ Abi.linuxArm: Int32(),
+ Abi.linuxArm64: Int64(),
+ Abi.linuxIA32: Int32(),
+ Abi.linuxX64: Int64(),
+ Abi.linuxRiscv32: Int32(),
+ Abi.linuxRiscv64: Int64(),
+ Abi.macosArm64: Int64(),
+ Abi.macosX64: Int64(),
+ Abi.windowsArm64: Int64(),
+ Abi.windowsIA32: Int32(),
+ Abi.windowsX64: Int64(),
+})
+class IntPtr extends AbiSpecificInteger {
+ const IntPtr();
+}
+
+/// The C `uintptr_t` type.
+///
+/// The [UintPtr] type is a native type, and should not be constructed in
+/// Dart code.
+/// It occurs only in native type signatures and as annotation on [Struct] and
+/// [Union] fields.
+@AbiSpecificIntegerMapping({
+ Abi.androidArm: Uint32(),
+ Abi.androidArm64: Uint64(),
+ Abi.androidIA32: Uint32(),
+ Abi.androidX64: Uint64(),
+ Abi.fuchsiaArm64: Uint64(),
+ Abi.fuchsiaX64: Uint64(),
+ Abi.iosArm: Uint32(),
+ Abi.iosArm64: Uint64(),
+ Abi.iosX64: Uint64(),
+ Abi.linuxArm: Uint32(),
+ Abi.linuxArm64: Uint64(),
+ Abi.linuxIA32: Uint32(),
+ Abi.linuxX64: Uint64(),
+ Abi.linuxRiscv32: Uint32(),
+ Abi.linuxRiscv64: Uint64(),
+ Abi.macosArm64: Uint64(),
+ Abi.macosX64: Uint64(),
+ Abi.windowsArm64: Uint64(),
+ Abi.windowsIA32: Uint32(),
+ Abi.windowsX64: Uint64(),
+})
+class UintPtr extends AbiSpecificInteger {
+ const UintPtr();
+}
+
+/// The C `size_t` type.
+///
+/// The [Size] type is a native type, and should not be constructed in
+/// Dart code.
+/// It occurs only in native type signatures and as annotation on [Struct] and
+/// [Union] fields.
+@AbiSpecificIntegerMapping({
+ Abi.androidArm: Uint32(),
+ Abi.androidArm64: Uint64(),
+ Abi.androidIA32: Uint32(),
+ Abi.androidX64: Uint64(),
+ Abi.fuchsiaArm64: Uint64(),
+ Abi.fuchsiaX64: Uint64(),
+ Abi.iosArm: Uint32(),
+ Abi.iosArm64: Uint64(),
+ Abi.iosX64: Uint64(),
+ Abi.linuxArm: Uint32(),
+ Abi.linuxArm64: Uint64(),
+ Abi.linuxIA32: Uint32(),
+ Abi.linuxX64: Uint64(),
+ Abi.linuxRiscv32: Uint32(),
+ Abi.linuxRiscv64: Uint64(),
+ Abi.macosArm64: Uint64(),
+ Abi.macosX64: Uint64(),
+ Abi.windowsArm64: Uint64(),
+ Abi.windowsIA32: Uint32(),
+ Abi.windowsX64: Uint64(),
+})
+class Size extends AbiSpecificInteger {
+ const Size();
+}
+
+/// The C `wchar_t` type.
+///
+/// The signedness of `wchar_t` is undefined in C. Here, it is exposed as the
+/// defaults on the tested [Abi]s.
+///
+/// The [WChar] type is a native type, and should not be constructed in
+/// Dart code.
+/// It occurs only in native type signatures and as annotation on [Struct] and
+/// [Union] fields.
+@AbiSpecificIntegerMapping({
+ Abi.androidArm: Uint32(),
+ Abi.androidArm64: Uint32(),
+ Abi.androidIA32: Uint32(),
+ Abi.androidX64: Uint32(),
+ Abi.fuchsiaArm64: Uint32(),
+ Abi.fuchsiaX64: Int32(),
+ Abi.iosArm: Int32(),
+ Abi.iosArm64: Int32(),
+ Abi.iosX64: Int32(),
+ Abi.linuxArm: Uint32(),
+ Abi.linuxArm64: Uint32(),
+ Abi.linuxIA32: Int32(),
+ Abi.linuxX64: Int32(),
+ Abi.linuxRiscv32: Uint32(),
+ Abi.linuxRiscv64: Uint32(),
+ Abi.macosArm64: Int32(),
+ Abi.macosX64: Int32(),
+ Abi.windowsArm64: Uint16(),
+ Abi.windowsIA32: Uint16(),
+ Abi.windowsX64: Uint16(),
+})
+class WChar extends AbiSpecificInteger {
+ const WChar();
+}
diff --git a/sdk/lib/ffi/ffi.dart b/sdk/lib/ffi/ffi.dart
index b1d53a6..9a7afe2 100644
--- a/sdk/lib/ffi/ffi.dart
+++ b/sdk/lib/ffi/ffi.dart
@@ -20,6 +20,7 @@
part 'native_type.dart';
part 'allocation.dart';
part 'annotations.dart';
+part 'c_type.dart';
part 'dynamic_library.dart';
part 'struct.dart';
part 'union.dart';
diff --git a/sdk/lib/ffi/native_type.dart b/sdk/lib/ffi/native_type.dart
index dbbea7c..55a9f6d 100644
--- a/sdk/lib/ffi/native_type.dart
+++ b/sdk/lib/ffi/native_type.dart
@@ -98,36 +98,6 @@
const Uint64();
}
-/// Represents a native pointer-sized integer in C.
-///
-/// [IntPtr] is not constructible in the Dart code and serves purely as marker
-/// in type signatures.
-@AbiSpecificIntegerMapping({
- Abi.androidArm: Int32(),
- Abi.androidArm64: Int64(),
- Abi.androidIA32: Int32(),
- Abi.androidX64: Int64(),
- Abi.fuchsiaArm64: Int64(),
- Abi.fuchsiaX64: Int64(),
- Abi.iosArm: Int32(),
- Abi.iosArm64: Int64(),
- Abi.iosX64: Int64(),
- Abi.linuxArm: Int32(),
- Abi.linuxArm64: Int64(),
- Abi.linuxIA32: Int32(),
- Abi.linuxX64: Int64(),
- Abi.linuxRiscv32: Int32(),
- Abi.linuxRiscv64: Int64(),
- Abi.macosArm64: Int64(),
- Abi.macosX64: Int64(),
- Abi.windowsArm64: Int64(),
- Abi.windowsIA32: Int32(),
- Abi.windowsX64: Int64(),
-})
-class IntPtr extends AbiSpecificInteger {
- const IntPtr();
-}
-
/// Represents a native 32 bit float in C.
///
/// [Float] is not constructible in the Dart code and serves purely as marker
diff --git a/tests/ffi/abi_specific_int_test.dart b/tests/ffi/abi_specific_int_test.dart
index 266655c..cea45b1 100644
--- a/tests/ffi/abi_specific_int_test.dart
+++ b/tests/ffi/abi_specific_int_test.dart
@@ -8,8 +8,6 @@
import 'package:expect/expect.dart';
import 'package:ffi/ffi.dart';
-import 'abi_specific_ints.dart';
-
void main() {
testSizeOf();
testStoreLoad();
diff --git a/tests/ffi/abi_specific_ints.dart b/tests/ffi/abi_specific_ints.dart
deleted file mode 100644
index c0cd3f0..0000000
--- a/tests/ffi/abi_specific_ints.dart
+++ /dev/null
@@ -1,145 +0,0 @@
-// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
-// 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.
-
-import 'dart:ffi';
-
-// TODO(dacoharkes): These should move to `package:ffi`.
-
-// `int` in C.
-typedef Int = Int32;
-
-// `unsigned int` in C.
-typedef UnsignedInt = Uint32;
-
-// `size_t` in C.
-typedef Size = UintPtr;
-
-// `ssize_t` in C.
-typedef SSize = IntPtr;
-
-// `off_t` in C.
-typedef Off = Long;
-
-/// Represents a native unsigned pointer-sized integer in C.
-///
-/// [UintPtr] is not constructible in the Dart code and serves purely as marker in
-/// type signatures.
-@AbiSpecificIntegerMapping({
- Abi.androidArm: Uint32(),
- Abi.androidArm64: Uint64(),
- Abi.androidIA32: Uint32(),
- Abi.androidX64: Uint64(),
- Abi.fuchsiaArm64: Uint64(),
- Abi.fuchsiaX64: Uint64(),
- Abi.iosArm: Uint32(),
- Abi.iosArm64: Uint64(),
- Abi.iosX64: Uint64(),
- Abi.linuxArm: Uint32(),
- Abi.linuxArm64: Uint64(),
- Abi.linuxIA32: Uint32(),
- Abi.linuxX64: Uint64(),
- Abi.linuxRiscv32: Uint32(),
- Abi.linuxRiscv64: Uint64(),
- Abi.macosArm64: Uint64(),
- Abi.macosX64: Uint64(),
- Abi.windowsArm64: Uint64(),
- Abi.windowsIA32: Uint32(),
- Abi.windowsX64: Uint64(),
-})
-class UintPtr extends AbiSpecificInteger {
- const UintPtr();
-}
-
-/// `long` in C.
-///
-/// [Long] is not constructible in the Dart code and serves purely as marker in
-/// type signatures.
-@AbiSpecificIntegerMapping({
- Abi.androidArm: Int32(),
- Abi.androidArm64: Int64(),
- Abi.androidIA32: Int32(),
- Abi.androidX64: Int64(),
- Abi.fuchsiaArm64: Int64(),
- Abi.fuchsiaX64: Int64(),
- Abi.iosArm: Int32(),
- Abi.iosArm64: Int64(),
- Abi.iosX64: Int64(),
- Abi.linuxArm: Int32(),
- Abi.linuxArm64: Int64(),
- Abi.linuxIA32: Int32(),
- Abi.linuxX64: Int64(),
- Abi.linuxRiscv32: Int32(),
- Abi.linuxRiscv64: Int64(),
- Abi.macosArm64: Int64(),
- Abi.macosX64: Int64(),
- Abi.windowsArm64: Int32(),
- Abi.windowsIA32: Int32(),
- Abi.windowsX64: Int32(),
-})
-class Long extends AbiSpecificInteger {
- const Long();
-}
-
-/// `unsigned long` in C.
-///
-/// [UnsignedLong] is not constructible in the Dart code and serves purely as marker in
-/// type signatures.
-@AbiSpecificIntegerMapping({
- Abi.androidArm: Uint32(),
- Abi.androidArm64: Uint64(),
- Abi.androidIA32: Uint32(),
- Abi.androidX64: Uint64(),
- Abi.fuchsiaArm64: Uint64(),
- Abi.fuchsiaX64: Uint64(),
- Abi.iosArm: Uint32(),
- Abi.iosArm64: Uint64(),
- Abi.iosX64: Uint64(),
- Abi.linuxArm: Uint32(),
- Abi.linuxArm64: Uint64(),
- Abi.linuxIA32: Uint32(),
- Abi.linuxX64: Uint64(),
- Abi.linuxRiscv32: Uint32(),
- Abi.linuxRiscv64: Uint64(),
- Abi.macosArm64: Uint64(),
- Abi.macosX64: Uint64(),
- Abi.windowsArm64: Uint32(),
- Abi.windowsIA32: Uint32(),
- Abi.windowsX64: Uint32(),
-})
-class UnsignedLong extends AbiSpecificInteger {
- const UnsignedLong();
-}
-
-/// `wchar_t` in C.
-///
-/// The signedness of `wchar_t` is undefined in C. Here, it is exposed as an
-/// unsigned integer.
-///
-/// [WChar] is not constructible in the Dart code and serves purely as marker in
-/// type signatures.
-@AbiSpecificIntegerMapping({
- Abi.androidArm: Uint32(),
- Abi.androidArm64: Uint32(),
- Abi.androidIA32: Uint32(),
- Abi.androidX64: Uint32(),
- Abi.fuchsiaArm64: Uint32(),
- Abi.fuchsiaX64: Uint32(),
- Abi.iosArm: Uint32(),
- Abi.iosArm64: Uint32(),
- Abi.iosX64: Uint32(),
- Abi.linuxArm: Uint32(),
- Abi.linuxArm64: Uint32(),
- Abi.linuxIA32: Uint32(),
- Abi.linuxX64: Uint32(),
- Abi.linuxRiscv32: Uint32(),
- Abi.linuxRiscv64: Uint32(),
- Abi.macosArm64: Uint32(),
- Abi.macosX64: Uint32(),
- Abi.windowsArm64: Uint16(),
- Abi.windowsIA32: Uint16(),
- Abi.windowsX64: Uint16(),
-})
-class WChar extends AbiSpecificInteger {
- const WChar();
-}
diff --git a/tests/ffi/c_types_test.dart b/tests/ffi/c_types_test.dart
index d423c2c..3c2e815 100644
--- a/tests/ffi/c_types_test.dart
+++ b/tests/ffi/c_types_test.dart
@@ -7,11 +7,11 @@
// SharedObjects=ffi_test_functions
import 'dart:ffi';
-
-import "package:expect/expect.dart";
import 'dart:io' show Platform;
-import 'abi_specific_ints.dart';
+import 'package:expect/expect.dart';
+import 'package:ffi/ffi.dart';
+
import 'ffi_test_helpers.dart';
void main() {
@@ -20,62 +20,162 @@
testIntAssumptions();
testSizeTAssumptions();
testLongAssumptions();
- testOffTAssumptions();
testWCharTAssumptions();
}
class CType {
final int ffiSize;
+ final int Function(Pointer)? ffiLoad;
final String modifier;
final String type;
+ final String type2;
- CType(this.ffiSize, this.type, [this.modifier = ""]);
+ CType(this.ffiSize, this.type,
+ {this.type2 = '', this.modifier = '', this.ffiLoad});
- String get cRepresentation => "$modifier $type".trim();
+ String get cRepresentation => '$modifier $type $type2'.trim();
- String get _getSizeName => "FfiSizeOf_$modifier\_$type";
+ String get _getSizeName => 'FfiSizeOf_$modifier\_$type\_$type2';
+
+ String get _getSignName => 'FfiSignOf_$modifier\_$type\_$type2';
int Function() get sizeFunction => ffiTestFunctions
.lookupFunction<Uint64 Function(), int Function()>(_getSizeName);
+ int Function() get signFunction => ffiTestFunctions
+ .lookupFunction<Uint64 Function(), int Function()>(_getSignName);
+
int get size => sizeFunction();
+ bool get isSigned => signFunction() != 0;
+
+ bool? get ffiIsSigned {
+ final ffiLoad_ = ffiLoad;
+ if (ffiLoad_ == null) {
+ return null;
+ }
+ assert(size < 8);
+ return using((Arena arena) {
+ final p = arena<Int64>()..value = -1;
+ return ffiLoad_(p) < 0;
+ });
+ }
+
String toString() => cRepresentation;
}
-final intptr_t = CType(sizeOf<IntPtr>(), "intptr_t");
-final uintptr_t = CType(sizeOf<UintPtr>(), "uintptr_t");
-final int_ = CType(sizeOf<Int>(), "int");
-final uint = CType(sizeOf<UnsignedInt>(), "int", "unsigned");
-final long = CType(sizeOf<Long>(), "long");
-final ulong = CType(sizeOf<UnsignedLong>(), "long", "unsigned");
-final wchar_t = CType(sizeOf<WChar>(), "wchar_t");
-final size_t = CType(sizeOf<Size>(), "size_t");
-final ssize_t = CType(sizeOf<SSize>(), "ssize_t");
-final off_t = CType(sizeOf<Off>(), "off_t");
+final char = CType(
+ sizeOf<Char>(),
+ 'char',
+ ffiLoad: (Pointer p) => p.cast<Char>().value,
+);
+final uchar = CType(
+ sizeOf<UnsignedChar>(),
+ 'char',
+ modifier: 'unsigned',
+ ffiLoad: (Pointer p) => p.cast<UnsignedChar>().value,
+);
+final schar = CType(
+ sizeOf<SignedChar>(),
+ 'char',
+ modifier: 'signed',
+ ffiLoad: (Pointer p) => p.cast<SignedChar>().value,
+);
+final short = CType(
+ sizeOf<Short>(),
+ 'short',
+ ffiLoad: (Pointer p) => p.cast<Short>().value,
+);
+final ushort = CType(
+ sizeOf<UnsignedShort>(),
+ 'short',
+ modifier: 'unsigned',
+ ffiLoad: (Pointer p) => p.cast<UnsignedShort>().value,
+);
+final int_ = CType(
+ sizeOf<Int>(),
+ 'int',
+ ffiLoad: (Pointer p) => p.cast<Int>().value,
+);
+final uint = CType(
+ sizeOf<UnsignedInt>(),
+ 'int',
+ modifier: 'unsigned',
+ ffiLoad: (Pointer p) => p.cast<UnsignedInt>().value,
+);
+final long = CType(
+ sizeOf<Long>(),
+ 'long',
+);
+final ulong = CType(
+ sizeOf<UnsignedLong>(),
+ 'long',
+ modifier: 'unsigned',
+);
+final longlong = CType(
+ sizeOf<LongLong>(),
+ 'long',
+ type2: 'long',
+);
+final ulonglong = CType(
+ sizeOf<UnsignedLongLong>(),
+ 'long',
+ type2: 'long',
+ modifier: 'unsigned',
+);
+final intptr_t = CType(
+ sizeOf<IntPtr>(),
+ 'intptr_t',
+);
+final uintptr_t = CType(
+ sizeOf<UintPtr>(),
+ 'uintptr_t',
+);
+final size_t = CType(
+ sizeOf<Size>(),
+ 'size_t',
+);
+final wchar_t = CType(
+ sizeOf<WChar>(),
+ 'wchar_t',
+ ffiLoad: (Pointer p) => p.cast<WChar>().value,
+);
final cTypes = [
- intptr_t,
- uintptr_t,
+ char,
+ uchar,
+ schar,
+ short,
+ ushort,
int_,
uint,
long,
ulong,
- wchar_t,
+ longlong,
+ ulonglong,
+ intptr_t,
+ uintptr_t,
size_t,
- ssize_t,
- off_t
+ wchar_t,
];
void printSizes() {
cTypes.forEach((element) {
- print("${element.cRepresentation.padRight(20)}: ${element.size}");
+ final cName = element.cRepresentation.padRight(20);
+ final size = element.size;
+ final signed = element.isSigned ? 'signed' : 'unsigned';
+ print('$cName: $size $signed');
});
}
void testSizes() {
cTypes.forEach((element) {
+ print(element);
Expect.equals(element.size, element.ffiSize);
+ final ffiIsSigned = element.ffiIsSigned;
+ if (ffiIsSigned != null) {
+ Expect.equals(element.isSigned, ffiIsSigned);
+ }
});
}
@@ -86,7 +186,6 @@
void testSizeTAssumptions() {
Expect.equals(intptr_t.size, size_t.size);
- Expect.equals(intptr_t.size, ssize_t.size);
}
void testLongAssumptions() {
@@ -99,13 +198,9 @@
}
}
-void testOffTAssumptions() {
- Expect.equals(long.size, off_t.size);
-}
-
void testWCharTAssumptions() {
- final bool isSigned = wCharMinValue() != 0;
- print("wchar_t isSigned $isSigned");
+ final bool isSigned = wchar_t.isSigned;
+ print('wchar_t isSigned $isSigned');
if (Platform.isWindows) {
Expect.equals(2, wchar_t.size);
if (isSigned) {
diff --git a/tests/ffi/function_callbacks_structs_by_value_generated_test.dart b/tests/ffi/function_callbacks_structs_by_value_generated_test.dart
index 2276d2f..2fbccd1 100644
--- a/tests/ffi/function_callbacks_structs_by_value_generated_test.dart
+++ b/tests/ffi/function_callbacks_structs_by_value_generated_test.dart
@@ -16,9 +16,6 @@
import "package:expect/expect.dart";
import "package:ffi/ffi.dart";
-// Reuse the AbiSpecificInts.
-import 'abi_specific_ints.dart';
-
import 'callback_tests_utils.dart';
import 'dylib_utils.dart';
diff --git a/tests/ffi/function_structs_by_value_generated_compounds.dart b/tests/ffi/function_structs_by_value_generated_compounds.dart
index 439e9a34..666ef20 100644
--- a/tests/ffi/function_structs_by_value_generated_compounds.dart
+++ b/tests/ffi/function_structs_by_value_generated_compounds.dart
@@ -7,9 +7,6 @@
import 'dart:ffi';
-// Reuse the AbiSpecificInts.
-import 'abi_specific_ints.dart';
-
class Struct1ByteBool extends Struct {
@Bool()
external bool a0;
diff --git a/tests/ffi/function_structs_by_value_generated_leaf_test.dart b/tests/ffi/function_structs_by_value_generated_leaf_test.dart
index 283faad..7704417 100644
--- a/tests/ffi/function_structs_by_value_generated_leaf_test.dart
+++ b/tests/ffi/function_structs_by_value_generated_leaf_test.dart
@@ -16,9 +16,6 @@
import "package:expect/expect.dart";
import "package:ffi/ffi.dart";
-// Reuse the AbiSpecificInts.
-import 'abi_specific_ints.dart';
-
import 'dylib_utils.dart';
// Reuse the compound classes.
diff --git a/tests/ffi/function_structs_by_value_generated_test.dart b/tests/ffi/function_structs_by_value_generated_test.dart
index 1f4c5d3..897472c 100644
--- a/tests/ffi/function_structs_by_value_generated_test.dart
+++ b/tests/ffi/function_structs_by_value_generated_test.dart
@@ -16,9 +16,6 @@
import "package:expect/expect.dart";
import "package:ffi/ffi.dart";
-// Reuse the AbiSpecificInts.
-import 'abi_specific_ints.dart';
-
import 'dylib_utils.dart';
// Reuse the compound classes.
diff --git a/tests/ffi/generator/structs_by_value_tests_generator.dart b/tests/ffi/generator/structs_by_value_tests_generator.dart
index 4c260b9..3a18095 100644
--- a/tests/ffi/generator/structs_by_value_tests_generator.dart
+++ b/tests/ffi/generator/structs_by_value_tests_generator.dart
@@ -922,8 +922,6 @@
import 'dart:ffi';
-// Reuse the AbiSpecificInts.
-import 'abi_specific_ints.dart';
""";
}
@@ -967,8 +965,6 @@
import "package:expect/expect.dart";
import "package:ffi/ffi.dart";
-// Reuse the AbiSpecificInts.
-import 'abi_specific_ints.dart';
import 'dylib_utils.dart';
@@ -1029,8 +1025,6 @@
import "package:expect/expect.dart";
import "package:ffi/ffi.dart";
-// Reuse the AbiSpecificInts.
-import 'abi_specific_ints.dart';
import 'callback_tests_utils.dart';
diff --git a/tests/ffi_2/abi_specific_int_test.dart b/tests/ffi_2/abi_specific_int_test.dart
index 152c159..57daa3f 100644
--- a/tests/ffi_2/abi_specific_int_test.dart
+++ b/tests/ffi_2/abi_specific_int_test.dart
@@ -10,8 +10,6 @@
import 'package:expect/expect.dart';
import 'package:ffi/ffi.dart';
-import 'abi_specific_ints.dart';
-
void main() {
testSizeOf();
testStoreLoad();
diff --git a/tests/ffi_2/abi_specific_ints.dart b/tests/ffi_2/abi_specific_ints.dart
deleted file mode 100644
index c1d8302..0000000
--- a/tests/ffi_2/abi_specific_ints.dart
+++ /dev/null
@@ -1,132 +0,0 @@
-// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
-// 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.
-
-// @dart = 2.9
-
-import 'dart:ffi';
-
-// TODO(dacoharkes): These should move to `package:ffi`.
-
-/// Represents a native unsigned pointer-sized integer in C.
-///
-/// [UintPtr] is not constructible in the Dart code and serves purely as marker in
-/// type signatures.
-@AbiSpecificIntegerMapping({
- Abi.androidArm: Uint32(),
- Abi.androidArm64: Uint64(),
- Abi.androidIA32: Uint32(),
- Abi.androidX64: Uint64(),
- Abi.fuchsiaArm64: Uint64(),
- Abi.fuchsiaX64: Uint64(),
- Abi.iosArm: Uint32(),
- Abi.iosArm64: Uint64(),
- Abi.iosX64: Uint64(),
- Abi.linuxArm: Uint32(),
- Abi.linuxArm64: Uint64(),
- Abi.linuxIA32: Uint32(),
- Abi.linuxX64: Uint64(),
- Abi.linuxRiscv32: Uint32(),
- Abi.linuxRiscv64: Uint64(),
- Abi.macosArm64: Uint64(),
- Abi.macosX64: Uint64(),
- Abi.windowsArm64: Uint64(),
- Abi.windowsIA32: Uint32(),
- Abi.windowsX64: Uint64(),
-})
-class UintPtr extends AbiSpecificInteger {
- const UintPtr();
-}
-
-/// `long` in C.
-///
-/// [Long] is not constructible in the Dart code and serves purely as marker in
-/// type signatures.
-@AbiSpecificIntegerMapping({
- Abi.androidArm: Int32(),
- Abi.androidArm64: Int64(),
- Abi.androidIA32: Int32(),
- Abi.androidX64: Int64(),
- Abi.fuchsiaArm64: Int64(),
- Abi.fuchsiaX64: Int64(),
- Abi.iosArm: Int32(),
- Abi.iosArm64: Int64(),
- Abi.iosX64: Int64(),
- Abi.linuxArm: Int32(),
- Abi.linuxArm64: Int64(),
- Abi.linuxIA32: Int32(),
- Abi.linuxX64: Int64(),
- Abi.linuxRiscv32: Int32(),
- Abi.linuxRiscv64: Int64(),
- Abi.macosArm64: Int64(),
- Abi.macosX64: Int64(),
- Abi.windowsArm64: Int32(),
- Abi.windowsIA32: Int32(),
- Abi.windowsX64: Int32(),
-})
-class Long extends AbiSpecificInteger {
- const Long();
-}
-
-/// `unsigned long` in C.
-///
-/// [UnsignedLong] is not constructible in the Dart code and serves purely as marker in
-/// type signatures.
-@AbiSpecificIntegerMapping({
- Abi.androidArm: Uint32(),
- Abi.androidArm64: Uint64(),
- Abi.androidIA32: Uint32(),
- Abi.androidX64: Uint64(),
- Abi.fuchsiaArm64: Uint64(),
- Abi.fuchsiaX64: Uint64(),
- Abi.iosArm: Uint32(),
- Abi.iosArm64: Uint64(),
- Abi.iosX64: Uint64(),
- Abi.linuxArm: Uint32(),
- Abi.linuxArm64: Uint64(),
- Abi.linuxIA32: Uint32(),
- Abi.linuxX64: Uint64(),
- Abi.linuxRiscv32: Uint32(),
- Abi.linuxRiscv64: Uint64(),
- Abi.macosArm64: Uint64(),
- Abi.macosX64: Uint64(),
- Abi.windowsArm64: Uint32(),
- Abi.windowsIA32: Uint32(),
- Abi.windowsX64: Uint32(),
-})
-class UnsignedLong extends AbiSpecificInteger {
- const UnsignedLong();
-}
-
-/// `wchar_t` in C.
-///
-/// The signedness of `wchar_t` is undefined in C. Here, it is exposed as an
-/// unsigned integer.
-///
-/// [WChar] is not constructible in the Dart code and serves purely as marker in
-/// type signatures.
-@AbiSpecificIntegerMapping({
- Abi.androidArm: Uint32(),
- Abi.androidArm64: Uint32(),
- Abi.androidIA32: Uint32(),
- Abi.androidX64: Uint32(),
- Abi.fuchsiaArm64: Uint32(),
- Abi.fuchsiaX64: Uint32(),
- Abi.iosArm: Uint32(),
- Abi.iosArm64: Uint32(),
- Abi.iosX64: Uint32(),
- Abi.linuxArm: Uint32(),
- Abi.linuxArm64: Uint32(),
- Abi.linuxIA32: Uint32(),
- Abi.linuxX64: Uint32(),
- Abi.linuxRiscv32: Uint32(),
- Abi.linuxRiscv64: Uint32(),
- Abi.macosArm64: Uint32(),
- Abi.macosX64: Uint32(),
- Abi.windowsArm64: Uint16(),
- Abi.windowsIA32: Uint16(),
- Abi.windowsX64: Uint16(),
-})
-class WChar extends AbiSpecificInteger {
- const WChar();
-}
diff --git a/tests/ffi_2/c_types_test.dart b/tests/ffi_2/c_types_test.dart
index fa762bd..7a651ce 100644
--- a/tests/ffi_2/c_types_test.dart
+++ b/tests/ffi_2/c_types_test.dart
@@ -9,65 +9,187 @@
// @dart = 2.9
import 'dart:ffi';
-
-import "package:expect/expect.dart";
import 'dart:io' show Platform;
-import 'abi_specific_ints.dart';
+import 'package:expect/expect.dart';
+import 'package:ffi/ffi.dart';
+
import 'ffi_test_helpers.dart';
void main() {
printSizes();
testSizes();
+ testIntAssumptions();
+ testSizeTAssumptions();
testLongAssumptions();
testWCharTAssumptions();
}
class CType {
final int ffiSize;
+ final int Function(Pointer) ffiLoad;
final String modifier;
final String type;
+ final String type2;
- CType(this.ffiSize, this.type, [this.modifier = ""]);
+ CType(this.ffiSize, this.type,
+ {this.type2 = '', this.modifier = '', this.ffiLoad});
- String get cRepresentation => "$modifier $type".trim();
+ String get cRepresentation => '$modifier $type $type2'.trim();
- String get _getSizeName => "FfiSizeOf_$modifier\_$type";
+ String get _getSizeName => 'FfiSizeOf_$modifier\_$type\_$type2';
+
+ String get _getSignName => 'FfiSignOf_$modifier\_$type\_$type2';
int Function() get sizeFunction => ffiTestFunctions
.lookupFunction<Uint64 Function(), int Function()>(_getSizeName);
+ int Function() get signFunction => ffiTestFunctions
+ .lookupFunction<Uint64 Function(), int Function()>(_getSignName);
+
int get size => sizeFunction();
+ bool get isSigned => signFunction() != 0;
+
+ bool get ffiIsSigned {
+ final ffiLoad_ = ffiLoad;
+ if (ffiLoad_ == null) {
+ return null;
+ }
+ assert(size < 8);
+ return using((Arena arena) {
+ final p = arena<Int64>()..value = -1;
+ return ffiLoad_(p) < 0;
+ });
+ }
+
String toString() => cRepresentation;
}
-final intptr_t = CType(sizeOf<IntPtr>(), "intptr_t");
-final uintptr_t = CType(sizeOf<UintPtr>(), "uintptr_t");
-final long = CType(sizeOf<Long>(), "long");
-final ulong = CType(sizeOf<UnsignedLong>(), "long", "unsigned");
-final wchar_t = CType(sizeOf<WChar>(), "wchar_t");
+final char = CType(
+ sizeOf<Char>(),
+ 'char',
+ ffiLoad: (Pointer p) => p.cast<Char>().value,
+);
+final uchar = CType(
+ sizeOf<UnsignedChar>(),
+ 'char',
+ modifier: 'unsigned',
+ ffiLoad: (Pointer p) => p.cast<UnsignedChar>().value,
+);
+final schar = CType(
+ sizeOf<SignedChar>(),
+ 'char',
+ modifier: 'signed',
+ ffiLoad: (Pointer p) => p.cast<SignedChar>().value,
+);
+final short = CType(
+ sizeOf<Short>(),
+ 'short',
+ ffiLoad: (Pointer p) => p.cast<Short>().value,
+);
+final ushort = CType(
+ sizeOf<UnsignedShort>(),
+ 'short',
+ modifier: 'unsigned',
+ ffiLoad: (Pointer p) => p.cast<UnsignedShort>().value,
+);
+final int_ = CType(
+ sizeOf<Int>(),
+ 'int',
+ ffiLoad: (Pointer p) => p.cast<Int>().value,
+);
+final uint = CType(
+ sizeOf<UnsignedInt>(),
+ 'int',
+ modifier: 'unsigned',
+ ffiLoad: (Pointer p) => p.cast<UnsignedInt>().value,
+);
+final long = CType(
+ sizeOf<Long>(),
+ 'long',
+);
+final ulong = CType(
+ sizeOf<UnsignedLong>(),
+ 'long',
+ modifier: 'unsigned',
+);
+final longlong = CType(
+ sizeOf<LongLong>(),
+ 'long',
+ type2: 'long',
+);
+final ulonglong = CType(
+ sizeOf<UnsignedLongLong>(),
+ 'long',
+ type2: 'long',
+ modifier: 'unsigned',
+);
+final intptr_t = CType(
+ sizeOf<IntPtr>(),
+ 'intptr_t',
+);
+final uintptr_t = CType(
+ sizeOf<UintPtr>(),
+ 'uintptr_t',
+);
+final size_t = CType(
+ sizeOf<Size>(),
+ 'size_t',
+);
+final wchar_t = CType(
+ sizeOf<WChar>(),
+ 'wchar_t',
+ ffiLoad: (Pointer p) => p.cast<WChar>().value,
+);
final cTypes = [
- intptr_t,
- uintptr_t,
+ char,
+ uchar,
+ schar,
+ short,
+ ushort,
+ int_,
+ uint,
long,
ulong,
+ longlong,
+ ulonglong,
+ intptr_t,
+ uintptr_t,
+ size_t,
wchar_t,
];
void printSizes() {
cTypes.forEach((element) {
- print("${element.cRepresentation.padRight(20)}: ${element.size}");
+ final cName = element.cRepresentation.padRight(20);
+ final size = element.size;
+ final signed = element.isSigned ? 'signed' : 'unsigned';
+ print('$cName: $size $signed');
});
}
void testSizes() {
cTypes.forEach((element) {
+ print(element);
Expect.equals(element.size, element.ffiSize);
+ final ffiIsSigned = element.ffiIsSigned;
+ if (ffiIsSigned != null) {
+ Expect.equals(element.isSigned, ffiIsSigned);
+ }
});
}
+void testIntAssumptions() {
+ Expect.equals(4, int_.size);
+ Expect.equals(4, uint.size);
+}
+
+void testSizeTAssumptions() {
+ Expect.equals(intptr_t.size, size_t.size);
+}
+
void testLongAssumptions() {
if (Platform.isWindows) {
Expect.equals(4, long.size);
@@ -79,8 +201,8 @@
}
void testWCharTAssumptions() {
- final bool isSigned = wCharMinValue() != 0;
- print("wchar_t isSigned $isSigned");
+ final bool isSigned = wchar_t.isSigned;
+ print('wchar_t isSigned $isSigned');
if (Platform.isWindows) {
Expect.equals(2, wchar_t.size);
if (isSigned) {
diff --git a/tests/ffi_2/function_callbacks_structs_by_value_generated_test.dart b/tests/ffi_2/function_callbacks_structs_by_value_generated_test.dart
index f4100fb..b890cbc 100644
--- a/tests/ffi_2/function_callbacks_structs_by_value_generated_test.dart
+++ b/tests/ffi_2/function_callbacks_structs_by_value_generated_test.dart
@@ -18,9 +18,6 @@
import "package:expect/expect.dart";
import "package:ffi/ffi.dart";
-// Reuse the AbiSpecificInts.
-import 'abi_specific_ints.dart';
-
import 'callback_tests_utils.dart';
import 'dylib_utils.dart';
diff --git a/tests/ffi_2/function_structs_by_value_generated_compounds.dart b/tests/ffi_2/function_structs_by_value_generated_compounds.dart
index 6908177..cd3fdf1 100644
--- a/tests/ffi_2/function_structs_by_value_generated_compounds.dart
+++ b/tests/ffi_2/function_structs_by_value_generated_compounds.dart
@@ -9,9 +9,6 @@
import 'dart:ffi';
-// Reuse the AbiSpecificInts.
-import 'abi_specific_ints.dart';
-
class Struct1ByteBool extends Struct {
@Bool()
bool a0;
diff --git a/tests/ffi_2/function_structs_by_value_generated_leaf_test.dart b/tests/ffi_2/function_structs_by_value_generated_leaf_test.dart
index 7c64296..8c01056 100644
--- a/tests/ffi_2/function_structs_by_value_generated_leaf_test.dart
+++ b/tests/ffi_2/function_structs_by_value_generated_leaf_test.dart
@@ -18,9 +18,6 @@
import "package:expect/expect.dart";
import "package:ffi/ffi.dart";
-// Reuse the AbiSpecificInts.
-import 'abi_specific_ints.dart';
-
import 'dylib_utils.dart';
// Reuse the compound classes.
diff --git a/tests/ffi_2/function_structs_by_value_generated_test.dart b/tests/ffi_2/function_structs_by_value_generated_test.dart
index ef24ad2..6329287 100644
--- a/tests/ffi_2/function_structs_by_value_generated_test.dart
+++ b/tests/ffi_2/function_structs_by_value_generated_test.dart
@@ -18,9 +18,6 @@
import "package:expect/expect.dart";
import "package:ffi/ffi.dart";
-// Reuse the AbiSpecificInts.
-import 'abi_specific_ints.dart';
-
import 'dylib_utils.dart';
// Reuse the compound classes.
diff --git a/tools/VERSION b/tools/VERSION
index a6ed96c..fc2fee1 100644
--- a/tools/VERSION
+++ b/tools/VERSION
@@ -27,5 +27,5 @@
MAJOR 2
MINOR 17
PATCH 0
-PRERELEASE 37
+PRERELEASE 38
PRERELEASE_PATCH 0
\ No newline at end of file