[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 <rnystrom@google.com> Reviewed-by: Bob Nystrom <rnystrom@google.com> Auto-Submit: Daco Harkes <dacoharkes@google.com> Commit-Queue: Daco Harkes <dacoharkes@google.com>
This commit is contained in:
committed by
Commit Queue
parent
546ddc645e
commit
0768228750
@@ -44,20 +44,22 @@ final Pointer<EVP_MD> Function() EVP_sha512 = ssl
|
||||
/// ```c
|
||||
/// EVP_MD_CTX *EVP_MD_CTX_new(void);
|
||||
/// ```
|
||||
final Pointer<EVP_MD_CTX> Function() EVP_MD_CTX_new = ssl.lookupFunction<
|
||||
Pointer<EVP_MD_CTX> Function(),
|
||||
Pointer<EVP_MD_CTX> Function()
|
||||
>('EVP_MD_CTX_new');
|
||||
final Pointer<EVP_MD_CTX> Function() EVP_MD_CTX_new = ssl
|
||||
.lookupFunction<
|
||||
Pointer<EVP_MD_CTX> Function(),
|
||||
Pointer<EVP_MD_CTX> 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>) EVP_MD_CTX_free = ssl.lookupFunction<
|
||||
Void Function(Pointer<EVP_MD_CTX>),
|
||||
void Function(Pointer<EVP_MD_CTX>)
|
||||
>('EVP_MD_CTX_free');
|
||||
final void Function(Pointer<EVP_MD_CTX>) EVP_MD_CTX_free = ssl
|
||||
.lookupFunction<
|
||||
Void Function(Pointer<EVP_MD_CTX>),
|
||||
void Function(Pointer<EVP_MD_CTX>)
|
||||
>('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<EVP_MD_CTX>, Pointer<Data>, int) EVP_DigestUpdate =
|
||||
/// unsigned int *out_size);
|
||||
/// ```
|
||||
final int Function(Pointer<EVP_MD_CTX>, Pointer<Bytes>, Pointer<Uint32>)
|
||||
EVP_DigestFinal = ssl.lookupFunction<
|
||||
Int32 Function(Pointer<EVP_MD_CTX>, Pointer<Bytes>, Pointer<Uint32>),
|
||||
int Function(Pointer<EVP_MD_CTX>, Pointer<Bytes>, Pointer<Uint32>)
|
||||
>('EVP_DigestFinal');
|
||||
EVP_DigestFinal = ssl
|
||||
.lookupFunction<
|
||||
Int32 Function(Pointer<EVP_MD_CTX>, Pointer<Bytes>, Pointer<Uint32>),
|
||||
int Function(Pointer<EVP_MD_CTX>, Pointer<Bytes>, Pointer<Uint32>)
|
||||
>('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>) EVP_MD_CTX_size = ssl.lookupFunction<
|
||||
IntPtr Function(Pointer<EVP_MD_CTX>),
|
||||
int Function(Pointer<EVP_MD_CTX>)
|
||||
>('EVP_MD_CTX_size');
|
||||
final int Function(Pointer<EVP_MD_CTX>) EVP_MD_CTX_size = ssl
|
||||
.lookupFunction<
|
||||
IntPtr Function(Pointer<EVP_MD_CTX>),
|
||||
int Function(Pointer<EVP_MD_CTX>)
|
||||
>('EVP_MD_CTX_size');
|
||||
|
||||
@@ -63,18 +63,15 @@ class Int64Mintx01 extends FfiBenchmarkBase {
|
||||
final Function1int f;
|
||||
|
||||
Int64Mintx01({isLeaf = false})
|
||||
: f =
|
||||
isLeaf
|
||||
? ffiTestFunctions
|
||||
.lookupFunction<NativeFunction1Int64, Function1int>(
|
||||
'Function1Int64',
|
||||
isLeaf: true,
|
||||
)
|
||||
: ffiTestFunctions
|
||||
.lookupFunction<NativeFunction1Int64, Function1int>(
|
||||
'Function1Int64',
|
||||
isLeaf: false,
|
||||
),
|
||||
: f = isLeaf
|
||||
? ffiTestFunctions.lookupFunction<NativeFunction1Int64, Function1int>(
|
||||
'Function1Int64',
|
||||
isLeaf: true,
|
||||
)
|
||||
: ffiTestFunctions.lookupFunction<NativeFunction1Int64, Function1int>(
|
||||
'Function1Int64',
|
||||
isLeaf: false,
|
||||
),
|
||||
super('FfiCall.Int64Mintx01', isLeaf: isLeaf);
|
||||
|
||||
@override
|
||||
|
||||
@@ -632,18 +632,15 @@ class Int8x01 extends FfiBenchmarkBase {
|
||||
final Function1int f;
|
||||
|
||||
Int8x01({bool isLeaf = false})
|
||||
: f =
|
||||
isLeaf
|
||||
? ffiTestFunctions
|
||||
.lookupFunction<NativeFunction1Int8, Function1int>(
|
||||
'Function1Int8',
|
||||
isLeaf: true,
|
||||
)
|
||||
: ffiTestFunctions
|
||||
.lookupFunction<NativeFunction1Int8, Function1int>(
|
||||
'Function1Int8',
|
||||
isLeaf: false,
|
||||
),
|
||||
: f = isLeaf
|
||||
? ffiTestFunctions.lookupFunction<NativeFunction1Int8, Function1int>(
|
||||
'Function1Int8',
|
||||
isLeaf: true,
|
||||
)
|
||||
: ffiTestFunctions.lookupFunction<NativeFunction1Int8, Function1int>(
|
||||
'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<NativeFunction1Int16, Function1int>(
|
||||
'Function1Int16',
|
||||
isLeaf: true,
|
||||
)
|
||||
: ffiTestFunctions
|
||||
.lookupFunction<NativeFunction1Int16, Function1int>(
|
||||
'Function1Int16',
|
||||
isLeaf: false,
|
||||
),
|
||||
: f = isLeaf
|
||||
? ffiTestFunctions.lookupFunction<NativeFunction1Int16, Function1int>(
|
||||
'Function1Int16',
|
||||
isLeaf: true,
|
||||
)
|
||||
: ffiTestFunctions.lookupFunction<NativeFunction1Int16, Function1int>(
|
||||
'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<NativeFunction1Int32, Function1int>(
|
||||
'Function1Int32',
|
||||
isLeaf: true,
|
||||
)
|
||||
: ffiTestFunctions
|
||||
.lookupFunction<NativeFunction1Int32, Function1int>(
|
||||
'Function1Int32',
|
||||
isLeaf: false,
|
||||
),
|
||||
: f = isLeaf
|
||||
? ffiTestFunctions.lookupFunction<NativeFunction1Int32, Function1int>(
|
||||
'Function1Int32',
|
||||
isLeaf: true,
|
||||
)
|
||||
: ffiTestFunctions.lookupFunction<NativeFunction1Int32, Function1int>(
|
||||
'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<NativeFunction2Int32, Function2int>(
|
||||
'Function2Int32',
|
||||
isLeaf: true,
|
||||
)
|
||||
: ffiTestFunctions
|
||||
.lookupFunction<NativeFunction2Int32, Function2int>(
|
||||
'Function2Int32',
|
||||
isLeaf: false,
|
||||
),
|
||||
: f = isLeaf
|
||||
? ffiTestFunctions.lookupFunction<NativeFunction2Int32, Function2int>(
|
||||
'Function2Int32',
|
||||
isLeaf: true,
|
||||
)
|
||||
: ffiTestFunctions.lookupFunction<NativeFunction2Int32, Function2int>(
|
||||
'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<NativeFunction4Int32, Function4int>(
|
||||
'Function4Int32',
|
||||
isLeaf: true,
|
||||
)
|
||||
: ffiTestFunctions
|
||||
.lookupFunction<NativeFunction4Int32, Function4int>(
|
||||
'Function4Int32',
|
||||
isLeaf: false,
|
||||
),
|
||||
: f = isLeaf
|
||||
? ffiTestFunctions.lookupFunction<NativeFunction4Int32, Function4int>(
|
||||
'Function4Int32',
|
||||
isLeaf: true,
|
||||
)
|
||||
: ffiTestFunctions.lookupFunction<NativeFunction4Int32, Function4int>(
|
||||
'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<NativeFunction10Int32, Function10int>(
|
||||
'Function10Int32',
|
||||
isLeaf: true,
|
||||
)
|
||||
: ffiTestFunctions
|
||||
.lookupFunction<NativeFunction10Int32, Function10int>(
|
||||
'Function10Int32',
|
||||
isLeaf: false,
|
||||
),
|
||||
: f = isLeaf
|
||||
? ffiTestFunctions
|
||||
.lookupFunction<NativeFunction10Int32, Function10int>(
|
||||
'Function10Int32',
|
||||
isLeaf: true,
|
||||
)
|
||||
: ffiTestFunctions
|
||||
.lookupFunction<NativeFunction10Int32, Function10int>(
|
||||
'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<NativeFunction20Int32, Function20int>(
|
||||
'Function20Int32',
|
||||
isLeaf: true,
|
||||
)
|
||||
: ffiTestFunctions
|
||||
.lookupFunction<NativeFunction20Int32, Function20int>(
|
||||
'Function20Int32',
|
||||
isLeaf: false,
|
||||
),
|
||||
: f = isLeaf
|
||||
? ffiTestFunctions
|
||||
.lookupFunction<NativeFunction20Int32, Function20int>(
|
||||
'Function20Int32',
|
||||
isLeaf: true,
|
||||
)
|
||||
: ffiTestFunctions
|
||||
.lookupFunction<NativeFunction20Int32, Function20int>(
|
||||
'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<NativeFunction1Int64, Function1int>(
|
||||
'Function1Int64',
|
||||
isLeaf: true,
|
||||
)
|
||||
: ffiTestFunctions
|
||||
.lookupFunction<NativeFunction1Int64, Function1int>(
|
||||
'Function1Int64',
|
||||
isLeaf: false,
|
||||
),
|
||||
: f = isLeaf
|
||||
? ffiTestFunctions.lookupFunction<NativeFunction1Int64, Function1int>(
|
||||
'Function1Int64',
|
||||
isLeaf: true,
|
||||
)
|
||||
: ffiTestFunctions.lookupFunction<NativeFunction1Int64, Function1int>(
|
||||
'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<NativeFunction2Int64, Function2int>(
|
||||
'Function2Int64',
|
||||
isLeaf: true,
|
||||
)
|
||||
: ffiTestFunctions
|
||||
.lookupFunction<NativeFunction2Int64, Function2int>(
|
||||
'Function2Int64',
|
||||
isLeaf: false,
|
||||
),
|
||||
: f = isLeaf
|
||||
? ffiTestFunctions.lookupFunction<NativeFunction2Int64, Function2int>(
|
||||
'Function2Int64',
|
||||
isLeaf: true,
|
||||
)
|
||||
: ffiTestFunctions.lookupFunction<NativeFunction2Int64, Function2int>(
|
||||
'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<NativeFunction4Int64, Function4int>(
|
||||
'Function4Int64',
|
||||
isLeaf: true,
|
||||
)
|
||||
: ffiTestFunctions
|
||||
.lookupFunction<NativeFunction4Int64, Function4int>(
|
||||
'Function4Int64',
|
||||
isLeaf: false,
|
||||
),
|
||||
: f = isLeaf
|
||||
? ffiTestFunctions.lookupFunction<NativeFunction4Int64, Function4int>(
|
||||
'Function4Int64',
|
||||
isLeaf: true,
|
||||
)
|
||||
: ffiTestFunctions.lookupFunction<NativeFunction4Int64, Function4int>(
|
||||
'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<NativeFunction10Int64, Function10int>(
|
||||
'Function10Int64',
|
||||
isLeaf: true,
|
||||
)
|
||||
: ffiTestFunctions
|
||||
.lookupFunction<NativeFunction10Int64, Function10int>(
|
||||
'Function10Int64',
|
||||
isLeaf: false,
|
||||
),
|
||||
: f = isLeaf
|
||||
? ffiTestFunctions
|
||||
.lookupFunction<NativeFunction10Int64, Function10int>(
|
||||
'Function10Int64',
|
||||
isLeaf: true,
|
||||
)
|
||||
: ffiTestFunctions
|
||||
.lookupFunction<NativeFunction10Int64, Function10int>(
|
||||
'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<NativeFunction20Int64, Function20int>(
|
||||
'Function20Int64',
|
||||
isLeaf: true,
|
||||
)
|
||||
: ffiTestFunctions
|
||||
.lookupFunction<NativeFunction20Int64, Function20int>(
|
||||
'Function20Int64',
|
||||
isLeaf: false,
|
||||
),
|
||||
: f = isLeaf
|
||||
? ffiTestFunctions
|
||||
.lookupFunction<NativeFunction20Int64, Function20int>(
|
||||
'Function20Int64',
|
||||
isLeaf: true,
|
||||
)
|
||||
: ffiTestFunctions
|
||||
.lookupFunction<NativeFunction20Int64, Function20int>(
|
||||
'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<NativeFunction1Uint8, Function1int>(
|
||||
'Function1Uint8',
|
||||
isLeaf: true,
|
||||
)
|
||||
: ffiTestFunctions
|
||||
.lookupFunction<NativeFunction1Uint8, Function1int>(
|
||||
'Function1Uint8',
|
||||
isLeaf: false,
|
||||
),
|
||||
: f = isLeaf
|
||||
? ffiTestFunctions.lookupFunction<NativeFunction1Uint8, Function1int>(
|
||||
'Function1Uint8',
|
||||
isLeaf: true,
|
||||
)
|
||||
: ffiTestFunctions.lookupFunction<NativeFunction1Uint8, Function1int>(
|
||||
'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<NativeFunction1Uint16, Function1int>(
|
||||
'Function1Uint16',
|
||||
isLeaf: true,
|
||||
)
|
||||
: ffiTestFunctions
|
||||
.lookupFunction<NativeFunction1Uint16, Function1int>(
|
||||
'Function1Uint16',
|
||||
isLeaf: false,
|
||||
),
|
||||
: f = isLeaf
|
||||
? ffiTestFunctions
|
||||
.lookupFunction<NativeFunction1Uint16, Function1int>(
|
||||
'Function1Uint16',
|
||||
isLeaf: true,
|
||||
)
|
||||
: ffiTestFunctions
|
||||
.lookupFunction<NativeFunction1Uint16, Function1int>(
|
||||
'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<NativeFunction1Uint32, Function1int>(
|
||||
'Function1Uint32',
|
||||
isLeaf: true,
|
||||
)
|
||||
: ffiTestFunctions
|
||||
.lookupFunction<NativeFunction1Uint32, Function1int>(
|
||||
'Function1Uint32',
|
||||
isLeaf: false,
|
||||
),
|
||||
: f = isLeaf
|
||||
? ffiTestFunctions
|
||||
.lookupFunction<NativeFunction1Uint32, Function1int>(
|
||||
'Function1Uint32',
|
||||
isLeaf: true,
|
||||
)
|
||||
: ffiTestFunctions
|
||||
.lookupFunction<NativeFunction1Uint32, Function1int>(
|
||||
'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<NativeFunction1Uint64, Function1int>(
|
||||
'Function1Uint64',
|
||||
isLeaf: true,
|
||||
)
|
||||
: ffiTestFunctions
|
||||
.lookupFunction<NativeFunction1Uint64, Function1int>(
|
||||
'Function1Uint64',
|
||||
isLeaf: false,
|
||||
),
|
||||
: f = isLeaf
|
||||
? ffiTestFunctions
|
||||
.lookupFunction<NativeFunction1Uint64, Function1int>(
|
||||
'Function1Uint64',
|
||||
isLeaf: true,
|
||||
)
|
||||
: ffiTestFunctions
|
||||
.lookupFunction<NativeFunction1Uint64, Function1int>(
|
||||
'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<NativeFunction1Float, Function1double>(
|
||||
'Function1Float',
|
||||
isLeaf: true,
|
||||
)
|
||||
: ffiTestFunctions
|
||||
.lookupFunction<NativeFunction1Float, Function1double>(
|
||||
'Function1Float',
|
||||
isLeaf: false,
|
||||
),
|
||||
: f = isLeaf
|
||||
? ffiTestFunctions
|
||||
.lookupFunction<NativeFunction1Float, Function1double>(
|
||||
'Function1Float',
|
||||
isLeaf: true,
|
||||
)
|
||||
: ffiTestFunctions
|
||||
.lookupFunction<NativeFunction1Float, Function1double>(
|
||||
'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<NativeFunction2Float, Function2double>(
|
||||
'Function2Float',
|
||||
isLeaf: true,
|
||||
)
|
||||
: ffiTestFunctions
|
||||
.lookupFunction<NativeFunction2Float, Function2double>(
|
||||
'Function2Float',
|
||||
isLeaf: false,
|
||||
),
|
||||
: f = isLeaf
|
||||
? ffiTestFunctions
|
||||
.lookupFunction<NativeFunction2Float, Function2double>(
|
||||
'Function2Float',
|
||||
isLeaf: true,
|
||||
)
|
||||
: ffiTestFunctions
|
||||
.lookupFunction<NativeFunction2Float, Function2double>(
|
||||
'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<NativeFunction4Float, Function4double>(
|
||||
'Function4Float',
|
||||
isLeaf: true,
|
||||
)
|
||||
: ffiTestFunctions
|
||||
.lookupFunction<NativeFunction4Float, Function4double>(
|
||||
'Function4Float',
|
||||
isLeaf: false,
|
||||
),
|
||||
: f = isLeaf
|
||||
? ffiTestFunctions
|
||||
.lookupFunction<NativeFunction4Float, Function4double>(
|
||||
'Function4Float',
|
||||
isLeaf: true,
|
||||
)
|
||||
: ffiTestFunctions
|
||||
.lookupFunction<NativeFunction4Float, Function4double>(
|
||||
'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<NativeFunction10Float, Function10double>(
|
||||
'Function10Float',
|
||||
isLeaf: true,
|
||||
)
|
||||
: ffiTestFunctions
|
||||
.lookupFunction<NativeFunction10Float, Function10double>(
|
||||
'Function10Float',
|
||||
isLeaf: false,
|
||||
),
|
||||
: f = isLeaf
|
||||
? ffiTestFunctions
|
||||
.lookupFunction<NativeFunction10Float, Function10double>(
|
||||
'Function10Float',
|
||||
isLeaf: true,
|
||||
)
|
||||
: ffiTestFunctions
|
||||
.lookupFunction<NativeFunction10Float, Function10double>(
|
||||
'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<NativeFunction20Float, Function20double>(
|
||||
'Function20Float',
|
||||
isLeaf: true,
|
||||
)
|
||||
: ffiTestFunctions
|
||||
.lookupFunction<NativeFunction20Float, Function20double>(
|
||||
'Function20Float',
|
||||
isLeaf: false,
|
||||
),
|
||||
: f = isLeaf
|
||||
? ffiTestFunctions
|
||||
.lookupFunction<NativeFunction20Float, Function20double>(
|
||||
'Function20Float',
|
||||
isLeaf: true,
|
||||
)
|
||||
: ffiTestFunctions
|
||||
.lookupFunction<NativeFunction20Float, Function20double>(
|
||||
'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<NativeFunction1Double, Function1double>(
|
||||
'Function1Double',
|
||||
isLeaf: true,
|
||||
)
|
||||
: ffiTestFunctions
|
||||
.lookupFunction<NativeFunction1Double, Function1double>(
|
||||
'Function1Double',
|
||||
isLeaf: false,
|
||||
),
|
||||
: f = isLeaf
|
||||
? ffiTestFunctions
|
||||
.lookupFunction<NativeFunction1Double, Function1double>(
|
||||
'Function1Double',
|
||||
isLeaf: true,
|
||||
)
|
||||
: ffiTestFunctions
|
||||
.lookupFunction<NativeFunction1Double, Function1double>(
|
||||
'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<NativeFunction2Double, Function2double>(
|
||||
'Function2Double',
|
||||
isLeaf: true,
|
||||
)
|
||||
: ffiTestFunctions
|
||||
.lookupFunction<NativeFunction2Double, Function2double>(
|
||||
'Function2Double',
|
||||
isLeaf: false,
|
||||
),
|
||||
: f = isLeaf
|
||||
? ffiTestFunctions
|
||||
.lookupFunction<NativeFunction2Double, Function2double>(
|
||||
'Function2Double',
|
||||
isLeaf: true,
|
||||
)
|
||||
: ffiTestFunctions
|
||||
.lookupFunction<NativeFunction2Double, Function2double>(
|
||||
'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<NativeFunction4Double, Function4double>(
|
||||
'Function4Double',
|
||||
isLeaf: true,
|
||||
)
|
||||
: ffiTestFunctions
|
||||
.lookupFunction<NativeFunction4Double, Function4double>(
|
||||
'Function4Double',
|
||||
isLeaf: false,
|
||||
),
|
||||
: f = isLeaf
|
||||
? ffiTestFunctions
|
||||
.lookupFunction<NativeFunction4Double, Function4double>(
|
||||
'Function4Double',
|
||||
isLeaf: true,
|
||||
)
|
||||
: ffiTestFunctions
|
||||
.lookupFunction<NativeFunction4Double, Function4double>(
|
||||
'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<NativeFunction10Double, Function10double>(
|
||||
'Function10Double',
|
||||
isLeaf: true,
|
||||
)
|
||||
: ffiTestFunctions
|
||||
.lookupFunction<NativeFunction10Double, Function10double>(
|
||||
'Function10Double',
|
||||
isLeaf: false,
|
||||
),
|
||||
: f = isLeaf
|
||||
? ffiTestFunctions
|
||||
.lookupFunction<NativeFunction10Double, Function10double>(
|
||||
'Function10Double',
|
||||
isLeaf: true,
|
||||
)
|
||||
: ffiTestFunctions
|
||||
.lookupFunction<NativeFunction10Double, Function10double>(
|
||||
'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<NativeFunction20Double, Function20double>(
|
||||
'Function20Double',
|
||||
isLeaf: true,
|
||||
)
|
||||
: ffiTestFunctions
|
||||
.lookupFunction<NativeFunction20Double, Function20double>(
|
||||
'Function20Double',
|
||||
isLeaf: false,
|
||||
),
|
||||
: f = isLeaf
|
||||
? ffiTestFunctions
|
||||
.lookupFunction<NativeFunction20Double, Function20double>(
|
||||
'Function20Double',
|
||||
isLeaf: true,
|
||||
)
|
||||
: ffiTestFunctions
|
||||
.lookupFunction<NativeFunction20Double, Function20double>(
|
||||
'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<Uint8> 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<Uint8> 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<Uint8> 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<Uint8> 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<Uint8> p1 = nullptr;
|
||||
|
||||
@@ -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<Pointer<Void> Function(Pointer<Char>, Int)>()
|
||||
external Pointer<Void> dlopen(Pointer<Char> file, int mode);
|
||||
|
||||
@@ -166,10 +166,9 @@ void generateBenchmarkDouble(StringBuffer buffer, List<String> 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<String> 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';
|
||||
|
||||
@@ -75,10 +75,11 @@ abstract class FfiCallbackBenchmark {
|
||||
final class Uint8x1 extends FfiCallbackBenchmark {
|
||||
Uint8x1() : super('FfiCallbackBenchmark.Uint8x1');
|
||||
|
||||
final function = ffiTestFunctions.lookupFunction<
|
||||
Void Function(Pointer<NativeFunction<Void Function(Uint8)>>, Uint32),
|
||||
void Function(Pointer<NativeFunction<Void Function(Uint8)>>, int)
|
||||
>('CallFunction1Uint8');
|
||||
final function = ffiTestFunctions
|
||||
.lookupFunction<
|
||||
Void Function(Pointer<NativeFunction<Void Function(Uint8)>>, Uint32),
|
||||
void Function(Pointer<NativeFunction<Void Function(Uint8)>>, 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<String> args) {
|
||||
final results = argParser.parse(args);
|
||||
|
||||
@@ -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<String> args) {
|
||||
final results = argParser.parse(args);
|
||||
|
||||
@@ -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<Uint8> a0;
|
||||
|
||||
@@ -28,8 +28,11 @@ main() async {
|
||||
print("Dart: Setup.");
|
||||
Expect.isTrue(NativeApi.majorVersion == 2);
|
||||
Expect.isTrue(NativeApi.minorVersion >= 2);
|
||||
final initializeApi = dl.lookupFunction<IntPtr Function(Pointer<Void>),
|
||||
int Function(Pointer<Void>)>("InitDartApiDL");
|
||||
final initializeApi = dl
|
||||
.lookupFunction<
|
||||
IntPtr Function(Pointer<Void>),
|
||||
int Function(Pointer<Void>)
|
||||
>("InitDartApiDL");
|
||||
Expect.isTrue(initializeApi(NativeApi.initializeApiDLData) == 0);
|
||||
|
||||
final interactiveCppRequests = ReceivePort()..listen(requestExecuteCallback);
|
||||
@@ -82,28 +85,42 @@ final callback2FP = Pointer.fromFunction<Void Function(IntPtr)>(callback2);
|
||||
|
||||
final dl = dlopenPlatformSpecific("ffi_test_functions");
|
||||
|
||||
final registerCallback1 = dl.lookupFunction<
|
||||
Void Function(Int64 sendPort,
|
||||
Pointer<NativeFunction<IntPtr Function(IntPtr)>> functionPointer),
|
||||
void Function(int sendPort,
|
||||
Pointer<NativeFunction<IntPtr Function(IntPtr)>> functionPointer)>(
|
||||
'RegisterMyCallbackBlocking');
|
||||
final registerCallback1 = dl
|
||||
.lookupFunction<
|
||||
Void Function(
|
||||
Int64 sendPort,
|
||||
Pointer<NativeFunction<IntPtr Function(IntPtr)>> functionPointer,
|
||||
),
|
||||
void Function(
|
||||
int sendPort,
|
||||
Pointer<NativeFunction<IntPtr Function(IntPtr)>> functionPointer,
|
||||
)
|
||||
>('RegisterMyCallbackBlocking');
|
||||
|
||||
final registerCallback2 = dl.lookupFunction<
|
||||
Void Function(Int64 sendPort,
|
||||
Pointer<NativeFunction<Void Function(IntPtr)>> functionPointer),
|
||||
void Function(int sendPort,
|
||||
Pointer<NativeFunction<Void Function(IntPtr)>> functionPointer)>(
|
||||
'RegisterMyCallbackNonBlocking');
|
||||
final registerCallback2 = dl
|
||||
.lookupFunction<
|
||||
Void Function(
|
||||
Int64 sendPort,
|
||||
Pointer<NativeFunction<Void Function(IntPtr)>> functionPointer,
|
||||
),
|
||||
void Function(
|
||||
int sendPort,
|
||||
Pointer<NativeFunction<Void Function(IntPtr)>> functionPointer,
|
||||
)
|
||||
>('RegisterMyCallbackNonBlocking');
|
||||
|
||||
final startWorkSimulator =
|
||||
dl.lookupFunction<Void Function(), void Function()>('StartWorkSimulator');
|
||||
final startWorkSimulator = dl.lookupFunction<Void Function(), void Function()>(
|
||||
'StartWorkSimulator',
|
||||
);
|
||||
|
||||
final stopWorkSimulator =
|
||||
dl.lookupFunction<Void Function(), void Function()>('StopWorkSimulator');
|
||||
final stopWorkSimulator = dl.lookupFunction<Void Function(), void Function()>(
|
||||
'StopWorkSimulator',
|
||||
);
|
||||
|
||||
final executeCallback = dl.lookupFunction<Void Function(Pointer<Work>),
|
||||
void Function(Pointer<Work>)>('ExecuteCallback');
|
||||
final executeCallback = dl
|
||||
.lookupFunction<Void Function(Pointer<Work>), void Function(Pointer<Work>)>(
|
||||
'ExecuteCallback',
|
||||
);
|
||||
|
||||
final class Work extends Opaque {}
|
||||
|
||||
|
||||
@@ -37,8 +37,11 @@ main() async {
|
||||
print("Dart: Setup.");
|
||||
Expect.isTrue(NativeApi.majorVersion == 2);
|
||||
Expect.isTrue(NativeApi.minorVersion >= 2);
|
||||
final initializeApi = dl.lookupFunction<IntPtr Function(Pointer<Void>),
|
||||
int Function(Pointer<Void>)>("InitDartApiDL");
|
||||
final initializeApi = dl
|
||||
.lookupFunction<
|
||||
IntPtr Function(Pointer<Void>),
|
||||
int Function(Pointer<Void>)
|
||||
>("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<Void Function(Int64 sendPort),
|
||||
void Function(int sendPort)>('RegisterSendPort');
|
||||
final registerSendPort = dl
|
||||
.lookupFunction<Void Function(Int64 sendPort), void Function(int sendPort)>(
|
||||
'RegisterSendPort',
|
||||
);
|
||||
|
||||
final startWorkSimulator2 =
|
||||
dl.lookupFunction<Void Function(), void Function()>('StartWorkSimulator2');
|
||||
final startWorkSimulator2 = dl.lookupFunction<Void Function(), void Function()>(
|
||||
'StartWorkSimulator2',
|
||||
);
|
||||
|
||||
final stopWorkSimulator2 =
|
||||
dl.lookupFunction<Void Function(), void Function()>('StopWorkSimulator2');
|
||||
final stopWorkSimulator2 = dl.lookupFunction<Void Function(), void Function()>(
|
||||
'StopWorkSimulator2',
|
||||
);
|
||||
|
||||
Future asyncSleep(int ms) {
|
||||
return new Future.delayed(Duration(milliseconds: ms), () => true);
|
||||
|
||||
@@ -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<SomeResource> 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<SomeResource> Function(),
|
||||
Pointer<SomeResource> Function()>("AllocateResource");
|
||||
final allocateResource = ffiTestDynamicLibrary
|
||||
.lookupFunction<
|
||||
Pointer<SomeResource> Function(),
|
||||
Pointer<SomeResource> Function()
|
||||
>("AllocateResource");
|
||||
|
||||
final useResource = ffiTestDynamicLibrary.lookupFunction<
|
||||
Void Function(Pointer<SomeResource>),
|
||||
void Function(Pointer<SomeResource>)>("UseResource");
|
||||
final useResource = ffiTestDynamicLibrary
|
||||
.lookupFunction<
|
||||
Void Function(Pointer<SomeResource>),
|
||||
void Function(Pointer<SomeResource>)
|
||||
>("UseResource");
|
||||
|
||||
final releaseResource = ffiTestDynamicLibrary.lookupFunction<
|
||||
Void Function(Pointer<SomeResource>),
|
||||
void Function(Pointer<SomeResource>)>("ReleaseResource");
|
||||
final releaseResource = ffiTestDynamicLibrary
|
||||
.lookupFunction<
|
||||
Void Function(Pointer<SomeResource>),
|
||||
void Function(Pointer<SomeResource>)
|
||||
>("ReleaseResource");
|
||||
|
||||
/// Represents some opaque resource being managed by a library.
|
||||
final class SomeResource extends Opaque {}
|
||||
|
||||
@@ -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<Void>, Pointer<Void>, IntPtr),
|
||||
void Function(Pointer<Void>, Pointer<Void>, int)>("MemMove");
|
||||
final MemMove = ffiTestDynamicLibrary
|
||||
.lookupFunction<
|
||||
Void Function(Pointer<Void>, Pointer<Void>, IntPtr),
|
||||
void Function(Pointer<Void>, Pointer<Void>, 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<SomeResource> Function(),
|
||||
Pointer<SomeResource> Function()>("AllocateResource");
|
||||
final allocateResource = ffiTestDynamicLibrary
|
||||
.lookupFunction<
|
||||
Pointer<SomeResource> Function(),
|
||||
Pointer<SomeResource> Function()
|
||||
>("AllocateResource");
|
||||
|
||||
final useResource = ffiTestDynamicLibrary.lookupFunction<
|
||||
Void Function(Pointer<SomeResource>),
|
||||
void Function(Pointer<SomeResource>)>("UseResource");
|
||||
final useResource = ffiTestDynamicLibrary
|
||||
.lookupFunction<
|
||||
Void Function(Pointer<SomeResource>),
|
||||
void Function(Pointer<SomeResource>)
|
||||
>("UseResource");
|
||||
|
||||
final releaseResource = ffiTestDynamicLibrary.lookupFunction<
|
||||
Void Function(Pointer<SomeResource>),
|
||||
void Function(Pointer<SomeResource>)>("ReleaseResource");
|
||||
final releaseResource = ffiTestDynamicLibrary
|
||||
.lookupFunction<
|
||||
Void Function(Pointer<SomeResource>),
|
||||
void Function(Pointer<SomeResource>)
|
||||
>("ReleaseResource");
|
||||
|
||||
// Using an FFI call to release a resource.
|
||||
using((Arena arena) {
|
||||
|
||||
@@ -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<Void>, Pointer<Void>, IntPtr),
|
||||
void Function(Pointer<Void>, Pointer<Void>, int)>("MemMove");
|
||||
final MemMove = ffiTestDynamicLibrary
|
||||
.lookupFunction<
|
||||
Void Function(Pointer<Void>, Pointer<Void>, IntPtr),
|
||||
void Function(Pointer<Void>, Pointer<Void>, 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<SomeResource> Function(),
|
||||
Pointer<SomeResource> Function()>("AllocateResource");
|
||||
final allocateResource = ffiTestDynamicLibrary
|
||||
.lookupFunction<
|
||||
Pointer<SomeResource> Function(),
|
||||
Pointer<SomeResource> Function()
|
||||
>("AllocateResource");
|
||||
|
||||
final useResource = ffiTestDynamicLibrary.lookupFunction<
|
||||
Void Function(Pointer<SomeResource>),
|
||||
void Function(Pointer<SomeResource>)>("UseResource");
|
||||
final useResource = ffiTestDynamicLibrary
|
||||
.lookupFunction<
|
||||
Void Function(Pointer<SomeResource>),
|
||||
void Function(Pointer<SomeResource>)
|
||||
>("UseResource");
|
||||
|
||||
final releaseResource = ffiTestDynamicLibrary.lookupFunction<
|
||||
Void Function(Pointer<SomeResource>),
|
||||
void Function(Pointer<SomeResource>)>("ReleaseResource");
|
||||
final releaseResource = ffiTestDynamicLibrary
|
||||
.lookupFunction<
|
||||
Void Function(Pointer<SomeResource>),
|
||||
void Function(Pointer<SomeResource>)
|
||||
>("ReleaseResource");
|
||||
|
||||
// Using an FFI call to release a resource.
|
||||
withZoneArena(() {
|
||||
|
||||
@@ -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<Void>, Pointer<Void>, IntPtr),
|
||||
void Function(Pointer<Void>, Pointer<Void>, int)>("MemMove");
|
||||
final memMove = ffiTestDynamicLibrary
|
||||
.lookupFunction<
|
||||
Void Function(Pointer<Void>, Pointer<Void>, IntPtr),
|
||||
void Function(Pointer<Void>, Pointer<Void>, int)
|
||||
>("MemMove");
|
||||
|
||||
// To ensure resources are freed, call free manually.
|
||||
//
|
||||
|
||||
@@ -46,7 +46,8 @@ extension Utf8Helpers on Pointer<Utf8> {
|
||||
/// Returns a Dart string containing the decoded code points.
|
||||
String contents() {
|
||||
final int length = strlen;
|
||||
return utf8.decode(Uint8List.view(
|
||||
this.cast<Uint8>().asTypedList(length).buffer, 0, length));
|
||||
return utf8.decode(
|
||||
Uint8List.view(this.cast<Uint8>().asTypedList(length).buffer, 0, length),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<Int64> Function(Pointer<Int64>);
|
||||
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<NativeBinaryOp, BinaryOp>("SumPlus42");
|
||||
BinaryOp sumPlus42 = ffiTestFunctions
|
||||
.lookupFunction<NativeBinaryOp, BinaryOp>("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<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,
|
||||
);
|
||||
print(result);
|
||||
print(result.runtimeType);
|
||||
}
|
||||
@@ -184,8 +245,28 @@ main() {
|
||||
// Function with many arguments, ints and doubles mixed.
|
||||
VigesimalOp sumManyNumbers = ffiTestFunctions
|
||||
.lookupFunction<NativeVigesimalOp, VigesimalOp>("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<Int64PointerUnOp, Int64PointerUnOp>(
|
||||
"NullableInt64ElemAt1");
|
||||
Int64PointerUnOp nullableInt64ElemAt1 = ffiTestFunctions
|
||||
.lookupFunction<Int64PointerUnOp, Int64PointerUnOp>(
|
||||
"NullableInt64ElemAt1",
|
||||
);
|
||||
|
||||
Pointer<Int64> result = nullableInt64ElemAt1(nullptr);
|
||||
print(result);
|
||||
|
||||
@@ -11,19 +11,22 @@ import 'dylib_utils.dart';
|
||||
|
||||
typedef NativeCoordinateOp = Pointer<Coordinate> Function(Pointer<Coordinate>);
|
||||
|
||||
typedef CoordinateTrice = Pointer<Coordinate> Function(
|
||||
Pointer<NativeFunction<NativeCoordinateOp>>, Pointer<Coordinate>);
|
||||
typedef CoordinateTrice =
|
||||
Pointer<Coordinate> Function(
|
||||
Pointer<NativeFunction<NativeCoordinateOp>>,
|
||||
Pointer<Coordinate>,
|
||||
);
|
||||
|
||||
typedef BinaryOp = int Function(int, int);
|
||||
typedef NativeIntptrBinOp = IntPtr Function(IntPtr, IntPtr);
|
||||
typedef NativeIntptrBinOpLookup = Pointer<NativeFunction<NativeIntptrBinOp>>
|
||||
Function();
|
||||
typedef NativeIntptrBinOpLookup =
|
||||
Pointer<NativeFunction<NativeIntptrBinOp>> Function();
|
||||
|
||||
typedef NativeApplyTo42And74Type = IntPtr Function(
|
||||
Pointer<NativeFunction<NativeIntptrBinOp>>);
|
||||
typedef NativeApplyTo42And74Type =
|
||||
IntPtr Function(Pointer<NativeFunction<NativeIntptrBinOp>>);
|
||||
|
||||
typedef ApplyTo42And74Type = int Function(
|
||||
Pointer<NativeFunction<NativeIntptrBinOp>>);
|
||||
typedef ApplyTo42And74Type =
|
||||
int Function(Pointer<NativeFunction<NativeIntptrBinOp>>);
|
||||
|
||||
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<NativeFunction<NativeCoordinateOp>> transposeCoordinatePointer =
|
||||
ffiTestFunctions.lookup("TransposeCoordinate");
|
||||
Pointer<NativeFunction<CoordinateTrice>> p2 =
|
||||
ffiTestFunctions.lookup("CoordinateUnOpTrice");
|
||||
Pointer<NativeFunction<CoordinateTrice>> p2 = ffiTestFunctions.lookup(
|
||||
"CoordinateUnOpTrice",
|
||||
);
|
||||
CoordinateTrice coordinateUnOpTrice = p2.asFunction();
|
||||
final c1 = calloc<Coordinate>()
|
||||
..ref.x = 10.0
|
||||
@@ -58,8 +63,8 @@ main() {
|
||||
|
||||
{
|
||||
// Return a c pointer to a c function from a c function.
|
||||
Pointer<NativeFunction<NativeIntptrBinOpLookup>> p14 =
|
||||
ffiTestFunctions.lookup("IntptrAdditionClosure");
|
||||
Pointer<NativeFunction<NativeIntptrBinOpLookup>> p14 = ffiTestFunctions
|
||||
.lookup("IntptrAdditionClosure");
|
||||
NativeIntptrBinOpLookup intptrAdditionClosure = p14.asFunction();
|
||||
|
||||
Pointer<NativeFunction<NativeIntptrBinOp>> intptrAdditionPointer =
|
||||
@@ -69,12 +74,14 @@ main() {
|
||||
}
|
||||
|
||||
{
|
||||
Pointer<NativeFunction<NativeIntptrBinOp>> pointer =
|
||||
Pointer.fromFunction(myPlus, 0);
|
||||
Pointer<NativeFunction<NativeIntptrBinOp>> pointer = Pointer.fromFunction(
|
||||
myPlus,
|
||||
0,
|
||||
);
|
||||
print(pointer);
|
||||
|
||||
Pointer<NativeFunction<NativeApplyTo42And74Type>> p17 =
|
||||
ffiTestFunctions.lookup("ApplyTo42And74");
|
||||
Pointer<NativeFunction<NativeApplyTo42And74Type>> p17 = ffiTestFunctions
|
||||
.lookup("ApplyTo42And74");
|
||||
ApplyTo42And74Type applyTo42And74 = p17.asFunction();
|
||||
|
||||
int result = applyTo42And74(pointer);
|
||||
|
||||
@@ -34,9 +34,10 @@ void main() {
|
||||
|
||||
final testLibrary = dlopenPlatformSpecific("ffi_test_functions");
|
||||
|
||||
final registerClosureCallback =
|
||||
testLibrary.lookupFunction<Void Function(Handle), void Function(Object)>(
|
||||
"RegisterClosureCallback");
|
||||
final registerClosureCallback = testLibrary
|
||||
.lookupFunction<Void Function(Handle), void Function(Object)>(
|
||||
"RegisterClosureCallback",
|
||||
);
|
||||
|
||||
final invokeClosureCallback = testLibrary
|
||||
.lookupFunction<Void Function(), void Function()>("InvokeClosureCallback");
|
||||
@@ -49,19 +50,23 @@ void doClosureCallback(Object callback) {
|
||||
callback_as_function();
|
||||
}
|
||||
|
||||
final closureCallbackPointer =
|
||||
Pointer.fromFunction<Void Function(Handle)>(doClosureCallback);
|
||||
final closureCallbackPointer = Pointer.fromFunction<Void Function(Handle)>(
|
||||
doClosureCallback,
|
||||
);
|
||||
|
||||
void doDynamicLinking() {
|
||||
Expect.isTrue(NativeApi.majorVersion == 2);
|
||||
Expect.isTrue(NativeApi.minorVersion >= 2);
|
||||
final initializeApi = testLibrary.lookupFunction<
|
||||
IntPtr Function(Pointer<Void>),
|
||||
int Function(Pointer<Void>)>("InitDartApiDL");
|
||||
final initializeApi = testLibrary
|
||||
.lookupFunction<
|
||||
IntPtr Function(Pointer<Void>),
|
||||
int Function(Pointer<Void>)
|
||||
>("InitDartApiDL");
|
||||
Expect.isTrue(initializeApi(NativeApi.initializeApiDLData) == 0);
|
||||
|
||||
final registerClosureCallback = testLibrary.lookupFunction<
|
||||
Void Function(Pointer),
|
||||
void Function(Pointer)>("RegisterClosureCallbackFP");
|
||||
final registerClosureCallback = testLibrary
|
||||
.lookupFunction<Void Function(Pointer), void Function(Pointer)>(
|
||||
"RegisterClosureCallbackFP",
|
||||
);
|
||||
registerClosureCallback(closureCallbackPointer);
|
||||
}
|
||||
|
||||
@@ -14,13 +14,15 @@ typedef NativeCoordinateOp = Pointer<Coordinate> Function(Pointer<Coordinate>);
|
||||
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<NativeFunction<NativeCoordinateOp>> p1 =
|
||||
ffiTestFunctions.lookup("TransposeCoordinate");
|
||||
Pointer<NativeFunction<NativeCoordinateOp>> p1 = ffiTestFunctions.lookup(
|
||||
"TransposeCoordinate",
|
||||
);
|
||||
NativeCoordinateOp f1 = p1.asFunction();
|
||||
|
||||
final c1 = calloc<Coordinate>()
|
||||
@@ -45,8 +47,9 @@ main() {
|
||||
|
||||
{
|
||||
// Pass an array of structs to a c function.
|
||||
Pointer<NativeFunction<NativeCoordinateOp>> p1 =
|
||||
ffiTestFunctions.lookup("CoordinateElemAt1");
|
||||
Pointer<NativeFunction<NativeCoordinateOp>> p1 = ffiTestFunctions.lookup(
|
||||
"CoordinateElemAt1",
|
||||
);
|
||||
NativeCoordinateOp f1 = p1.asFunction();
|
||||
|
||||
Pointer<Coordinate> c1 = calloc<Coordinate>(3);
|
||||
|
||||
Reference in New Issue
Block a user