mirror of
https://github.com/dart-lang/sdk
synced 2024-09-05 08:24:39 +00:00
Reland "[vm/ffi] Add common C types"
We're adding these types to `dart:ffi` rather than `package:ffi` so that they can be used with `FfiNative`s. Adds `NativeType`s for the following C types: * unsigned char * signed char * short * unsigned short * int * unsigned int * long * unsigned long * long long * unsigned long long * uintptr_t * size_t * wchar_t Because the C standard only defines minimum sizes for many of these types, future platforms might diverge from the typical size even if all platforms currently agree on a size. To avoid having to reification later, we define all types as AbiSpecificIntegers rather than typedefs, even if all current target platforms agree on the size. Closes: https://github.com/dart-lang/sdk/issues/36140 TEST=tests/ffi/c_types_test.dart Original patch in patchset 1. * Removes `Char` for now until package:win32 has rolled to 2.3.8 in Flutter. https://pub.dev/packages/win32/versions/2.3.8/changelog https://logs.chromium.org/logs/flutter/buildbucket/cr-buildbucket/8824468064587445729/+/u/Android_Views_Integration_Tests/stdout * Adds `c_type.dart` in `ffi_source.gni` which should fix `IntPtr` missing when analyzing `path_provider_linux`. (However, I was unable to reproduce the issue locally.) https://logs.chromium.org/logs/flutter/buildbucket/cr-buildbucket/8824468064571399025/+/u/run_test.dart_for_flutter_plugins_shard_and_subshard_analyze/test_stdout `/tmp/flutter_plugins.KZMNMC/packages/path_provider/path_provider_linux$ ~/flt/engine/src/out/host_debug/dart-sdk/bin/dart analyze --fatal-infos` Change-Id: I89130cccba285fc9c483bb53f5710a302f2b104f Cq-Include-Trybots: luci.dart.try:dart-sdk-linux-try,dart-sdk-mac-try,dart-sdk-win-try,vm-ffi-android-debug-arm64c-try,vm-ffi-android-debug-arm-try,vm-canary-linux-debug-try,vm-fuchsia-release-x64-try,vm-kernel-gcc-linux-try,vm-kernel-asan-linux-release-x64-try,vm-kernel-linux-debug-x64-try,vm-kernel-linux-debug-ia32-try,vm-kernel-mac-debug-x64-try,vm-kernel-mac-release-arm64-try,vm-kernel-nnbd-win-release-ia32-try,vm-kernel-nnbd-win-release-x64-try,vm-precomp-ffi-qemu-linux-release-arm-try,vm-kernel-win-release-x64-try,flutter-analyze-try,flutter-engine-linux-try,flutter-frontend-try Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/229156 Reviewed-by: Martin Kustermann <kustermann@google.com> Commit-Queue: Daco Harkes <dacoharkes@google.com>
This commit is contained in:
parent
bc7554107b
commit
045b9c1715
|
@ -15,36 +15,6 @@ import 'dart:typed_data';
|
||||||
import 'package:ffi/ffi.dart';
|
import 'package:ffi/ffi.dart';
|
||||||
import 'package:benchmark_harness/benchmark_harness.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.
|
// Pointer store.
|
||||||
//
|
//
|
||||||
|
|
|
@ -17,36 +17,6 @@ import 'dart:typed_data';
|
||||||
import 'package:ffi/ffi.dart';
|
import 'package:ffi/ffi.dart';
|
||||||
import 'package:benchmark_harness/benchmark_harness.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.
|
// Pointer store.
|
||||||
//
|
//
|
||||||
|
|
|
@ -40,7 +40,7 @@ constants {
|
||||||
|
|
||||||
Constructor coverage from constants:
|
Constructor coverage from constants:
|
||||||
org-dartlang-testcase:///ffi_sample.dart:
|
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)
|
- _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)
|
- 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)
|
- Object. (from org-dartlang-sdk:///sdk/lib/core/object.dart:25:9)
|
||||||
|
|
|
@ -40,7 +40,7 @@ constants {
|
||||||
|
|
||||||
Constructor coverage from constants:
|
Constructor coverage from constants:
|
||||||
org-dartlang-testcase:///ffi_sample.dart:
|
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)
|
- _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)
|
- 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)
|
- Object. (from org-dartlang-sdk:///sdk/lib/core/object.dart:25:9)
|
||||||
|
|
|
@ -74,7 +74,7 @@ constants {
|
||||||
|
|
||||||
Constructor coverage from constants:
|
Constructor coverage from constants:
|
||||||
org-dartlang-testcase:///ffi_sample.dart:
|
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)
|
- _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)
|
- 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)
|
- Object. (from org-dartlang-sdk:///sdk/lib/core/object.dart:25:9)
|
||||||
|
|
|
@ -63,6 +63,7 @@ additionalExports = (ffi::nullptr,
|
||||||
ffi::FloatArray,
|
ffi::FloatArray,
|
||||||
ffi::FloatPointer,
|
ffi::FloatPointer,
|
||||||
ffi::Handle,
|
ffi::Handle,
|
||||||
|
ffi::Int,
|
||||||
ffi::Int16,
|
ffi::Int16,
|
||||||
ffi::Int16Array,
|
ffi::Int16Array,
|
||||||
ffi::Int16Pointer,
|
ffi::Int16Pointer,
|
||||||
|
@ -76,6 +77,8 @@ additionalExports = (ffi::nullptr,
|
||||||
ffi::Int8Array,
|
ffi::Int8Array,
|
||||||
ffi::Int8Pointer,
|
ffi::Int8Pointer,
|
||||||
ffi::IntPtr,
|
ffi::IntPtr,
|
||||||
|
ffi::Long,
|
||||||
|
ffi::LongLong,
|
||||||
ffi::NativeApi,
|
ffi::NativeApi,
|
||||||
ffi::NativeFunction,
|
ffi::NativeFunction,
|
||||||
ffi::NativeFunctionPointer,
|
ffi::NativeFunctionPointer,
|
||||||
|
@ -86,6 +89,9 @@ additionalExports = (ffi::nullptr,
|
||||||
ffi::Pointer,
|
ffi::Pointer,
|
||||||
ffi::PointerArray,
|
ffi::PointerArray,
|
||||||
ffi::PointerPointer,
|
ffi::PointerPointer,
|
||||||
|
ffi::Short,
|
||||||
|
ffi::SignedChar,
|
||||||
|
ffi::Size,
|
||||||
ffi::Struct,
|
ffi::Struct,
|
||||||
ffi::StructArray,
|
ffi::StructArray,
|
||||||
ffi::StructPointer,
|
ffi::StructPointer,
|
||||||
|
@ -101,11 +107,18 @@ additionalExports = (ffi::nullptr,
|
||||||
ffi::Uint8,
|
ffi::Uint8,
|
||||||
ffi::Uint8Array,
|
ffi::Uint8Array,
|
||||||
ffi::Uint8Pointer,
|
ffi::Uint8Pointer,
|
||||||
|
ffi::UintPtr,
|
||||||
ffi::Union,
|
ffi::Union,
|
||||||
ffi::UnionArray,
|
ffi::UnionArray,
|
||||||
ffi::UnionPointer,
|
ffi::UnionPointer,
|
||||||
|
ffi::UnsignedChar,
|
||||||
|
ffi::UnsignedInt,
|
||||||
|
ffi::UnsignedLong,
|
||||||
|
ffi::UnsignedLongLong,
|
||||||
|
ffi::UnsignedShort,
|
||||||
ffi::Unsized,
|
ffi::Unsized,
|
||||||
ffi::Void)
|
ffi::Void,
|
||||||
|
ffi::WChar)
|
||||||
|
|
||||||
export "org-dartlang-test:///lib3.dart";
|
export "org-dartlang-test:///lib3.dart";
|
||||||
|
|
||||||
|
@ -139,6 +152,7 @@ additionalExports = (ffi::nullptr,
|
||||||
ffi::FloatArray,
|
ffi::FloatArray,
|
||||||
ffi::FloatPointer,
|
ffi::FloatPointer,
|
||||||
ffi::Handle,
|
ffi::Handle,
|
||||||
|
ffi::Int,
|
||||||
ffi::Int16,
|
ffi::Int16,
|
||||||
ffi::Int16Array,
|
ffi::Int16Array,
|
||||||
ffi::Int16Pointer,
|
ffi::Int16Pointer,
|
||||||
|
@ -152,6 +166,8 @@ additionalExports = (ffi::nullptr,
|
||||||
ffi::Int8Array,
|
ffi::Int8Array,
|
||||||
ffi::Int8Pointer,
|
ffi::Int8Pointer,
|
||||||
ffi::IntPtr,
|
ffi::IntPtr,
|
||||||
|
ffi::Long,
|
||||||
|
ffi::LongLong,
|
||||||
ffi::NativeApi,
|
ffi::NativeApi,
|
||||||
ffi::NativeFunction,
|
ffi::NativeFunction,
|
||||||
ffi::NativeFunctionPointer,
|
ffi::NativeFunctionPointer,
|
||||||
|
@ -162,6 +178,9 @@ additionalExports = (ffi::nullptr,
|
||||||
ffi::Pointer,
|
ffi::Pointer,
|
||||||
ffi::PointerArray,
|
ffi::PointerArray,
|
||||||
ffi::PointerPointer,
|
ffi::PointerPointer,
|
||||||
|
ffi::Short,
|
||||||
|
ffi::SignedChar,
|
||||||
|
ffi::Size,
|
||||||
ffi::Struct,
|
ffi::Struct,
|
||||||
ffi::StructArray,
|
ffi::StructArray,
|
||||||
ffi::StructPointer,
|
ffi::StructPointer,
|
||||||
|
@ -177,11 +196,18 @@ additionalExports = (ffi::nullptr,
|
||||||
ffi::Uint8,
|
ffi::Uint8,
|
||||||
ffi::Uint8Array,
|
ffi::Uint8Array,
|
||||||
ffi::Uint8Pointer,
|
ffi::Uint8Pointer,
|
||||||
|
ffi::UintPtr,
|
||||||
ffi::Union,
|
ffi::Union,
|
||||||
ffi::UnionArray,
|
ffi::UnionArray,
|
||||||
ffi::UnionPointer,
|
ffi::UnionPointer,
|
||||||
|
ffi::UnsignedChar,
|
||||||
|
ffi::UnsignedInt,
|
||||||
|
ffi::UnsignedLong,
|
||||||
|
ffi::UnsignedLongLong,
|
||||||
|
ffi::UnsignedShort,
|
||||||
ffi::Unsized,
|
ffi::Unsized,
|
||||||
ffi::Void)
|
ffi::Void,
|
||||||
|
ffi::WChar)
|
||||||
|
|
||||||
export "dart:ffi";
|
export "dart:ffi";
|
||||||
|
|
||||||
|
|
|
@ -63,6 +63,7 @@ additionalExports = (ffi::nullptr,
|
||||||
ffi::FloatArray,
|
ffi::FloatArray,
|
||||||
ffi::FloatPointer,
|
ffi::FloatPointer,
|
||||||
ffi::Handle,
|
ffi::Handle,
|
||||||
|
ffi::Int,
|
||||||
ffi::Int16,
|
ffi::Int16,
|
||||||
ffi::Int16Array,
|
ffi::Int16Array,
|
||||||
ffi::Int16Pointer,
|
ffi::Int16Pointer,
|
||||||
|
@ -76,6 +77,8 @@ additionalExports = (ffi::nullptr,
|
||||||
ffi::Int8Array,
|
ffi::Int8Array,
|
||||||
ffi::Int8Pointer,
|
ffi::Int8Pointer,
|
||||||
ffi::IntPtr,
|
ffi::IntPtr,
|
||||||
|
ffi::Long,
|
||||||
|
ffi::LongLong,
|
||||||
ffi::NativeApi,
|
ffi::NativeApi,
|
||||||
ffi::NativeFunction,
|
ffi::NativeFunction,
|
||||||
ffi::NativeFunctionPointer,
|
ffi::NativeFunctionPointer,
|
||||||
|
@ -86,6 +89,9 @@ additionalExports = (ffi::nullptr,
|
||||||
ffi::Pointer,
|
ffi::Pointer,
|
||||||
ffi::PointerArray,
|
ffi::PointerArray,
|
||||||
ffi::PointerPointer,
|
ffi::PointerPointer,
|
||||||
|
ffi::Short,
|
||||||
|
ffi::SignedChar,
|
||||||
|
ffi::Size,
|
||||||
ffi::Struct,
|
ffi::Struct,
|
||||||
ffi::StructArray,
|
ffi::StructArray,
|
||||||
ffi::StructPointer,
|
ffi::StructPointer,
|
||||||
|
@ -101,11 +107,18 @@ additionalExports = (ffi::nullptr,
|
||||||
ffi::Uint8,
|
ffi::Uint8,
|
||||||
ffi::Uint8Array,
|
ffi::Uint8Array,
|
||||||
ffi::Uint8Pointer,
|
ffi::Uint8Pointer,
|
||||||
|
ffi::UintPtr,
|
||||||
ffi::Union,
|
ffi::Union,
|
||||||
ffi::UnionArray,
|
ffi::UnionArray,
|
||||||
ffi::UnionPointer,
|
ffi::UnionPointer,
|
||||||
|
ffi::UnsignedChar,
|
||||||
|
ffi::UnsignedInt,
|
||||||
|
ffi::UnsignedLong,
|
||||||
|
ffi::UnsignedLongLong,
|
||||||
|
ffi::UnsignedShort,
|
||||||
ffi::Unsized,
|
ffi::Unsized,
|
||||||
ffi::Void)
|
ffi::Void,
|
||||||
|
ffi::WChar)
|
||||||
|
|
||||||
export "org-dartlang-test:///lib3.dart";
|
export "org-dartlang-test:///lib3.dart";
|
||||||
|
|
||||||
|
@ -139,6 +152,7 @@ additionalExports = (ffi::nullptr,
|
||||||
ffi::FloatArray,
|
ffi::FloatArray,
|
||||||
ffi::FloatPointer,
|
ffi::FloatPointer,
|
||||||
ffi::Handle,
|
ffi::Handle,
|
||||||
|
ffi::Int,
|
||||||
ffi::Int16,
|
ffi::Int16,
|
||||||
ffi::Int16Array,
|
ffi::Int16Array,
|
||||||
ffi::Int16Pointer,
|
ffi::Int16Pointer,
|
||||||
|
@ -152,6 +166,8 @@ additionalExports = (ffi::nullptr,
|
||||||
ffi::Int8Array,
|
ffi::Int8Array,
|
||||||
ffi::Int8Pointer,
|
ffi::Int8Pointer,
|
||||||
ffi::IntPtr,
|
ffi::IntPtr,
|
||||||
|
ffi::Long,
|
||||||
|
ffi::LongLong,
|
||||||
ffi::NativeApi,
|
ffi::NativeApi,
|
||||||
ffi::NativeFunction,
|
ffi::NativeFunction,
|
||||||
ffi::NativeFunctionPointer,
|
ffi::NativeFunctionPointer,
|
||||||
|
@ -162,6 +178,9 @@ additionalExports = (ffi::nullptr,
|
||||||
ffi::Pointer,
|
ffi::Pointer,
|
||||||
ffi::PointerArray,
|
ffi::PointerArray,
|
||||||
ffi::PointerPointer,
|
ffi::PointerPointer,
|
||||||
|
ffi::Short,
|
||||||
|
ffi::SignedChar,
|
||||||
|
ffi::Size,
|
||||||
ffi::Struct,
|
ffi::Struct,
|
||||||
ffi::StructArray,
|
ffi::StructArray,
|
||||||
ffi::StructPointer,
|
ffi::StructPointer,
|
||||||
|
@ -177,11 +196,18 @@ additionalExports = (ffi::nullptr,
|
||||||
ffi::Uint8,
|
ffi::Uint8,
|
||||||
ffi::Uint8Array,
|
ffi::Uint8Array,
|
||||||
ffi::Uint8Pointer,
|
ffi::Uint8Pointer,
|
||||||
|
ffi::UintPtr,
|
||||||
ffi::Union,
|
ffi::Union,
|
||||||
ffi::UnionArray,
|
ffi::UnionArray,
|
||||||
ffi::UnionPointer,
|
ffi::UnionPointer,
|
||||||
|
ffi::UnsignedChar,
|
||||||
|
ffi::UnsignedInt,
|
||||||
|
ffi::UnsignedLong,
|
||||||
|
ffi::UnsignedLongLong,
|
||||||
|
ffi::UnsignedShort,
|
||||||
ffi::Unsized,
|
ffi::Unsized,
|
||||||
ffi::Void)
|
ffi::Void,
|
||||||
|
ffi::WChar)
|
||||||
|
|
||||||
export "dart:ffi";
|
export "dart:ffi";
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ constants {
|
||||||
|
|
||||||
Constructor coverage from constants:
|
Constructor coverage from constants:
|
||||||
org-dartlang-testcase:///ffi_sample.dart:
|
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)
|
- _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)
|
- 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)
|
- Object. (from org-dartlang-sdk:///sdk/lib/core/object.dart:25:9)
|
||||||
|
|
|
@ -65,7 +65,7 @@ constants {
|
||||||
|
|
||||||
Constructor coverage from constants:
|
Constructor coverage from constants:
|
||||||
org-dartlang-testcase:///ffi_sample.dart:
|
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)
|
- _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)
|
- 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)
|
- Object. (from org-dartlang-sdk:///sdk/lib/core/object.dart:25:9)
|
||||||
|
|
|
@ -34,7 +34,7 @@ constants {
|
||||||
|
|
||||||
Constructor coverage from constants:
|
Constructor coverage from constants:
|
||||||
org-dartlang-testcase:///ffi_sample.dart:
|
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)
|
- _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)
|
- 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)
|
- Object. (from org-dartlang-sdk:///sdk/lib/core/object.dart:25:9)
|
||||||
|
|
|
@ -34,7 +34,7 @@ constants {
|
||||||
|
|
||||||
Constructor coverage from constants:
|
Constructor coverage from constants:
|
||||||
org-dartlang-testcase:///ffi_sample.dart:
|
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)
|
- _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)
|
- 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)
|
- Object. (from org-dartlang-sdk:///sdk/lib/core/object.dart:25:9)
|
||||||
|
|
|
@ -65,7 +65,7 @@ constants {
|
||||||
|
|
||||||
Constructor coverage from constants:
|
Constructor coverage from constants:
|
||||||
org-dartlang-testcase:///ffi_sample.dart:
|
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)
|
- _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)
|
- 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)
|
- Object. (from org-dartlang-sdk:///sdk/lib/core/object.dart:25:9)
|
||||||
|
|
|
@ -25,5 +25,5 @@ constants {
|
||||||
|
|
||||||
Constructor coverage from constants:
|
Constructor coverage from constants:
|
||||||
org-dartlang-testcase:///ffi_struct_inline_array.dart:
|
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)
|
- Object. (from org-dartlang-sdk:///sdk/lib/core/object.dart:25:9)
|
||||||
|
|
|
@ -52,5 +52,5 @@ constants {
|
||||||
|
|
||||||
Constructor coverage from constants:
|
Constructor coverage from constants:
|
||||||
org-dartlang-testcase:///ffi_struct_inline_array.dart:
|
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)
|
- Object. (from org-dartlang-sdk:///sdk/lib/core/object.dart:25:9)
|
||||||
|
|
|
@ -25,5 +25,5 @@ constants {
|
||||||
|
|
||||||
Constructor coverage from constants:
|
Constructor coverage from constants:
|
||||||
org-dartlang-testcase:///ffi_struct_inline_array.dart:
|
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)
|
- Object. (from org-dartlang-sdk:///sdk/lib/core/object.dart:25:9)
|
||||||
|
|
|
@ -25,5 +25,5 @@ constants {
|
||||||
|
|
||||||
Constructor coverage from constants:
|
Constructor coverage from constants:
|
||||||
org-dartlang-testcase:///ffi_struct_inline_array.dart:
|
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)
|
- Object. (from org-dartlang-sdk:///sdk/lib/core/object.dart:25:9)
|
||||||
|
|
|
@ -52,5 +52,5 @@ constants {
|
||||||
|
|
||||||
Constructor coverage from constants:
|
Constructor coverage from constants:
|
||||||
org-dartlang-testcase:///ffi_struct_inline_array.dart:
|
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)
|
- Object. (from org-dartlang-sdk:///sdk/lib/core/object.dart:25:9)
|
||||||
|
|
|
@ -33,5 +33,5 @@ constants {
|
||||||
|
|
||||||
Constructor coverage from constants:
|
Constructor coverage from constants:
|
||||||
org-dartlang-testcase:///ffi_struct_inline_array_multi_dimensional.dart:
|
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)
|
- Object. (from org-dartlang-sdk:///sdk/lib/core/object.dart:25:9)
|
||||||
|
|
|
@ -84,5 +84,5 @@ Extra constant evaluation: evaluated: 110, effectively constant: 2
|
||||||
|
|
||||||
Constructor coverage from constants:
|
Constructor coverage from constants:
|
||||||
org-dartlang-testcase:///ffi_struct_inline_array_multi_dimensional.dart:
|
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)
|
- Object. (from org-dartlang-sdk:///sdk/lib/core/object.dart:25:9)
|
||||||
|
|
|
@ -33,5 +33,5 @@ constants {
|
||||||
|
|
||||||
Constructor coverage from constants:
|
Constructor coverage from constants:
|
||||||
org-dartlang-testcase:///ffi_struct_inline_array_multi_dimensional.dart:
|
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)
|
- Object. (from org-dartlang-sdk:///sdk/lib/core/object.dart:25:9)
|
||||||
|
|
|
@ -33,5 +33,5 @@ constants {
|
||||||
|
|
||||||
Constructor coverage from constants:
|
Constructor coverage from constants:
|
||||||
org-dartlang-testcase:///ffi_struct_inline_array_multi_dimensional.dart:
|
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)
|
- Object. (from org-dartlang-sdk:///sdk/lib/core/object.dart:25:9)
|
||||||
|
|
|
@ -84,5 +84,5 @@ Extra constant evaluation: evaluated: 110, effectively constant: 2
|
||||||
|
|
||||||
Constructor coverage from constants:
|
Constructor coverage from constants:
|
||||||
org-dartlang-testcase:///ffi_struct_inline_array_multi_dimensional.dart:
|
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)
|
- Object. (from org-dartlang-sdk:///sdk/lib/core/object.dart:25:9)
|
||||||
|
|
|
@ -1138,27 +1138,36 @@ DART_EXPORT uint64_t SizeOfStruct3BytesPackedInt() {
|
||||||
typedef intptr_t ssize_t;
|
typedef intptr_t ssize_t;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define DEFINE_SIZE_OF(type_modifier, type) \
|
#define DEFINE_SIZE_OF_AND_SIGN_OF(type_modifier, type, type2) \
|
||||||
DART_EXPORT uint64_t FfiSizeOf_##type_modifier##_##type() { \
|
DART_EXPORT uint64_t FfiSizeOf_##type_modifier##_##type##_##type2() { \
|
||||||
return sizeof(type_modifier type); \
|
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) \
|
#define TYPES(F) \
|
||||||
F(, intptr_t) \
|
F(, char, ) /* NOLINT */ \
|
||||||
F(, uintptr_t) \
|
F(signed, char, ) /* NOLINT */ \
|
||||||
F(, int) \
|
F(unsigned, char, ) /* NOLINT */ \
|
||||||
F(unsigned, int) \
|
F(, short, ) /* NOLINT */ \
|
||||||
F(, long) /* NOLINT */ \
|
F(unsigned, short, ) /* NOLINT */ \
|
||||||
F(unsigned, long) /* NOLINT */ \
|
F(, int, ) /* NOLINT */ \
|
||||||
F(, wchar_t) \
|
F(unsigned, int, ) /* NOLINT */ \
|
||||||
F(, size_t) \
|
F(, long, ) /* NOLINT */ \
|
||||||
F(, ssize_t) \
|
F(unsigned, long, ) /* NOLINT */ \
|
||||||
F(, off_t)
|
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 DEFINE_SIZE_OF_AND_SIGN_OF
|
||||||
#undef SIZES
|
#undef TYPES
|
||||||
|
|
||||||
DART_EXPORT int64_t WCharMinValue() {
|
DART_EXPORT int64_t WCharMinValue() {
|
||||||
return WCHAR_MIN;
|
return WCHAR_MIN;
|
||||||
|
|
|
@ -55,11 +55,6 @@ class Uint32 extends _NativeInteger {}
|
||||||
@pragma("vm:entry-point")
|
@pragma("vm:entry-point")
|
||||||
class Uint64 extends _NativeInteger {}
|
class Uint64 extends _NativeInteger {}
|
||||||
|
|
||||||
// TODO(http://dartbug.com/47938): Implement as AbiSpecificInteger.
|
|
||||||
@patch
|
|
||||||
@pragma("vm:entry-point")
|
|
||||||
class IntPtr extends _NativeInteger {}
|
|
||||||
|
|
||||||
@patch
|
@patch
|
||||||
@pragma("vm:entry-point")
|
@pragma("vm:entry-point")
|
||||||
class Float extends _NativeDouble {}
|
class Float extends _NativeDouble {}
|
||||||
|
|
|
@ -13,10 +13,12 @@ part of dart.ffi;
|
||||||
/// For example:
|
/// 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
|
/// /// The [UintPtr] type is a native type, and should not be constructed in
|
||||||
/// /// marker in type signatures.
|
/// /// Dart code.
|
||||||
|
/// /// It occurs only in native type signatures and as annotation on [Struct]
|
||||||
|
/// /// and [Union] fields.
|
||||||
/// @AbiSpecificIntegerMapping({
|
/// @AbiSpecificIntegerMapping({
|
||||||
/// Abi.androidArm: Uint32(),
|
/// Abi.androidArm: Uint32(),
|
||||||
/// Abi.androidArm64: Uint64(),
|
/// Abi.androidArm64: Uint64(),
|
||||||
|
|
503
sdk/lib/ffi/c_type.dart
Normal file
503
sdk/lib/ffi/c_type.dart
Normal file
|
@ -0,0 +1,503 @@
|
||||||
|
// 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 `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 [SignedChar].
|
||||||
|
///
|
||||||
|
/// 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();
|
||||||
|
}
|
|
@ -20,6 +20,7 @@ part 'abi_specific.dart';
|
||||||
part 'native_type.dart';
|
part 'native_type.dart';
|
||||||
part 'allocation.dart';
|
part 'allocation.dart';
|
||||||
part 'annotations.dart';
|
part 'annotations.dart';
|
||||||
|
part 'c_type.dart';
|
||||||
part 'dynamic_library.dart';
|
part 'dynamic_library.dart';
|
||||||
part 'struct.dart';
|
part 'struct.dart';
|
||||||
part 'union.dart';
|
part 'union.dart';
|
||||||
|
|
|
@ -10,6 +10,7 @@ ffi_sdk_sources = [
|
||||||
"abi_specific.dart",
|
"abi_specific.dart",
|
||||||
"allocation.dart",
|
"allocation.dart",
|
||||||
"annotations.dart",
|
"annotations.dart",
|
||||||
|
"c_type.dart",
|
||||||
"dynamic_library.dart",
|
"dynamic_library.dart",
|
||||||
"native_type.dart",
|
"native_type.dart",
|
||||||
"struct.dart",
|
"struct.dart",
|
||||||
|
|
|
@ -98,36 +98,6 @@ class Uint64 extends _NativeInteger {
|
||||||
const Uint64();
|
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.
|
/// Represents a native 32 bit float in C.
|
||||||
///
|
///
|
||||||
/// [Float] is not constructible in the Dart code and serves purely as marker
|
/// [Float] is not constructible in the Dart code and serves purely as marker
|
||||||
|
|
|
@ -8,8 +8,6 @@ import 'dart:io';
|
||||||
import 'package:expect/expect.dart';
|
import 'package:expect/expect.dart';
|
||||||
import 'package:ffi/ffi.dart';
|
import 'package:ffi/ffi.dart';
|
||||||
|
|
||||||
import 'abi_specific_ints.dart';
|
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
testSizeOf();
|
testSizeOf();
|
||||||
testStoreLoad();
|
testStoreLoad();
|
||||||
|
|
|
@ -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();
|
|
||||||
}
|
|
|
@ -7,11 +7,11 @@
|
||||||
// SharedObjects=ffi_test_functions
|
// SharedObjects=ffi_test_functions
|
||||||
|
|
||||||
import 'dart:ffi';
|
import 'dart:ffi';
|
||||||
|
|
||||||
import "package:expect/expect.dart";
|
|
||||||
import 'dart:io' show Platform;
|
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';
|
import 'ffi_test_helpers.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
|
@ -20,62 +20,156 @@ void main() {
|
||||||
testIntAssumptions();
|
testIntAssumptions();
|
||||||
testSizeTAssumptions();
|
testSizeTAssumptions();
|
||||||
testLongAssumptions();
|
testLongAssumptions();
|
||||||
testOffTAssumptions();
|
|
||||||
testWCharTAssumptions();
|
testWCharTAssumptions();
|
||||||
}
|
}
|
||||||
|
|
||||||
class CType {
|
class CType {
|
||||||
final int ffiSize;
|
final int ffiSize;
|
||||||
|
final int Function(Pointer)? ffiLoad;
|
||||||
final String modifier;
|
final String modifier;
|
||||||
final String type;
|
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
|
int Function() get sizeFunction => ffiTestFunctions
|
||||||
.lookupFunction<Uint64 Function(), int Function()>(_getSizeName);
|
.lookupFunction<Uint64 Function(), int Function()>(_getSizeName);
|
||||||
|
|
||||||
|
int Function() get signFunction => ffiTestFunctions
|
||||||
|
.lookupFunction<Uint64 Function(), int Function()>(_getSignName);
|
||||||
|
|
||||||
int get size => sizeFunction();
|
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;
|
String toString() => cRepresentation;
|
||||||
}
|
}
|
||||||
|
|
||||||
final intptr_t = CType(sizeOf<IntPtr>(), "intptr_t");
|
final uchar = CType(
|
||||||
final uintptr_t = CType(sizeOf<UintPtr>(), "uintptr_t");
|
sizeOf<UnsignedChar>(),
|
||||||
final int_ = CType(sizeOf<Int>(), "int");
|
'char',
|
||||||
final uint = CType(sizeOf<UnsignedInt>(), "int", "unsigned");
|
modifier: 'unsigned',
|
||||||
final long = CType(sizeOf<Long>(), "long");
|
ffiLoad: (Pointer p) => p.cast<UnsignedChar>().value,
|
||||||
final ulong = CType(sizeOf<UnsignedLong>(), "long", "unsigned");
|
);
|
||||||
final wchar_t = CType(sizeOf<WChar>(), "wchar_t");
|
final schar = CType(
|
||||||
final size_t = CType(sizeOf<Size>(), "size_t");
|
sizeOf<SignedChar>(),
|
||||||
final ssize_t = CType(sizeOf<SSize>(), "ssize_t");
|
'char',
|
||||||
final off_t = CType(sizeOf<Off>(), "off_t");
|
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 = [
|
final cTypes = [
|
||||||
intptr_t,
|
uchar,
|
||||||
uintptr_t,
|
schar,
|
||||||
|
short,
|
||||||
|
ushort,
|
||||||
int_,
|
int_,
|
||||||
uint,
|
uint,
|
||||||
long,
|
long,
|
||||||
ulong,
|
ulong,
|
||||||
wchar_t,
|
longlong,
|
||||||
|
ulonglong,
|
||||||
|
intptr_t,
|
||||||
|
uintptr_t,
|
||||||
size_t,
|
size_t,
|
||||||
ssize_t,
|
wchar_t,
|
||||||
off_t
|
|
||||||
];
|
];
|
||||||
|
|
||||||
void printSizes() {
|
void printSizes() {
|
||||||
cTypes.forEach((element) {
|
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() {
|
void testSizes() {
|
||||||
cTypes.forEach((element) {
|
cTypes.forEach((element) {
|
||||||
|
print(element);
|
||||||
Expect.equals(element.size, element.ffiSize);
|
Expect.equals(element.size, element.ffiSize);
|
||||||
|
final ffiIsSigned = element.ffiIsSigned;
|
||||||
|
if (ffiIsSigned != null) {
|
||||||
|
Expect.equals(element.isSigned, ffiIsSigned);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,7 +180,6 @@ void testIntAssumptions() {
|
||||||
|
|
||||||
void testSizeTAssumptions() {
|
void testSizeTAssumptions() {
|
||||||
Expect.equals(intptr_t.size, size_t.size);
|
Expect.equals(intptr_t.size, size_t.size);
|
||||||
Expect.equals(intptr_t.size, ssize_t.size);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void testLongAssumptions() {
|
void testLongAssumptions() {
|
||||||
|
@ -99,13 +192,9 @@ void testLongAssumptions() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void testOffTAssumptions() {
|
|
||||||
Expect.equals(long.size, off_t.size);
|
|
||||||
}
|
|
||||||
|
|
||||||
void testWCharTAssumptions() {
|
void testWCharTAssumptions() {
|
||||||
final bool isSigned = wCharMinValue() != 0;
|
final bool isSigned = wchar_t.isSigned;
|
||||||
print("wchar_t isSigned $isSigned");
|
print('wchar_t isSigned $isSigned');
|
||||||
if (Platform.isWindows) {
|
if (Platform.isWindows) {
|
||||||
Expect.equals(2, wchar_t.size);
|
Expect.equals(2, wchar_t.size);
|
||||||
if (isSigned) {
|
if (isSigned) {
|
||||||
|
|
|
@ -16,9 +16,6 @@ import 'dart:ffi';
|
||||||
import "package:expect/expect.dart";
|
import "package:expect/expect.dart";
|
||||||
import "package:ffi/ffi.dart";
|
import "package:ffi/ffi.dart";
|
||||||
|
|
||||||
// Reuse the AbiSpecificInts.
|
|
||||||
import 'abi_specific_ints.dart';
|
|
||||||
|
|
||||||
import 'callback_tests_utils.dart';
|
import 'callback_tests_utils.dart';
|
||||||
|
|
||||||
import 'dylib_utils.dart';
|
import 'dylib_utils.dart';
|
||||||
|
|
|
@ -7,9 +7,6 @@
|
||||||
|
|
||||||
import 'dart:ffi';
|
import 'dart:ffi';
|
||||||
|
|
||||||
// Reuse the AbiSpecificInts.
|
|
||||||
import 'abi_specific_ints.dart';
|
|
||||||
|
|
||||||
class Struct1ByteBool extends Struct {
|
class Struct1ByteBool extends Struct {
|
||||||
@Bool()
|
@Bool()
|
||||||
external bool a0;
|
external bool a0;
|
||||||
|
|
|
@ -16,9 +16,6 @@ import 'dart:ffi';
|
||||||
import "package:expect/expect.dart";
|
import "package:expect/expect.dart";
|
||||||
import "package:ffi/ffi.dart";
|
import "package:ffi/ffi.dart";
|
||||||
|
|
||||||
// Reuse the AbiSpecificInts.
|
|
||||||
import 'abi_specific_ints.dart';
|
|
||||||
|
|
||||||
import 'dylib_utils.dart';
|
import 'dylib_utils.dart';
|
||||||
|
|
||||||
// Reuse the compound classes.
|
// Reuse the compound classes.
|
||||||
|
|
|
@ -16,9 +16,6 @@ import 'dart:ffi';
|
||||||
import "package:expect/expect.dart";
|
import "package:expect/expect.dart";
|
||||||
import "package:ffi/ffi.dart";
|
import "package:ffi/ffi.dart";
|
||||||
|
|
||||||
// Reuse the AbiSpecificInts.
|
|
||||||
import 'abi_specific_ints.dart';
|
|
||||||
|
|
||||||
import 'dylib_utils.dart';
|
import 'dylib_utils.dart';
|
||||||
|
|
||||||
// Reuse the compound classes.
|
// Reuse the compound classes.
|
||||||
|
|
|
@ -922,8 +922,6 @@ $dartVersion
|
||||||
|
|
||||||
import 'dart:ffi';
|
import 'dart:ffi';
|
||||||
|
|
||||||
// Reuse the AbiSpecificInts.
|
|
||||||
import 'abi_specific_ints.dart';
|
|
||||||
""";
|
""";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -967,8 +965,6 @@ import 'dart:ffi';
|
||||||
import "package:expect/expect.dart";
|
import "package:expect/expect.dart";
|
||||||
import "package:ffi/ffi.dart";
|
import "package:ffi/ffi.dart";
|
||||||
|
|
||||||
// Reuse the AbiSpecificInts.
|
|
||||||
import 'abi_specific_ints.dart';
|
|
||||||
|
|
||||||
import 'dylib_utils.dart';
|
import 'dylib_utils.dart';
|
||||||
|
|
||||||
|
@ -1029,8 +1025,6 @@ import 'dart:ffi';
|
||||||
import "package:expect/expect.dart";
|
import "package:expect/expect.dart";
|
||||||
import "package:ffi/ffi.dart";
|
import "package:ffi/ffi.dart";
|
||||||
|
|
||||||
// Reuse the AbiSpecificInts.
|
|
||||||
import 'abi_specific_ints.dart';
|
|
||||||
|
|
||||||
import 'callback_tests_utils.dart';
|
import 'callback_tests_utils.dart';
|
||||||
|
|
||||||
|
|
|
@ -10,8 +10,6 @@ import 'dart:io';
|
||||||
import 'package:expect/expect.dart';
|
import 'package:expect/expect.dart';
|
||||||
import 'package:ffi/ffi.dart';
|
import 'package:ffi/ffi.dart';
|
||||||
|
|
||||||
import 'abi_specific_ints.dart';
|
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
testSizeOf();
|
testSizeOf();
|
||||||
testStoreLoad();
|
testStoreLoad();
|
||||||
|
|
|
@ -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();
|
|
||||||
}
|
|
|
@ -9,65 +9,181 @@
|
||||||
// @dart = 2.9
|
// @dart = 2.9
|
||||||
|
|
||||||
import 'dart:ffi';
|
import 'dart:ffi';
|
||||||
|
|
||||||
import "package:expect/expect.dart";
|
|
||||||
import 'dart:io' show Platform;
|
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';
|
import 'ffi_test_helpers.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
printSizes();
|
printSizes();
|
||||||
testSizes();
|
testSizes();
|
||||||
|
testIntAssumptions();
|
||||||
|
testSizeTAssumptions();
|
||||||
testLongAssumptions();
|
testLongAssumptions();
|
||||||
testWCharTAssumptions();
|
testWCharTAssumptions();
|
||||||
}
|
}
|
||||||
|
|
||||||
class CType {
|
class CType {
|
||||||
final int ffiSize;
|
final int ffiSize;
|
||||||
|
final int Function(Pointer) ffiLoad;
|
||||||
final String modifier;
|
final String modifier;
|
||||||
final String type;
|
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
|
int Function() get sizeFunction => ffiTestFunctions
|
||||||
.lookupFunction<Uint64 Function(), int Function()>(_getSizeName);
|
.lookupFunction<Uint64 Function(), int Function()>(_getSizeName);
|
||||||
|
|
||||||
|
int Function() get signFunction => ffiTestFunctions
|
||||||
|
.lookupFunction<Uint64 Function(), int Function()>(_getSignName);
|
||||||
|
|
||||||
int get size => sizeFunction();
|
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;
|
String toString() => cRepresentation;
|
||||||
}
|
}
|
||||||
|
|
||||||
final intptr_t = CType(sizeOf<IntPtr>(), "intptr_t");
|
final uchar = CType(
|
||||||
final uintptr_t = CType(sizeOf<UintPtr>(), "uintptr_t");
|
sizeOf<UnsignedChar>(),
|
||||||
final long = CType(sizeOf<Long>(), "long");
|
'char',
|
||||||
final ulong = CType(sizeOf<UnsignedLong>(), "long", "unsigned");
|
modifier: 'unsigned',
|
||||||
final wchar_t = CType(sizeOf<WChar>(), "wchar_t");
|
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 = [
|
final cTypes = [
|
||||||
intptr_t,
|
uchar,
|
||||||
uintptr_t,
|
schar,
|
||||||
|
short,
|
||||||
|
ushort,
|
||||||
|
int_,
|
||||||
|
uint,
|
||||||
long,
|
long,
|
||||||
ulong,
|
ulong,
|
||||||
|
longlong,
|
||||||
|
ulonglong,
|
||||||
|
intptr_t,
|
||||||
|
uintptr_t,
|
||||||
|
size_t,
|
||||||
wchar_t,
|
wchar_t,
|
||||||
];
|
];
|
||||||
|
|
||||||
void printSizes() {
|
void printSizes() {
|
||||||
cTypes.forEach((element) {
|
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() {
|
void testSizes() {
|
||||||
cTypes.forEach((element) {
|
cTypes.forEach((element) {
|
||||||
|
print(element);
|
||||||
Expect.equals(element.size, element.ffiSize);
|
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() {
|
void testLongAssumptions() {
|
||||||
if (Platform.isWindows) {
|
if (Platform.isWindows) {
|
||||||
Expect.equals(4, long.size);
|
Expect.equals(4, long.size);
|
||||||
|
@ -79,8 +195,8 @@ void testLongAssumptions() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void testWCharTAssumptions() {
|
void testWCharTAssumptions() {
|
||||||
final bool isSigned = wCharMinValue() != 0;
|
final bool isSigned = wchar_t.isSigned;
|
||||||
print("wchar_t isSigned $isSigned");
|
print('wchar_t isSigned $isSigned');
|
||||||
if (Platform.isWindows) {
|
if (Platform.isWindows) {
|
||||||
Expect.equals(2, wchar_t.size);
|
Expect.equals(2, wchar_t.size);
|
||||||
if (isSigned) {
|
if (isSigned) {
|
||||||
|
|
|
@ -18,9 +18,6 @@ import 'dart:ffi';
|
||||||
import "package:expect/expect.dart";
|
import "package:expect/expect.dart";
|
||||||
import "package:ffi/ffi.dart";
|
import "package:ffi/ffi.dart";
|
||||||
|
|
||||||
// Reuse the AbiSpecificInts.
|
|
||||||
import 'abi_specific_ints.dart';
|
|
||||||
|
|
||||||
import 'callback_tests_utils.dart';
|
import 'callback_tests_utils.dart';
|
||||||
|
|
||||||
import 'dylib_utils.dart';
|
import 'dylib_utils.dart';
|
||||||
|
|
|
@ -9,9 +9,6 @@
|
||||||
|
|
||||||
import 'dart:ffi';
|
import 'dart:ffi';
|
||||||
|
|
||||||
// Reuse the AbiSpecificInts.
|
|
||||||
import 'abi_specific_ints.dart';
|
|
||||||
|
|
||||||
class Struct1ByteBool extends Struct {
|
class Struct1ByteBool extends Struct {
|
||||||
@Bool()
|
@Bool()
|
||||||
bool a0;
|
bool a0;
|
||||||
|
|
|
@ -18,9 +18,6 @@ import 'dart:ffi';
|
||||||
import "package:expect/expect.dart";
|
import "package:expect/expect.dart";
|
||||||
import "package:ffi/ffi.dart";
|
import "package:ffi/ffi.dart";
|
||||||
|
|
||||||
// Reuse the AbiSpecificInts.
|
|
||||||
import 'abi_specific_ints.dart';
|
|
||||||
|
|
||||||
import 'dylib_utils.dart';
|
import 'dylib_utils.dart';
|
||||||
|
|
||||||
// Reuse the compound classes.
|
// Reuse the compound classes.
|
||||||
|
|
|
@ -18,9 +18,6 @@ import 'dart:ffi';
|
||||||
import "package:expect/expect.dart";
|
import "package:expect/expect.dart";
|
||||||
import "package:ffi/ffi.dart";
|
import "package:ffi/ffi.dart";
|
||||||
|
|
||||||
// Reuse the AbiSpecificInts.
|
|
||||||
import 'abi_specific_ints.dart';
|
|
||||||
|
|
||||||
import 'dylib_utils.dart';
|
import 'dylib_utils.dart';
|
||||||
|
|
||||||
// Reuse the compound classes.
|
// Reuse the compound classes.
|
||||||
|
|
Loading…
Reference in a new issue