From 07682287507e5fa178e9c0c859440252ccdc3305 Mon Sep 17 00:00:00 2001 From: Daco Harkes Date: Fri, 11 Apr 2025 07:53:45 -0700 Subject: [PATCH] [ffi] Format samples and benchmarks with Dart 3.8 Change-Id: I4f8e695ac648becc0de3466b6ba2058cbae7c408 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/422103 Commit-Queue: Bob Nystrom Reviewed-by: Bob Nystrom Auto-Submit: Daco Harkes Commit-Queue: Daco Harkes --- benchmarks/FfiBoringssl/dart/digest.dart | 36 +- benchmarks/FfiCall/dart/FfiCall.dart | 21 +- .../FfiCall/dart/benchmark_generated.dart | 675 ++++++++---------- benchmarks/FfiCall/dart/dlopen_helper.dart | 7 +- benchmarks/FfiCall/generate_benchmarks.dart | 13 +- benchmarks/FfiCallback/dart/FfiCallback.dart | 18 +- .../FfiStructCopy/dart/FfiStructCopy.dart | 9 +- .../FfiStructCopy/generate_benchmarks.dart | 3 +- samples/ffi/async/sample_async_callback.dart | 57 +- .../ffi/async/sample_native_port_call.dart | 29 +- .../arena_isolate_shutdown_sample.dart | 41 +- .../ffi/resource_management/arena_sample.dart | 37 +- .../arena_zoned_sample.dart | 37 +- .../resource_management/unmanaged_sample.dart | 13 +- .../ffi/resource_management/utf8_helpers.dart | 5 +- samples/ffi/sample_ffi_functions.dart | 212 ++++-- .../ffi/sample_ffi_functions_callbacks.dart | 43 +- ...mple_ffi_functions_callbacks_closures.dart | 27 +- samples/ffi/sample_ffi_functions_structs.dart | 15 +- 19 files changed, 697 insertions(+), 601 deletions(-) diff --git a/benchmarks/FfiBoringssl/dart/digest.dart b/benchmarks/FfiBoringssl/dart/digest.dart index 5b558ef3430..5fa7a804aa4 100644 --- a/benchmarks/FfiBoringssl/dart/digest.dart +++ b/benchmarks/FfiBoringssl/dart/digest.dart @@ -44,20 +44,22 @@ final Pointer Function() EVP_sha512 = ssl /// ```c /// EVP_MD_CTX *EVP_MD_CTX_new(void); /// ``` -final Pointer Function() EVP_MD_CTX_new = ssl.lookupFunction< - Pointer Function(), - Pointer Function() ->('EVP_MD_CTX_new'); +final Pointer Function() EVP_MD_CTX_new = ssl + .lookupFunction< + Pointer Function(), + Pointer Function() + >('EVP_MD_CTX_new'); /// EVP_MD_CTX_free calls EVP_MD_CTX_cleanup and then frees ctx itself. /// /// ```c /// void EVP_MD_CTX_free(EVP_MD_CTX *ctx); /// ``` -final void Function(Pointer) EVP_MD_CTX_free = ssl.lookupFunction< - Void Function(Pointer), - void Function(Pointer) ->('EVP_MD_CTX_free'); +final void Function(Pointer) EVP_MD_CTX_free = ssl + .lookupFunction< + Void Function(Pointer), + void Function(Pointer) + >('EVP_MD_CTX_free'); /// EVP_DigestInit acts like EVP_DigestInit_ex except that ctx is initialised /// before use. @@ -92,10 +94,11 @@ final int Function(Pointer, Pointer, int) EVP_DigestUpdate = /// unsigned int *out_size); /// ``` final int Function(Pointer, Pointer, Pointer) -EVP_DigestFinal = ssl.lookupFunction< - Int32 Function(Pointer, Pointer, Pointer), - int Function(Pointer, Pointer, Pointer) ->('EVP_DigestFinal'); +EVP_DigestFinal = ssl + .lookupFunction< + Int32 Function(Pointer, Pointer, Pointer), + int Function(Pointer, Pointer, Pointer) + >('EVP_DigestFinal'); /// EVP_MD_CTX_size returns the digest size of ctx, in bytes. It will crash if /// a digest hasn't been set on ctx. @@ -103,7 +106,8 @@ EVP_DigestFinal = ssl.lookupFunction< /// ```c /// size_t EVP_MD_CTX_size(const EVP_MD_CTX *ctx); /// ``` -final int Function(Pointer) EVP_MD_CTX_size = ssl.lookupFunction< - IntPtr Function(Pointer), - int Function(Pointer) ->('EVP_MD_CTX_size'); +final int Function(Pointer) EVP_MD_CTX_size = ssl + .lookupFunction< + IntPtr Function(Pointer), + int Function(Pointer) + >('EVP_MD_CTX_size'); diff --git a/benchmarks/FfiCall/dart/FfiCall.dart b/benchmarks/FfiCall/dart/FfiCall.dart index 2805bcd4515..aaeb28fa1b2 100644 --- a/benchmarks/FfiCall/dart/FfiCall.dart +++ b/benchmarks/FfiCall/dart/FfiCall.dart @@ -63,18 +63,15 @@ class Int64Mintx01 extends FfiBenchmarkBase { final Function1int f; Int64Mintx01({isLeaf = false}) - : f = - isLeaf - ? ffiTestFunctions - .lookupFunction( - 'Function1Int64', - isLeaf: true, - ) - : ffiTestFunctions - .lookupFunction( - 'Function1Int64', - isLeaf: false, - ), + : f = isLeaf + ? ffiTestFunctions.lookupFunction( + 'Function1Int64', + isLeaf: true, + ) + : ffiTestFunctions.lookupFunction( + 'Function1Int64', + isLeaf: false, + ), super('FfiCall.Int64Mintx01', isLeaf: isLeaf); @override diff --git a/benchmarks/FfiCall/dart/benchmark_generated.dart b/benchmarks/FfiCall/dart/benchmark_generated.dart index 8011e6fc6d6..46f502c249c 100644 --- a/benchmarks/FfiCall/dart/benchmark_generated.dart +++ b/benchmarks/FfiCall/dart/benchmark_generated.dart @@ -632,18 +632,15 @@ class Int8x01 extends FfiBenchmarkBase { final Function1int f; Int8x01({bool isLeaf = false}) - : f = - isLeaf - ? ffiTestFunctions - .lookupFunction( - 'Function1Int8', - isLeaf: true, - ) - : ffiTestFunctions - .lookupFunction( - 'Function1Int8', - isLeaf: false, - ), + : f = isLeaf + ? ffiTestFunctions.lookupFunction( + 'Function1Int8', + isLeaf: true, + ) + : ffiTestFunctions.lookupFunction( + 'Function1Int8', + isLeaf: false, + ), super('FfiCall.Int8x01', isLeaf: isLeaf); @override @@ -692,18 +689,15 @@ class Int16x01 extends FfiBenchmarkBase { final Function1int f; Int16x01({bool isLeaf = false}) - : f = - isLeaf - ? ffiTestFunctions - .lookupFunction( - 'Function1Int16', - isLeaf: true, - ) - : ffiTestFunctions - .lookupFunction( - 'Function1Int16', - isLeaf: false, - ), + : f = isLeaf + ? ffiTestFunctions.lookupFunction( + 'Function1Int16', + isLeaf: true, + ) + : ffiTestFunctions.lookupFunction( + 'Function1Int16', + isLeaf: false, + ), super('FfiCall.Int16x01', isLeaf: isLeaf); @override @@ -752,18 +746,15 @@ class Int32x01 extends FfiBenchmarkBase { final Function1int f; Int32x01({bool isLeaf = false}) - : f = - isLeaf - ? ffiTestFunctions - .lookupFunction( - 'Function1Int32', - isLeaf: true, - ) - : ffiTestFunctions - .lookupFunction( - 'Function1Int32', - isLeaf: false, - ), + : f = isLeaf + ? ffiTestFunctions.lookupFunction( + 'Function1Int32', + isLeaf: true, + ) + : ffiTestFunctions.lookupFunction( + 'Function1Int32', + isLeaf: false, + ), super('FfiCall.Int32x01', isLeaf: isLeaf); @override @@ -812,18 +803,15 @@ class Int32x02 extends FfiBenchmarkBase { final Function2int f; Int32x02({bool isLeaf = false}) - : f = - isLeaf - ? ffiTestFunctions - .lookupFunction( - 'Function2Int32', - isLeaf: true, - ) - : ffiTestFunctions - .lookupFunction( - 'Function2Int32', - isLeaf: false, - ), + : f = isLeaf + ? ffiTestFunctions.lookupFunction( + 'Function2Int32', + isLeaf: true, + ) + : ffiTestFunctions.lookupFunction( + 'Function2Int32', + isLeaf: false, + ), super('FfiCall.Int32x02', isLeaf: isLeaf); @override @@ -872,18 +860,15 @@ class Int32x04 extends FfiBenchmarkBase { final Function4int f; Int32x04({bool isLeaf = false}) - : f = - isLeaf - ? ffiTestFunctions - .lookupFunction( - 'Function4Int32', - isLeaf: true, - ) - : ffiTestFunctions - .lookupFunction( - 'Function4Int32', - isLeaf: false, - ), + : f = isLeaf + ? ffiTestFunctions.lookupFunction( + 'Function4Int32', + isLeaf: true, + ) + : ffiTestFunctions.lookupFunction( + 'Function4Int32', + isLeaf: false, + ), super('FfiCall.Int32x04', isLeaf: isLeaf); @override @@ -932,18 +917,17 @@ class Int32x10 extends FfiBenchmarkBase { final Function10int f; Int32x10({bool isLeaf = false}) - : f = - isLeaf - ? ffiTestFunctions - .lookupFunction( - 'Function10Int32', - isLeaf: true, - ) - : ffiTestFunctions - .lookupFunction( - 'Function10Int32', - isLeaf: false, - ), + : f = isLeaf + ? ffiTestFunctions + .lookupFunction( + 'Function10Int32', + isLeaf: true, + ) + : ffiTestFunctions + .lookupFunction( + 'Function10Int32', + isLeaf: false, + ), super('FfiCall.Int32x10', isLeaf: isLeaf); @override @@ -1014,18 +998,17 @@ class Int32x20 extends FfiBenchmarkBase { final Function20int f; Int32x20({bool isLeaf = false}) - : f = - isLeaf - ? ffiTestFunctions - .lookupFunction( - 'Function20Int32', - isLeaf: true, - ) - : ffiTestFunctions - .lookupFunction( - 'Function20Int32', - isLeaf: false, - ), + : f = isLeaf + ? ffiTestFunctions + .lookupFunction( + 'Function20Int32', + isLeaf: true, + ) + : ffiTestFunctions + .lookupFunction( + 'Function20Int32', + isLeaf: false, + ), super('FfiCall.Int32x20', isLeaf: isLeaf); @override @@ -1158,18 +1141,15 @@ class Int64x01 extends FfiBenchmarkBase { final Function1int f; Int64x01({bool isLeaf = false}) - : f = - isLeaf - ? ffiTestFunctions - .lookupFunction( - 'Function1Int64', - isLeaf: true, - ) - : ffiTestFunctions - .lookupFunction( - 'Function1Int64', - isLeaf: false, - ), + : f = isLeaf + ? ffiTestFunctions.lookupFunction( + 'Function1Int64', + isLeaf: true, + ) + : ffiTestFunctions.lookupFunction( + 'Function1Int64', + isLeaf: false, + ), super('FfiCall.Int64x01', isLeaf: isLeaf); @override @@ -1218,18 +1198,15 @@ class Int64x02 extends FfiBenchmarkBase { final Function2int f; Int64x02({bool isLeaf = false}) - : f = - isLeaf - ? ffiTestFunctions - .lookupFunction( - 'Function2Int64', - isLeaf: true, - ) - : ffiTestFunctions - .lookupFunction( - 'Function2Int64', - isLeaf: false, - ), + : f = isLeaf + ? ffiTestFunctions.lookupFunction( + 'Function2Int64', + isLeaf: true, + ) + : ffiTestFunctions.lookupFunction( + 'Function2Int64', + isLeaf: false, + ), super('FfiCall.Int64x02', isLeaf: isLeaf); @override @@ -1278,18 +1255,15 @@ class Int64x04 extends FfiBenchmarkBase { final Function4int f; Int64x04({bool isLeaf = false}) - : f = - isLeaf - ? ffiTestFunctions - .lookupFunction( - 'Function4Int64', - isLeaf: true, - ) - : ffiTestFunctions - .lookupFunction( - 'Function4Int64', - isLeaf: false, - ), + : f = isLeaf + ? ffiTestFunctions.lookupFunction( + 'Function4Int64', + isLeaf: true, + ) + : ffiTestFunctions.lookupFunction( + 'Function4Int64', + isLeaf: false, + ), super('FfiCall.Int64x04', isLeaf: isLeaf); @override @@ -1338,18 +1312,17 @@ class Int64x10 extends FfiBenchmarkBase { final Function10int f; Int64x10({bool isLeaf = false}) - : f = - isLeaf - ? ffiTestFunctions - .lookupFunction( - 'Function10Int64', - isLeaf: true, - ) - : ffiTestFunctions - .lookupFunction( - 'Function10Int64', - isLeaf: false, - ), + : f = isLeaf + ? ffiTestFunctions + .lookupFunction( + 'Function10Int64', + isLeaf: true, + ) + : ffiTestFunctions + .lookupFunction( + 'Function10Int64', + isLeaf: false, + ), super('FfiCall.Int64x10', isLeaf: isLeaf); @override @@ -1420,18 +1393,17 @@ class Int64x20 extends FfiBenchmarkBase { final Function20int f; Int64x20({bool isLeaf = false}) - : f = - isLeaf - ? ffiTestFunctions - .lookupFunction( - 'Function20Int64', - isLeaf: true, - ) - : ffiTestFunctions - .lookupFunction( - 'Function20Int64', - isLeaf: false, - ), + : f = isLeaf + ? ffiTestFunctions + .lookupFunction( + 'Function20Int64', + isLeaf: true, + ) + : ffiTestFunctions + .lookupFunction( + 'Function20Int64', + isLeaf: false, + ), super('FfiCall.Int64x20', isLeaf: isLeaf); @override @@ -1564,18 +1536,15 @@ class Uint8x01 extends FfiBenchmarkBase { final Function1int f; Uint8x01({bool isLeaf = false}) - : f = - isLeaf - ? ffiTestFunctions - .lookupFunction( - 'Function1Uint8', - isLeaf: true, - ) - : ffiTestFunctions - .lookupFunction( - 'Function1Uint8', - isLeaf: false, - ), + : f = isLeaf + ? ffiTestFunctions.lookupFunction( + 'Function1Uint8', + isLeaf: true, + ) + : ffiTestFunctions.lookupFunction( + 'Function1Uint8', + isLeaf: false, + ), super('FfiCall.Uint8x01', isLeaf: isLeaf); @override @@ -1624,18 +1593,17 @@ class Uint16x01 extends FfiBenchmarkBase { final Function1int f; Uint16x01({bool isLeaf = false}) - : f = - isLeaf - ? ffiTestFunctions - .lookupFunction( - 'Function1Uint16', - isLeaf: true, - ) - : ffiTestFunctions - .lookupFunction( - 'Function1Uint16', - isLeaf: false, - ), + : f = isLeaf + ? ffiTestFunctions + .lookupFunction( + 'Function1Uint16', + isLeaf: true, + ) + : ffiTestFunctions + .lookupFunction( + 'Function1Uint16', + isLeaf: false, + ), super('FfiCall.Uint16x01', isLeaf: isLeaf); @override @@ -1684,18 +1652,17 @@ class Uint32x01 extends FfiBenchmarkBase { final Function1int f; Uint32x01({bool isLeaf = false}) - : f = - isLeaf - ? ffiTestFunctions - .lookupFunction( - 'Function1Uint32', - isLeaf: true, - ) - : ffiTestFunctions - .lookupFunction( - 'Function1Uint32', - isLeaf: false, - ), + : f = isLeaf + ? ffiTestFunctions + .lookupFunction( + 'Function1Uint32', + isLeaf: true, + ) + : ffiTestFunctions + .lookupFunction( + 'Function1Uint32', + isLeaf: false, + ), super('FfiCall.Uint32x01', isLeaf: isLeaf); @override @@ -1744,18 +1711,17 @@ class Uint64x01 extends FfiBenchmarkBase { final Function1int f; Uint64x01({bool isLeaf = false}) - : f = - isLeaf - ? ffiTestFunctions - .lookupFunction( - 'Function1Uint64', - isLeaf: true, - ) - : ffiTestFunctions - .lookupFunction( - 'Function1Uint64', - isLeaf: false, - ), + : f = isLeaf + ? ffiTestFunctions + .lookupFunction( + 'Function1Uint64', + isLeaf: true, + ) + : ffiTestFunctions + .lookupFunction( + 'Function1Uint64', + isLeaf: false, + ), super('FfiCall.Uint64x01', isLeaf: isLeaf); @override @@ -1804,18 +1770,17 @@ class Floatx01 extends FfiBenchmarkBase { final Function1double f; Floatx01({bool isLeaf = false}) - : f = - isLeaf - ? ffiTestFunctions - .lookupFunction( - 'Function1Float', - isLeaf: true, - ) - : ffiTestFunctions - .lookupFunction( - 'Function1Float', - isLeaf: false, - ), + : f = isLeaf + ? ffiTestFunctions + .lookupFunction( + 'Function1Float', + isLeaf: true, + ) + : ffiTestFunctions + .lookupFunction( + 'Function1Float', + isLeaf: false, + ), super('FfiCall.Floatx01', isLeaf: isLeaf); @override @@ -1867,18 +1832,17 @@ class Floatx02 extends FfiBenchmarkBase { final Function2double f; Floatx02({bool isLeaf = false}) - : f = - isLeaf - ? ffiTestFunctions - .lookupFunction( - 'Function2Float', - isLeaf: true, - ) - : ffiTestFunctions - .lookupFunction( - 'Function2Float', - isLeaf: false, - ), + : f = isLeaf + ? ffiTestFunctions + .lookupFunction( + 'Function2Float', + isLeaf: true, + ) + : ffiTestFunctions + .lookupFunction( + 'Function2Float', + isLeaf: false, + ), super('FfiCall.Floatx02', isLeaf: isLeaf); @override @@ -1930,18 +1894,17 @@ class Floatx04 extends FfiBenchmarkBase { final Function4double f; Floatx04({bool isLeaf = false}) - : f = - isLeaf - ? ffiTestFunctions - .lookupFunction( - 'Function4Float', - isLeaf: true, - ) - : ffiTestFunctions - .lookupFunction( - 'Function4Float', - isLeaf: false, - ), + : f = isLeaf + ? ffiTestFunctions + .lookupFunction( + 'Function4Float', + isLeaf: true, + ) + : ffiTestFunctions + .lookupFunction( + 'Function4Float', + isLeaf: false, + ), super('FfiCall.Floatx04', isLeaf: isLeaf); @override @@ -1993,18 +1956,17 @@ class Floatx10 extends FfiBenchmarkBase { final Function10double f; Floatx10({bool isLeaf = false}) - : f = - isLeaf - ? ffiTestFunctions - .lookupFunction( - 'Function10Float', - isLeaf: true, - ) - : ffiTestFunctions - .lookupFunction( - 'Function10Float', - isLeaf: false, - ), + : f = isLeaf + ? ffiTestFunctions + .lookupFunction( + 'Function10Float', + isLeaf: true, + ) + : ffiTestFunctions + .lookupFunction( + 'Function10Float', + isLeaf: false, + ), super('FfiCall.Floatx10', isLeaf: isLeaf); @override @@ -2089,18 +2051,17 @@ class Floatx20 extends FfiBenchmarkBase { final Function20double f; Floatx20({bool isLeaf = false}) - : f = - isLeaf - ? ffiTestFunctions - .lookupFunction( - 'Function20Float', - isLeaf: true, - ) - : ffiTestFunctions - .lookupFunction( - 'Function20Float', - isLeaf: false, - ), + : f = isLeaf + ? ffiTestFunctions + .lookupFunction( + 'Function20Float', + isLeaf: true, + ) + : ffiTestFunctions + .lookupFunction( + 'Function20Float', + isLeaf: false, + ), super('FfiCall.Floatx20', isLeaf: isLeaf); @override @@ -2257,18 +2218,17 @@ class Doublex01 extends FfiBenchmarkBase { final Function1double f; Doublex01({bool isLeaf = false}) - : f = - isLeaf - ? ffiTestFunctions - .lookupFunction( - 'Function1Double', - isLeaf: true, - ) - : ffiTestFunctions - .lookupFunction( - 'Function1Double', - isLeaf: false, - ), + : f = isLeaf + ? ffiTestFunctions + .lookupFunction( + 'Function1Double', + isLeaf: true, + ) + : ffiTestFunctions + .lookupFunction( + 'Function1Double', + isLeaf: false, + ), super('FfiCall.Doublex01', isLeaf: isLeaf); @override @@ -2320,18 +2280,17 @@ class Doublex02 extends FfiBenchmarkBase { final Function2double f; Doublex02({bool isLeaf = false}) - : f = - isLeaf - ? ffiTestFunctions - .lookupFunction( - 'Function2Double', - isLeaf: true, - ) - : ffiTestFunctions - .lookupFunction( - 'Function2Double', - isLeaf: false, - ), + : f = isLeaf + ? ffiTestFunctions + .lookupFunction( + 'Function2Double', + isLeaf: true, + ) + : ffiTestFunctions + .lookupFunction( + 'Function2Double', + isLeaf: false, + ), super('FfiCall.Doublex02', isLeaf: isLeaf); @override @@ -2383,18 +2342,17 @@ class Doublex04 extends FfiBenchmarkBase { final Function4double f; Doublex04({bool isLeaf = false}) - : f = - isLeaf - ? ffiTestFunctions - .lookupFunction( - 'Function4Double', - isLeaf: true, - ) - : ffiTestFunctions - .lookupFunction( - 'Function4Double', - isLeaf: false, - ), + : f = isLeaf + ? ffiTestFunctions + .lookupFunction( + 'Function4Double', + isLeaf: true, + ) + : ffiTestFunctions + .lookupFunction( + 'Function4Double', + isLeaf: false, + ), super('FfiCall.Doublex04', isLeaf: isLeaf); @override @@ -2446,18 +2404,17 @@ class Doublex10 extends FfiBenchmarkBase { final Function10double f; Doublex10({bool isLeaf = false}) - : f = - isLeaf - ? ffiTestFunctions - .lookupFunction( - 'Function10Double', - isLeaf: true, - ) - : ffiTestFunctions - .lookupFunction( - 'Function10Double', - isLeaf: false, - ), + : f = isLeaf + ? ffiTestFunctions + .lookupFunction( + 'Function10Double', + isLeaf: true, + ) + : ffiTestFunctions + .lookupFunction( + 'Function10Double', + isLeaf: false, + ), super('FfiCall.Doublex10', isLeaf: isLeaf); @override @@ -2542,18 +2499,17 @@ class Doublex20 extends FfiBenchmarkBase { final Function20double f; Doublex20({bool isLeaf = false}) - : f = - isLeaf - ? ffiTestFunctions - .lookupFunction( - 'Function20Double', - isLeaf: true, - ) - : ffiTestFunctions - .lookupFunction( - 'Function20Double', - isLeaf: false, - ), + : f = isLeaf + ? ffiTestFunctions + .lookupFunction( + 'Function20Double', + isLeaf: true, + ) + : ffiTestFunctions + .lookupFunction( + 'Function20Double', + isLeaf: false, + ), super('FfiCall.Doublex20', isLeaf: isLeaf); @override @@ -2710,16 +2666,15 @@ class PointerUint8x01 extends FfiBenchmarkBase { final Function1PointerUint8 f; PointerUint8x01({bool isLeaf = false}) - : f = - isLeaf - ? ffiTestFunctions.lookupFunction< - NativeFunction1PointerUint8, - Function1PointerUint8 - >('Function1PointerUint8', isLeaf: true) - : ffiTestFunctions.lookupFunction< - NativeFunction1PointerUint8, - Function1PointerUint8 - >('Function1PointerUint8', isLeaf: false), + : f = isLeaf + ? ffiTestFunctions.lookupFunction< + NativeFunction1PointerUint8, + Function1PointerUint8 + >('Function1PointerUint8', isLeaf: true) + : ffiTestFunctions.lookupFunction< + NativeFunction1PointerUint8, + Function1PointerUint8 + >('Function1PointerUint8', isLeaf: false), super('FfiCall.PointerUint8x01', isLeaf: isLeaf); Pointer p1 = nullptr; @@ -2812,16 +2767,15 @@ class PointerUint8x02 extends FfiBenchmarkBase { final Function2PointerUint8 f; PointerUint8x02({bool isLeaf = false}) - : f = - isLeaf - ? ffiTestFunctions.lookupFunction< - NativeFunction2PointerUint8, - Function2PointerUint8 - >('Function2PointerUint8', isLeaf: true) - : ffiTestFunctions.lookupFunction< - NativeFunction2PointerUint8, - Function2PointerUint8 - >('Function2PointerUint8', isLeaf: false), + : f = isLeaf + ? ffiTestFunctions.lookupFunction< + NativeFunction2PointerUint8, + Function2PointerUint8 + >('Function2PointerUint8', isLeaf: true) + : ffiTestFunctions.lookupFunction< + NativeFunction2PointerUint8, + Function2PointerUint8 + >('Function2PointerUint8', isLeaf: false), super('FfiCall.PointerUint8x02', isLeaf: isLeaf); Pointer p1 = nullptr; @@ -2926,16 +2880,15 @@ class PointerUint8x04 extends FfiBenchmarkBase { final Function4PointerUint8 f; PointerUint8x04({bool isLeaf = false}) - : f = - isLeaf - ? ffiTestFunctions.lookupFunction< - NativeFunction4PointerUint8, - Function4PointerUint8 - >('Function4PointerUint8', isLeaf: true) - : ffiTestFunctions.lookupFunction< - NativeFunction4PointerUint8, - Function4PointerUint8 - >('Function4PointerUint8', isLeaf: false), + : f = isLeaf + ? ffiTestFunctions.lookupFunction< + NativeFunction4PointerUint8, + Function4PointerUint8 + >('Function4PointerUint8', isLeaf: true) + : ffiTestFunctions.lookupFunction< + NativeFunction4PointerUint8, + Function4PointerUint8 + >('Function4PointerUint8', isLeaf: false), super('FfiCall.PointerUint8x04', isLeaf: isLeaf); Pointer p1 = nullptr; @@ -3056,16 +3009,15 @@ class PointerUint8x10 extends FfiBenchmarkBase { final Function10PointerUint8 f; PointerUint8x10({bool isLeaf = false}) - : f = - isLeaf - ? ffiTestFunctions.lookupFunction< - NativeFunction10PointerUint8, - Function10PointerUint8 - >('Function10PointerUint8', isLeaf: true) - : ffiTestFunctions.lookupFunction< - NativeFunction10PointerUint8, - Function10PointerUint8 - >('Function10PointerUint8', isLeaf: false), + : f = isLeaf + ? ffiTestFunctions.lookupFunction< + NativeFunction10PointerUint8, + Function10PointerUint8 + >('Function10PointerUint8', isLeaf: true) + : ffiTestFunctions.lookupFunction< + NativeFunction10PointerUint8, + Function10PointerUint8 + >('Function10PointerUint8', isLeaf: false), super('FfiCall.PointerUint8x10', isLeaf: isLeaf); Pointer p1 = nullptr; @@ -3234,16 +3186,15 @@ class PointerUint8x20 extends FfiBenchmarkBase { final Function20PointerUint8 f; PointerUint8x20({bool isLeaf = false}) - : f = - isLeaf - ? ffiTestFunctions.lookupFunction< - NativeFunction20PointerUint8, - Function20PointerUint8 - >('Function20PointerUint8', isLeaf: true) - : ffiTestFunctions.lookupFunction< - NativeFunction20PointerUint8, - Function20PointerUint8 - >('Function20PointerUint8', isLeaf: false), + : f = isLeaf + ? ffiTestFunctions.lookupFunction< + NativeFunction20PointerUint8, + Function20PointerUint8 + >('Function20PointerUint8', isLeaf: true) + : ffiTestFunctions.lookupFunction< + NativeFunction20PointerUint8, + Function20PointerUint8 + >('Function20PointerUint8', isLeaf: false), super('FfiCall.PointerUint8x20', isLeaf: isLeaf); Pointer p1 = nullptr; diff --git a/benchmarks/FfiCall/dart/dlopen_helper.dart b/benchmarks/FfiCall/dart/dlopen_helper.dart index 2c061527181..e47fd11ff85 100644 --- a/benchmarks/FfiCall/dart/dlopen_helper.dart +++ b/benchmarks/FfiCall/dart/dlopen_helper.dart @@ -72,10 +72,9 @@ const RTLD_GLOBAL_android_arm32 = 0x00002; /// On Linux and Android Arm64. const RTLD_GLOBAL_rest = 0x00100; -final RTLD_GLOBAL = - Abi.current() == Abi.androidArm - ? RTLD_GLOBAL_android_arm32 - : RTLD_GLOBAL_rest; +final RTLD_GLOBAL = Abi.current() == Abi.androidArm + ? RTLD_GLOBAL_android_arm32 + : RTLD_GLOBAL_rest; @Native Function(Pointer, Int)>() external Pointer dlopen(Pointer file, int mode); diff --git a/benchmarks/FfiCall/generate_benchmarks.dart b/benchmarks/FfiCall/generate_benchmarks.dart index 103f15a0437..056948b3854 100644 --- a/benchmarks/FfiCall/generate_benchmarks.dart +++ b/benchmarks/FfiCall/generate_benchmarks.dart @@ -166,10 +166,9 @@ void generateBenchmarkDouble(StringBuffer buffer, List types) { final String dartType = toIdentifier(nativeToDartType[type]!); for (int number in generateFor[type]!) { final String name = '${typeName}x${'$number'.padLeft(2, '0')}'; - final String expected = - number == 1 - ? 'N + N * 42.0' // Do work with single arg. - : 'N * $number * ($number + 1) / 2 '; // The rest sums arguments. + final String expected = number == 1 + ? 'N + N * 42.0' // Do work with single arg. + : 'N * $number * ($number + 1) / 2 '; // The rest sums arguments. final String functionType = 'Function$number$dartType'; final String functionNativeType = 'NativeFunction$number$typeName'; final String functionNameC = 'Function$number$typeName'; @@ -242,8 +241,10 @@ void generateBenchmarkPointer(StringBuffer buffer, List types) { final String pointers = pointerNames .map((n) => '$type $n = nullptr;') .join('\n'); - final String setup = - List.generate(number - 1, (i) => 'p${i + 2} = p1 + ${i + 1};').join(); + final String setup = List.generate( + number - 1, + (i) => 'p${i + 2} = p1 + ${i + 1};', + ).join(); final String functionType = 'Function$number$dartTypeName'; final String functionNativeType = 'NativeFunction$number$typeName'; final String functionNameC = 'Function$number$typeName'; diff --git a/benchmarks/FfiCallback/dart/FfiCallback.dart b/benchmarks/FfiCallback/dart/FfiCallback.dart index 05136bf9b69..308fb4ea381 100644 --- a/benchmarks/FfiCallback/dart/FfiCallback.dart +++ b/benchmarks/FfiCallback/dart/FfiCallback.dart @@ -75,10 +75,11 @@ abstract class FfiCallbackBenchmark { final class Uint8x1 extends FfiCallbackBenchmark { Uint8x1() : super('FfiCallbackBenchmark.Uint8x1'); - final function = ffiTestFunctions.lookupFunction< - Void Function(Pointer>, Uint32), - void Function(Pointer>, int) - >('CallFunction1Uint8'); + final function = ffiTestFunctions + .lookupFunction< + Void Function(Pointer>, Uint32), + void Function(Pointer>, int) + >('CallFunction1Uint8'); static int x = 0; @@ -104,13 +105,8 @@ final class Uint8x1 extends FfiCallbackBenchmark { } } -final argParser = - ArgParser()..addFlag( - 'verbose', - abbr: 'v', - help: 'Verbose output', - defaultsTo: false, - ); +final argParser = ArgParser() + ..addFlag('verbose', abbr: 'v', help: 'Verbose output', defaultsTo: false); void main(List args) { final results = argParser.parse(args); diff --git a/benchmarks/FfiStructCopy/dart/FfiStructCopy.dart b/benchmarks/FfiStructCopy/dart/FfiStructCopy.dart index cee50796c61..88d0dc61215 100644 --- a/benchmarks/FfiStructCopy/dart/FfiStructCopy.dart +++ b/benchmarks/FfiStructCopy/dart/FfiStructCopy.dart @@ -83,13 +83,8 @@ abstract class StructCopyBenchmark { void run(int batchSize); } -final argParser = - ArgParser()..addFlag( - 'verbose', - abbr: 'v', - help: 'Verbose output', - defaultsTo: false, - ); +final argParser = ArgParser() + ..addFlag('verbose', abbr: 'v', help: 'Verbose output', defaultsTo: false); void main(List args) { final results = argParser.parse(args); diff --git a/benchmarks/FfiStructCopy/generate_benchmarks.dart b/benchmarks/FfiStructCopy/generate_benchmarks.dart index e07c0747fe3..24ae5f23318 100644 --- a/benchmarks/FfiStructCopy/generate_benchmarks.dart +++ b/benchmarks/FfiStructCopy/generate_benchmarks.dart @@ -29,7 +29,8 @@ import 'package:ffi/ffi.dart'; import 'FfiStructCopy.dart'; '''; -String generateSize(int size) => ''' +String generateSize(int size) => + ''' final class Struct${size}Bytes extends Struct { @Array($size) external Array a0; diff --git a/samples/ffi/async/sample_async_callback.dart b/samples/ffi/async/sample_async_callback.dart index 96b3cff44a4..f317dd0ca8a 100644 --- a/samples/ffi/async/sample_async_callback.dart +++ b/samples/ffi/async/sample_async_callback.dart @@ -28,8 +28,11 @@ main() async { print("Dart: Setup."); Expect.isTrue(NativeApi.majorVersion == 2); Expect.isTrue(NativeApi.minorVersion >= 2); - final initializeApi = dl.lookupFunction), - int Function(Pointer)>("InitDartApiDL"); + final initializeApi = dl + .lookupFunction< + IntPtr Function(Pointer), + int Function(Pointer) + >("InitDartApiDL"); Expect.isTrue(initializeApi(NativeApi.initializeApiDLData) == 0); final interactiveCppRequests = ReceivePort()..listen(requestExecuteCallback); @@ -82,28 +85,42 @@ final callback2FP = Pointer.fromFunction(callback2); final dl = dlopenPlatformSpecific("ffi_test_functions"); -final registerCallback1 = dl.lookupFunction< - Void Function(Int64 sendPort, - Pointer> functionPointer), - void Function(int sendPort, - Pointer> functionPointer)>( - 'RegisterMyCallbackBlocking'); +final registerCallback1 = dl + .lookupFunction< + Void Function( + Int64 sendPort, + Pointer> functionPointer, + ), + void Function( + int sendPort, + Pointer> functionPointer, + ) + >('RegisterMyCallbackBlocking'); -final registerCallback2 = dl.lookupFunction< - Void Function(Int64 sendPort, - Pointer> functionPointer), - void Function(int sendPort, - Pointer> functionPointer)>( - 'RegisterMyCallbackNonBlocking'); +final registerCallback2 = dl + .lookupFunction< + Void Function( + Int64 sendPort, + Pointer> functionPointer, + ), + void Function( + int sendPort, + Pointer> functionPointer, + ) + >('RegisterMyCallbackNonBlocking'); -final startWorkSimulator = - dl.lookupFunction('StartWorkSimulator'); +final startWorkSimulator = dl.lookupFunction( + 'StartWorkSimulator', +); -final stopWorkSimulator = - dl.lookupFunction('StopWorkSimulator'); +final stopWorkSimulator = dl.lookupFunction( + 'StopWorkSimulator', +); -final executeCallback = dl.lookupFunction), - void Function(Pointer)>('ExecuteCallback'); +final executeCallback = dl + .lookupFunction), void Function(Pointer)>( + 'ExecuteCallback', + ); final class Work extends Opaque {} diff --git a/samples/ffi/async/sample_native_port_call.dart b/samples/ffi/async/sample_native_port_call.dart index 11cf3c98262..481939d0374 100644 --- a/samples/ffi/async/sample_native_port_call.dart +++ b/samples/ffi/async/sample_native_port_call.dart @@ -37,8 +37,11 @@ main() async { print("Dart: Setup."); Expect.isTrue(NativeApi.majorVersion == 2); Expect.isTrue(NativeApi.minorVersion >= 2); - final initializeApi = dl.lookupFunction), - int Function(Pointer)>("InitDartApiDL"); + final initializeApi = dl + .lookupFunction< + IntPtr Function(Pointer), + int Function(Pointer) + >("InitDartApiDL"); Expect.isTrue(initializeApi(NativeApi.initializeApiDLData) == 0); final interactiveCppRequests = ReceivePort()..listen(handleCppRequests); @@ -111,8 +114,10 @@ void handleCppRequests(dynamic message) { // the argument to the function. final int argument = cppRequest.data[0]; final int result = myCallback1(argument); - final cppResponse = - CppResponse(cppRequest.pendingCall!, Uint8List.fromList([result])); + final cppResponse = CppResponse( + cppRequest.pendingCall!, + Uint8List.fromList([result]), + ); print('Dart: Responding: $cppResponse'); cppRequest.replyPort!.send(cppResponse.toCppMessage()); } else if (cppRequest.method == 'myCallback2') { @@ -123,14 +128,18 @@ void handleCppRequests(dynamic message) { final dl = dlopenPlatformSpecific("ffi_test_functions"); -final registerSendPort = dl.lookupFunction('RegisterSendPort'); +final registerSendPort = dl + .lookupFunction( + 'RegisterSendPort', + ); -final startWorkSimulator2 = - dl.lookupFunction('StartWorkSimulator2'); +final startWorkSimulator2 = dl.lookupFunction( + 'StartWorkSimulator2', +); -final stopWorkSimulator2 = - dl.lookupFunction('StopWorkSimulator2'); +final stopWorkSimulator2 = dl.lookupFunction( + 'StopWorkSimulator2', +); Future asyncSleep(int ms) { return new Future.delayed(Duration(milliseconds: ms), () => true); diff --git a/samples/ffi/resource_management/arena_isolate_shutdown_sample.dart b/samples/ffi/resource_management/arena_isolate_shutdown_sample.dart index 3e8b7c3881f..93ac360c115 100644 --- a/samples/ffi/resource_management/arena_isolate_shutdown_sample.dart +++ b/samples/ffi/resource_management/arena_isolate_shutdown_sample.dart @@ -16,11 +16,10 @@ import '../dylib_utils.dart'; void main() { final receiveFromHelper = ReceivePort(); - Isolate.spawn(helperIsolateMain, receiveFromHelper.sendPort) - .then((helperIsolate) { - helperIsolate.addOnExitListener( - receiveFromHelper.sendPort, - ); + Isolate.spawn(helperIsolateMain, receiveFromHelper.sendPort).then(( + helperIsolate, + ) { + helperIsolate.addOnExitListener(receiveFromHelper.sendPort); print("Main: Helper started."); Pointer resource = nullptr; receiveFromHelper.listen((message) { @@ -34,7 +33,8 @@ void main() { Expect.isNull(message); print("Main: Helper is shut down."); print( - "Main: Trying to use resource after isolate that was supposed to free it was shut down."); + "Main: Trying to use resource after isolate that was supposed to free it was shut down.", + ); useResource(resource); print("Main: Releasing resource manually."); releaseResource(resource); @@ -70,20 +70,27 @@ void helperIsolateMain(SendPort sendToMain) { }); } -final ffiTestDynamicLibrary = - dlopenPlatformSpecific("ffi_test_dynamic_library"); +final ffiTestDynamicLibrary = dlopenPlatformSpecific( + "ffi_test_dynamic_library", +); -final allocateResource = ffiTestDynamicLibrary.lookupFunction< - Pointer Function(), - Pointer Function()>("AllocateResource"); +final allocateResource = ffiTestDynamicLibrary + .lookupFunction< + Pointer Function(), + Pointer Function() + >("AllocateResource"); -final useResource = ffiTestDynamicLibrary.lookupFunction< - Void Function(Pointer), - void Function(Pointer)>("UseResource"); +final useResource = ffiTestDynamicLibrary + .lookupFunction< + Void Function(Pointer), + void Function(Pointer) + >("UseResource"); -final releaseResource = ffiTestDynamicLibrary.lookupFunction< - Void Function(Pointer), - void Function(Pointer)>("ReleaseResource"); +final releaseResource = ffiTestDynamicLibrary + .lookupFunction< + Void Function(Pointer), + void Function(Pointer) + >("ReleaseResource"); /// Represents some opaque resource being managed by a library. final class SomeResource extends Opaque {} diff --git a/samples/ffi/resource_management/arena_sample.dart b/samples/ffi/resource_management/arena_sample.dart index 8dcdfda81dc..cb37ae9173a 100644 --- a/samples/ffi/resource_management/arena_sample.dart +++ b/samples/ffi/resource_management/arena_sample.dart @@ -14,12 +14,15 @@ import 'utf8_helpers.dart'; import '../dylib_utils.dart'; main() async { - final ffiTestDynamicLibrary = - dlopenPlatformSpecific("ffi_test_dynamic_library"); + final ffiTestDynamicLibrary = dlopenPlatformSpecific( + "ffi_test_dynamic_library", + ); - final MemMove = ffiTestDynamicLibrary.lookupFunction< - Void Function(Pointer, Pointer, IntPtr), - void Function(Pointer, Pointer, int)>("MemMove"); + final MemMove = ffiTestDynamicLibrary + .lookupFunction< + Void Function(Pointer, Pointer, IntPtr), + void Function(Pointer, Pointer, int) + >("MemMove"); // To ensure resources are freed, wrap them in a [using] call. using((Arena arena) { @@ -79,17 +82,23 @@ main() async { print(p.contents()); }); - final allocateResource = ffiTestDynamicLibrary.lookupFunction< - Pointer Function(), - Pointer Function()>("AllocateResource"); + final allocateResource = ffiTestDynamicLibrary + .lookupFunction< + Pointer Function(), + Pointer Function() + >("AllocateResource"); - final useResource = ffiTestDynamicLibrary.lookupFunction< - Void Function(Pointer), - void Function(Pointer)>("UseResource"); + final useResource = ffiTestDynamicLibrary + .lookupFunction< + Void Function(Pointer), + void Function(Pointer) + >("UseResource"); - final releaseResource = ffiTestDynamicLibrary.lookupFunction< - Void Function(Pointer), - void Function(Pointer)>("ReleaseResource"); + final releaseResource = ffiTestDynamicLibrary + .lookupFunction< + Void Function(Pointer), + void Function(Pointer) + >("ReleaseResource"); // Using an FFI call to release a resource. using((Arena arena) { diff --git a/samples/ffi/resource_management/arena_zoned_sample.dart b/samples/ffi/resource_management/arena_zoned_sample.dart index f3bdf44e645..739d1c40c7f 100644 --- a/samples/ffi/resource_management/arena_zoned_sample.dart +++ b/samples/ffi/resource_management/arena_zoned_sample.dart @@ -13,12 +13,15 @@ import 'utf8_helpers.dart'; import '../dylib_utils.dart'; main() async { - final ffiTestDynamicLibrary = - dlopenPlatformSpecific("ffi_test_dynamic_library"); + final ffiTestDynamicLibrary = dlopenPlatformSpecific( + "ffi_test_dynamic_library", + ); - final MemMove = ffiTestDynamicLibrary.lookupFunction< - Void Function(Pointer, Pointer, IntPtr), - void Function(Pointer, Pointer, int)>("MemMove"); + final MemMove = ffiTestDynamicLibrary + .lookupFunction< + Void Function(Pointer, Pointer, IntPtr), + void Function(Pointer, Pointer, int) + >("MemMove"); // To ensure resources are freed, wrap them in a [withZoneArena] call. withZoneArena(() { @@ -77,17 +80,23 @@ main() async { print(p.contents()); }); - final allocateResource = ffiTestDynamicLibrary.lookupFunction< - Pointer Function(), - Pointer Function()>("AllocateResource"); + final allocateResource = ffiTestDynamicLibrary + .lookupFunction< + Pointer Function(), + Pointer Function() + >("AllocateResource"); - final useResource = ffiTestDynamicLibrary.lookupFunction< - Void Function(Pointer), - void Function(Pointer)>("UseResource"); + final useResource = ffiTestDynamicLibrary + .lookupFunction< + Void Function(Pointer), + void Function(Pointer) + >("UseResource"); - final releaseResource = ffiTestDynamicLibrary.lookupFunction< - Void Function(Pointer), - void Function(Pointer)>("ReleaseResource"); + final releaseResource = ffiTestDynamicLibrary + .lookupFunction< + Void Function(Pointer), + void Function(Pointer) + >("ReleaseResource"); // Using an FFI call to release a resource. withZoneArena(() { diff --git a/samples/ffi/resource_management/unmanaged_sample.dart b/samples/ffi/resource_management/unmanaged_sample.dart index ac38f3e1ca0..ff551b5bcb3 100644 --- a/samples/ffi/resource_management/unmanaged_sample.dart +++ b/samples/ffi/resource_management/unmanaged_sample.dart @@ -13,12 +13,15 @@ import 'utf8_helpers.dart'; import '../dylib_utils.dart'; main() { - final ffiTestDynamicLibrary = - dlopenPlatformSpecific("ffi_test_dynamic_library"); + final ffiTestDynamicLibrary = dlopenPlatformSpecific( + "ffi_test_dynamic_library", + ); - final memMove = ffiTestDynamicLibrary.lookupFunction< - Void Function(Pointer, Pointer, IntPtr), - void Function(Pointer, Pointer, int)>("MemMove"); + final memMove = ffiTestDynamicLibrary + .lookupFunction< + Void Function(Pointer, Pointer, IntPtr), + void Function(Pointer, Pointer, int) + >("MemMove"); // To ensure resources are freed, call free manually. // diff --git a/samples/ffi/resource_management/utf8_helpers.dart b/samples/ffi/resource_management/utf8_helpers.dart index 09dddc130f7..5275d5a22f8 100644 --- a/samples/ffi/resource_management/utf8_helpers.dart +++ b/samples/ffi/resource_management/utf8_helpers.dart @@ -46,7 +46,8 @@ extension Utf8Helpers on Pointer { /// Returns a Dart string containing the decoded code points. String contents() { final int length = strlen; - return utf8.decode(Uint8List.view( - this.cast().asTypedList(length).buffer, 0, length)); + return utf8.decode( + Uint8List.view(this.cast().asTypedList(length).buffer, 0, length), + ); } } diff --git a/samples/ffi/sample_ffi_functions.dart b/samples/ffi/sample_ffi_functions.dart index 4630bf972fb..fda5c076bfb 100644 --- a/samples/ffi/sample_ffi_functions.dart +++ b/samples/ffi/sample_ffi_functions.dart @@ -18,72 +18,121 @@ typedef NativeQuadOpUnsigned = Uint64 Function(Uint8, Uint16, Uint32, Uint64); typedef NativeFunc4 = IntPtr Function(IntPtr); typedef NativeDoubleUnaryOp = Double Function(Double); typedef NativeFloatUnaryOp = Float Function(Float); -typedef NativeDecenaryOp = IntPtr Function(IntPtr, IntPtr, IntPtr, IntPtr, - IntPtr, IntPtr, IntPtr, IntPtr, IntPtr, IntPtr); -typedef NativeDecenaryOp2 = Int16 Function( - Int8, Int16, Int8, Int16, Int8, Int16, Int8, Int16, Int8, Int16); -typedef NativeDoubleDecenaryOp = Double Function(Double, Double, Double, Double, - Double, Double, Double, Double, Double, Double); -typedef NativeVigesimalOp = Double Function( - IntPtr, - Float, - IntPtr, - Double, - IntPtr, - Float, - IntPtr, - Double, - IntPtr, - Float, - IntPtr, - Double, - IntPtr, - Float, - IntPtr, - Double, - IntPtr, - Float, - IntPtr, - Double); +typedef NativeDecenaryOp = + IntPtr Function( + IntPtr, + IntPtr, + IntPtr, + IntPtr, + IntPtr, + IntPtr, + IntPtr, + IntPtr, + IntPtr, + IntPtr, + ); +typedef NativeDecenaryOp2 = + Int16 Function( + Int8, + Int16, + Int8, + Int16, + Int8, + Int16, + Int8, + Int16, + Int8, + Int16, + ); +typedef NativeDoubleDecenaryOp = + Double Function( + Double, + Double, + Double, + Double, + Double, + Double, + Double, + Double, + Double, + Double, + ); +typedef NativeVigesimalOp = + Double Function( + IntPtr, + Float, + IntPtr, + Double, + IntPtr, + Float, + IntPtr, + Double, + IntPtr, + Float, + IntPtr, + Double, + IntPtr, + Float, + IntPtr, + Double, + IntPtr, + Float, + IntPtr, + Double, + ); typedef Int64PointerUnOp = Pointer Function(Pointer); typedef QuadOp = int Function(int, int, int, int); typedef DoubleUnaryOp = double Function(double); -typedef DecenaryOp = int Function( - int, int, int, int, int, int, int, int, int, int); -typedef DoubleDecenaryOp = double Function(double, double, double, double, - double, double, double, double, double, double); -typedef VigesimalOp = double Function( - int, - double, - int, - double, - int, - double, - int, - double, - int, - double, - int, - double, - int, - double, - int, - double, - int, - double, - int, - double); +typedef DecenaryOp = + int Function(int, int, int, int, int, int, int, int, int, int); +typedef DoubleDecenaryOp = + double Function( + double, + double, + double, + double, + double, + double, + double, + double, + double, + double, + ); +typedef VigesimalOp = + double Function( + int, + double, + int, + double, + int, + double, + int, + double, + int, + double, + int, + double, + int, + double, + int, + double, + int, + double, + int, + double, + ); main() { print('start main'); - DynamicLibrary ffiTestFunctions = - dlopenPlatformSpecific("ffi_test_functions"); + DynamicLibrary ffiTestFunctions = dlopenPlatformSpecific( + "ffi_test_functions", + ); { // A int32 bin op. - BinaryOp sumPlus42 = - ffiTestFunctions.lookupFunction("SumPlus42"); + BinaryOp sumPlus42 = ffiTestFunctions + .lookupFunction("SumPlus42"); var result = sumPlus42(3, 17); print(result); @@ -172,10 +221,22 @@ main() { { // Function with many double arguments. - DoubleDecenaryOp sumManyDoubles = ffiTestFunctions.lookupFunction< - NativeDoubleDecenaryOp, DoubleDecenaryOp>("SumManyDoubles"); - var result = - sumManyDoubles(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0); + DoubleDecenaryOp sumManyDoubles = ffiTestFunctions + .lookupFunction( + "SumManyDoubles", + ); + var result = sumManyDoubles( + 1.0, + 2.0, + 3.0, + 4.0, + 5.0, + 6.0, + 7.0, + 8.0, + 9.0, + 10.0, + ); print(result); print(result.runtimeType); } @@ -184,8 +245,28 @@ main() { // Function with many arguments, ints and doubles mixed. VigesimalOp sumManyNumbers = ffiTestFunctions .lookupFunction("SumManyNumbers"); - var result = sumManyNumbers(1, 2.0, 3, 4.0, 5, 6.0, 7, 8.0, 9, 10.0, 11, - 12.0, 13, 14.0, 15, 16.0, 17, 18.0, 19, 20.0); + var result = sumManyNumbers( + 1, + 2.0, + 3, + 4.0, + 5, + 6.0, + 7, + 8.0, + 9, + 10.0, + 11, + 12.0, + 13, + 14.0, + 15, + 16.0, + 17, + 18.0, + 19, + 20.0, + ); print(result); print(result.runtimeType); } @@ -211,9 +292,10 @@ main() { { // Passing in nullptr for a pointer argument results in a nullptr in c. - Int64PointerUnOp nullableInt64ElemAt1 = - ffiTestFunctions.lookupFunction( - "NullableInt64ElemAt1"); + Int64PointerUnOp nullableInt64ElemAt1 = ffiTestFunctions + .lookupFunction( + "NullableInt64ElemAt1", + ); Pointer result = nullableInt64ElemAt1(nullptr); print(result); diff --git a/samples/ffi/sample_ffi_functions_callbacks.dart b/samples/ffi/sample_ffi_functions_callbacks.dart index f571dd167b9..ab85c79338e 100644 --- a/samples/ffi/sample_ffi_functions_callbacks.dart +++ b/samples/ffi/sample_ffi_functions_callbacks.dart @@ -11,19 +11,22 @@ import 'dylib_utils.dart'; typedef NativeCoordinateOp = Pointer Function(Pointer); -typedef CoordinateTrice = Pointer Function( - Pointer>, Pointer); +typedef CoordinateTrice = + Pointer Function( + Pointer>, + Pointer, + ); typedef BinaryOp = int Function(int, int); typedef NativeIntptrBinOp = IntPtr Function(IntPtr, IntPtr); -typedef NativeIntptrBinOpLookup = Pointer> - Function(); +typedef NativeIntptrBinOpLookup = + Pointer> Function(); -typedef NativeApplyTo42And74Type = IntPtr Function( - Pointer>); +typedef NativeApplyTo42And74Type = + IntPtr Function(Pointer>); -typedef ApplyTo42And74Type = int Function( - Pointer>); +typedef ApplyTo42And74Type = + int Function(Pointer>); int myPlus(int a, int b) { print("myPlus"); @@ -35,15 +38,17 @@ int myPlus(int a, int b) { main() { print('start main'); - DynamicLibrary ffiTestFunctions = - dlopenPlatformSpecific("ffi_test_functions"); + DynamicLibrary ffiTestFunctions = dlopenPlatformSpecific( + "ffi_test_functions", + ); { // Pass a c pointer to a c function as an argument to a c function. Pointer> transposeCoordinatePointer = ffiTestFunctions.lookup("TransposeCoordinate"); - Pointer> p2 = - ffiTestFunctions.lookup("CoordinateUnOpTrice"); + Pointer> p2 = ffiTestFunctions.lookup( + "CoordinateUnOpTrice", + ); CoordinateTrice coordinateUnOpTrice = p2.asFunction(); final c1 = calloc() ..ref.x = 10.0 @@ -58,8 +63,8 @@ main() { { // Return a c pointer to a c function from a c function. - Pointer> p14 = - ffiTestFunctions.lookup("IntptrAdditionClosure"); + Pointer> p14 = ffiTestFunctions + .lookup("IntptrAdditionClosure"); NativeIntptrBinOpLookup intptrAdditionClosure = p14.asFunction(); Pointer> intptrAdditionPointer = @@ -69,12 +74,14 @@ main() { } { - Pointer> pointer = - Pointer.fromFunction(myPlus, 0); + Pointer> pointer = Pointer.fromFunction( + myPlus, + 0, + ); print(pointer); - Pointer> p17 = - ffiTestFunctions.lookup("ApplyTo42And74"); + Pointer> p17 = ffiTestFunctions + .lookup("ApplyTo42And74"); ApplyTo42And74Type applyTo42And74 = p17.asFunction(); int result = applyTo42And74(pointer); diff --git a/samples/ffi/sample_ffi_functions_callbacks_closures.dart b/samples/ffi/sample_ffi_functions_callbacks_closures.dart index 6f96071a226..e0a826362bc 100644 --- a/samples/ffi/sample_ffi_functions_callbacks_closures.dart +++ b/samples/ffi/sample_ffi_functions_callbacks_closures.dart @@ -34,9 +34,10 @@ void main() { final testLibrary = dlopenPlatformSpecific("ffi_test_functions"); -final registerClosureCallback = - testLibrary.lookupFunction( - "RegisterClosureCallback"); +final registerClosureCallback = testLibrary + .lookupFunction( + "RegisterClosureCallback", + ); final invokeClosureCallback = testLibrary .lookupFunction("InvokeClosureCallback"); @@ -49,19 +50,23 @@ void doClosureCallback(Object callback) { callback_as_function(); } -final closureCallbackPointer = - Pointer.fromFunction(doClosureCallback); +final closureCallbackPointer = Pointer.fromFunction( + doClosureCallback, +); void doDynamicLinking() { Expect.isTrue(NativeApi.majorVersion == 2); Expect.isTrue(NativeApi.minorVersion >= 2); - final initializeApi = testLibrary.lookupFunction< - IntPtr Function(Pointer), - int Function(Pointer)>("InitDartApiDL"); + final initializeApi = testLibrary + .lookupFunction< + IntPtr Function(Pointer), + int Function(Pointer) + >("InitDartApiDL"); Expect.isTrue(initializeApi(NativeApi.initializeApiDLData) == 0); - final registerClosureCallback = testLibrary.lookupFunction< - Void Function(Pointer), - void Function(Pointer)>("RegisterClosureCallbackFP"); + final registerClosureCallback = testLibrary + .lookupFunction( + "RegisterClosureCallbackFP", + ); registerClosureCallback(closureCallbackPointer); } diff --git a/samples/ffi/sample_ffi_functions_structs.dart b/samples/ffi/sample_ffi_functions_structs.dart index 9d12a137c7c..b506d13af33 100644 --- a/samples/ffi/sample_ffi_functions_structs.dart +++ b/samples/ffi/sample_ffi_functions_structs.dart @@ -14,13 +14,15 @@ typedef NativeCoordinateOp = Pointer Function(Pointer); main() { print('start main'); - DynamicLibrary ffiTestFunctions = - dlopenPlatformSpecific("ffi_test_functions"); + DynamicLibrary ffiTestFunctions = dlopenPlatformSpecific( + "ffi_test_functions", + ); { // Pass a struct to a c function and get a struct as return value. - Pointer> p1 = - ffiTestFunctions.lookup("TransposeCoordinate"); + Pointer> p1 = ffiTestFunctions.lookup( + "TransposeCoordinate", + ); NativeCoordinateOp f1 = p1.asFunction(); final c1 = calloc() @@ -45,8 +47,9 @@ main() { { // Pass an array of structs to a c function. - Pointer> p1 = - ffiTestFunctions.lookup("CoordinateElemAt1"); + Pointer> p1 = ffiTestFunctions.lookup( + "CoordinateElemAt1", + ); NativeCoordinateOp f1 = p1.asFunction(); Pointer c1 = calloc(3);