diff --git a/benchmarks/FfiMemory/dart/FfiMemory.dart b/benchmarks/FfiMemory/dart/FfiMemory.dart index 6178f24fd34..881eff2d3d7 100644 --- a/benchmarks/FfiMemory/dart/FfiMemory.dart +++ b/benchmarks/FfiMemory/dart/FfiMemory.dart @@ -15,6 +15,36 @@ import 'dart:typed_data'; 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 b3a6cf9d099..86f7e1f90ab 100644 --- a/benchmarks/FfiMemory/dart2/FfiMemory.dart +++ b/benchmarks/FfiMemory/dart2/FfiMemory.dart @@ -17,6 +17,36 @@ import 'dart:typed_data'; 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 d92782a30a5..8c513a44aaf 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) +- Double. (from org-dartlang-sdk:///sdk/lib/ffi/native_type.dart:144: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 d92782a30a5..8c513a44aaf 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) +- Double. (from org-dartlang-sdk:///sdk/lib/ffi/native_type.dart:144: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 0765c4c028c..ae497d5a5fa 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) +- Double. (from org-dartlang-sdk:///sdk/lib/ffi/native_type.dart:144: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 7e198e7f430..6c37a20df30 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,7 +51,6 @@ additionalExports = (ffi::nullptr, ffi::Bool, ffi::BoolArray, ffi::BoolPointer, - ffi::Char, ffi::DartRepresentationOf, ffi::Dart_CObject, ffi::Double, @@ -64,7 +63,6 @@ additionalExports = (ffi::nullptr, ffi::FloatArray, ffi::FloatPointer, ffi::Handle, - ffi::Int, ffi::Int16, ffi::Int16Array, ffi::Int16Pointer, @@ -78,8 +76,6 @@ additionalExports = (ffi::nullptr, ffi::Int8Array, ffi::Int8Pointer, ffi::IntPtr, - ffi::Long, - ffi::LongLong, ffi::NativeApi, ffi::NativeFunction, ffi::NativeFunctionPointer, @@ -90,9 +86,6 @@ additionalExports = (ffi::nullptr, ffi::Pointer, ffi::PointerArray, ffi::PointerPointer, - ffi::Short, - ffi::SignedChar, - ffi::Size, ffi::Struct, ffi::StructArray, ffi::StructPointer, @@ -108,18 +101,11 @@ additionalExports = (ffi::nullptr, 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::WChar) + ffi::Void) export "org-dartlang-test:///lib3.dart"; @@ -141,7 +127,6 @@ additionalExports = (ffi::nullptr, ffi::Bool, ffi::BoolArray, ffi::BoolPointer, - ffi::Char, ffi::DartRepresentationOf, ffi::Dart_CObject, ffi::Double, @@ -154,7 +139,6 @@ additionalExports = (ffi::nullptr, ffi::FloatArray, ffi::FloatPointer, ffi::Handle, - ffi::Int, ffi::Int16, ffi::Int16Array, ffi::Int16Pointer, @@ -168,8 +152,6 @@ additionalExports = (ffi::nullptr, ffi::Int8Array, ffi::Int8Pointer, ffi::IntPtr, - ffi::Long, - ffi::LongLong, ffi::NativeApi, ffi::NativeFunction, ffi::NativeFunctionPointer, @@ -180,9 +162,6 @@ additionalExports = (ffi::nullptr, ffi::Pointer, ffi::PointerArray, ffi::PointerPointer, - ffi::Short, - ffi::SignedChar, - ffi::Size, ffi::Struct, ffi::StructArray, ffi::StructPointer, @@ -198,18 +177,11 @@ additionalExports = (ffi::nullptr, 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::WChar) + ffi::Void) 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 934102e1caa..e7c047a37ce 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,7 +51,6 @@ additionalExports = (ffi::nullptr, ffi::Bool, ffi::BoolArray, ffi::BoolPointer, - ffi::Char, ffi::DartRepresentationOf, ffi::Dart_CObject, ffi::Double, @@ -64,7 +63,6 @@ additionalExports = (ffi::nullptr, ffi::FloatArray, ffi::FloatPointer, ffi::Handle, - ffi::Int, ffi::Int16, ffi::Int16Array, ffi::Int16Pointer, @@ -78,8 +76,6 @@ additionalExports = (ffi::nullptr, ffi::Int8Array, ffi::Int8Pointer, ffi::IntPtr, - ffi::Long, - ffi::LongLong, ffi::NativeApi, ffi::NativeFunction, ffi::NativeFunctionPointer, @@ -90,9 +86,6 @@ additionalExports = (ffi::nullptr, ffi::Pointer, ffi::PointerArray, ffi::PointerPointer, - ffi::Short, - ffi::SignedChar, - ffi::Size, ffi::Struct, ffi::StructArray, ffi::StructPointer, @@ -108,18 +101,11 @@ additionalExports = (ffi::nullptr, 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::WChar) + ffi::Void) export "org-dartlang-test:///lib3.dart"; @@ -141,7 +127,6 @@ additionalExports = (ffi::nullptr, ffi::Bool, ffi::BoolArray, ffi::BoolPointer, - ffi::Char, ffi::DartRepresentationOf, ffi::Dart_CObject, ffi::Double, @@ -154,7 +139,6 @@ additionalExports = (ffi::nullptr, ffi::FloatArray, ffi::FloatPointer, ffi::Handle, - ffi::Int, ffi::Int16, ffi::Int16Array, ffi::Int16Pointer, @@ -168,8 +152,6 @@ additionalExports = (ffi::nullptr, ffi::Int8Array, ffi::Int8Pointer, ffi::IntPtr, - ffi::Long, - ffi::LongLong, ffi::NativeApi, ffi::NativeFunction, ffi::NativeFunctionPointer, @@ -180,9 +162,6 @@ additionalExports = (ffi::nullptr, ffi::Pointer, ffi::PointerArray, ffi::PointerPointer, - ffi::Short, - ffi::SignedChar, - ffi::Size, ffi::Struct, ffi::StructArray, ffi::StructPointer, @@ -198,18 +177,11 @@ additionalExports = (ffi::nullptr, 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::WChar) + ffi::Void) 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 b190b3a9c29..35dda106cf7 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) +- Double. (from org-dartlang-sdk:///sdk/lib/ffi/native_type.dart:144: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 fccf63463e3..02dfd2a915f 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) +- Double. (from org-dartlang-sdk:///sdk/lib/ffi/native_type.dart:144: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 b190b3a9c29..35dda106cf7 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) +- Double. (from org-dartlang-sdk:///sdk/lib/ffi/native_type.dart:144: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 b190b3a9c29..35dda106cf7 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) +- Double. (from org-dartlang-sdk:///sdk/lib/ffi/native_type.dart:144: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 fccf63463e3..02dfd2a915f 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) +- Double. (from org-dartlang-sdk:///sdk/lib/ffi/native_type.dart:144: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 4d771b3fe31..0db513dff49 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 @@ constants { Constructor coverage from constants: org-dartlang-testcase:///ffi_struct_inline_array.dart: -- _ArraySize. (from org-dartlang-sdk:///sdk/lib/ffi/ffi.dart:139:9) +- _ArraySize. (from org-dartlang-sdk:///sdk/lib/ffi/ffi.dart:138: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 f3903c0958c..525cfd922bd 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 @@ constants { Constructor coverage from constants: org-dartlang-testcase:///ffi_struct_inline_array.dart: -- _ArraySize. (from org-dartlang-sdk:///sdk/lib/ffi/ffi.dart:139:9) +- _ArraySize. (from org-dartlang-sdk:///sdk/lib/ffi/ffi.dart:138: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 e179ab5d07d..e6c0f958734 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 @@ constants { Constructor coverage from constants: org-dartlang-testcase:///ffi_struct_inline_array.dart: -- _ArraySize. (from org-dartlang-sdk:///sdk/lib/ffi/ffi.dart:139:9) +- _ArraySize. (from org-dartlang-sdk:///sdk/lib/ffi/ffi.dart:138: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 e179ab5d07d..e6c0f958734 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 @@ constants { Constructor coverage from constants: org-dartlang-testcase:///ffi_struct_inline_array.dart: -- _ArraySize. (from org-dartlang-sdk:///sdk/lib/ffi/ffi.dart:139:9) +- _ArraySize. (from org-dartlang-sdk:///sdk/lib/ffi/ffi.dart:138: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 24cfa9601b1..b38ad344607 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 @@ constants { Constructor coverage from constants: org-dartlang-testcase:///ffi_struct_inline_array.dart: -- _ArraySize. (from org-dartlang-sdk:///sdk/lib/ffi/ffi.dart:139:9) +- _ArraySize. (from org-dartlang-sdk:///sdk/lib/ffi/ffi.dart:138: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 dd7fa306a70..0e058b10c06 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 @@ constants { Constructor coverage from constants: org-dartlang-testcase:///ffi_struct_inline_array_multi_dimensional.dart: -- _ArraySize. (from org-dartlang-sdk:///sdk/lib/ffi/ffi.dart:139:9) +- _ArraySize. (from org-dartlang-sdk:///sdk/lib/ffi/ffi.dart:138: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 a16945b05a6..ecf21c080b3 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 @@ Extra constant evaluation: evaluated: 110, effectively constant: 2 Constructor coverage from constants: org-dartlang-testcase:///ffi_struct_inline_array_multi_dimensional.dart: -- _ArraySize. (from org-dartlang-sdk:///sdk/lib/ffi/ffi.dart:139:9) +- _ArraySize. (from org-dartlang-sdk:///sdk/lib/ffi/ffi.dart:138: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 be09548d6b9..5e4b756023e 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 @@ constants { Constructor coverage from constants: org-dartlang-testcase:///ffi_struct_inline_array_multi_dimensional.dart: -- _ArraySize. (from org-dartlang-sdk:///sdk/lib/ffi/ffi.dart:139:9) +- _ArraySize. (from org-dartlang-sdk:///sdk/lib/ffi/ffi.dart:138: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 be09548d6b9..5e4b756023e 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 @@ constants { Constructor coverage from constants: org-dartlang-testcase:///ffi_struct_inline_array_multi_dimensional.dart: -- _ArraySize. (from org-dartlang-sdk:///sdk/lib/ffi/ffi.dart:139:9) +- _ArraySize. (from org-dartlang-sdk:///sdk/lib/ffi/ffi.dart:138: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 a83a86b7e37..a9ba39c9ed8 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 @@ Extra constant evaluation: evaluated: 110, effectively constant: 2 Constructor coverage from constants: org-dartlang-testcase:///ffi_struct_inline_array_multi_dimensional.dart: -- _ArraySize. (from org-dartlang-sdk:///sdk/lib/ffi/ffi.dart:139:9) +- _ArraySize. (from org-dartlang-sdk:///sdk/lib/ffi/ffi.dart:138: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 1545f8ee8bc..dd5e41fdb7a 100644 --- a/runtime/bin/ffi_test/ffi_test_functions.cc +++ b/runtime/bin/ffi_test/ffi_test_functions.cc @@ -1138,36 +1138,27 @@ DART_EXPORT uint64_t SizeOfStruct3BytesPackedInt() { typedef intptr_t ssize_t; #endif -#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::is_signed; \ +#define DEFINE_SIZE_OF(type_modifier, type) \ + DART_EXPORT uint64_t FfiSizeOf_##type_modifier##_##type() { \ + return sizeof(type_modifier type); \ } -#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 */ +#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) -TYPES(DEFINE_SIZE_OF_AND_SIGN_OF) +SIZES(DEFINE_SIZE_OF) -#undef DEFINE_SIZE_OF_AND_SIGN_OF -#undef TYPES +#undef DEFINE_SIZE_OF +#undef SIZES 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 ca47a83cba4..92e23c1cf18 100644 --- a/sdk/lib/_internal/vm/lib/ffi_native_type_patch.dart +++ b/sdk/lib/_internal/vm/lib/ffi_native_type_patch.dart @@ -55,6 +55,11 @@ class Uint32 extends _NativeInteger {} @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/ffi/abi_specific.dart b/sdk/lib/ffi/abi_specific.dart index a41308c44be..d84f74eea2c 100644 --- a/sdk/lib/ffi/abi_specific.dart +++ b/sdk/lib/ffi/abi_specific.dart @@ -13,12 +13,10 @@ part of dart.ffi; /// For example: /// /// ``` -/// /// The C `uintptr_t` type. +/// /// Represents a `uintptr_t` in C. /// /// -/// /// 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. +/// /// [UintPtr] is not constructible in the Dart code and serves purely as +/// /// marker in type signatures. /// @AbiSpecificIntegerMapping({ /// Abi.androidArm: Uint32(), /// Abi.androidArm64: Uint64(), diff --git a/sdk/lib/ffi/c_type.dart b/sdk/lib/ffi/c_type.dart deleted file mode 100644 index 9370fdc5dbd..00000000000 --- a/sdk/lib/ffi/c_type.dart +++ /dev/null @@ -1,541 +0,0 @@ -// 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 9a7afe26464..b1d53a68616 100644 --- a/sdk/lib/ffi/ffi.dart +++ b/sdk/lib/ffi/ffi.dart @@ -20,7 +20,6 @@ part 'abi_specific.dart'; 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 55a9f6d5246..dbbea7c85fc 100644 --- a/sdk/lib/ffi/native_type.dart +++ b/sdk/lib/ffi/native_type.dart @@ -98,6 +98,36 @@ class Uint64 extends _NativeInteger { 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 cea45b146d8..266655cce6d 100644 --- a/tests/ffi/abi_specific_int_test.dart +++ b/tests/ffi/abi_specific_int_test.dart @@ -8,6 +8,8 @@ import 'dart:io'; 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 new file mode 100644 index 00000000000..c0cd3f05026 --- /dev/null +++ b/tests/ffi/abi_specific_ints.dart @@ -0,0 +1,145 @@ +// 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 3c2e8152018..d423c2c0390 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 'package:expect/expect.dart'; -import 'package:ffi/ffi.dart'; - +import 'abi_specific_ints.dart'; import 'ffi_test_helpers.dart'; void main() { @@ -20,162 +20,62 @@ void main() { 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.type2 = '', this.modifier = '', this.ffiLoad}); + CType(this.ffiSize, this.type, [this.modifier = ""]); - String get cRepresentation => '$modifier $type $type2'.trim(); + String get cRepresentation => "$modifier $type".trim(); - String get _getSizeName => 'FfiSizeOf_$modifier\_$type\_$type2'; - - String get _getSignName => 'FfiSignOf_$modifier\_$type\_$type2'; + String get _getSizeName => "FfiSizeOf_$modifier\_$type"; int Function() get sizeFunction => ffiTestFunctions .lookupFunction(_getSizeName); - int Function() get signFunction => ffiTestFunctions - .lookupFunction(_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()..value = -1; - return ffiLoad_(p) < 0; - }); - } - String toString() => cRepresentation; } -final char = CType( - sizeOf(), - 'char', - ffiLoad: (Pointer p) => p.cast().value, -); -final uchar = CType( - sizeOf(), - 'char', - modifier: 'unsigned', - ffiLoad: (Pointer p) => p.cast().value, -); -final schar = CType( - sizeOf(), - 'char', - modifier: 'signed', - ffiLoad: (Pointer p) => p.cast().value, -); -final short = CType( - sizeOf(), - 'short', - ffiLoad: (Pointer p) => p.cast().value, -); -final ushort = CType( - sizeOf(), - 'short', - modifier: 'unsigned', - ffiLoad: (Pointer p) => p.cast().value, -); -final int_ = CType( - sizeOf(), - 'int', - ffiLoad: (Pointer p) => p.cast().value, -); -final uint = CType( - sizeOf(), - 'int', - modifier: 'unsigned', - ffiLoad: (Pointer p) => p.cast().value, -); -final long = CType( - sizeOf(), - 'long', -); -final ulong = CType( - sizeOf(), - 'long', - modifier: 'unsigned', -); -final longlong = CType( - sizeOf(), - 'long', - type2: 'long', -); -final ulonglong = CType( - sizeOf(), - 'long', - type2: 'long', - modifier: 'unsigned', -); -final intptr_t = CType( - sizeOf(), - 'intptr_t', -); -final uintptr_t = CType( - sizeOf(), - 'uintptr_t', -); -final size_t = CType( - sizeOf(), - 'size_t', -); -final wchar_t = CType( - sizeOf(), - 'wchar_t', - ffiLoad: (Pointer p) => p.cast().value, -); +final intptr_t = CType(sizeOf(), "intptr_t"); +final uintptr_t = CType(sizeOf(), "uintptr_t"); +final int_ = CType(sizeOf(), "int"); +final uint = CType(sizeOf(), "int", "unsigned"); +final long = CType(sizeOf(), "long"); +final ulong = CType(sizeOf(), "long", "unsigned"); +final wchar_t = CType(sizeOf(), "wchar_t"); +final size_t = CType(sizeOf(), "size_t"); +final ssize_t = CType(sizeOf(), "ssize_t"); +final off_t = CType(sizeOf(), "off_t"); final cTypes = [ - char, - uchar, - schar, - short, - ushort, + intptr_t, + uintptr_t, int_, uint, long, ulong, - longlong, - ulonglong, - intptr_t, - uintptr_t, - size_t, wchar_t, + size_t, + ssize_t, + off_t ]; void printSizes() { cTypes.forEach((element) { - final cName = element.cRepresentation.padRight(20); - final size = element.size; - final signed = element.isSigned ? 'signed' : 'unsigned'; - print('$cName: $size $signed'); + print("${element.cRepresentation.padRight(20)}: ${element.size}"); }); } 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); - } }); } @@ -186,6 +86,7 @@ void testIntAssumptions() { void testSizeTAssumptions() { Expect.equals(intptr_t.size, size_t.size); + Expect.equals(intptr_t.size, ssize_t.size); } void testLongAssumptions() { @@ -198,9 +99,13 @@ void testLongAssumptions() { } } +void testOffTAssumptions() { + Expect.equals(long.size, off_t.size); +} + void testWCharTAssumptions() { - final bool isSigned = wchar_t.isSigned; - print('wchar_t isSigned $isSigned'); + final bool isSigned = wCharMinValue() != 0; + 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 2fbccd18f63..2276d2f01e6 100644 --- a/tests/ffi/function_callbacks_structs_by_value_generated_test.dart +++ b/tests/ffi/function_callbacks_structs_by_value_generated_test.dart @@ -16,6 +16,9 @@ import 'dart:ffi'; 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 666ef20e1d9..439e9a349b7 100644 --- a/tests/ffi/function_structs_by_value_generated_compounds.dart +++ b/tests/ffi/function_structs_by_value_generated_compounds.dart @@ -7,6 +7,9 @@ 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 770441739da..283faad9d6a 100644 --- a/tests/ffi/function_structs_by_value_generated_leaf_test.dart +++ b/tests/ffi/function_structs_by_value_generated_leaf_test.dart @@ -16,6 +16,9 @@ import 'dart:ffi'; 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 897472cd2d7..1f4c5d3df7a 100644 --- a/tests/ffi/function_structs_by_value_generated_test.dart +++ b/tests/ffi/function_structs_by_value_generated_test.dart @@ -16,6 +16,9 @@ import 'dart:ffi'; 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 3a18095d500..4c260b9d6b8 100644 --- a/tests/ffi/generator/structs_by_value_tests_generator.dart +++ b/tests/ffi/generator/structs_by_value_tests_generator.dart @@ -922,6 +922,8 @@ $dartVersion import 'dart:ffi'; +// Reuse the AbiSpecificInts. +import 'abi_specific_ints.dart'; """; } @@ -965,6 +967,8 @@ import 'dart:ffi'; import "package:expect/expect.dart"; import "package:ffi/ffi.dart"; +// Reuse the AbiSpecificInts. +import 'abi_specific_ints.dart'; import 'dylib_utils.dart'; @@ -1025,6 +1029,8 @@ import 'dart:ffi'; 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 57daa3f3cf0..152c159034c 100644 --- a/tests/ffi_2/abi_specific_int_test.dart +++ b/tests/ffi_2/abi_specific_int_test.dart @@ -10,6 +10,8 @@ import 'dart:io'; 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 new file mode 100644 index 00000000000..c1d830251a2 --- /dev/null +++ b/tests/ffi_2/abi_specific_ints.dart @@ -0,0 +1,132 @@ +// 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 7a651ce8c37..fa762bdf7ba 100644 --- a/tests/ffi_2/c_types_test.dart +++ b/tests/ffi_2/c_types_test.dart @@ -9,187 +9,65 @@ // @dart = 2.9 import 'dart:ffi'; + +import "package:expect/expect.dart"; import 'dart:io' show Platform; -import 'package:expect/expect.dart'; -import 'package:ffi/ffi.dart'; - +import 'abi_specific_ints.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.type2 = '', this.modifier = '', this.ffiLoad}); + CType(this.ffiSize, this.type, [this.modifier = ""]); - String get cRepresentation => '$modifier $type $type2'.trim(); + String get cRepresentation => "$modifier $type".trim(); - String get _getSizeName => 'FfiSizeOf_$modifier\_$type\_$type2'; - - String get _getSignName => 'FfiSignOf_$modifier\_$type\_$type2'; + String get _getSizeName => "FfiSizeOf_$modifier\_$type"; int Function() get sizeFunction => ffiTestFunctions .lookupFunction(_getSizeName); - int Function() get signFunction => ffiTestFunctions - .lookupFunction(_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()..value = -1; - return ffiLoad_(p) < 0; - }); - } - String toString() => cRepresentation; } -final char = CType( - sizeOf(), - 'char', - ffiLoad: (Pointer p) => p.cast().value, -); -final uchar = CType( - sizeOf(), - 'char', - modifier: 'unsigned', - ffiLoad: (Pointer p) => p.cast().value, -); -final schar = CType( - sizeOf(), - 'char', - modifier: 'signed', - ffiLoad: (Pointer p) => p.cast().value, -); -final short = CType( - sizeOf(), - 'short', - ffiLoad: (Pointer p) => p.cast().value, -); -final ushort = CType( - sizeOf(), - 'short', - modifier: 'unsigned', - ffiLoad: (Pointer p) => p.cast().value, -); -final int_ = CType( - sizeOf(), - 'int', - ffiLoad: (Pointer p) => p.cast().value, -); -final uint = CType( - sizeOf(), - 'int', - modifier: 'unsigned', - ffiLoad: (Pointer p) => p.cast().value, -); -final long = CType( - sizeOf(), - 'long', -); -final ulong = CType( - sizeOf(), - 'long', - modifier: 'unsigned', -); -final longlong = CType( - sizeOf(), - 'long', - type2: 'long', -); -final ulonglong = CType( - sizeOf(), - 'long', - type2: 'long', - modifier: 'unsigned', -); -final intptr_t = CType( - sizeOf(), - 'intptr_t', -); -final uintptr_t = CType( - sizeOf(), - 'uintptr_t', -); -final size_t = CType( - sizeOf(), - 'size_t', -); -final wchar_t = CType( - sizeOf(), - 'wchar_t', - ffiLoad: (Pointer p) => p.cast().value, -); +final intptr_t = CType(sizeOf(), "intptr_t"); +final uintptr_t = CType(sizeOf(), "uintptr_t"); +final long = CType(sizeOf(), "long"); +final ulong = CType(sizeOf(), "long", "unsigned"); +final wchar_t = CType(sizeOf(), "wchar_t"); final cTypes = [ - char, - uchar, - schar, - short, - ushort, - int_, - uint, - long, - ulong, - longlong, - ulonglong, intptr_t, uintptr_t, - size_t, + long, + ulong, wchar_t, ]; void printSizes() { cTypes.forEach((element) { - final cName = element.cRepresentation.padRight(20); - final size = element.size; - final signed = element.isSigned ? 'signed' : 'unsigned'; - print('$cName: $size $signed'); + print("${element.cRepresentation.padRight(20)}: ${element.size}"); }); } 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); @@ -201,8 +79,8 @@ void testLongAssumptions() { } void testWCharTAssumptions() { - final bool isSigned = wchar_t.isSigned; - print('wchar_t isSigned $isSigned'); + final bool isSigned = wCharMinValue() != 0; + 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 b890cbc1c5b..f4100fbf115 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,6 +18,9 @@ import 'dart:ffi'; 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 cd3fdf1800d..69081770c04 100644 --- a/tests/ffi_2/function_structs_by_value_generated_compounds.dart +++ b/tests/ffi_2/function_structs_by_value_generated_compounds.dart @@ -9,6 +9,9 @@ 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 8c010567d92..7c642963cbc 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,6 +18,9 @@ import 'dart:ffi'; 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 6329287ff76..ef24ad2ce7a 100644 --- a/tests/ffi_2/function_structs_by_value_generated_test.dart +++ b/tests/ffi_2/function_structs_by_value_generated_test.dart @@ -18,6 +18,9 @@ import 'dart:ffi'; 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.