[vm/ffi] Migrate tests/ffi(_2) to CallocAllocator

This CL does not yet roll `package:ffi` to use `Allocator`, because that
breaks the checked in Dart in Flutter in g3. Instead, this uses the copy
of `_CallocAllocator` from `package:ffi` in `calloc.dart`.

New API landed in: https://dart-review.googlesource.com/c/sdk/+/177705

Issue: https://github.com/dart-lang/sdk/issues/44621
Issue: https://github.com/dart-lang/sdk/issues/38721

Change-Id: I10e53a363cd87c4c11e7042989e6957b82ae2a09
Cq-Include-Trybots: luci.dart.try:vm-kernel-win-debug-x64-try,vm-kernel-linux-debug-x64-try,vm-kernel-mac-debug-x64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/178992
Reviewed-by: Aske Simon Christensen <askesc@google.com>
Commit-Queue: Daco Harkes <dacoharkes@google.com>
This commit is contained in:
Daco Harkes
2021-01-14 12:36:27 +00:00
committed by commit-bot@chromium.org
parent c36028b002
commit 0bfbdfad78
45 changed files with 2060 additions and 2103 deletions
+33 -32
View File
@@ -13,6 +13,7 @@ import 'dart:ffi';
import "package:ffi/ffi.dart";
import "package:expect/expect.dart";
import 'calloc.dart';
import 'ffi_test_helpers.dart';
void main() {
@@ -35,28 +36,28 @@ void main() {
}
void testNonAlias() {
final source = allocate<Int64>();
final source = calloc<Int64>();
source.value = 42;
final int a = source.value;
source.value = 1984;
// alias.value should be re-executed, as we wrote to alias.
Expect.notEquals(a, source.value);
free(source);
calloc.free(source);
}
void testAliasCast() {
final source = allocate<Int64>();
final source = calloc<Int64>();
final alias = source.cast<Int8>().cast<Int64>();
source.value = 42;
final int a = source.value;
alias.value = 1984;
// source.value should be re-executed, we wrote alias which aliases source.
Expect.notEquals(a, source.value);
free(source);
calloc.free(source);
}
void testAliasCast2() {
final source = allocate<Int64>();
final source = calloc<Int64>();
final alias = source.cast<Int16>().cast<Int64>();
final alias2 = source.cast<Int8>().cast<Int64>();
alias.value = 42;
@@ -64,22 +65,22 @@ void testAliasCast2() {
alias2.value = 1984;
// alias.value should be re-executed, we wrote alias2 which aliases alias.
Expect.notEquals(a, alias.value);
free(source);
calloc.free(source);
}
void testAliasOffsetBy() {
final source = allocate<Int64>(count: 2);
final source = calloc<Int64>(2);
final alias = source.offsetBy(8).offsetBy(-8);
source.value = 42;
final int a = source.value;
alias.value = 1984;
// source.value should be re-executed, we wrote alias which aliases source.
Expect.notEquals(a, source.value);
free(source);
calloc.free(source);
}
void testAliasOffsetBy2() {
final source = allocate<Int64>(count: 3);
final source = calloc<Int64>(3);
final alias = source.offsetBy(16).offsetBy(-16);
final alias2 = source.offsetBy(8).offsetBy(-8);
alias.value = 42;
@@ -87,22 +88,22 @@ void testAliasOffsetBy2() {
alias2.value = 1984;
// alias.value should be re-executed, we wrote alias2 which aliases alias.
Expect.notEquals(a, alias.value);
free(source);
calloc.free(source);
}
void testAliasElementAt() {
final source = allocate<Int64>(count: 2);
final source = calloc<Int64>(2);
final alias = source.elementAt(1).elementAt(-1);
source.value = 42;
final int a = source.value;
alias.value = 1984;
// source.value should be re-executed, we wrote alias which aliases source.
Expect.notEquals(a, source.value);
free(source);
calloc.free(source);
}
void testAliasElementAt2() {
final source = allocate<Int64>(count: 3);
final source = calloc<Int64>(3);
final alias = source.elementAt(2).elementAt(-2);
final alias2 = source.elementAt(1).elementAt(-1);
alias.value = 42;
@@ -110,22 +111,22 @@ void testAliasElementAt2() {
alias2.value = 1984;
// alias.value should be re-executed, we wrote alias2 which aliases alias.
Expect.notEquals(a, alias.value);
free(source);
calloc.free(source);
}
void testAliasFromAddress() {
final source = allocate<Int64>();
final source = calloc<Int64>();
final alias = Pointer<Int64>.fromAddress(source.address);
source.value = 42;
final int a = source.value;
alias.value = 1984;
// source.value should be re-executed, we wrote alias which aliases source.
Expect.notEquals(a, source.value);
free(source);
calloc.free(source);
}
void testAliasFromAddress2() {
final source = allocate<Int64>();
final source = calloc<Int64>();
final alias = Pointer<Int64>.fromAddress(source.address);
final alias2 = Pointer<Int64>.fromAddress(source.address);
alias.value = 42;
@@ -133,12 +134,12 @@ void testAliasFromAddress2() {
alias2.value = 1984;
// alias.value should be re-executed, we wrote alias2 which aliases alias.
Expect.notEquals(a, alias.value);
free(source);
calloc.free(source);
}
void testAliasFromAddressViaMemory() {
final helper = allocate<IntPtr>();
final source = allocate<Int64>();
final helper = calloc<IntPtr>();
final source = calloc<Int64>();
helper.value = source.address;
final alias = Pointer<Int64>.fromAddress(helper.value);
source.value = 42;
@@ -146,13 +147,13 @@ void testAliasFromAddressViaMemory() {
alias.value = 1984;
// source.value should be re-executed, we wrote alias which aliases source.
Expect.notEquals(a, source.value);
free(helper);
free(source);
calloc.free(helper);
calloc.free(source);
}
void testAliasFromAddressViaMemory2() {
final helper = allocate<IntPtr>();
final source = allocate<Int64>();
final helper = calloc<IntPtr>();
final source = calloc<Int64>();
helper.value = source.address;
final alias = Pointer<Int64>.fromAddress(helper.value);
final alias2 = Pointer<Int64>.fromAddress(helper.value);
@@ -161,8 +162,8 @@ void testAliasFromAddressViaMemory2() {
alias2.value = 1984;
// alias.value should be re-executed, we wrote alias2 which aliases alias.
Expect.notEquals(a, alias.value);
free(helper);
free(source);
calloc.free(helper);
calloc.free(source);
}
typedef NativeQuadOpSigned = Int64 Function(Int8, Int16, Int32, Int64);
@@ -172,7 +173,7 @@ QuadOp intComputation = ffiTestFunctions
.lookupFunction<NativeQuadOpSigned, QuadOp>("IntComputation");
void testAliasFromAddressViaNativeFunction() {
final source = allocate<Int64>();
final source = calloc<Int64>();
final alias =
Pointer<Int64>.fromAddress(intComputation(0, 0, 0, source.address));
source.value = 42;
@@ -180,11 +181,11 @@ void testAliasFromAddressViaNativeFunction() {
alias.value = 1984;
// source.value should be re-executed, we wrote alias which aliases source.
Expect.notEquals(a, source.value);
free(source);
calloc.free(source);
}
void testAliasFromAddressViaNativeFunction2() {
final source = allocate<Int64>();
final source = calloc<Int64>();
final alias =
Pointer<Int64>.fromAddress(intComputation(0, 0, 0, source.address));
final alias2 =
@@ -194,7 +195,7 @@ void testAliasFromAddressViaNativeFunction2() {
alias2.value = 1984;
// alias.value should be re-executed, we wrote alias2 which aliases alias.
Expect.notEquals(a, alias.value);
free(source);
calloc.free(source);
}
@pragma('vm:never-inline')
@@ -202,11 +203,11 @@ Pointer<Int8> makeDerived(Pointer<Int64> source) =>
source.offsetBy(7).cast<Int8>();
testPartialOverlap() {
final source = allocate<Int64>(count: 2);
final source = calloc<Int64>(2);
final derived = makeDerived(source);
source.value = 0x1122334455667788;
final int value = source.value;
derived.value = 0xaa;
Expect.notEquals(value, source.value);
free(source);
calloc.free(source);
}
+1 -1
View File
@@ -54,7 +54,7 @@ class _CallocAllocator implements Allocator {
/// Allocates [byteCount] bytes of zero-initialized of memory on the native
/// heap.
///
/// For POSIX-based systems, this uses `malloc`. On Windows, it uses
/// For POSIX-based systems, this uses `calloc`. On Windows, it uses
/// `HeapAlloc` against the default public heap.
///
/// Throws an [ArgumentError] if the number of bytes or alignment cannot be
+3 -2
View File
@@ -17,8 +17,9 @@ class Coordinate extends Struct {
external Pointer<Coordinate> next;
factory Coordinate.allocate(double x, double y, Pointer<Coordinate> next) {
return allocate<Coordinate>().ref
factory Coordinate.allocate(
Allocator allocator, double x, double y, Pointer<Coordinate> next) {
return allocator<Coordinate>().ref
..x = x
..y = y
..next = next;
+3 -2
View File
@@ -20,8 +20,9 @@ class Coordinate extends Struct {
external Pointer<Coordinate> get next;
external set next(Pointer<Coordinate> v);
factory Coordinate.allocate(double x, double y, Pointer<Coordinate> next) {
return allocate<Coordinate>().ref
factory Coordinate.allocate(
Allocator allocator, double x, double y, Pointer<Coordinate> next) {
return allocator<Coordinate>().ref
..x = x
..y = y
..next = next;
+6 -4
View File
@@ -4,7 +4,7 @@
//
// Dart test program for testing dart:ffi primitive data pointers.
//
// These mallocs trigger an asan alarm, so these tests are in a separate file
// These callocs trigger an asan alarm, so these tests are in a separate file
// which is excluded in asan mode.
import 'dart:ffi';
@@ -12,6 +12,8 @@ import 'dart:ffi';
import "package:ffi/ffi.dart";
import "package:expect/expect.dart";
import 'calloc.dart';
void main() {
testPointerAllocateTooLarge();
testPointerAllocateNegative();
@@ -20,16 +22,16 @@ void main() {
void testPointerAllocateTooLarge() {
// Try to allocate something that doesn't fit in 64 bit address space.
int maxInt = 9223372036854775807; // 2^63 - 1
Expect.throws(() => allocate<Int64>(count: maxInt));
Expect.throws(() => calloc<Int64>(maxInt));
// Try to allocate almost the full 64 bit address space.
int maxInt1_8 = 1152921504606846975; // 2^60 -1
Expect.throws(() => allocate<Int64>(count: maxInt1_8));
Expect.throws(() => calloc<Int64>(maxInt1_8));
}
void testPointerAllocateNegative() {
// Passing in -1 will be converted into an unsigned integer. So, it will try
// to allocate SIZE_MAX - 1 + 1 bytes. This will fail as it is the max amount
// of addressable memory on the system.
Expect.throws(() => allocate<Int8>(count: -1));
Expect.throws(() => calloc<Int8>(-1));
}
+70 -69
View File
@@ -11,6 +11,7 @@ import 'dart:ffi';
import "package:expect/expect.dart";
import "package:ffi/ffi.dart";
import 'calloc.dart';
import 'ffi_test_helpers.dart';
void main() {
@@ -56,66 +57,66 @@ void main() {
}
void testPointerBasic() {
Pointer<Int64> p = allocate();
Pointer<Int64> p = calloc();
p.value = 42;
Expect.equals(42, p.value);
free(p);
calloc.free(p);
}
void testPointerFromPointer() {
Pointer<Int64> p = allocate();
Pointer<Int64> p = calloc();
p.value = 1337;
int ptr = p.address;
Pointer<Int64> p2 = Pointer.fromAddress(ptr);
Expect.equals(1337, p2.value);
free(p);
calloc.free(p);
}
void testPointerPointerArithmetic() {
Pointer<Int64> p = allocate(count: 2);
Pointer<Int64> p = calloc(2);
Pointer<Int64> p2 = p.elementAt(1);
p2.value = 100;
Pointer<Int64> p3 = p.offsetBy(8);
Expect.equals(100, p3.value);
free(p);
calloc.free(p);
}
void testPointerPointerArithmeticSizes() {
Pointer<Int64> p = allocate(count: 2);
Pointer<Int64> p = calloc(2);
Pointer<Int64> p2 = p.elementAt(1);
int addr = p.address;
Expect.equals(addr + 8, p2.address);
free(p);
calloc.free(p);
Pointer<Int32> p3 = allocate(count: 2);
Pointer<Int32> p3 = calloc(2);
Pointer<Int32> p4 = p3.elementAt(1);
addr = p3.address;
Expect.equals(addr + 4, p4.address);
free(p3);
calloc.free(p3);
}
void testPointerAllocateZero() {
// > If size is 0, either a null pointer or a unique pointer that can be
// > successfully passed to free() shall be returned.
// http://pubs.opengroup.org/onlinepubs/009695399/functions/malloc.html
// > successfully passed to calloc.free() shall be returned.
// http://pubs.opengroup.org/onlinepubs/009695399/functions/calloc.html
//
// Null pointer throws a Dart exception.
bool returnedNullPointer = false;
Pointer<Int8> p = nullptr;
try {
p = allocate<Int8>(count: 0);
p = calloc<Int8>(0);
} on Exception {
returnedNullPointer = true;
}
if (!returnedNullPointer) {
free(p);
calloc.free(p);
}
}
void testPointerCast() {
Pointer<Int64> p = allocate();
Pointer<Int64> p = calloc();
p.cast<Int32>(); // gets the correct type args back
free(p);
calloc.free(p);
}
void testCastGeneric() {
@@ -123,9 +124,9 @@ void testCastGeneric() {
return p.cast();
}
Pointer<Int16> p = allocate();
Pointer<Int16> p = calloc();
Pointer<Int64> p2 = generic(p);
free(p);
calloc.free(p);
}
void testCastGeneric2() {
@@ -133,41 +134,41 @@ void testCastGeneric2() {
return p.cast();
}
Pointer<Int16> p = allocate();
Pointer<Int16> p = calloc();
Pointer<Int64> p2 = generic(p);
free(p);
calloc.free(p);
}
void testCastNativeType() {
Pointer<Int64> p = allocate();
Pointer<Int64> p = calloc();
p.cast<Pointer>();
free(p);
calloc.free(p);
}
void testCondensedNumbersInt8() {
Pointer<Int8> p = allocate(count: 8);
Pointer<Int8> p = calloc(8);
for (var i in [0, 1, 2, 3, 4, 5, 6, 7]) {
p[i] = i * 3;
}
for (var i in [0, 1, 2, 3, 4, 5, 6, 7]) {
Expect.equals(i * 3, p[i]);
}
free(p);
calloc.free(p);
}
void testCondensedNumbersFloat() {
Pointer<Float> p = allocate(count: 8);
Pointer<Float> p = calloc(8);
for (var i in [0, 1, 2, 3, 4, 5, 6, 7]) {
p[i] = 1.511366173271439e-13;
}
for (var i in [0, 1, 2, 3, 4, 5, 6, 7]) {
Expect.equals(1.511366173271439e-13, p[i]);
}
free(p);
calloc.free(p);
}
void testRangeInt8() {
Pointer<Int8> p = allocate();
Pointer<Int8> p = calloc();
p.value = 127;
Expect.equals(127, p.value);
p.value = -128;
@@ -182,11 +183,11 @@ void testRangeInt8() {
Expect.equals(0x000000000000007F, 127);
p.value = -129;
Expect.equals(127, p.value); // truncated
free(p);
calloc.free(p);
}
void testRangeUint8() {
Pointer<Uint8> p = allocate();
Pointer<Uint8> p = calloc();
p.value = 255;
Expect.equals(255, p.value);
p.value = 0;
@@ -201,11 +202,11 @@ void testRangeUint8() {
Expect.equals(0x00000000000000FF, 255);
p.value = -1;
Expect.equals(255, p.value); // truncated
free(p);
calloc.free(p);
}
void testRangeInt16() {
Pointer<Int16> p = allocate();
Pointer<Int16> p = calloc();
p.value = 0x7FFF;
Expect.equals(0x7FFF, p.value);
p.value = -0x8000;
@@ -214,11 +215,11 @@ void testRangeInt16() {
Expect.equals(0xFFFFFFFFFFFF8000, p.value); // truncated and sign extended
p.value = -0x8001;
Expect.equals(0x7FFF, p.value); // truncated
free(p);
calloc.free(p);
}
void testRangeUint16() {
Pointer<Uint16> p = allocate();
Pointer<Uint16> p = calloc();
p.value = 0xFFFF;
Expect.equals(0xFFFF, p.value);
p.value = 0;
@@ -227,11 +228,11 @@ void testRangeUint16() {
Expect.equals(0, p.value); // truncated
p.value = -1;
Expect.equals(0xFFFF, p.value); // truncated
free(p);
calloc.free(p);
}
void testRangeInt32() {
Pointer<Int32> p = allocate();
Pointer<Int32> p = calloc();
p.value = 0x7FFFFFFF;
Expect.equals(0x7FFFFFFF, p.value);
p.value = -0x80000000;
@@ -240,11 +241,11 @@ void testRangeInt32() {
Expect.equals(0xFFFFFFFF80000000, p.value); // truncated and sign extended
p.value = -0x80000001;
Expect.equals(0x7FFFFFFF, p.value); // truncated
free(p);
calloc.free(p);
}
void testRangeUint32() {
Pointer<Uint32> p = allocate();
Pointer<Uint32> p = calloc();
p.value = 0xFFFFFFFF;
Expect.equals(0xFFFFFFFF, p.value);
p.value = 0;
@@ -253,20 +254,20 @@ void testRangeUint32() {
Expect.equals(0, p.value); // truncated
p.value = -1;
Expect.equals(0xFFFFFFFF, p.value); // truncated
free(p);
calloc.free(p);
}
void testRangeInt64() {
Pointer<Int64> p = allocate();
Pointer<Int64> p = calloc();
p.value = 0x7FFFFFFFFFFFFFFF; // 2 ^ 63 - 1
Expect.equals(0x7FFFFFFFFFFFFFFF, p.value);
p.value = -0x8000000000000000; // -2 ^ 63
Expect.equals(-0x8000000000000000, p.value);
free(p);
calloc.free(p);
}
void testRangeUint64() {
Pointer<Uint64> p = allocate();
Pointer<Uint64> p = calloc();
p.value = 0x7FFFFFFFFFFFFFFF; // 2 ^ 63 - 1
Expect.equals(0x7FFFFFFFFFFFFFFF, p.value);
p.value = -0x8000000000000000; // -2 ^ 63 interpreted as 2 ^ 63
@@ -277,69 +278,69 @@ void testRangeUint64() {
p.value = -1; // -1 interpreted as 2 ^ 64 - 1
Expect.equals(-1, p.value);
Expect.equals(0xFFFFFFFFFFFFFFFF, p.value);
free(p);
calloc.free(p);
}
void testRangeIntPtr() {
Pointer<IntPtr> p = allocate();
Pointer<IntPtr> p = calloc();
int pAddr = p.address;
p.value = pAddr; // its own address should fit
p.value = 0x7FFFFFFF; // and 32 bit addresses should fit
Expect.equals(0x7FFFFFFF, p.value);
p.value = -0x80000000;
Expect.equals(-0x80000000, p.value);
free(p);
calloc.free(p);
}
void testFloat() {
Pointer<Float> p = allocate();
Pointer<Float> p = calloc();
p.value = 1.511366173271439e-13;
Expect.equals(1.511366173271439e-13, p.value);
p.value = 1.4260258159703532e-105; // float does not have enough precision
Expect.notEquals(1.4260258159703532e-105, p.value);
free(p);
calloc.free(p);
}
void testDouble() {
Pointer<Double> p = allocate();
Pointer<Double> p = calloc();
p.value = 1.4260258159703532e-105;
Expect.equals(1.4260258159703532e-105, p.value);
free(p);
calloc.free(p);
}
void testVoid() {
Pointer<IntPtr> p1 = allocate();
Pointer<IntPtr> p1 = calloc();
Pointer<Void> p2 = p1.cast(); // make this dart pointer opaque
p2.address; // we can print the address
free(p2);
calloc.free(p2);
}
void testPointerPointer() {
Pointer<Int16> p = allocate();
Pointer<Int16> p = calloc();
p.value = 17;
Pointer<Pointer<Int16>> p2 = allocate();
Pointer<Pointer<Int16>> p2 = calloc();
p2.value = p;
Expect.equals(17, p2.value.value);
free(p2);
free(p);
calloc.free(p2);
calloc.free(p);
}
void testPointerPointerNull() {
Pointer<Pointer<Int8>> pointerToPointer = allocate();
Pointer<Pointer<Int8>> pointerToPointer = calloc();
Pointer<Int8> value = nullptr;
pointerToPointer.value = value;
value = pointerToPointer.value;
Expect.equals(value, nullptr);
value = allocate();
value = calloc();
pointerToPointer.value = value;
value = pointerToPointer.value;
Expect.isNotNull(value);
free(value);
calloc.free(value);
value = nullptr;
pointerToPointer.value = value;
value = pointerToPointer.value;
Expect.equals(value, nullptr);
free(pointerToPointer);
calloc.free(pointerToPointer);
}
void testSizeOf() {
@@ -363,7 +364,7 @@ void testPointerChain(int length) {
head.value = value;
return;
}
Pointer<IntPtr> next = allocate();
Pointer<IntPtr> next = calloc();
head.value = next.address;
createChain(next, length - 1, value);
}
@@ -378,14 +379,14 @@ void testPointerChain(int length) {
void freeChain(Pointer<IntPtr> head, int length) {
Pointer<IntPtr> next = Pointer.fromAddress(head.value);
free(head);
calloc.free(head);
if (length == 0) {
return;
}
freeChain(next, length - 1);
}
Pointer<IntPtr> head = allocate();
Pointer<IntPtr> head = calloc();
createChain(head, length, 512);
int tailValue = getChainValue(head, length);
Expect.equals(512, tailValue);
@@ -393,16 +394,16 @@ void testPointerChain(int length) {
}
void testTypeTest() {
Pointer<Int8> p = allocate();
Pointer<Int8> p = calloc();
Expect.isTrue(p is Pointer);
free(p);
calloc.free(p);
}
void testToString() {
Pointer<Int16> p = allocate();
Pointer<Int16> p = calloc();
Expect.stringEquals(
"Pointer<Int16>: address=0x", p.toString().substring(0, 26));
free(p);
calloc.free(p);
Pointer<Int64> p2 = Pointer.fromAddress(0x123abc);
Expect.stringEquals("Pointer<Int64>: address=0x123abc", p2.toString());
}
@@ -423,13 +424,13 @@ typedef Int8UnOp = Int8 Function(Int8);
void testAllocateVoid() {
Expect.throws(() {
Pointer<Void> p = allocate();
Pointer<Void> p = calloc();
});
}
void testAllocateNativeFunction() {
Expect.throws(() {
Pointer<NativeFunction<Int8UnOp>> p = allocate();
Pointer<NativeFunction<Int8UnOp>> p = calloc();
});
}
@@ -463,7 +464,7 @@ void testSizeOfNativeType() {
}
void testDynamicInvocation() {
dynamic p = allocate<Int8>();
dynamic p = calloc<Int8>();
Expect.throws(() {
final int i = p.value;
});
@@ -471,7 +472,7 @@ void testDynamicInvocation() {
p.elementAt(5); // Works, but is slow.
final int addr = p.address;
final Pointer<Int16> p2 = p.cast<Int16>();
free(p);
calloc.free(p);
}
final nullableInt64ElementAt1 = ffiTestFunctions.lookupFunction<
+12 -10
View File
@@ -7,6 +7,8 @@ import 'dart:ffi';
import "package:expect/expect.dart";
import "package:ffi/ffi.dart";
import 'calloc.dart';
main(List<String> arguments) {
for (int i = 0; i < 100; i++) {
testStoreLoad();
@@ -15,7 +17,7 @@ main(List<String> arguments) {
}
testStoreLoad() {
final p = allocate<Int8>(count: 2);
final p = calloc<Int8>(2);
p.value = 10;
Expect.equals(10, p.value);
p[1] = 20;
@@ -30,33 +32,33 @@ testStoreLoad() {
final pUseNegative = p.elementAt(1);
Expect.equals(10, pUseNegative[-1]);
final p1 = allocate<Double>(count: 2);
final p1 = calloc<Double>(2);
p1.value = 10.0;
Expect.approxEquals(10.0, p1.value);
p1[1] = 20.0;
Expect.approxEquals(20.0, p1[1]);
free(p1);
calloc.free(p1);
final p2 = allocate<Pointer<Int8>>(count: 2);
final p2 = calloc<Pointer<Int8>>(2);
p2.value = p;
Expect.equals(p, p2.value);
p2[1] = p;
Expect.equals(p, p2[1]);
free(p2);
free(p);
calloc.free(p2);
calloc.free(p);
final p3 = allocate<Foo>();
final p3 = calloc<Foo>();
Foo foo = p3.ref;
foo.a = 1;
Expect.equals(1, foo.a);
free(p3);
calloc.free(p3);
}
testReifiedGeneric() {
final p = allocate<Pointer<Int8>>();
final p = calloc<Pointer<Int8>>();
Pointer<Pointer<NativeType>> p2 = p;
Expect.isTrue(p2.value is Pointer<Int8>);
free(p);
calloc.free(p);
}
class Foo extends Struct {
+46 -44
View File
@@ -9,6 +9,8 @@ import 'dart:typed_data';
import 'package:expect/expect.dart';
import "package:ffi/ffi.dart";
import 'calloc.dart';
main() {
testInt8Load();
testInt8Store();
@@ -41,162 +43,162 @@ main() {
void testInt8Load() {
// Load
Pointer<Int8> ptr = allocate();
Pointer<Int8> ptr = calloc();
ptr.value = 0xff;
Int8List list = ptr.asTypedList(1);
Expect.equals(list[0], -1);
Expect.equals(list.length, 1);
free(ptr);
calloc.free(ptr);
}
void testInt8Store() {
// Store
Pointer<Int8> ptr = allocate();
Pointer<Int8> ptr = calloc();
Int8List list = ptr.asTypedList(1);
list[0] = 0xff;
Expect.equals(list.length, 1);
Expect.equals(ptr.value, -1);
free(ptr);
calloc.free(ptr);
}
void testUint8Load() {
// Load
Pointer<Uint8> ptr = allocate();
Pointer<Uint8> ptr = calloc();
ptr.value = 0xff;
Uint8List list = ptr.asTypedList(1);
Expect.equals(list[0], 0xff);
Expect.equals(list.length, 1);
free(ptr);
calloc.free(ptr);
}
void testUint8Store() {
// Store
Pointer<Uint8> ptr = allocate();
Pointer<Uint8> ptr = calloc();
Uint8List list = ptr.asTypedList(1);
list[0] = 0xff;
Expect.equals(list.length, 1);
Expect.equals(ptr.value, 0xff);
free(ptr);
calloc.free(ptr);
}
void testInt16Load() {
// Load
Pointer<Int16> ptr = allocate();
Pointer<Int16> ptr = calloc();
ptr.value = 0xffff;
Int16List list = ptr.asTypedList(1);
Expect.equals(list[0], -1);
Expect.equals(list.length, 1);
free(ptr);
calloc.free(ptr);
}
void testInt16Store() {
// Store
Pointer<Int16> ptr = allocate();
Pointer<Int16> ptr = calloc();
Int16List list = ptr.asTypedList(1);
list[0] = 0xffff;
Expect.equals(list.length, 1);
Expect.equals(ptr.value, -1);
free(ptr);
calloc.free(ptr);
}
void testUint16Load() {
// Load
Pointer<Uint16> ptr = allocate();
Pointer<Uint16> ptr = calloc();
ptr.value = 0xffff;
Uint16List list = ptr.asTypedList(1);
Expect.equals(list[0], 0xffff);
Expect.equals(list.length, 1);
free(ptr);
calloc.free(ptr);
}
void testUint16Store() {
// Store
Pointer<Uint16> ptr = allocate();
Pointer<Uint16> ptr = calloc();
Uint16List list = ptr.asTypedList(1);
list[0] = 0xffff;
Expect.equals(list.length, 1);
Expect.equals(ptr.value, 0xffff);
free(ptr);
calloc.free(ptr);
}
void testInt32Load() {
// Load
Pointer<Int32> ptr = allocate();
Pointer<Int32> ptr = calloc();
ptr.value = 0xffffffff;
Int32List list = ptr.asTypedList(1);
Expect.equals(list[0], -1);
Expect.equals(list.length, 1);
free(ptr);
calloc.free(ptr);
}
void testInt32Store() {
// Store
Pointer<Int32> ptr = allocate();
Pointer<Int32> ptr = calloc();
Int32List list = ptr.asTypedList(1);
list[0] = 0xffffffff;
Expect.equals(list.length, 1);
Expect.equals(ptr.value, -1);
free(ptr);
calloc.free(ptr);
}
void testUint32Load() {
// Load
Pointer<Uint32> ptr = allocate();
Pointer<Uint32> ptr = calloc();
ptr.value = 0xffffffff;
Uint32List list = ptr.asTypedList(1);
Expect.equals(list[0], 0xffffffff);
Expect.equals(list.length, 1);
free(ptr);
calloc.free(ptr);
}
void testUint32Store() {
// Store
Pointer<Uint32> ptr = allocate();
Pointer<Uint32> ptr = calloc();
Uint32List list = ptr.asTypedList(1);
list[0] = 0xffffffff;
Expect.equals(list.length, 1);
Expect.equals(ptr.value, 0xffffffff);
free(ptr);
calloc.free(ptr);
}
void testInt64Load() {
// Load
Pointer<Int64> ptr = allocate();
Pointer<Int64> ptr = calloc();
ptr.value = 0xffffffffffffffff;
Int64List list = ptr.asTypedList(1);
Expect.equals(list[0], -1);
Expect.equals(list.length, 1);
free(ptr);
calloc.free(ptr);
}
void testInt64Store() {
// Store
Pointer<Int64> ptr = allocate();
Pointer<Int64> ptr = calloc();
Int64List list = ptr.asTypedList(1);
list[0] = 0xffffffffffffffff;
Expect.equals(list.length, 1);
Expect.equals(ptr.value, -1);
free(ptr);
calloc.free(ptr);
}
void testUint64Load() {
// Load
Pointer<Uint64> ptr = allocate();
Pointer<Uint64> ptr = calloc();
ptr.value = 0xffffffffffffffff;
Uint64List list = ptr.asTypedList(1);
Expect.equals(list[0], 0xffffffffffffffff);
Expect.equals(list.length, 1);
free(ptr);
calloc.free(ptr);
}
void testUint64Store() {
// Store
Pointer<Uint64> ptr = allocate();
Pointer<Uint64> ptr = calloc();
Uint64List list = ptr.asTypedList(1);
list[0] = 0xffffffffffffffff;
Expect.equals(list.length, 1);
Expect.equals(ptr.value, 0xffffffffffffffff);
free(ptr);
calloc.free(ptr);
}
double maxFloat = (2 - pow(2, -23)) * pow(2, 127) as double;
@@ -204,47 +206,47 @@ double maxDouble = (2 - pow(2, -52)) * pow(2, pow(2, 10) - 1) as double;
void testFloatLoad() {
// Load
Pointer<Float> ptr = allocate();
Pointer<Float> ptr = calloc();
ptr.value = maxFloat;
Float32List list = ptr.asTypedList(1);
Expect.equals(list[0], maxFloat);
Expect.equals(list.length, 1);
free(ptr);
calloc.free(ptr);
}
void testFloatStore() {
// Store
Pointer<Float> ptr = allocate();
Pointer<Float> ptr = calloc();
Float32List list = ptr.asTypedList(1);
list[0] = maxFloat;
Expect.equals(list.length, 1);
Expect.equals(ptr.value, maxFloat);
free(ptr);
calloc.free(ptr);
}
void testDoubleLoad() {
// Load
Pointer<Double> ptr = allocate();
Pointer<Double> ptr = calloc();
ptr.value = maxDouble;
Float64List list = ptr.asTypedList(1);
Expect.equals(list[0], maxDouble);
Expect.equals(list.length, 1);
free(ptr);
calloc.free(ptr);
}
void testDoubleStore() {
// Store
Pointer<Double> ptr = allocate();
Pointer<Double> ptr = calloc();
Float64List list = ptr.asTypedList(1);
list[0] = maxDouble;
Expect.equals(list.length, 1);
Expect.equals(ptr.value, maxDouble);
free(ptr);
calloc.free(ptr);
}
void testArrayLoad() {
const int count = 0x100;
Pointer<Int32> ptr = allocate(count: count);
Pointer<Int32> ptr = calloc(count);
for (int i = 0; i < count; ++i) {
ptr[i] = i;
}
@@ -252,12 +254,12 @@ void testArrayLoad() {
for (int i = 0; i < count; ++i) {
Expect.equals(array[i], i);
}
free(ptr);
calloc.free(ptr);
}
void testArrayStore() {
const int count = 0x100;
Pointer<Int32> ptr = allocate(count: count);
Pointer<Int32> ptr = calloc(count);
Int32List array = ptr.asTypedList(count);
for (int i = 0; i < count; ++i) {
array[i] = i;
@@ -265,7 +267,7 @@ void testArrayStore() {
for (int i = 0; i < count; ++i) {
Expect.equals(ptr[i], i);
}
free(ptr);
calloc.free(ptr);
}
void testNegativeArray() {
@@ -16,6 +16,7 @@ import "package:expect/expect.dart";
import "package:ffi/ffi.dart";
import 'callback_tests_utils.dart';
import 'calloc.dart';
// Reuse the struct classes.
import 'function_structs_by_value_generated_test.dart';
@@ -5244,7 +5245,7 @@ int returnStruct1ByteInt_a0 = 0;
Struct1ByteInt returnStruct1ByteIntResult = Struct1ByteInt();
Struct1ByteInt returnStruct1ByteIntCalculateResult() {
Struct1ByteInt result = allocate<Struct1ByteInt>().ref;
Struct1ByteInt result = calloc<Struct1ByteInt>().ref;
result.a0 = returnStruct1ByteInt_a0;
@@ -5275,13 +5276,13 @@ Struct1ByteInt returnStruct1ByteInt(int a0) {
}
void returnStruct1ByteIntAfterCallback() {
free(returnStruct1ByteIntResult.addressOf);
calloc.free(returnStruct1ByteIntResult.addressOf);
final result = returnStruct1ByteIntCalculateResult();
print("after callback result = $result");
free(returnStruct1ByteIntResult.addressOf);
calloc.free(returnStruct1ByteIntResult.addressOf);
}
typedef ReturnStruct3BytesHomogeneousUint8Type = Struct3BytesHomogeneousUint8
@@ -5299,7 +5300,7 @@ Struct3BytesHomogeneousUint8 returnStruct3BytesHomogeneousUint8Result =
Struct3BytesHomogeneousUint8
returnStruct3BytesHomogeneousUint8CalculateResult() {
Struct3BytesHomogeneousUint8 result =
allocate<Struct3BytesHomogeneousUint8>().ref;
calloc<Struct3BytesHomogeneousUint8>().ref;
result.a0 = returnStruct3BytesHomogeneousUint8_a0;
result.a1 = returnStruct3BytesHomogeneousUint8_a1;
@@ -5335,13 +5336,13 @@ Struct3BytesHomogeneousUint8 returnStruct3BytesHomogeneousUint8(
}
void returnStruct3BytesHomogeneousUint8AfterCallback() {
free(returnStruct3BytesHomogeneousUint8Result.addressOf);
calloc.free(returnStruct3BytesHomogeneousUint8Result.addressOf);
final result = returnStruct3BytesHomogeneousUint8CalculateResult();
print("after callback result = $result");
free(returnStruct3BytesHomogeneousUint8Result.addressOf);
calloc.free(returnStruct3BytesHomogeneousUint8Result.addressOf);
}
typedef ReturnStruct3BytesInt2ByteAlignedType = Struct3BytesInt2ByteAligned
@@ -5357,7 +5358,7 @@ Struct3BytesInt2ByteAligned returnStruct3BytesInt2ByteAlignedResult =
Struct3BytesInt2ByteAligned returnStruct3BytesInt2ByteAlignedCalculateResult() {
Struct3BytesInt2ByteAligned result =
allocate<Struct3BytesInt2ByteAligned>().ref;
calloc<Struct3BytesInt2ByteAligned>().ref;
result.a0 = returnStruct3BytesInt2ByteAligned_a0;
result.a1 = returnStruct3BytesInt2ByteAligned_a1;
@@ -5391,13 +5392,13 @@ Struct3BytesInt2ByteAligned returnStruct3BytesInt2ByteAligned(int a0, int a1) {
}
void returnStruct3BytesInt2ByteAlignedAfterCallback() {
free(returnStruct3BytesInt2ByteAlignedResult.addressOf);
calloc.free(returnStruct3BytesInt2ByteAlignedResult.addressOf);
final result = returnStruct3BytesInt2ByteAlignedCalculateResult();
print("after callback result = $result");
free(returnStruct3BytesInt2ByteAlignedResult.addressOf);
calloc.free(returnStruct3BytesInt2ByteAlignedResult.addressOf);
}
typedef ReturnStruct4BytesHomogeneousInt16Type = Struct4BytesHomogeneousInt16
@@ -5414,7 +5415,7 @@ Struct4BytesHomogeneousInt16 returnStruct4BytesHomogeneousInt16Result =
Struct4BytesHomogeneousInt16
returnStruct4BytesHomogeneousInt16CalculateResult() {
Struct4BytesHomogeneousInt16 result =
allocate<Struct4BytesHomogeneousInt16>().ref;
calloc<Struct4BytesHomogeneousInt16>().ref;
result.a0 = returnStruct4BytesHomogeneousInt16_a0;
result.a1 = returnStruct4BytesHomogeneousInt16_a1;
@@ -5448,13 +5449,13 @@ Struct4BytesHomogeneousInt16 returnStruct4BytesHomogeneousInt16(
}
void returnStruct4BytesHomogeneousInt16AfterCallback() {
free(returnStruct4BytesHomogeneousInt16Result.addressOf);
calloc.free(returnStruct4BytesHomogeneousInt16Result.addressOf);
final result = returnStruct4BytesHomogeneousInt16CalculateResult();
print("after callback result = $result");
free(returnStruct4BytesHomogeneousInt16Result.addressOf);
calloc.free(returnStruct4BytesHomogeneousInt16Result.addressOf);
}
typedef ReturnStruct7BytesHomogeneousUint8Type = Struct7BytesHomogeneousUint8
@@ -5476,7 +5477,7 @@ Struct7BytesHomogeneousUint8 returnStruct7BytesHomogeneousUint8Result =
Struct7BytesHomogeneousUint8
returnStruct7BytesHomogeneousUint8CalculateResult() {
Struct7BytesHomogeneousUint8 result =
allocate<Struct7BytesHomogeneousUint8>().ref;
calloc<Struct7BytesHomogeneousUint8>().ref;
result.a0 = returnStruct7BytesHomogeneousUint8_a0;
result.a1 = returnStruct7BytesHomogeneousUint8_a1;
@@ -5521,13 +5522,13 @@ Struct7BytesHomogeneousUint8 returnStruct7BytesHomogeneousUint8(
}
void returnStruct7BytesHomogeneousUint8AfterCallback() {
free(returnStruct7BytesHomogeneousUint8Result.addressOf);
calloc.free(returnStruct7BytesHomogeneousUint8Result.addressOf);
final result = returnStruct7BytesHomogeneousUint8CalculateResult();
print("after callback result = $result");
free(returnStruct7BytesHomogeneousUint8Result.addressOf);
calloc.free(returnStruct7BytesHomogeneousUint8Result.addressOf);
}
typedef ReturnStruct7BytesInt4ByteAlignedType = Struct7BytesInt4ByteAligned
@@ -5544,7 +5545,7 @@ Struct7BytesInt4ByteAligned returnStruct7BytesInt4ByteAlignedResult =
Struct7BytesInt4ByteAligned returnStruct7BytesInt4ByteAlignedCalculateResult() {
Struct7BytesInt4ByteAligned result =
allocate<Struct7BytesInt4ByteAligned>().ref;
calloc<Struct7BytesInt4ByteAligned>().ref;
result.a0 = returnStruct7BytesInt4ByteAligned_a0;
result.a1 = returnStruct7BytesInt4ByteAligned_a1;
@@ -5581,13 +5582,13 @@ Struct7BytesInt4ByteAligned returnStruct7BytesInt4ByteAligned(
}
void returnStruct7BytesInt4ByteAlignedAfterCallback() {
free(returnStruct7BytesInt4ByteAlignedResult.addressOf);
calloc.free(returnStruct7BytesInt4ByteAlignedResult.addressOf);
final result = returnStruct7BytesInt4ByteAlignedCalculateResult();
print("after callback result = $result");
free(returnStruct7BytesInt4ByteAlignedResult.addressOf);
calloc.free(returnStruct7BytesInt4ByteAlignedResult.addressOf);
}
typedef ReturnStruct8BytesIntType = Struct8BytesInt Function(
@@ -5602,7 +5603,7 @@ int returnStruct8BytesInt_a2 = 0;
Struct8BytesInt returnStruct8BytesIntResult = Struct8BytesInt();
Struct8BytesInt returnStruct8BytesIntCalculateResult() {
Struct8BytesInt result = allocate<Struct8BytesInt>().ref;
Struct8BytesInt result = calloc<Struct8BytesInt>().ref;
result.a0 = returnStruct8BytesInt_a0;
result.a1 = returnStruct8BytesInt_a1;
@@ -5637,13 +5638,13 @@ Struct8BytesInt returnStruct8BytesInt(int a0, int a1, int a2) {
}
void returnStruct8BytesIntAfterCallback() {
free(returnStruct8BytesIntResult.addressOf);
calloc.free(returnStruct8BytesIntResult.addressOf);
final result = returnStruct8BytesIntCalculateResult();
print("after callback result = $result");
free(returnStruct8BytesIntResult.addressOf);
calloc.free(returnStruct8BytesIntResult.addressOf);
}
typedef ReturnStruct8BytesHomogeneousFloatType = Struct8BytesHomogeneousFloat
@@ -5660,7 +5661,7 @@ Struct8BytesHomogeneousFloat returnStruct8BytesHomogeneousFloatResult =
Struct8BytesHomogeneousFloat
returnStruct8BytesHomogeneousFloatCalculateResult() {
Struct8BytesHomogeneousFloat result =
allocate<Struct8BytesHomogeneousFloat>().ref;
calloc<Struct8BytesHomogeneousFloat>().ref;
result.a0 = returnStruct8BytesHomogeneousFloat_a0;
result.a1 = returnStruct8BytesHomogeneousFloat_a1;
@@ -5694,13 +5695,13 @@ Struct8BytesHomogeneousFloat returnStruct8BytesHomogeneousFloat(
}
void returnStruct8BytesHomogeneousFloatAfterCallback() {
free(returnStruct8BytesHomogeneousFloatResult.addressOf);
calloc.free(returnStruct8BytesHomogeneousFloatResult.addressOf);
final result = returnStruct8BytesHomogeneousFloatCalculateResult();
print("after callback result = $result");
free(returnStruct8BytesHomogeneousFloatResult.addressOf);
calloc.free(returnStruct8BytesHomogeneousFloatResult.addressOf);
}
typedef ReturnStruct8BytesMixedType = Struct8BytesMixed Function(
@@ -5715,7 +5716,7 @@ int returnStruct8BytesMixed_a2 = 0;
Struct8BytesMixed returnStruct8BytesMixedResult = Struct8BytesMixed();
Struct8BytesMixed returnStruct8BytesMixedCalculateResult() {
Struct8BytesMixed result = allocate<Struct8BytesMixed>().ref;
Struct8BytesMixed result = calloc<Struct8BytesMixed>().ref;
result.a0 = returnStruct8BytesMixed_a0;
result.a1 = returnStruct8BytesMixed_a1;
@@ -5750,13 +5751,13 @@ Struct8BytesMixed returnStruct8BytesMixed(double a0, int a1, int a2) {
}
void returnStruct8BytesMixedAfterCallback() {
free(returnStruct8BytesMixedResult.addressOf);
calloc.free(returnStruct8BytesMixedResult.addressOf);
final result = returnStruct8BytesMixedCalculateResult();
print("after callback result = $result");
free(returnStruct8BytesMixedResult.addressOf);
calloc.free(returnStruct8BytesMixedResult.addressOf);
}
typedef ReturnStruct9BytesHomogeneousUint8Type = Struct9BytesHomogeneousUint8
@@ -5780,7 +5781,7 @@ Struct9BytesHomogeneousUint8 returnStruct9BytesHomogeneousUint8Result =
Struct9BytesHomogeneousUint8
returnStruct9BytesHomogeneousUint8CalculateResult() {
Struct9BytesHomogeneousUint8 result =
allocate<Struct9BytesHomogeneousUint8>().ref;
calloc<Struct9BytesHomogeneousUint8>().ref;
result.a0 = returnStruct9BytesHomogeneousUint8_a0;
result.a1 = returnStruct9BytesHomogeneousUint8_a1;
@@ -5831,13 +5832,13 @@ Struct9BytesHomogeneousUint8 returnStruct9BytesHomogeneousUint8(
}
void returnStruct9BytesHomogeneousUint8AfterCallback() {
free(returnStruct9BytesHomogeneousUint8Result.addressOf);
calloc.free(returnStruct9BytesHomogeneousUint8Result.addressOf);
final result = returnStruct9BytesHomogeneousUint8CalculateResult();
print("after callback result = $result");
free(returnStruct9BytesHomogeneousUint8Result.addressOf);
calloc.free(returnStruct9BytesHomogeneousUint8Result.addressOf);
}
typedef ReturnStruct9BytesInt4Or8ByteAlignedType
@@ -5854,7 +5855,7 @@ Struct9BytesInt4Or8ByteAligned returnStruct9BytesInt4Or8ByteAlignedResult =
Struct9BytesInt4Or8ByteAligned
returnStruct9BytesInt4Or8ByteAlignedCalculateResult() {
Struct9BytesInt4Or8ByteAligned result =
allocate<Struct9BytesInt4Or8ByteAligned>().ref;
calloc<Struct9BytesInt4Or8ByteAligned>().ref;
result.a0 = returnStruct9BytesInt4Or8ByteAligned_a0;
result.a1 = returnStruct9BytesInt4Or8ByteAligned_a1;
@@ -5890,13 +5891,13 @@ Struct9BytesInt4Or8ByteAligned returnStruct9BytesInt4Or8ByteAligned(
}
void returnStruct9BytesInt4Or8ByteAlignedAfterCallback() {
free(returnStruct9BytesInt4Or8ByteAlignedResult.addressOf);
calloc.free(returnStruct9BytesInt4Or8ByteAlignedResult.addressOf);
final result = returnStruct9BytesInt4Or8ByteAlignedCalculateResult();
print("after callback result = $result");
free(returnStruct9BytesInt4Or8ByteAlignedResult.addressOf);
calloc.free(returnStruct9BytesInt4Or8ByteAlignedResult.addressOf);
}
typedef ReturnStruct12BytesHomogeneousFloatType = Struct12BytesHomogeneousFloat
@@ -5914,7 +5915,7 @@ Struct12BytesHomogeneousFloat returnStruct12BytesHomogeneousFloatResult =
Struct12BytesHomogeneousFloat
returnStruct12BytesHomogeneousFloatCalculateResult() {
Struct12BytesHomogeneousFloat result =
allocate<Struct12BytesHomogeneousFloat>().ref;
calloc<Struct12BytesHomogeneousFloat>().ref;
result.a0 = returnStruct12BytesHomogeneousFloat_a0;
result.a1 = returnStruct12BytesHomogeneousFloat_a1;
@@ -5951,13 +5952,13 @@ Struct12BytesHomogeneousFloat returnStruct12BytesHomogeneousFloat(
}
void returnStruct12BytesHomogeneousFloatAfterCallback() {
free(returnStruct12BytesHomogeneousFloatResult.addressOf);
calloc.free(returnStruct12BytesHomogeneousFloatResult.addressOf);
final result = returnStruct12BytesHomogeneousFloatCalculateResult();
print("after callback result = $result");
free(returnStruct12BytesHomogeneousFloatResult.addressOf);
calloc.free(returnStruct12BytesHomogeneousFloatResult.addressOf);
}
typedef ReturnStruct16BytesHomogeneousFloatType = Struct16BytesHomogeneousFloat
@@ -5976,7 +5977,7 @@ Struct16BytesHomogeneousFloat returnStruct16BytesHomogeneousFloatResult =
Struct16BytesHomogeneousFloat
returnStruct16BytesHomogeneousFloatCalculateResult() {
Struct16BytesHomogeneousFloat result =
allocate<Struct16BytesHomogeneousFloat>().ref;
calloc<Struct16BytesHomogeneousFloat>().ref;
result.a0 = returnStruct16BytesHomogeneousFloat_a0;
result.a1 = returnStruct16BytesHomogeneousFloat_a1;
@@ -6014,13 +6015,13 @@ Struct16BytesHomogeneousFloat returnStruct16BytesHomogeneousFloat(
}
void returnStruct16BytesHomogeneousFloatAfterCallback() {
free(returnStruct16BytesHomogeneousFloatResult.addressOf);
calloc.free(returnStruct16BytesHomogeneousFloatResult.addressOf);
final result = returnStruct16BytesHomogeneousFloatCalculateResult();
print("after callback result = $result");
free(returnStruct16BytesHomogeneousFloatResult.addressOf);
calloc.free(returnStruct16BytesHomogeneousFloatResult.addressOf);
}
typedef ReturnStruct16BytesMixedType = Struct16BytesMixed Function(
@@ -6034,7 +6035,7 @@ int returnStruct16BytesMixed_a1 = 0;
Struct16BytesMixed returnStruct16BytesMixedResult = Struct16BytesMixed();
Struct16BytesMixed returnStruct16BytesMixedCalculateResult() {
Struct16BytesMixed result = allocate<Struct16BytesMixed>().ref;
Struct16BytesMixed result = calloc<Struct16BytesMixed>().ref;
result.a0 = returnStruct16BytesMixed_a0;
result.a1 = returnStruct16BytesMixed_a1;
@@ -6067,13 +6068,13 @@ Struct16BytesMixed returnStruct16BytesMixed(double a0, int a1) {
}
void returnStruct16BytesMixedAfterCallback() {
free(returnStruct16BytesMixedResult.addressOf);
calloc.free(returnStruct16BytesMixedResult.addressOf);
final result = returnStruct16BytesMixedCalculateResult();
print("after callback result = $result");
free(returnStruct16BytesMixedResult.addressOf);
calloc.free(returnStruct16BytesMixedResult.addressOf);
}
typedef ReturnStruct16BytesMixed2Type = Struct16BytesMixed2 Function(
@@ -6089,7 +6090,7 @@ int returnStruct16BytesMixed2_a3 = 0;
Struct16BytesMixed2 returnStruct16BytesMixed2Result = Struct16BytesMixed2();
Struct16BytesMixed2 returnStruct16BytesMixed2CalculateResult() {
Struct16BytesMixed2 result = allocate<Struct16BytesMixed2>().ref;
Struct16BytesMixed2 result = calloc<Struct16BytesMixed2>().ref;
result.a0 = returnStruct16BytesMixed2_a0;
result.a1 = returnStruct16BytesMixed2_a1;
@@ -6128,13 +6129,13 @@ Struct16BytesMixed2 returnStruct16BytesMixed2(
}
void returnStruct16BytesMixed2AfterCallback() {
free(returnStruct16BytesMixed2Result.addressOf);
calloc.free(returnStruct16BytesMixed2Result.addressOf);
final result = returnStruct16BytesMixed2CalculateResult();
print("after callback result = $result");
free(returnStruct16BytesMixed2Result.addressOf);
calloc.free(returnStruct16BytesMixed2Result.addressOf);
}
typedef ReturnStruct17BytesIntType = Struct17BytesInt Function(
@@ -6149,7 +6150,7 @@ int returnStruct17BytesInt_a2 = 0;
Struct17BytesInt returnStruct17BytesIntResult = Struct17BytesInt();
Struct17BytesInt returnStruct17BytesIntCalculateResult() {
Struct17BytesInt result = allocate<Struct17BytesInt>().ref;
Struct17BytesInt result = calloc<Struct17BytesInt>().ref;
result.a0 = returnStruct17BytesInt_a0;
result.a1 = returnStruct17BytesInt_a1;
@@ -6186,13 +6187,13 @@ Struct17BytesInt returnStruct17BytesInt(int a0, int a1, int a2) {
}
void returnStruct17BytesIntAfterCallback() {
free(returnStruct17BytesIntResult.addressOf);
calloc.free(returnStruct17BytesIntResult.addressOf);
final result = returnStruct17BytesIntCalculateResult();
print("after callback result = $result");
free(returnStruct17BytesIntResult.addressOf);
calloc.free(returnStruct17BytesIntResult.addressOf);
}
typedef ReturnStruct19BytesHomogeneousUint8Type
@@ -6245,7 +6246,7 @@ Struct19BytesHomogeneousUint8 returnStruct19BytesHomogeneousUint8Result =
Struct19BytesHomogeneousUint8
returnStruct19BytesHomogeneousUint8CalculateResult() {
Struct19BytesHomogeneousUint8 result =
allocate<Struct19BytesHomogeneousUint8>().ref;
calloc<Struct19BytesHomogeneousUint8>().ref;
result.a0 = returnStruct19BytesHomogeneousUint8_a0;
result.a1 = returnStruct19BytesHomogeneousUint8_a1;
@@ -6334,13 +6335,13 @@ Struct19BytesHomogeneousUint8 returnStruct19BytesHomogeneousUint8(
}
void returnStruct19BytesHomogeneousUint8AfterCallback() {
free(returnStruct19BytesHomogeneousUint8Result.addressOf);
calloc.free(returnStruct19BytesHomogeneousUint8Result.addressOf);
final result = returnStruct19BytesHomogeneousUint8CalculateResult();
print("after callback result = $result");
free(returnStruct19BytesHomogeneousUint8Result.addressOf);
calloc.free(returnStruct19BytesHomogeneousUint8Result.addressOf);
}
typedef ReturnStruct20BytesHomogeneousInt32Type = Struct20BytesHomogeneousInt32
@@ -6360,7 +6361,7 @@ Struct20BytesHomogeneousInt32 returnStruct20BytesHomogeneousInt32Result =
Struct20BytesHomogeneousInt32
returnStruct20BytesHomogeneousInt32CalculateResult() {
Struct20BytesHomogeneousInt32 result =
allocate<Struct20BytesHomogeneousInt32>().ref;
calloc<Struct20BytesHomogeneousInt32>().ref;
result.a0 = returnStruct20BytesHomogeneousInt32_a0;
result.a1 = returnStruct20BytesHomogeneousInt32_a1;
@@ -6401,13 +6402,13 @@ Struct20BytesHomogeneousInt32 returnStruct20BytesHomogeneousInt32(
}
void returnStruct20BytesHomogeneousInt32AfterCallback() {
free(returnStruct20BytesHomogeneousInt32Result.addressOf);
calloc.free(returnStruct20BytesHomogeneousInt32Result.addressOf);
final result = returnStruct20BytesHomogeneousInt32CalculateResult();
print("after callback result = $result");
free(returnStruct20BytesHomogeneousInt32Result.addressOf);
calloc.free(returnStruct20BytesHomogeneousInt32Result.addressOf);
}
typedef ReturnStruct20BytesHomogeneousFloatType = Struct20BytesHomogeneousFloat
@@ -6427,7 +6428,7 @@ Struct20BytesHomogeneousFloat returnStruct20BytesHomogeneousFloatResult =
Struct20BytesHomogeneousFloat
returnStruct20BytesHomogeneousFloatCalculateResult() {
Struct20BytesHomogeneousFloat result =
allocate<Struct20BytesHomogeneousFloat>().ref;
calloc<Struct20BytesHomogeneousFloat>().ref;
result.a0 = returnStruct20BytesHomogeneousFloat_a0;
result.a1 = returnStruct20BytesHomogeneousFloat_a1;
@@ -6468,13 +6469,13 @@ Struct20BytesHomogeneousFloat returnStruct20BytesHomogeneousFloat(
}
void returnStruct20BytesHomogeneousFloatAfterCallback() {
free(returnStruct20BytesHomogeneousFloatResult.addressOf);
calloc.free(returnStruct20BytesHomogeneousFloatResult.addressOf);
final result = returnStruct20BytesHomogeneousFloatCalculateResult();
print("after callback result = $result");
free(returnStruct20BytesHomogeneousFloatResult.addressOf);
calloc.free(returnStruct20BytesHomogeneousFloatResult.addressOf);
}
typedef ReturnStruct32BytesHomogeneousDoubleType
@@ -6493,7 +6494,7 @@ Struct32BytesHomogeneousDouble returnStruct32BytesHomogeneousDoubleResult =
Struct32BytesHomogeneousDouble
returnStruct32BytesHomogeneousDoubleCalculateResult() {
Struct32BytesHomogeneousDouble result =
allocate<Struct32BytesHomogeneousDouble>().ref;
calloc<Struct32BytesHomogeneousDouble>().ref;
result.a0 = returnStruct32BytesHomogeneousDouble_a0;
result.a1 = returnStruct32BytesHomogeneousDouble_a1;
@@ -6532,13 +6533,13 @@ Struct32BytesHomogeneousDouble returnStruct32BytesHomogeneousDouble(
}
void returnStruct32BytesHomogeneousDoubleAfterCallback() {
free(returnStruct32BytesHomogeneousDoubleResult.addressOf);
calloc.free(returnStruct32BytesHomogeneousDoubleResult.addressOf);
final result = returnStruct32BytesHomogeneousDoubleCalculateResult();
print("after callback result = $result");
free(returnStruct32BytesHomogeneousDoubleResult.addressOf);
calloc.free(returnStruct32BytesHomogeneousDoubleResult.addressOf);
}
typedef ReturnStruct40BytesHomogeneousDoubleType
@@ -6559,7 +6560,7 @@ Struct40BytesHomogeneousDouble returnStruct40BytesHomogeneousDoubleResult =
Struct40BytesHomogeneousDouble
returnStruct40BytesHomogeneousDoubleCalculateResult() {
Struct40BytesHomogeneousDouble result =
allocate<Struct40BytesHomogeneousDouble>().ref;
calloc<Struct40BytesHomogeneousDouble>().ref;
result.a0 = returnStruct40BytesHomogeneousDouble_a0;
result.a1 = returnStruct40BytesHomogeneousDouble_a1;
@@ -6601,13 +6602,13 @@ Struct40BytesHomogeneousDouble returnStruct40BytesHomogeneousDouble(
}
void returnStruct40BytesHomogeneousDoubleAfterCallback() {
free(returnStruct40BytesHomogeneousDoubleResult.addressOf);
calloc.free(returnStruct40BytesHomogeneousDoubleResult.addressOf);
final result = returnStruct40BytesHomogeneousDoubleCalculateResult();
print("after callback result = $result");
free(returnStruct40BytesHomogeneousDoubleResult.addressOf);
calloc.free(returnStruct40BytesHomogeneousDoubleResult.addressOf);
}
typedef ReturnStruct1024BytesHomogeneousUint64Type
@@ -6878,7 +6879,7 @@ Struct1024BytesHomogeneousUint64 returnStruct1024BytesHomogeneousUint64Result =
Struct1024BytesHomogeneousUint64
returnStruct1024BytesHomogeneousUint64CalculateResult() {
Struct1024BytesHomogeneousUint64 result =
allocate<Struct1024BytesHomogeneousUint64>().ref;
calloc<Struct1024BytesHomogeneousUint64>().ref;
result.a0 = returnStruct1024BytesHomogeneousUint64_a0;
result.a1 = returnStruct1024BytesHomogeneousUint64_a1;
@@ -7293,13 +7294,13 @@ Struct1024BytesHomogeneousUint64 returnStruct1024BytesHomogeneousUint64(
}
void returnStruct1024BytesHomogeneousUint64AfterCallback() {
free(returnStruct1024BytesHomogeneousUint64Result.addressOf);
calloc.free(returnStruct1024BytesHomogeneousUint64Result.addressOf);
final result = returnStruct1024BytesHomogeneousUint64CalculateResult();
print("after callback result = $result");
free(returnStruct1024BytesHomogeneousUint64Result.addressOf);
calloc.free(returnStruct1024BytesHomogeneousUint64Result.addressOf);
}
typedef ReturnStructArgumentStruct1ByteIntType = Struct1ByteInt Function(
@@ -7618,7 +7619,7 @@ int returnStructAlignmentInt16_a2 = 0;
StructAlignmentInt16 returnStructAlignmentInt16Result = StructAlignmentInt16();
StructAlignmentInt16 returnStructAlignmentInt16CalculateResult() {
StructAlignmentInt16 result = allocate<StructAlignmentInt16>().ref;
StructAlignmentInt16 result = calloc<StructAlignmentInt16>().ref;
result.a0 = returnStructAlignmentInt16_a0;
result.a1 = returnStructAlignmentInt16_a1;
@@ -7653,13 +7654,13 @@ StructAlignmentInt16 returnStructAlignmentInt16(int a0, int a1, int a2) {
}
void returnStructAlignmentInt16AfterCallback() {
free(returnStructAlignmentInt16Result.addressOf);
calloc.free(returnStructAlignmentInt16Result.addressOf);
final result = returnStructAlignmentInt16CalculateResult();
print("after callback result = $result");
free(returnStructAlignmentInt16Result.addressOf);
calloc.free(returnStructAlignmentInt16Result.addressOf);
}
typedef ReturnStructAlignmentInt32Type = StructAlignmentInt32 Function(
@@ -7674,7 +7675,7 @@ int returnStructAlignmentInt32_a2 = 0;
StructAlignmentInt32 returnStructAlignmentInt32Result = StructAlignmentInt32();
StructAlignmentInt32 returnStructAlignmentInt32CalculateResult() {
StructAlignmentInt32 result = allocate<StructAlignmentInt32>().ref;
StructAlignmentInt32 result = calloc<StructAlignmentInt32>().ref;
result.a0 = returnStructAlignmentInt32_a0;
result.a1 = returnStructAlignmentInt32_a1;
@@ -7709,13 +7710,13 @@ StructAlignmentInt32 returnStructAlignmentInt32(int a0, int a1, int a2) {
}
void returnStructAlignmentInt32AfterCallback() {
free(returnStructAlignmentInt32Result.addressOf);
calloc.free(returnStructAlignmentInt32Result.addressOf);
final result = returnStructAlignmentInt32CalculateResult();
print("after callback result = $result");
free(returnStructAlignmentInt32Result.addressOf);
calloc.free(returnStructAlignmentInt32Result.addressOf);
}
typedef ReturnStructAlignmentInt64Type = StructAlignmentInt64 Function(
@@ -7730,7 +7731,7 @@ int returnStructAlignmentInt64_a2 = 0;
StructAlignmentInt64 returnStructAlignmentInt64Result = StructAlignmentInt64();
StructAlignmentInt64 returnStructAlignmentInt64CalculateResult() {
StructAlignmentInt64 result = allocate<StructAlignmentInt64>().ref;
StructAlignmentInt64 result = calloc<StructAlignmentInt64>().ref;
result.a0 = returnStructAlignmentInt64_a0;
result.a1 = returnStructAlignmentInt64_a1;
@@ -7765,13 +7766,13 @@ StructAlignmentInt64 returnStructAlignmentInt64(int a0, int a1, int a2) {
}
void returnStructAlignmentInt64AfterCallback() {
free(returnStructAlignmentInt64Result.addressOf);
calloc.free(returnStructAlignmentInt64Result.addressOf);
final result = returnStructAlignmentInt64CalculateResult();
print("after callback result = $result");
free(returnStructAlignmentInt64Result.addressOf);
calloc.free(returnStructAlignmentInt64Result.addressOf);
}
typedef ReturnStruct8BytesNestedIntType = Struct8BytesNestedInt Function(
@@ -7788,7 +7789,7 @@ Struct8BytesNestedInt returnStruct8BytesNestedIntResult =
Struct8BytesNestedInt();
Struct8BytesNestedInt returnStruct8BytesNestedIntCalculateResult() {
Struct8BytesNestedInt result = allocate<Struct8BytesNestedInt>().ref;
Struct8BytesNestedInt result = calloc<Struct8BytesNestedInt>().ref;
result.a0.a0 = returnStruct8BytesNestedInt_a0.a0;
result.a0.a1 = returnStruct8BytesNestedInt_a0.a1;
@@ -7824,13 +7825,13 @@ Struct8BytesNestedInt returnStruct8BytesNestedInt(
}
void returnStruct8BytesNestedIntAfterCallback() {
free(returnStruct8BytesNestedIntResult.addressOf);
calloc.free(returnStruct8BytesNestedIntResult.addressOf);
final result = returnStruct8BytesNestedIntCalculateResult();
print("after callback result = $result");
free(returnStruct8BytesNestedIntResult.addressOf);
calloc.free(returnStruct8BytesNestedIntResult.addressOf);
}
typedef ReturnStruct8BytesNestedFloatType = Struct8BytesNestedFloat Function(
@@ -7845,7 +7846,7 @@ Struct8BytesNestedFloat returnStruct8BytesNestedFloatResult =
Struct8BytesNestedFloat();
Struct8BytesNestedFloat returnStruct8BytesNestedFloatCalculateResult() {
Struct8BytesNestedFloat result = allocate<Struct8BytesNestedFloat>().ref;
Struct8BytesNestedFloat result = calloc<Struct8BytesNestedFloat>().ref;
result.a0.a0 = returnStruct8BytesNestedFloat_a0.a0;
result.a1.a0 = returnStruct8BytesNestedFloat_a1.a0;
@@ -7879,13 +7880,13 @@ Struct8BytesNestedFloat returnStruct8BytesNestedFloat(
}
void returnStruct8BytesNestedFloatAfterCallback() {
free(returnStruct8BytesNestedFloatResult.addressOf);
calloc.free(returnStruct8BytesNestedFloatResult.addressOf);
final result = returnStruct8BytesNestedFloatCalculateResult();
print("after callback result = $result");
free(returnStruct8BytesNestedFloatResult.addressOf);
calloc.free(returnStruct8BytesNestedFloatResult.addressOf);
}
typedef ReturnStruct8BytesNestedFloat2Type = Struct8BytesNestedFloat2 Function(
@@ -7900,7 +7901,7 @@ Struct8BytesNestedFloat2 returnStruct8BytesNestedFloat2Result =
Struct8BytesNestedFloat2();
Struct8BytesNestedFloat2 returnStruct8BytesNestedFloat2CalculateResult() {
Struct8BytesNestedFloat2 result = allocate<Struct8BytesNestedFloat2>().ref;
Struct8BytesNestedFloat2 result = calloc<Struct8BytesNestedFloat2>().ref;
result.a0.a0 = returnStruct8BytesNestedFloat2_a0.a0;
result.a1 = returnStruct8BytesNestedFloat2_a1;
@@ -7935,13 +7936,13 @@ Struct8BytesNestedFloat2 returnStruct8BytesNestedFloat2(
}
void returnStruct8BytesNestedFloat2AfterCallback() {
free(returnStruct8BytesNestedFloat2Result.addressOf);
calloc.free(returnStruct8BytesNestedFloat2Result.addressOf);
final result = returnStruct8BytesNestedFloat2CalculateResult();
print("after callback result = $result");
free(returnStruct8BytesNestedFloat2Result.addressOf);
calloc.free(returnStruct8BytesNestedFloat2Result.addressOf);
}
typedef ReturnStruct8BytesNestedMixedType = Struct8BytesNestedMixed Function(
@@ -7957,7 +7958,7 @@ Struct8BytesNestedMixed returnStruct8BytesNestedMixedResult =
Struct8BytesNestedMixed();
Struct8BytesNestedMixed returnStruct8BytesNestedMixedCalculateResult() {
Struct8BytesNestedMixed result = allocate<Struct8BytesNestedMixed>().ref;
Struct8BytesNestedMixed result = calloc<Struct8BytesNestedMixed>().ref;
result.a0.a0 = returnStruct8BytesNestedMixed_a0.a0;
result.a0.a1 = returnStruct8BytesNestedMixed_a0.a1;
@@ -7992,13 +7993,13 @@ Struct8BytesNestedMixed returnStruct8BytesNestedMixed(
}
void returnStruct8BytesNestedMixedAfterCallback() {
free(returnStruct8BytesNestedMixedResult.addressOf);
calloc.free(returnStruct8BytesNestedMixedResult.addressOf);
final result = returnStruct8BytesNestedMixedCalculateResult();
print("after callback result = $result");
free(returnStruct8BytesNestedMixedResult.addressOf);
calloc.free(returnStruct8BytesNestedMixedResult.addressOf);
}
typedef ReturnStruct16BytesNestedIntType = Struct16BytesNestedInt Function(
@@ -8013,7 +8014,7 @@ Struct16BytesNestedInt returnStruct16BytesNestedIntResult =
Struct16BytesNestedInt();
Struct16BytesNestedInt returnStruct16BytesNestedIntCalculateResult() {
Struct16BytesNestedInt result = allocate<Struct16BytesNestedInt>().ref;
Struct16BytesNestedInt result = calloc<Struct16BytesNestedInt>().ref;
result.a0.a0.a0 = returnStruct16BytesNestedInt_a0.a0.a0;
result.a0.a0.a1 = returnStruct16BytesNestedInt_a0.a0.a1;
@@ -8053,13 +8054,13 @@ Struct16BytesNestedInt returnStruct16BytesNestedInt(
}
void returnStruct16BytesNestedIntAfterCallback() {
free(returnStruct16BytesNestedIntResult.addressOf);
calloc.free(returnStruct16BytesNestedIntResult.addressOf);
final result = returnStruct16BytesNestedIntCalculateResult();
print("after callback result = $result");
free(returnStruct16BytesNestedIntResult.addressOf);
calloc.free(returnStruct16BytesNestedIntResult.addressOf);
}
typedef ReturnStruct32BytesNestedIntType = Struct32BytesNestedInt Function(
@@ -8076,7 +8077,7 @@ Struct32BytesNestedInt returnStruct32BytesNestedIntResult =
Struct32BytesNestedInt();
Struct32BytesNestedInt returnStruct32BytesNestedIntCalculateResult() {
Struct32BytesNestedInt result = allocate<Struct32BytesNestedInt>().ref;
Struct32BytesNestedInt result = calloc<Struct32BytesNestedInt>().ref;
result.a0.a0.a0.a0 = returnStruct32BytesNestedInt_a0.a0.a0.a0;
result.a0.a0.a0.a1 = returnStruct32BytesNestedInt_a0.a0.a0.a1;
@@ -8124,13 +8125,13 @@ Struct32BytesNestedInt returnStruct32BytesNestedInt(
}
void returnStruct32BytesNestedIntAfterCallback() {
free(returnStruct32BytesNestedIntResult.addressOf);
calloc.free(returnStruct32BytesNestedIntResult.addressOf);
final result = returnStruct32BytesNestedIntCalculateResult();
print("after callback result = $result");
free(returnStruct32BytesNestedIntResult.addressOf);
calloc.free(returnStruct32BytesNestedIntResult.addressOf);
}
typedef ReturnStructNestedIntStructAlignmentInt16Type
@@ -8151,7 +8152,7 @@ StructNestedIntStructAlignmentInt16
StructNestedIntStructAlignmentInt16
returnStructNestedIntStructAlignmentInt16CalculateResult() {
StructNestedIntStructAlignmentInt16 result =
allocate<StructNestedIntStructAlignmentInt16>().ref;
calloc<StructNestedIntStructAlignmentInt16>().ref;
result.a0.a0 = returnStructNestedIntStructAlignmentInt16_a0.a0;
result.a0.a1 = returnStructNestedIntStructAlignmentInt16_a0.a1;
@@ -8190,13 +8191,13 @@ StructNestedIntStructAlignmentInt16 returnStructNestedIntStructAlignmentInt16(
}
void returnStructNestedIntStructAlignmentInt16AfterCallback() {
free(returnStructNestedIntStructAlignmentInt16Result.addressOf);
calloc.free(returnStructNestedIntStructAlignmentInt16Result.addressOf);
final result = returnStructNestedIntStructAlignmentInt16CalculateResult();
print("after callback result = $result");
free(returnStructNestedIntStructAlignmentInt16Result.addressOf);
calloc.free(returnStructNestedIntStructAlignmentInt16Result.addressOf);
}
typedef ReturnStructNestedIntStructAlignmentInt32Type
@@ -8217,7 +8218,7 @@ StructNestedIntStructAlignmentInt32
StructNestedIntStructAlignmentInt32
returnStructNestedIntStructAlignmentInt32CalculateResult() {
StructNestedIntStructAlignmentInt32 result =
allocate<StructNestedIntStructAlignmentInt32>().ref;
calloc<StructNestedIntStructAlignmentInt32>().ref;
result.a0.a0 = returnStructNestedIntStructAlignmentInt32_a0.a0;
result.a0.a1 = returnStructNestedIntStructAlignmentInt32_a0.a1;
@@ -8256,13 +8257,13 @@ StructNestedIntStructAlignmentInt32 returnStructNestedIntStructAlignmentInt32(
}
void returnStructNestedIntStructAlignmentInt32AfterCallback() {
free(returnStructNestedIntStructAlignmentInt32Result.addressOf);
calloc.free(returnStructNestedIntStructAlignmentInt32Result.addressOf);
final result = returnStructNestedIntStructAlignmentInt32CalculateResult();
print("after callback result = $result");
free(returnStructNestedIntStructAlignmentInt32Result.addressOf);
calloc.free(returnStructNestedIntStructAlignmentInt32Result.addressOf);
}
typedef ReturnStructNestedIntStructAlignmentInt64Type
@@ -8283,7 +8284,7 @@ StructNestedIntStructAlignmentInt64
StructNestedIntStructAlignmentInt64
returnStructNestedIntStructAlignmentInt64CalculateResult() {
StructNestedIntStructAlignmentInt64 result =
allocate<StructNestedIntStructAlignmentInt64>().ref;
calloc<StructNestedIntStructAlignmentInt64>().ref;
result.a0.a0 = returnStructNestedIntStructAlignmentInt64_a0.a0;
result.a0.a1 = returnStructNestedIntStructAlignmentInt64_a0.a1;
@@ -8322,13 +8323,13 @@ StructNestedIntStructAlignmentInt64 returnStructNestedIntStructAlignmentInt64(
}
void returnStructNestedIntStructAlignmentInt64AfterCallback() {
free(returnStructNestedIntStructAlignmentInt64Result.addressOf);
calloc.free(returnStructNestedIntStructAlignmentInt64Result.addressOf);
final result = returnStructNestedIntStructAlignmentInt64CalculateResult();
print("after callback result = $result");
free(returnStructNestedIntStructAlignmentInt64Result.addressOf);
calloc.free(returnStructNestedIntStructAlignmentInt64Result.addressOf);
}
typedef ReturnStructNestedIrregularEvenBiggerType
@@ -8350,7 +8351,7 @@ StructNestedIrregularEvenBigger returnStructNestedIrregularEvenBiggerResult =
StructNestedIrregularEvenBigger
returnStructNestedIrregularEvenBiggerCalculateResult() {
StructNestedIrregularEvenBigger result =
allocate<StructNestedIrregularEvenBigger>().ref;
calloc<StructNestedIrregularEvenBigger>().ref;
result.a0 = returnStructNestedIrregularEvenBigger_a0;
result.a1.a0.a0 = returnStructNestedIrregularEvenBigger_a1.a0.a0;
@@ -8419,11 +8420,11 @@ StructNestedIrregularEvenBigger returnStructNestedIrregularEvenBigger(int a0,
}
void returnStructNestedIrregularEvenBiggerAfterCallback() {
free(returnStructNestedIrregularEvenBiggerResult.addressOf);
calloc.free(returnStructNestedIrregularEvenBiggerResult.addressOf);
final result = returnStructNestedIrregularEvenBiggerCalculateResult();
print("after callback result = $result");
free(returnStructNestedIrregularEvenBiggerResult.addressOf);
calloc.free(returnStructNestedIrregularEvenBiggerResult.addressOf);
}
@@ -11,6 +11,7 @@ import 'dart:ffi';
import "package:expect/expect.dart";
import "package:ffi/ffi.dart";
import 'calloc.dart';
// Reuse the struct classes.
import 'function_structs_by_value_generated_test.dart';
@@ -23,7 +24,7 @@ void main() {
}
void recursiveTest(int recursionCounter) {
final struct = allocate<Struct20BytesHomogeneousInt32>().ref;
final struct = calloc<Struct20BytesHomogeneousInt32>().ref;
struct.a0 = 1;
struct.a1 = 2;
struct.a2 = 3;
@@ -35,7 +36,7 @@ void recursiveTest(int recursionCounter) {
Expect.equals(struct.a2, result.a2);
Expect.equals(struct.a3, result.a3);
Expect.equals(struct.a4, result.a4);
free(struct.addressOf);
calloc.free(struct.addressOf);
}
Struct20BytesHomogeneousInt32 dartPassStructRecursive(
@@ -93,7 +94,7 @@ void testCopyLogic() {
_invokeReceiveStructByValue(_receiveStructByValuePointer);
Expect.isTrue(typedDataBackedStructSet);
final pointerBackedStruct = allocate<Struct8BytesNestedInt>().ref;
final pointerBackedStruct = calloc<Struct8BytesNestedInt>().ref;
void reset() {
pointerBackedStruct.a0.a0 = 1;
@@ -130,5 +131,5 @@ void testCopyLogic() {
Expect.equals(5, typedDataBackedStruct.a1.a0);
Expect.equals(6, typedDataBackedStruct.a1.a1);
free(pointerBackedStruct.addressOf);
calloc.free(pointerBackedStruct.addressOf);
}
File diff suppressed because it is too large Load Diff
+11 -8
View File
@@ -14,6 +14,7 @@ import 'dylib_utils.dart';
import "package:expect/expect.dart";
import "package:ffi/ffi.dart";
import 'calloc.dart';
import 'coordinate.dart';
import 'very_large_struct.dart';
@@ -33,8 +34,10 @@ void testFunctionWithStruct() {
ffiTestFunctions.lookup("TransposeCoordinate");
NativeCoordinateOp f1 = p1.asFunction();
Pointer<Coordinate> c1 = Coordinate.allocate(10.0, 20.0, nullptr).addressOf;
Pointer<Coordinate> c2 = Coordinate.allocate(42.0, 84.0, c1).addressOf;
Pointer<Coordinate> c1 =
Coordinate.allocate(calloc, 10.0, 20.0, nullptr).addressOf;
Pointer<Coordinate> c2 =
Coordinate.allocate(calloc, 42.0, 84.0, c1).addressOf;
c1.ref.next = c2;
Coordinate result = f1(c1).ref;
@@ -45,8 +48,8 @@ void testFunctionWithStruct() {
Expect.approxEquals(42.0, result.x);
Expect.approxEquals(84.0, result.y);
free(c1);
free(c2);
calloc.free(c1);
calloc.free(c2);
}
/// pass an array of structs to a c funtion
@@ -55,7 +58,7 @@ void testFunctionWithStructArray() {
ffiTestFunctions.lookup("CoordinateElemAt1");
NativeCoordinateOp f1 = p1.asFunction();
Coordinate c1 = allocate<Coordinate>(count: 3).ref;
Coordinate c1 = calloc<Coordinate>(3).ref;
Coordinate c2 = c1.addressOf[1];
Coordinate c3 = c1.addressOf[2];
c1.x = 10.0;
@@ -72,7 +75,7 @@ void testFunctionWithStructArray() {
Expect.approxEquals(20.0, result.x);
Expect.approxEquals(20.0, result.y);
free(c1.addressOf);
calloc.free(c1.addressOf);
}
typedef VeryLargeStructSum = int Function(Pointer<VeryLargeStruct>);
@@ -83,7 +86,7 @@ void testFunctionWithVeryLargeStruct() {
ffiTestFunctions.lookup("SumVeryLargeStruct");
VeryLargeStructSum f = p1.asFunction();
VeryLargeStruct vls1 = allocate<VeryLargeStruct>(count: 2).ref;
VeryLargeStruct vls1 = calloc<VeryLargeStruct>(2).ref;
VeryLargeStruct vls2 = vls1.addressOf[1];
List<VeryLargeStruct> structs = [vls1, vls2];
for (VeryLargeStruct struct in structs) {
@@ -114,5 +117,5 @@ void testFunctionWithVeryLargeStruct() {
result = f(vls2.addressOf);
Expect.equals(2048, result);
free(vls1.addressOf);
calloc.free(vls1.addressOf);
}
+11 -10
View File
@@ -15,11 +15,12 @@
import 'dart:ffi';
import 'dylib_utils.dart';
import "package:ffi/ffi.dart";
import "package:expect/expect.dart";
import 'calloc.dart';
import 'dylib_utils.dart';
void main() {
for (int i = 0; i < 100; ++i) {
testNativeFunctionFromCast();
@@ -50,11 +51,11 @@ typedef BinaryOp = int Function(int, int);
typedef GenericBinaryOp<T> = int Function(int, T);
void testNativeFunctionFromCast() {
Pointer<IntPtr> p1 = allocate();
Pointer<IntPtr> p1 = calloc();
Pointer<NativeFunction<NativeBinaryOp>> p2 = p1.cast();
p2.asFunction<BinaryOp>();
p2.asFunction<GenericBinaryOp<int>>();
free(p1);
calloc.free(p1);
}
typedef NativeQuadOpSigned = Int64 Function(Int8, Int16, Int32, Int64);
@@ -394,14 +395,14 @@ Int64PointerUnOp assign1337Index1 = ffiTestFunctions
.lookupFunction<Int64PointerUnOp, Int64PointerUnOp>("Assign1337Index1");
void testNativeFunctionPointer() {
Pointer<Int64> p2 = allocate(count: 2);
Pointer<Int64> p2 = calloc(2);
p2.value = 42;
p2[1] = 1000;
Pointer<Int64> result = assign1337Index1(p2);
Expect.equals(1337, result.value);
Expect.equals(1337, p2[1]);
Expect.equals(p2.elementAt(1).address, result.address);
free(p2);
calloc.free(p2);
}
Int64PointerUnOp nullableInt64ElemAt1 = ffiTestFunctions
@@ -411,10 +412,10 @@ void testNullPointers() {
Pointer<Int64> result = nullableInt64ElemAt1(nullptr);
Expect.equals(result, nullptr);
Pointer<Int64> p2 = allocate(count: 2);
Pointer<Int64> p2 = calloc(2);
result = nullableInt64ElemAt1(p2);
Expect.notEquals(result, nullptr);
free(p2);
calloc.free(p2);
}
typedef NativeFloatPointerToBool = Uint8 Function(Pointer<Float>);
@@ -424,13 +425,13 @@ FloatPointerToBool isRoughly1337 = ffiTestFunctions.lookupFunction<
NativeFloatPointerToBool, FloatPointerToBool>("IsRoughly1337");
void testFloatRounding() {
Pointer<Float> p2 = allocate();
Pointer<Float> p2 = calloc();
p2.value = 1337.0;
int result = isRoughly1337(p2);
Expect.equals(1, result);
free(p2);
calloc.free(p2);
}
typedef NativeFloatToVoid = Void Function(Float);
@@ -197,7 +197,7 @@ extension on CType {
return "${dartType} ${variableName};\n";
case StructType:
return "${dartType} ${variableName} = allocate<$dartType>().ref;\n";
return "${dartType} ${variableName} = calloc<$dartType>().ref;\n";
}
throw Exception("Not implemented for ${this.runtimeType}");
@@ -243,7 +243,7 @@ extension on CType {
return "";
case StructType:
return "free($variableName.addressOf);\n";
return "calloc.free($variableName.addressOf);\n";
}
throw Exception("Not implemented for ${this.runtimeType}");
@@ -485,7 +485,7 @@ extension on FunctionType {
case TestType.structReturn:
// Allocate a struct.
buildReturnValue = """
${returnValue.dartType} result = allocate<${returnValue.dartType}>().ref;
${returnValue.dartType} result = calloc<${returnValue.dartType}>().ref;
${arguments.copyValueStatements("${dartName}_", "result.")}
""";
@@ -749,6 +749,7 @@ import 'dart:ffi';
import "package:expect/expect.dart";
import "package:ffi/ffi.dart";
import 'calloc.dart';
import 'dylib_utils.dart';
final ffiTestFunctions = dlopenPlatformSpecific("ffi_test_functions");
@@ -801,6 +802,7 @@ import "package:expect/expect.dart";
import "package:ffi/ffi.dart";
import 'callback_tests_utils.dart';
import 'calloc.dart';
// Reuse the struct classes.
import 'function_structs_by_value_generated_test.dart';
+50 -48
View File
@@ -65,34 +65,36 @@ import 'dart:ffi';
import "package:expect/expect.dart";
import "package:ffi/ffi.dart";
import 'calloc.dart';
// ===== a.value = b ======
// The tests follow table cells left to right, top to bottom.
void store1() {
final Pointer<Pointer<Int8>> a = allocate<Pointer<Int8>>();
final Pointer<Int8> b = allocate<Int8>();
final Pointer<Pointer<Int8>> a = calloc<Pointer<Int8>>();
final Pointer<Int8> b = calloc<Int8>();
a.value = b;
free(a);
free(b);
calloc.free(a);
calloc.free(b);
}
void store2() {
final Pointer<Pointer<Int8>> a = allocate<Pointer<Int8>>();
final Pointer<Pointer<Int8>> a = calloc<Pointer<Int8>>();
final Pointer<NativeType> b =
allocate<Int8>(); // Reified Pointer<Int8> at runtime.
calloc<Int8>(); // Reified Pointer<Int8> at runtime.
// Successful implicit downcast of argument at runtime.
// Should succeed now, should statically be rejected when NNBD lands.
a.value = b as Pointer<Int8>;
free(a);
free(b);
calloc.free(a);
calloc.free(b);
}
void store3() {
final Pointer<Pointer<Int8>> a = allocate<Pointer<Int8>>();
final Pointer<NativeType> b = allocate<Int8>().cast<Pointer<NativeType>>();
final Pointer<Pointer<Int8>> a = calloc<Pointer<Int8>>();
final Pointer<NativeType> b = calloc<Int8>().cast<Pointer<NativeType>>();
// Failing implicit downcast of argument at runtime.
// Should fail now at runtime, should statically be rejected when NNBD lands.
@@ -100,124 +102,124 @@ void store3() {
a.value = b as Pointer<Int8>;
});
free(a);
free(b);
calloc.free(a);
calloc.free(b);
}
void store4() {
// Reified as Pointer<Pointer<Int8>> at runtime.
final Pointer<Pointer<NativeType>> a = allocate<Pointer<Int8>>();
final Pointer<Pointer<NativeType>> a = calloc<Pointer<Int8>>();
final Pointer<Int8> b = allocate<Int8>();
final Pointer<Int8> b = calloc<Int8>();
a.value = b;
free(a);
free(b);
calloc.free(a);
calloc.free(b);
}
void store5() {
// Reified as Pointer<Pointer<Int8>> at runtime.
final Pointer<Pointer<NativeType>> a = allocate<Pointer<Int8>>();
final Pointer<Pointer<NativeType>> a = calloc<Pointer<Int8>>();
final Pointer<NativeType> b =
allocate<Int8>(); // Reified as Pointer<Int8> at runtime.
calloc<Int8>(); // Reified as Pointer<Int8> at runtime.
a.value = b;
free(a);
free(b);
calloc.free(a);
calloc.free(b);
}
void store6() {
// Reified as Pointer<Pointer<Int8>> at runtime.
final Pointer<Pointer<NativeType>> a = allocate<Pointer<Int8>>();
final Pointer<NativeType> b = allocate<Int8>().cast<Pointer<NativeType>>();
final Pointer<Pointer<NativeType>> a = calloc<Pointer<Int8>>();
final Pointer<NativeType> b = calloc<Int8>().cast<Pointer<NativeType>>();
// Fails on type check of argument.
Expect.throws(() {
a.value = b;
});
free(a);
free(b);
calloc.free(a);
calloc.free(b);
}
void store7() {
final Pointer<Pointer<NativeType>> a = allocate<Pointer<NativeType>>();
final Pointer<Int8> b = allocate<Int8>();
final Pointer<Pointer<NativeType>> a = calloc<Pointer<NativeType>>();
final Pointer<Int8> b = calloc<Int8>();
a.value = b;
free(a);
free(b);
calloc.free(a);
calloc.free(b);
}
void store8() {
final Pointer<Pointer<NativeType>> a = allocate<Pointer<NativeType>>();
final Pointer<Pointer<NativeType>> a = calloc<Pointer<NativeType>>();
// Reified as Pointer<Int8> at runtime.
final Pointer<NativeType> b = allocate<Int8>();
final Pointer<NativeType> b = calloc<Int8>();
a.value = b;
free(a);
free(b);
calloc.free(a);
calloc.free(b);
}
void store9() {
final Pointer<Pointer<NativeType>> a = allocate<Pointer<NativeType>>();
final Pointer<NativeType> b = allocate<Int8>().cast<Pointer<NativeType>>();
final Pointer<Pointer<NativeType>> a = calloc<Pointer<NativeType>>();
final Pointer<NativeType> b = calloc<Int8>().cast<Pointer<NativeType>>();
a.value = b;
free(a);
free(b);
calloc.free(a);
calloc.free(b);
}
// ====== b = a.value ======
// The tests follow table cells left to right, top to bottom.
void load1() {
final Pointer<Pointer<Int8>> a = allocate<Pointer<Int8>>();
final Pointer<Pointer<Int8>> a = calloc<Pointer<Int8>>();
Pointer<Int8> b = a.value;
Expect.type<Pointer<Int8>>(b);
free(a);
calloc.free(a);
}
void load2() {
final Pointer<Pointer<Int8>> a = allocate<Pointer<Int8>>();
final Pointer<Pointer<Int8>> a = calloc<Pointer<Int8>>();
Pointer<NativeType> b = a.value;
Expect.type<Pointer<Int8>>(b);
free(a);
calloc.free(a);
}
void load3() {
// Reified as Pointer<Pointer<Int8>> at runtime.
final Pointer<Pointer<NativeType>> a = allocate<Pointer<Int8>>();
final Pointer<Pointer<NativeType>> a = calloc<Pointer<Int8>>();
Pointer<Int8> b = a.value as Pointer<Int8>;
Expect.type<Pointer<Int8>>(b);
free(a);
calloc.free(a);
}
void load4() {
// Reified as Pointer<Pointer<Int8>> at runtime.
final Pointer<Pointer<NativeType>> a = allocate<Pointer<Int8>>();
final Pointer<Pointer<NativeType>> a = calloc<Pointer<Int8>>();
// Return value runtime type is Pointer<Int8>.
Pointer<NativeType> b = a.value;
Expect.type<Pointer<Int8>>(b);
free(a);
calloc.free(a);
}
void load5() {
final Pointer<Pointer<NativeType>> a = allocate<Pointer<NativeType>>();
final Pointer<Pointer<NativeType>> a = calloc<Pointer<NativeType>>();
// Failing implicit downcast of return value at runtime.
// Should fail now at runtime, should statically be rejected when NNBD lands.
@@ -225,16 +227,16 @@ void load5() {
Pointer<Int8> b = a.value as Pointer<Int8>;
});
free(a);
calloc.free(a);
}
void load6() {
final Pointer<Pointer<NativeType>> a = allocate<Pointer<NativeType>>();
final Pointer<Pointer<NativeType>> a = calloc<Pointer<NativeType>>();
Pointer<NativeType> b = a.value;
Expect.type<Pointer<NativeType>>(b);
free(a);
calloc.free(a);
}
void main() {
+6 -3
View File
@@ -3,12 +3,15 @@
// BSD-style license that can be found in the LICENSE file.
import 'dart:ffi';
import "package:ffi/ffi.dart" show allocate, free;
import "package:ffi/ffi.dart";
import 'calloc.dart';
main() {
final data = allocate<Uint8>(count: 3);
final data = calloc<Uint8>(3);
for (int i = 0; i < 3; ++i) {
data.elementAt(i).value = 1;
}
free(data);
calloc.free(data);
}
+3 -2
View File
@@ -9,6 +9,7 @@ import 'dart:ffi';
import 'package:ffi/ffi.dart';
import 'package:expect/expect.dart';
import 'calloc.dart';
import 'dylib_utils.dart';
class Struct43693 extends Struct {
@@ -27,10 +28,10 @@ final int Function(Pointer<Struct43693>) readMyStructSomeValue =
final ffiTestFunctions = dlopenPlatformSpecific("ffi_test_functions");
void main() {
final myStructs = allocate<Struct43693>();
final myStructs = calloc<Struct43693>();
myStructs[0].somePtr = nullptr;
myStructs[0].someValue = 0xAAAAAAAABBBBBBBB;
final result = readMyStructSomeValue(myStructs);
Expect.equals(0xAAAAAAAABBBBBBBB, result);
free(myStructs);
calloc.free(myStructs);
}
+9 -8
View File
@@ -11,6 +11,7 @@ import 'dart:ffi';
import "package:expect/expect.dart";
import "package:ffi/ffi.dart";
import 'calloc.dart';
import 'dylib_utils.dart';
final ffiTestFunctions = dlopenPlatformSpecific("ffi_test_functions");
@@ -48,16 +49,16 @@ void testSizeOf() {
}
void testAllocate() {
final p = allocate<Struct8BytesNestedInt>();
final p = calloc<Struct8BytesNestedInt>();
Expect.type<Pointer<Struct8BytesNestedInt>>(p);
print(p);
free(p);
calloc.free(p);
}
/// Test that reading does not segfault, even uninitialized.
void testRead() {
print("read");
final p = allocate<Struct8BytesNestedInt>();
final p = calloc<Struct8BytesNestedInt>();
print(p);
print(p.ref.runtimeType);
print(p.ref.addressOf);
@@ -65,13 +66,13 @@ void testRead() {
print(p.ref.a0.runtimeType);
print(p.ref.a0.addressOf);
print(p.ref.a0.a0);
free(p);
calloc.free(p);
print("read");
}
void testWrite() {
print("write");
final p = allocate<Struct8BytesNestedInt>(count: 2);
final p = calloc<Struct8BytesNestedInt>(2);
p[0].a0.a0 = 12;
p[0].a0.a1 = 13;
p[0].a1.a0 = 14;
@@ -88,18 +89,18 @@ void testWrite() {
Expect.equals(17, p[1].a0.a1);
Expect.equals(18, p[1].a1.a0);
Expect.equals(19, p[1].a1.a1);
free(p);
calloc.free(p);
print("written");
}
void testCopy() {
print("copy");
final p = allocate<Struct8BytesNestedInt>();
final p = calloc<Struct8BytesNestedInt>();
p.ref.a0.a0 = 12;
p.ref.a0.a1 = 13;
p.ref.a1 = p.ref.a0;
Expect.equals(12, p.ref.a1.a0);
Expect.equals(13, p.ref.a1.a1);
free(p);
calloc.free(p);
print("copied");
}
+17 -13
View File
@@ -11,6 +11,7 @@ import 'dart:ffi';
import "package:expect/expect.dart";
import "package:ffi/ffi.dart";
import 'calloc.dart';
import 'coordinate_nnbd_workaround.dart';
void main() {
@@ -25,9 +26,12 @@ void main() {
/// allocates each coordinate separately in c memory
void testStructAllocate() {
Pointer<Coordinate> c1 = Coordinate.allocate(10.0, 10.0, nullptr).addressOf;
Pointer<Coordinate> c2 = Coordinate.allocate(20.0, 20.0, c1).addressOf;
Pointer<Coordinate> c3 = Coordinate.allocate(30.0, 30.0, c2).addressOf;
Pointer<Coordinate> c1 =
Coordinate.allocate(calloc, 10.0, 10.0, nullptr).addressOf;
Pointer<Coordinate> c2 =
Coordinate.allocate(calloc, 20.0, 20.0, c1).addressOf;
Pointer<Coordinate> c3 =
Coordinate.allocate(calloc, 30.0, 30.0, c2).addressOf;
c1.ref.next = c3;
Coordinate currentCoordinate = c1.ref;
@@ -39,14 +43,14 @@ void testStructAllocate() {
currentCoordinate = currentCoordinate.next.ref;
Expect.equals(10.0, currentCoordinate.x);
free(c1);
free(c2);
free(c3);
calloc.free(c1);
calloc.free(c2);
calloc.free(c3);
}
/// allocates coordinates consecutively in c memory
void testStructFromAddress() {
Pointer<Coordinate> c1 = allocate(count: 3);
Pointer<Coordinate> c1 = calloc(3);
Pointer<Coordinate> c2 = c1.elementAt(1);
Pointer<Coordinate> c3 = c1.elementAt(2);
c1.ref
@@ -71,30 +75,30 @@ void testStructFromAddress() {
currentCoordinate = currentCoordinate.next.ref;
Expect.equals(10.0, currentCoordinate.x);
free(c1);
calloc.free(c1);
}
void testStructWithNulls() {
Pointer<Coordinate> coordinate =
Coordinate.allocate(10.0, 10.0, nullptr).addressOf;
Coordinate.allocate(calloc, 10.0, 10.0, nullptr).addressOf;
Expect.equals(coordinate.ref.next, nullptr);
coordinate.ref.next = coordinate;
Expect.notEquals(coordinate.ref.next, nullptr);
coordinate.ref.next = nullptr;
Expect.equals(coordinate.ref.next, nullptr);
free(coordinate);
calloc.free(coordinate);
}
void testTypeTest() {
Coordinate c = Coordinate.allocate(10, 10, nullptr);
Coordinate c = Coordinate.allocate(calloc, 10, 10, nullptr);
Expect.isTrue(c is Struct);
Expect.isTrue(c.addressOf is Pointer<Coordinate>);
free(c.addressOf);
calloc.free(c.addressOf);
}
void testUtf8() {
final String test = 'Hasta Mañana';
final Pointer<Utf8> medium = Utf8.toUtf8(test);
Expect.equals(test, Utf8.fromUtf8(medium));
free(medium);
calloc.free(medium);
}
+20 -16
View File
@@ -11,9 +11,10 @@ import 'dart:ffi';
import "package:expect/expect.dart";
import "package:ffi/ffi.dart";
import 'ffi_test_helpers.dart';
import 'calloc.dart';
import 'coordinate_bare.dart' as bare;
import 'coordinate.dart';
import 'ffi_test_helpers.dart';
void main() {
for (int i = 0; i < 100; i++) {
@@ -28,9 +29,12 @@ void main() {
/// allocates each coordinate separately in c memory
void testStructAllocate() {
Pointer<Coordinate> c1 = Coordinate.allocate(10.0, 10.0, nullptr).addressOf;
Pointer<Coordinate> c2 = Coordinate.allocate(20.0, 20.0, c1).addressOf;
Pointer<Coordinate> c3 = Coordinate.allocate(30.0, 30.0, c2).addressOf;
Pointer<Coordinate> c1 =
Coordinate.allocate(calloc, 10.0, 10.0, nullptr).addressOf;
Pointer<Coordinate> c2 =
Coordinate.allocate(calloc, 20.0, 20.0, c1).addressOf;
Pointer<Coordinate> c3 =
Coordinate.allocate(calloc, 30.0, 30.0, c2).addressOf;
c1.ref.next = c3;
Coordinate currentCoordinate = c1.ref;
@@ -42,14 +46,14 @@ void testStructAllocate() {
currentCoordinate = currentCoordinate.next.ref;
Expect.equals(10.0, currentCoordinate.x);
free(c1);
free(c2);
free(c3);
calloc.free(c1);
calloc.free(c2);
calloc.free(c3);
}
/// allocates coordinates consecutively in c memory
void testStructFromAddress() {
Pointer<Coordinate> c1 = allocate(count: 3);
Pointer<Coordinate> c1 = calloc(3);
Pointer<Coordinate> c2 = c1.elementAt(1);
Pointer<Coordinate> c3 = c1.elementAt(2);
c1.ref
@@ -74,24 +78,24 @@ void testStructFromAddress() {
currentCoordinate = currentCoordinate.next.ref;
Expect.equals(10.0, currentCoordinate.x);
free(c1);
calloc.free(c1);
}
void testStructWithNulls() {
Pointer<Coordinate> coordinate =
Coordinate.allocate(10.0, 10.0, nullptr).addressOf;
Coordinate.allocate(calloc, 10.0, 10.0, nullptr).addressOf;
Expect.equals(coordinate.ref.next, nullptr);
coordinate.ref.next = coordinate;
Expect.notEquals(coordinate.ref.next, nullptr);
coordinate.ref.next = nullptr;
Expect.equals(coordinate.ref.next, nullptr);
free(coordinate);
calloc.free(coordinate);
}
void testBareStruct() {
int structSize = sizeOf<Double>() * 2 + sizeOf<IntPtr>();
bare.Coordinate c1 =
allocate<Uint8>(count: structSize * 3).cast<bare.Coordinate>().ref;
calloc<Uint8>(structSize * 3).cast<bare.Coordinate>().ref;
bare.Coordinate c2 =
c1.addressOf.offsetBy(structSize).cast<bare.Coordinate>().ref;
bare.Coordinate c3 =
@@ -115,19 +119,19 @@ void testBareStruct() {
currentCoordinate = currentCoordinate.next.ref;
Expect.equals(10.0, currentCoordinate.x);
free(c1.addressOf);
calloc.free(c1.addressOf);
}
void testTypeTest() {
Coordinate c = Coordinate.allocate(10, 10, nullptr);
Coordinate c = Coordinate.allocate(calloc, 10, 10, nullptr);
Expect.isTrue(c is Struct);
Expect.isTrue(c.addressOf is Pointer<Coordinate>);
free(c.addressOf);
calloc.free(c.addressOf);
}
void testUtf8() {
final String test = 'Hasta Mañana';
final Pointer<Utf8> medium = Utf8.toUtf8(test);
Expect.equals(test, Utf8.fromUtf8(medium));
free(medium);
calloc.free(medium);
}
+13 -12
View File
@@ -12,11 +12,12 @@
import 'dart:ffi';
import 'dylib_utils.dart';
import "package:expect/expect.dart";
import "package:ffi/ffi.dart";
import 'calloc.dart';
import 'dylib_utils.dart';
typedef Int64PointerParamOpDart = void Function(Pointer<Int64>);
typedef Int64PointerParamOp = Void Function(Pointer<Int64>);
typedef NaTyPointerParamOpDart = void Function(Pointer<NativeType>);
@@ -38,19 +39,19 @@ void paramInvariant1() {
final fp =
ffiTestFunctions.lookup<NativeFunction<Int64PointerParamOp>>(paramOpName);
final f = fp.asFunction<Int64PointerParamOpDart>();
final arg = allocate<Int64>();
final arg = calloc<Int64>();
f(arg);
free(arg);
calloc.free(arg);
}
void paramInvariant2() {
final fp =
ffiTestFunctions.lookup<NativeFunction<NaTyPointerParamOp>>(paramOpName);
final f = fp.asFunction<NaTyPointerParamOpDart>();
final arg = allocate<Int64>().cast<NativeType>();
final arg = calloc<Int64>().cast<NativeType>();
Expect.type<Pointer<NativeType>>(arg);
f(arg);
free(arg);
calloc.free(arg);
}
// Pass a statically and dynamically subtyped argument.
@@ -58,10 +59,10 @@ void paramSubtype1() {
final fp =
ffiTestFunctions.lookup<NativeFunction<NaTyPointerParamOp>>(paramOpName);
final f = fp.asFunction<NaTyPointerParamOpDart>();
final arg = allocate<Int64>();
final arg = calloc<Int64>();
Expect.type<Pointer<Int64>>(arg);
f(arg);
free(arg);
calloc.free(arg);
}
// Pass a statically subtyped but dynamically invariant argument.
@@ -69,10 +70,10 @@ void paramSubtype2() {
final fp =
ffiTestFunctions.lookup<NativeFunction<NaTyPointerParamOp>>(paramOpName);
final f = fp.asFunction<NaTyPointerParamOpDart>();
final Pointer<NativeType> arg = allocate<Int64>();
final Pointer<NativeType> arg = calloc<Int64>();
Expect.type<Pointer<Int64>>(arg);
f(arg);
free(arg);
calloc.free(arg);
}
void returnInvariant1() {
@@ -220,7 +221,7 @@ void callbackReturnInvariant2() {
}
void fromFunctionTests() {
data = allocate();
data = calloc();
for (int i = 0; i < 100; ++i) {
callbackParamInvariant1(); // Pointer<Int64> invariant
callbackParamInvariant2(); // Pointer<NativeType> invariant
@@ -229,7 +230,7 @@ void fromFunctionTests() {
callbackReturnInvariant1(); // Pointer<Int64> invariant
callbackReturnInvariant2(); // Pointer<NativeType> invariant
}
free(data);
calloc.free(data);
}
void main() {
+5 -2
View File
@@ -7,11 +7,14 @@
// VMOptions=--enable-ffi=false
import 'dart:ffi'; //# 01: compile-time error
import 'package:ffi/ffi.dart'; //# 01: compile-time error
import 'calloc.dart'; //# 01: compile-time error
void main() {
Pointer<Int8> p = //# 01: compile-time error
allocate(); //# 01: compile-time error
calloc(); //# 01: compile-time error
print(p.address); //# 01: compile-time error
free(p); //# 01: compile-time error
calloc.free(p); //# 01: compile-time error
}
+21 -20
View File
@@ -10,6 +10,7 @@ import 'dart:ffi';
import "package:ffi/ffi.dart";
import 'calloc.dart';
import 'dylib_utils.dart';
void main() {
@@ -67,20 +68,20 @@ void testGetGeneric() {
return result;
}
Pointer<Int8> p = allocate();
Pointer<Int8> p = calloc();
p.value = 123;
Pointer loseType = p;
generic(loseType);
free(p);
calloc.free(p);
}
void testGetGeneric2() {
T? generic<T extends Object>() {
Pointer<Int8> p = allocate();
Pointer<Int8> p = calloc();
p.value = 123;
T? result;
result = p.value; //# 21: compile-time error
free(p);
calloc.free(p);
return result;
}
@@ -88,12 +89,12 @@ void testGetGeneric2() {
}
void testGetVoid() {
Pointer<IntPtr> p1 = allocate();
Pointer<IntPtr> p1 = calloc();
Pointer<Void> p2 = p1.cast();
p2.value; //# 22: compile-time error
free(p1);
calloc.free(p1);
}
void testGetNativeFunction() {
@@ -106,14 +107,14 @@ void testGetNativeType() {
}
void testGetTypeMismatch() {
Pointer<Pointer<Int16>> p = allocate();
Pointer<Pointer<Int16>> p = calloc();
Pointer<Int16> typedNull = nullptr;
p.value = typedNull;
// this fails to compile due to type mismatch
Pointer<Int8> p2 = p.value; //# 25: compile-time error
free(p);
calloc.free(p);
}
void testSetGeneric() {
@@ -121,30 +122,30 @@ void testSetGeneric() {
p.value = 123; //# 26: compile-time error
}
Pointer<Int8> p = allocate();
Pointer<Int8> p = calloc();
p.value = 123;
Pointer loseType = p;
generic(loseType);
free(p);
calloc.free(p);
}
void testSetGeneric2() {
void generic<T extends Object>(T arg) {
Pointer<Int8> p = allocate();
Pointer<Int8> p = calloc();
p.value = arg; //# 27: compile-time error
free(p);
calloc.free(p);
}
generic<int>(123);
}
void testSetVoid() {
Pointer<IntPtr> p1 = allocate();
Pointer<IntPtr> p1 = calloc();
Pointer<Void> p2 = p1.cast();
p2.value = 1234; //# 28: compile-time error
free(p1);
calloc.free(p1);
}
void testSetNativeFunction() {
@@ -159,16 +160,16 @@ void testSetNativeType() {
void testSetTypeMismatch() {
// the pointer to pointer types must match up
Pointer<Int8> pHelper = allocate();
Pointer<Int8> pHelper = calloc();
pHelper.value = 123;
Pointer<Pointer<Int16>> p = allocate();
Pointer<Pointer<Int16>> p = calloc();
// this fails to compile due to type mismatch
p.value = pHelper; //# 40: compile-time error
free(pHelper);
free(p);
calloc.free(pHelper);
calloc.free(p);
}
void testAsFunctionGeneric() {
@@ -558,7 +559,7 @@ class HasNestedEmptyStruct extends Struct {
void testAllocateGeneric() {
Pointer<T> generic<T extends NativeType>() {
Pointer<T> pointer = nullptr;
pointer = malloc(); //# 1320: compile-time error
pointer = calloc(); //# 1320: compile-time error
return pointer;
}
@@ -566,5 +567,5 @@ void testAllocateGeneric() {
}
void testAllocateNativeType() {
malloc(); //# 1321: compile-time error
calloc(); //# 1321: compile-time error
}
+33 -32
View File
@@ -13,6 +13,7 @@ import 'dart:ffi';
import "package:ffi/ffi.dart";
import "package:expect/expect.dart";
import 'calloc.dart';
import 'ffi_test_helpers.dart';
void main() {
@@ -35,28 +36,28 @@ void main() {
}
void testNonAlias() {
final source = allocate<Int64>();
final source = calloc<Int64>();
source.value = 42;
final int a = source.value;
source.value = 1984;
// alias.value should be re-executed, as we wrote to alias.
Expect.notEquals(a, source.value);
free(source);
calloc.free(source);
}
void testAliasCast() {
final source = allocate<Int64>();
final source = calloc<Int64>();
final alias = source.cast<Int8>().cast<Int64>();
source.value = 42;
final int a = source.value;
alias.value = 1984;
// source.value should be re-executed, we wrote alias which aliases source.
Expect.notEquals(a, source.value);
free(source);
calloc.free(source);
}
void testAliasCast2() {
final source = allocate<Int64>();
final source = calloc<Int64>();
final alias = source.cast<Int16>().cast<Int64>();
final alias2 = source.cast<Int8>().cast<Int64>();
alias.value = 42;
@@ -64,22 +65,22 @@ void testAliasCast2() {
alias2.value = 1984;
// alias.value should be re-executed, we wrote alias2 which aliases alias.
Expect.notEquals(a, alias.value);
free(source);
calloc.free(source);
}
void testAliasOffsetBy() {
final source = allocate<Int64>(count: 2);
final source = calloc<Int64>(2);
final alias = source.offsetBy(8).offsetBy(-8);
source.value = 42;
final int a = source.value;
alias.value = 1984;
// source.value should be re-executed, we wrote alias which aliases source.
Expect.notEquals(a, source.value);
free(source);
calloc.free(source);
}
void testAliasOffsetBy2() {
final source = allocate<Int64>(count: 3);
final source = calloc<Int64>(3);
final alias = source.offsetBy(16).offsetBy(-16);
final alias2 = source.offsetBy(8).offsetBy(-8);
alias.value = 42;
@@ -87,22 +88,22 @@ void testAliasOffsetBy2() {
alias2.value = 1984;
// alias.value should be re-executed, we wrote alias2 which aliases alias.
Expect.notEquals(a, alias.value);
free(source);
calloc.free(source);
}
void testAliasElementAt() {
final source = allocate<Int64>(count: 2);
final source = calloc<Int64>(2);
final alias = source.elementAt(1).elementAt(-1);
source.value = 42;
final int a = source.value;
alias.value = 1984;
// source.value should be re-executed, we wrote alias which aliases source.
Expect.notEquals(a, source.value);
free(source);
calloc.free(source);
}
void testAliasElementAt2() {
final source = allocate<Int64>(count: 3);
final source = calloc<Int64>(3);
final alias = source.elementAt(2).elementAt(-2);
final alias2 = source.elementAt(1).elementAt(-1);
alias.value = 42;
@@ -110,22 +111,22 @@ void testAliasElementAt2() {
alias2.value = 1984;
// alias.value should be re-executed, we wrote alias2 which aliases alias.
Expect.notEquals(a, alias.value);
free(source);
calloc.free(source);
}
void testAliasFromAddress() {
final source = allocate<Int64>();
final source = calloc<Int64>();
final alias = Pointer<Int64>.fromAddress(source.address);
source.value = 42;
final int a = source.value;
alias.value = 1984;
// source.value should be re-executed, we wrote alias which aliases source.
Expect.notEquals(a, source.value);
free(source);
calloc.free(source);
}
void testAliasFromAddress2() {
final source = allocate<Int64>();
final source = calloc<Int64>();
final alias = Pointer<Int64>.fromAddress(source.address);
final alias2 = Pointer<Int64>.fromAddress(source.address);
alias.value = 42;
@@ -133,12 +134,12 @@ void testAliasFromAddress2() {
alias2.value = 1984;
// alias.value should be re-executed, we wrote alias2 which aliases alias.
Expect.notEquals(a, alias.value);
free(source);
calloc.free(source);
}
void testAliasFromAddressViaMemory() {
final helper = allocate<IntPtr>();
final source = allocate<Int64>();
final helper = calloc<IntPtr>();
final source = calloc<Int64>();
helper.value = source.address;
final alias = Pointer<Int64>.fromAddress(helper.value);
source.value = 42;
@@ -146,13 +147,13 @@ void testAliasFromAddressViaMemory() {
alias.value = 1984;
// source.value should be re-executed, we wrote alias which aliases source.
Expect.notEquals(a, source.value);
free(helper);
free(source);
calloc.free(helper);
calloc.free(source);
}
void testAliasFromAddressViaMemory2() {
final helper = allocate<IntPtr>();
final source = allocate<Int64>();
final helper = calloc<IntPtr>();
final source = calloc<Int64>();
helper.value = source.address;
final alias = Pointer<Int64>.fromAddress(helper.value);
final alias2 = Pointer<Int64>.fromAddress(helper.value);
@@ -161,8 +162,8 @@ void testAliasFromAddressViaMemory2() {
alias2.value = 1984;
// alias.value should be re-executed, we wrote alias2 which aliases alias.
Expect.notEquals(a, alias.value);
free(helper);
free(source);
calloc.free(helper);
calloc.free(source);
}
typedef NativeQuadOpSigned = Int64 Function(Int8, Int16, Int32, Int64);
@@ -172,7 +173,7 @@ QuadOp intComputation = ffiTestFunctions
.lookupFunction<NativeQuadOpSigned, QuadOp>("IntComputation");
void testAliasFromAddressViaNativeFunction() {
final source = allocate<Int64>();
final source = calloc<Int64>();
final alias =
Pointer<Int64>.fromAddress(intComputation(0, 0, 0, source.address));
source.value = 42;
@@ -180,11 +181,11 @@ void testAliasFromAddressViaNativeFunction() {
alias.value = 1984;
// source.value should be re-executed, we wrote alias which aliases source.
Expect.notEquals(a, source.value);
free(source);
calloc.free(source);
}
void testAliasFromAddressViaNativeFunction2() {
final source = allocate<Int64>();
final source = calloc<Int64>();
final alias =
Pointer<Int64>.fromAddress(intComputation(0, 0, 0, source.address));
final alias2 =
@@ -194,7 +195,7 @@ void testAliasFromAddressViaNativeFunction2() {
alias2.value = 1984;
// alias.value should be re-executed, we wrote alias2 which aliases alias.
Expect.notEquals(a, alias.value);
free(source);
calloc.free(source);
}
@pragma('vm:never-inline')
@@ -202,11 +203,11 @@ Pointer<Int8> makeDerived(Pointer<Int64> source) =>
source.offsetBy(7).cast<Int8>();
testPartialOverlap() {
final source = allocate<Int64>(count: 2);
final source = calloc<Int64>(2);
final derived = makeDerived(source);
source.value = 0x1122334455667788;
final int value = source.value;
derived.value = 0xaa;
Expect.notEquals(value, source.value);
free(source);
calloc.free(source);
}
+1 -1
View File
@@ -54,7 +54,7 @@ class _CallocAllocator implements Allocator {
/// Allocates [byteCount] bytes of zero-initialized of memory on the native
/// heap.
///
/// For POSIX-based systems, this uses `malloc`. On Windows, it uses
/// For POSIX-based systems, this uses `calloc`. On Windows, it uses
/// `HeapAlloc` against the default public heap.
///
/// Throws an [ArgumentError] if the number of bytes or alignment cannot be
+3 -2
View File
@@ -17,8 +17,9 @@ class Coordinate extends Struct {
Pointer<Coordinate> next;
factory Coordinate.allocate(double x, double y, Pointer<Coordinate> next) {
return allocate<Coordinate>().ref
factory Coordinate.allocate(
Allocator allocator, double x, double y, Pointer<Coordinate> next) {
return allocator<Coordinate>().ref
..x = x
..y = y
..next = next;
+6 -4
View File
@@ -4,7 +4,7 @@
//
// Dart test program for testing dart:ffi primitive data pointers.
//
// These mallocs trigger an asan alarm, so these tests are in a separate file
// These callocs trigger an asan alarm, so these tests are in a separate file
// which is excluded in asan mode.
import 'dart:ffi';
@@ -12,6 +12,8 @@ import 'dart:ffi';
import "package:ffi/ffi.dart";
import "package:expect/expect.dart";
import 'calloc.dart';
void main() {
testPointerAllocateTooLarge();
testPointerAllocateNegative();
@@ -20,16 +22,16 @@ void main() {
void testPointerAllocateTooLarge() {
// Try to allocate something that doesn't fit in 64 bit address space.
int maxInt = 9223372036854775807; // 2^63 - 1
Expect.throws(() => allocate<Int64>(count: maxInt));
Expect.throws(() => calloc<Int64>(maxInt));
// Try to allocate almost the full 64 bit address space.
int maxInt1_8 = 1152921504606846975; // 2^60 -1
Expect.throws(() => allocate<Int64>(count: maxInt1_8));
Expect.throws(() => calloc<Int64>(maxInt1_8));
}
void testPointerAllocateNegative() {
// Passing in -1 will be converted into an unsigned integer. So, it will try
// to allocate SIZE_MAX - 1 + 1 bytes. This will fail as it is the max amount
// of addressable memory on the system.
Expect.throws(() => allocate<Int8>(count: -1));
Expect.throws(() => calloc<Int8>(-1));
}
+70 -69
View File
@@ -11,6 +11,7 @@ import 'dart:ffi';
import "package:expect/expect.dart";
import "package:ffi/ffi.dart";
import 'calloc.dart';
import 'ffi_test_helpers.dart';
void main() {
@@ -56,66 +57,66 @@ void main() {
}
void testPointerBasic() {
Pointer<Int64> p = allocate();
Pointer<Int64> p = calloc();
p.value = 42;
Expect.equals(42, p.value);
free(p);
calloc.free(p);
}
void testPointerFromPointer() {
Pointer<Int64> p = allocate();
Pointer<Int64> p = calloc();
p.value = 1337;
int ptr = p.address;
Pointer<Int64> p2 = Pointer.fromAddress(ptr);
Expect.equals(1337, p2.value);
free(p);
calloc.free(p);
}
void testPointerPointerArithmetic() {
Pointer<Int64> p = allocate(count: 2);
Pointer<Int64> p = calloc(2);
Pointer<Int64> p2 = p.elementAt(1);
p2.value = 100;
Pointer<Int64> p3 = p.offsetBy(8);
Expect.equals(100, p3.value);
free(p);
calloc.free(p);
}
void testPointerPointerArithmeticSizes() {
Pointer<Int64> p = allocate(count: 2);
Pointer<Int64> p = calloc(2);
Pointer<Int64> p2 = p.elementAt(1);
int addr = p.address;
Expect.equals(addr + 8, p2.address);
free(p);
calloc.free(p);
Pointer<Int32> p3 = allocate(count: 2);
Pointer<Int32> p3 = calloc(2);
Pointer<Int32> p4 = p3.elementAt(1);
addr = p3.address;
Expect.equals(addr + 4, p4.address);
free(p3);
calloc.free(p3);
}
void testPointerAllocateZero() {
// > If size is 0, either a null pointer or a unique pointer that can be
// > successfully passed to free() shall be returned.
// http://pubs.opengroup.org/onlinepubs/009695399/functions/malloc.html
// > successfully passed to calloc.free() shall be returned.
// http://pubs.opengroup.org/onlinepubs/009695399/functions/calloc.html
//
// Null pointer throws a Dart exception.
bool returnedNullPointer = false;
Pointer<Int8> p;
try {
p = allocate<Int8>(count: 0);
p = calloc<Int8>(0);
} on Exception {
returnedNullPointer = true;
}
if (!returnedNullPointer) {
free(p);
calloc.free(p);
}
}
void testPointerCast() {
Pointer<Int64> p = allocate();
Pointer<Int64> p = calloc();
p.cast<Int32>(); // gets the correct type args back
free(p);
calloc.free(p);
}
void testCastGeneric() {
@@ -123,9 +124,9 @@ void testCastGeneric() {
return p.cast();
}
Pointer<Int16> p = allocate();
Pointer<Int16> p = calloc();
Pointer<Int64> p2 = generic(p);
free(p);
calloc.free(p);
}
void testCastGeneric2() {
@@ -133,41 +134,41 @@ void testCastGeneric2() {
return p.cast();
}
Pointer<Int16> p = allocate();
Pointer<Int16> p = calloc();
Pointer<Int64> p2 = generic(p);
free(p);
calloc.free(p);
}
void testCastNativeType() {
Pointer<Int64> p = allocate();
Pointer<Int64> p = calloc();
p.cast<Pointer>();
free(p);
calloc.free(p);
}
void testCondensedNumbersInt8() {
Pointer<Int8> p = allocate(count: 8);
Pointer<Int8> p = calloc(8);
for (var i in [0, 1, 2, 3, 4, 5, 6, 7]) {
p[i] = i * 3;
}
for (var i in [0, 1, 2, 3, 4, 5, 6, 7]) {
Expect.equals(i * 3, p[i]);
}
free(p);
calloc.free(p);
}
void testCondensedNumbersFloat() {
Pointer<Float> p = allocate(count: 8);
Pointer<Float> p = calloc(8);
for (var i in [0, 1, 2, 3, 4, 5, 6, 7]) {
p[i] = 1.511366173271439e-13;
}
for (var i in [0, 1, 2, 3, 4, 5, 6, 7]) {
Expect.equals(1.511366173271439e-13, p[i]);
}
free(p);
calloc.free(p);
}
void testRangeInt8() {
Pointer<Int8> p = allocate();
Pointer<Int8> p = calloc();
p.value = 127;
Expect.equals(127, p.value);
p.value = -128;
@@ -182,11 +183,11 @@ void testRangeInt8() {
Expect.equals(0x000000000000007F, 127);
p.value = -129;
Expect.equals(127, p.value); // truncated
free(p);
calloc.free(p);
}
void testRangeUint8() {
Pointer<Uint8> p = allocate();
Pointer<Uint8> p = calloc();
p.value = 255;
Expect.equals(255, p.value);
p.value = 0;
@@ -201,11 +202,11 @@ void testRangeUint8() {
Expect.equals(0x00000000000000FF, 255);
p.value = -1;
Expect.equals(255, p.value); // truncated
free(p);
calloc.free(p);
}
void testRangeInt16() {
Pointer<Int16> p = allocate();
Pointer<Int16> p = calloc();
p.value = 0x7FFF;
Expect.equals(0x7FFF, p.value);
p.value = -0x8000;
@@ -214,11 +215,11 @@ void testRangeInt16() {
Expect.equals(0xFFFFFFFFFFFF8000, p.value); // truncated and sign extended
p.value = -0x8001;
Expect.equals(0x7FFF, p.value); // truncated
free(p);
calloc.free(p);
}
void testRangeUint16() {
Pointer<Uint16> p = allocate();
Pointer<Uint16> p = calloc();
p.value = 0xFFFF;
Expect.equals(0xFFFF, p.value);
p.value = 0;
@@ -227,11 +228,11 @@ void testRangeUint16() {
Expect.equals(0, p.value); // truncated
p.value = -1;
Expect.equals(0xFFFF, p.value); // truncated
free(p);
calloc.free(p);
}
void testRangeInt32() {
Pointer<Int32> p = allocate();
Pointer<Int32> p = calloc();
p.value = 0x7FFFFFFF;
Expect.equals(0x7FFFFFFF, p.value);
p.value = -0x80000000;
@@ -240,11 +241,11 @@ void testRangeInt32() {
Expect.equals(0xFFFFFFFF80000000, p.value); // truncated and sign extended
p.value = -0x80000001;
Expect.equals(0x7FFFFFFF, p.value); // truncated
free(p);
calloc.free(p);
}
void testRangeUint32() {
Pointer<Uint32> p = allocate();
Pointer<Uint32> p = calloc();
p.value = 0xFFFFFFFF;
Expect.equals(0xFFFFFFFF, p.value);
p.value = 0;
@@ -253,20 +254,20 @@ void testRangeUint32() {
Expect.equals(0, p.value); // truncated
p.value = -1;
Expect.equals(0xFFFFFFFF, p.value); // truncated
free(p);
calloc.free(p);
}
void testRangeInt64() {
Pointer<Int64> p = allocate();
Pointer<Int64> p = calloc();
p.value = 0x7FFFFFFFFFFFFFFF; // 2 ^ 63 - 1
Expect.equals(0x7FFFFFFFFFFFFFFF, p.value);
p.value = -0x8000000000000000; // -2 ^ 63
Expect.equals(-0x8000000000000000, p.value);
free(p);
calloc.free(p);
}
void testRangeUint64() {
Pointer<Uint64> p = allocate();
Pointer<Uint64> p = calloc();
p.value = 0x7FFFFFFFFFFFFFFF; // 2 ^ 63 - 1
Expect.equals(0x7FFFFFFFFFFFFFFF, p.value);
p.value = -0x8000000000000000; // -2 ^ 63 interpreted as 2 ^ 63
@@ -277,69 +278,69 @@ void testRangeUint64() {
p.value = -1; // -1 interpreted as 2 ^ 64 - 1
Expect.equals(-1, p.value);
Expect.equals(0xFFFFFFFFFFFFFFFF, p.value);
free(p);
calloc.free(p);
}
void testRangeIntPtr() {
Pointer<IntPtr> p = allocate();
Pointer<IntPtr> p = calloc();
int pAddr = p.address;
p.value = pAddr; // its own address should fit
p.value = 0x7FFFFFFF; // and 32 bit addresses should fit
Expect.equals(0x7FFFFFFF, p.value);
p.value = -0x80000000;
Expect.equals(-0x80000000, p.value);
free(p);
calloc.free(p);
}
void testFloat() {
Pointer<Float> p = allocate();
Pointer<Float> p = calloc();
p.value = 1.511366173271439e-13;
Expect.equals(1.511366173271439e-13, p.value);
p.value = 1.4260258159703532e-105; // float does not have enough precision
Expect.notEquals(1.4260258159703532e-105, p.value);
free(p);
calloc.free(p);
}
void testDouble() {
Pointer<Double> p = allocate();
Pointer<Double> p = calloc();
p.value = 1.4260258159703532e-105;
Expect.equals(1.4260258159703532e-105, p.value);
free(p);
calloc.free(p);
}
void testVoid() {
Pointer<IntPtr> p1 = allocate();
Pointer<IntPtr> p1 = calloc();
Pointer<Void> p2 = p1.cast(); // make this dart pointer opaque
p2.address; // we can print the address
free(p2);
calloc.free(p2);
}
void testPointerPointer() {
Pointer<Int16> p = allocate();
Pointer<Int16> p = calloc();
p.value = 17;
Pointer<Pointer<Int16>> p2 = allocate();
Pointer<Pointer<Int16>> p2 = calloc();
p2.value = p;
Expect.equals(17, p2.value.value);
free(p2);
free(p);
calloc.free(p2);
calloc.free(p);
}
void testPointerPointerNull() {
Pointer<Pointer<Int8>> pointerToPointer = allocate();
Pointer<Pointer<Int8>> pointerToPointer = calloc();
Pointer<Int8> value = nullptr;
pointerToPointer.value = value;
value = pointerToPointer.value;
Expect.equals(value, nullptr);
value = allocate();
value = calloc();
pointerToPointer.value = value;
value = pointerToPointer.value;
Expect.isNotNull(value);
free(value);
calloc.free(value);
value = nullptr;
pointerToPointer.value = value;
value = pointerToPointer.value;
Expect.equals(value, nullptr);
free(pointerToPointer);
calloc.free(pointerToPointer);
}
void testSizeOf() {
@@ -363,7 +364,7 @@ void testPointerChain(int length) {
head.value = value;
return;
}
Pointer<IntPtr> next = allocate();
Pointer<IntPtr> next = calloc();
head.value = next.address;
createChain(next, length - 1, value);
}
@@ -378,14 +379,14 @@ void testPointerChain(int length) {
void freeChain(Pointer<IntPtr> head, int length) {
Pointer<IntPtr> next = Pointer.fromAddress(head.value);
free(head);
calloc.free(head);
if (length == 0) {
return;
}
freeChain(next, length - 1);
}
Pointer<IntPtr> head = allocate();
Pointer<IntPtr> head = calloc();
createChain(head, length, 512);
int tailValue = getChainValue(head, length);
Expect.equals(512, tailValue);
@@ -393,16 +394,16 @@ void testPointerChain(int length) {
}
void testTypeTest() {
Pointer<Int8> p = allocate();
Pointer<Int8> p = calloc();
Expect.isTrue(p is Pointer);
free(p);
calloc.free(p);
}
void testToString() {
Pointer<Int16> p = allocate();
Pointer<Int16> p = calloc();
Expect.stringEquals(
"Pointer<Int16>: address=0x", p.toString().substring(0, 26));
free(p);
calloc.free(p);
Pointer<Int64> p2 = Pointer.fromAddress(0x123abc);
Expect.stringEquals("Pointer<Int64>: address=0x123abc", p2.toString());
}
@@ -423,13 +424,13 @@ typedef Int8UnOp = Int8 Function(Int8);
void testAllocateVoid() {
Expect.throws(() {
Pointer<Void> p = allocate();
Pointer<Void> p = calloc();
});
}
void testAllocateNativeFunction() {
Expect.throws(() {
Pointer<NativeFunction<Int8UnOp>> p = allocate();
Pointer<NativeFunction<Int8UnOp>> p = calloc();
});
}
@@ -463,7 +464,7 @@ void testSizeOfNativeType() {
}
void testDynamicInvocation() {
dynamic p = allocate<Int8>();
dynamic p = calloc<Int8>();
Expect.throws(() {
final int i = p.value;
});
@@ -471,7 +472,7 @@ void testDynamicInvocation() {
p.elementAt(5); // Works, but is slow.
final int addr = p.address;
final Pointer<Int16> p2 = p.cast<Int16>();
free(p);
calloc.free(p);
}
final nullableInt64ElementAt1 = ffiTestFunctions.lookupFunction<
+12 -10
View File
@@ -7,6 +7,8 @@ import 'dart:ffi';
import "package:expect/expect.dart";
import "package:ffi/ffi.dart";
import 'calloc.dart';
main(List<String> arguments) {
for (int i = 0; i < 100; i++) {
testStoreLoad();
@@ -15,7 +17,7 @@ main(List<String> arguments) {
}
testStoreLoad() {
final p = allocate<Int8>(count: 2);
final p = calloc<Int8>(2);
p.value = 10;
Expect.equals(10, p.value);
p[1] = 20;
@@ -30,33 +32,33 @@ testStoreLoad() {
final pUseNegative = p.elementAt(1);
Expect.equals(10, pUseNegative[-1]);
final p1 = allocate<Double>(count: 2);
final p1 = calloc<Double>(2);
p1.value = 10.0;
Expect.approxEquals(10.0, p1.value);
p1[1] = 20.0;
Expect.approxEquals(20.0, p1[1]);
free(p1);
calloc.free(p1);
final p2 = allocate<Pointer<Int8>>(count: 2);
final p2 = calloc<Pointer<Int8>>(2);
p2.value = p;
Expect.equals(p, p2.value);
p2[1] = p;
Expect.equals(p, p2[1]);
free(p2);
free(p);
calloc.free(p2);
calloc.free(p);
final p3 = allocate<Foo>();
final p3 = calloc<Foo>();
Foo foo = p3.ref;
foo.a = 1;
Expect.equals(1, foo.a);
free(p3);
calloc.free(p3);
}
testReifiedGeneric() {
final p = allocate<Pointer<Int8>>();
final p = calloc<Pointer<Int8>>();
Pointer<Pointer<NativeType>> p2 = p;
Expect.isTrue(p2.value is Pointer<Int8>);
free(p);
calloc.free(p);
}
class Foo extends Struct {
+46 -44
View File
@@ -9,6 +9,8 @@ import 'dart:typed_data';
import 'package:expect/expect.dart';
import "package:ffi/ffi.dart";
import 'calloc.dart';
main() {
testInt8Load();
testInt8Store();
@@ -41,162 +43,162 @@ main() {
void testInt8Load() {
// Load
Pointer<Int8> ptr = allocate();
Pointer<Int8> ptr = calloc();
ptr.value = 0xff;
Int8List list = ptr.asTypedList(1);
Expect.equals(list[0], -1);
Expect.equals(list.length, 1);
free(ptr);
calloc.free(ptr);
}
void testInt8Store() {
// Store
Pointer<Int8> ptr = allocate();
Pointer<Int8> ptr = calloc();
Int8List list = ptr.asTypedList(1);
list[0] = 0xff;
Expect.equals(list.length, 1);
Expect.equals(ptr.value, -1);
free(ptr);
calloc.free(ptr);
}
void testUint8Load() {
// Load
Pointer<Uint8> ptr = allocate();
Pointer<Uint8> ptr = calloc();
ptr.value = 0xff;
Uint8List list = ptr.asTypedList(1);
Expect.equals(list[0], 0xff);
Expect.equals(list.length, 1);
free(ptr);
calloc.free(ptr);
}
void testUint8Store() {
// Store
Pointer<Uint8> ptr = allocate();
Pointer<Uint8> ptr = calloc();
Uint8List list = ptr.asTypedList(1);
list[0] = 0xff;
Expect.equals(list.length, 1);
Expect.equals(ptr.value, 0xff);
free(ptr);
calloc.free(ptr);
}
void testInt16Load() {
// Load
Pointer<Int16> ptr = allocate();
Pointer<Int16> ptr = calloc();
ptr.value = 0xffff;
Int16List list = ptr.asTypedList(1);
Expect.equals(list[0], -1);
Expect.equals(list.length, 1);
free(ptr);
calloc.free(ptr);
}
void testInt16Store() {
// Store
Pointer<Int16> ptr = allocate();
Pointer<Int16> ptr = calloc();
Int16List list = ptr.asTypedList(1);
list[0] = 0xffff;
Expect.equals(list.length, 1);
Expect.equals(ptr.value, -1);
free(ptr);
calloc.free(ptr);
}
void testUint16Load() {
// Load
Pointer<Uint16> ptr = allocate();
Pointer<Uint16> ptr = calloc();
ptr.value = 0xffff;
Uint16List list = ptr.asTypedList(1);
Expect.equals(list[0], 0xffff);
Expect.equals(list.length, 1);
free(ptr);
calloc.free(ptr);
}
void testUint16Store() {
// Store
Pointer<Uint16> ptr = allocate();
Pointer<Uint16> ptr = calloc();
Uint16List list = ptr.asTypedList(1);
list[0] = 0xffff;
Expect.equals(list.length, 1);
Expect.equals(ptr.value, 0xffff);
free(ptr);
calloc.free(ptr);
}
void testInt32Load() {
// Load
Pointer<Int32> ptr = allocate();
Pointer<Int32> ptr = calloc();
ptr.value = 0xffffffff;
Int32List list = ptr.asTypedList(1);
Expect.equals(list[0], -1);
Expect.equals(list.length, 1);
free(ptr);
calloc.free(ptr);
}
void testInt32Store() {
// Store
Pointer<Int32> ptr = allocate();
Pointer<Int32> ptr = calloc();
Int32List list = ptr.asTypedList(1);
list[0] = 0xffffffff;
Expect.equals(list.length, 1);
Expect.equals(ptr.value, -1);
free(ptr);
calloc.free(ptr);
}
void testUint32Load() {
// Load
Pointer<Uint32> ptr = allocate();
Pointer<Uint32> ptr = calloc();
ptr.value = 0xffffffff;
Uint32List list = ptr.asTypedList(1);
Expect.equals(list[0], 0xffffffff);
Expect.equals(list.length, 1);
free(ptr);
calloc.free(ptr);
}
void testUint32Store() {
// Store
Pointer<Uint32> ptr = allocate();
Pointer<Uint32> ptr = calloc();
Uint32List list = ptr.asTypedList(1);
list[0] = 0xffffffff;
Expect.equals(list.length, 1);
Expect.equals(ptr.value, 0xffffffff);
free(ptr);
calloc.free(ptr);
}
void testInt64Load() {
// Load
Pointer<Int64> ptr = allocate();
Pointer<Int64> ptr = calloc();
ptr.value = 0xffffffffffffffff;
Int64List list = ptr.asTypedList(1);
Expect.equals(list[0], -1);
Expect.equals(list.length, 1);
free(ptr);
calloc.free(ptr);
}
void testInt64Store() {
// Store
Pointer<Int64> ptr = allocate();
Pointer<Int64> ptr = calloc();
Int64List list = ptr.asTypedList(1);
list[0] = 0xffffffffffffffff;
Expect.equals(list.length, 1);
Expect.equals(ptr.value, -1);
free(ptr);
calloc.free(ptr);
}
void testUint64Load() {
// Load
Pointer<Uint64> ptr = allocate();
Pointer<Uint64> ptr = calloc();
ptr.value = 0xffffffffffffffff;
Uint64List list = ptr.asTypedList(1);
Expect.equals(list[0], 0xffffffffffffffff);
Expect.equals(list.length, 1);
free(ptr);
calloc.free(ptr);
}
void testUint64Store() {
// Store
Pointer<Uint64> ptr = allocate();
Pointer<Uint64> ptr = calloc();
Uint64List list = ptr.asTypedList(1);
list[0] = 0xffffffffffffffff;
Expect.equals(list.length, 1);
Expect.equals(ptr.value, 0xffffffffffffffff);
free(ptr);
calloc.free(ptr);
}
double maxFloat = (2 - pow(2, -23)) * pow(2, 127);
@@ -204,47 +206,47 @@ double maxDouble = (2 - pow(2, -52)) * pow(2, pow(2, 10) - 1);
void testFloatLoad() {
// Load
Pointer<Float> ptr = allocate();
Pointer<Float> ptr = calloc();
ptr.value = maxFloat;
Float32List list = ptr.asTypedList(1);
Expect.equals(list[0], maxFloat);
Expect.equals(list.length, 1);
free(ptr);
calloc.free(ptr);
}
void testFloatStore() {
// Store
Pointer<Float> ptr = allocate();
Pointer<Float> ptr = calloc();
Float32List list = ptr.asTypedList(1);
list[0] = maxFloat;
Expect.equals(list.length, 1);
Expect.equals(ptr.value, maxFloat);
free(ptr);
calloc.free(ptr);
}
void testDoubleLoad() {
// Load
Pointer<Double> ptr = allocate();
Pointer<Double> ptr = calloc();
ptr.value = maxDouble;
Float64List list = ptr.asTypedList(1);
Expect.equals(list[0], maxDouble);
Expect.equals(list.length, 1);
free(ptr);
calloc.free(ptr);
}
void testDoubleStore() {
// Store
Pointer<Double> ptr = allocate();
Pointer<Double> ptr = calloc();
Float64List list = ptr.asTypedList(1);
list[0] = maxDouble;
Expect.equals(list.length, 1);
Expect.equals(ptr.value, maxDouble);
free(ptr);
calloc.free(ptr);
}
void testArrayLoad() {
const int count = 0x100;
Pointer<Int32> ptr = allocate(count: count);
Pointer<Int32> ptr = calloc(count);
for (int i = 0; i < count; ++i) {
ptr[i] = i;
}
@@ -252,12 +254,12 @@ void testArrayLoad() {
for (int i = 0; i < count; ++i) {
Expect.equals(array[i], i);
}
free(ptr);
calloc.free(ptr);
}
void testArrayStore() {
const int count = 0x100;
Pointer<Int32> ptr = allocate(count: count);
Pointer<Int32> ptr = calloc(count);
Int32List array = ptr.asTypedList(count);
for (int i = 0; i < count; ++i) {
array[i] = i;
@@ -265,7 +267,7 @@ void testArrayStore() {
for (int i = 0; i < count; ++i) {
Expect.equals(ptr[i], i);
}
free(ptr);
calloc.free(ptr);
}
void testNegativeArray() {
@@ -16,6 +16,7 @@ import "package:expect/expect.dart";
import "package:ffi/ffi.dart";
import 'callback_tests_utils.dart';
import 'calloc.dart';
// Reuse the struct classes.
import 'function_structs_by_value_generated_test.dart';
@@ -5412,7 +5413,7 @@ int returnStruct1ByteInt_a0 = 0;
Struct1ByteInt returnStruct1ByteIntResult = Struct1ByteInt();
Struct1ByteInt returnStruct1ByteIntCalculateResult() {
Struct1ByteInt result = allocate<Struct1ByteInt>().ref;
Struct1ByteInt result = calloc<Struct1ByteInt>().ref;
result.a0 = returnStruct1ByteInt_a0;
@@ -5447,13 +5448,13 @@ Struct1ByteInt returnStruct1ByteInt(int a0) {
}
void returnStruct1ByteIntAfterCallback() {
free(returnStruct1ByteIntResult.addressOf);
calloc.free(returnStruct1ByteIntResult.addressOf);
final result = returnStruct1ByteIntCalculateResult();
print("after callback result = $result");
free(returnStruct1ByteIntResult.addressOf);
calloc.free(returnStruct1ByteIntResult.addressOf);
}
typedef ReturnStruct3BytesHomogeneousUint8Type = Struct3BytesHomogeneousUint8
@@ -5471,7 +5472,7 @@ Struct3BytesHomogeneousUint8 returnStruct3BytesHomogeneousUint8Result =
Struct3BytesHomogeneousUint8
returnStruct3BytesHomogeneousUint8CalculateResult() {
Struct3BytesHomogeneousUint8 result =
allocate<Struct3BytesHomogeneousUint8>().ref;
calloc<Struct3BytesHomogeneousUint8>().ref;
result.a0 = returnStruct3BytesHomogeneousUint8_a0;
result.a1 = returnStruct3BytesHomogeneousUint8_a1;
@@ -5511,13 +5512,13 @@ Struct3BytesHomogeneousUint8 returnStruct3BytesHomogeneousUint8(
}
void returnStruct3BytesHomogeneousUint8AfterCallback() {
free(returnStruct3BytesHomogeneousUint8Result.addressOf);
calloc.free(returnStruct3BytesHomogeneousUint8Result.addressOf);
final result = returnStruct3BytesHomogeneousUint8CalculateResult();
print("after callback result = $result");
free(returnStruct3BytesHomogeneousUint8Result.addressOf);
calloc.free(returnStruct3BytesHomogeneousUint8Result.addressOf);
}
typedef ReturnStruct3BytesInt2ByteAlignedType = Struct3BytesInt2ByteAligned
@@ -5533,7 +5534,7 @@ Struct3BytesInt2ByteAligned returnStruct3BytesInt2ByteAlignedResult =
Struct3BytesInt2ByteAligned returnStruct3BytesInt2ByteAlignedCalculateResult() {
Struct3BytesInt2ByteAligned result =
allocate<Struct3BytesInt2ByteAligned>().ref;
calloc<Struct3BytesInt2ByteAligned>().ref;
result.a0 = returnStruct3BytesInt2ByteAligned_a0;
result.a1 = returnStruct3BytesInt2ByteAligned_a1;
@@ -5571,13 +5572,13 @@ Struct3BytesInt2ByteAligned returnStruct3BytesInt2ByteAligned(int a0, int a1) {
}
void returnStruct3BytesInt2ByteAlignedAfterCallback() {
free(returnStruct3BytesInt2ByteAlignedResult.addressOf);
calloc.free(returnStruct3BytesInt2ByteAlignedResult.addressOf);
final result = returnStruct3BytesInt2ByteAlignedCalculateResult();
print("after callback result = $result");
free(returnStruct3BytesInt2ByteAlignedResult.addressOf);
calloc.free(returnStruct3BytesInt2ByteAlignedResult.addressOf);
}
typedef ReturnStruct4BytesHomogeneousInt16Type = Struct4BytesHomogeneousInt16
@@ -5594,7 +5595,7 @@ Struct4BytesHomogeneousInt16 returnStruct4BytesHomogeneousInt16Result =
Struct4BytesHomogeneousInt16
returnStruct4BytesHomogeneousInt16CalculateResult() {
Struct4BytesHomogeneousInt16 result =
allocate<Struct4BytesHomogeneousInt16>().ref;
calloc<Struct4BytesHomogeneousInt16>().ref;
result.a0 = returnStruct4BytesHomogeneousInt16_a0;
result.a1 = returnStruct4BytesHomogeneousInt16_a1;
@@ -5632,13 +5633,13 @@ Struct4BytesHomogeneousInt16 returnStruct4BytesHomogeneousInt16(
}
void returnStruct4BytesHomogeneousInt16AfterCallback() {
free(returnStruct4BytesHomogeneousInt16Result.addressOf);
calloc.free(returnStruct4BytesHomogeneousInt16Result.addressOf);
final result = returnStruct4BytesHomogeneousInt16CalculateResult();
print("after callback result = $result");
free(returnStruct4BytesHomogeneousInt16Result.addressOf);
calloc.free(returnStruct4BytesHomogeneousInt16Result.addressOf);
}
typedef ReturnStruct7BytesHomogeneousUint8Type = Struct7BytesHomogeneousUint8
@@ -5660,7 +5661,7 @@ Struct7BytesHomogeneousUint8 returnStruct7BytesHomogeneousUint8Result =
Struct7BytesHomogeneousUint8
returnStruct7BytesHomogeneousUint8CalculateResult() {
Struct7BytesHomogeneousUint8 result =
allocate<Struct7BytesHomogeneousUint8>().ref;
calloc<Struct7BytesHomogeneousUint8>().ref;
result.a0 = returnStruct7BytesHomogeneousUint8_a0;
result.a1 = returnStruct7BytesHomogeneousUint8_a1;
@@ -5709,13 +5710,13 @@ Struct7BytesHomogeneousUint8 returnStruct7BytesHomogeneousUint8(
}
void returnStruct7BytesHomogeneousUint8AfterCallback() {
free(returnStruct7BytesHomogeneousUint8Result.addressOf);
calloc.free(returnStruct7BytesHomogeneousUint8Result.addressOf);
final result = returnStruct7BytesHomogeneousUint8CalculateResult();
print("after callback result = $result");
free(returnStruct7BytesHomogeneousUint8Result.addressOf);
calloc.free(returnStruct7BytesHomogeneousUint8Result.addressOf);
}
typedef ReturnStruct7BytesInt4ByteAlignedType = Struct7BytesInt4ByteAligned
@@ -5732,7 +5733,7 @@ Struct7BytesInt4ByteAligned returnStruct7BytesInt4ByteAlignedResult =
Struct7BytesInt4ByteAligned returnStruct7BytesInt4ByteAlignedCalculateResult() {
Struct7BytesInt4ByteAligned result =
allocate<Struct7BytesInt4ByteAligned>().ref;
calloc<Struct7BytesInt4ByteAligned>().ref;
result.a0 = returnStruct7BytesInt4ByteAligned_a0;
result.a1 = returnStruct7BytesInt4ByteAligned_a1;
@@ -5773,13 +5774,13 @@ Struct7BytesInt4ByteAligned returnStruct7BytesInt4ByteAligned(
}
void returnStruct7BytesInt4ByteAlignedAfterCallback() {
free(returnStruct7BytesInt4ByteAlignedResult.addressOf);
calloc.free(returnStruct7BytesInt4ByteAlignedResult.addressOf);
final result = returnStruct7BytesInt4ByteAlignedCalculateResult();
print("after callback result = $result");
free(returnStruct7BytesInt4ByteAlignedResult.addressOf);
calloc.free(returnStruct7BytesInt4ByteAlignedResult.addressOf);
}
typedef ReturnStruct8BytesIntType = Struct8BytesInt Function(
@@ -5794,7 +5795,7 @@ int returnStruct8BytesInt_a2 = 0;
Struct8BytesInt returnStruct8BytesIntResult = Struct8BytesInt();
Struct8BytesInt returnStruct8BytesIntCalculateResult() {
Struct8BytesInt result = allocate<Struct8BytesInt>().ref;
Struct8BytesInt result = calloc<Struct8BytesInt>().ref;
result.a0 = returnStruct8BytesInt_a0;
result.a1 = returnStruct8BytesInt_a1;
@@ -5833,13 +5834,13 @@ Struct8BytesInt returnStruct8BytesInt(int a0, int a1, int a2) {
}
void returnStruct8BytesIntAfterCallback() {
free(returnStruct8BytesIntResult.addressOf);
calloc.free(returnStruct8BytesIntResult.addressOf);
final result = returnStruct8BytesIntCalculateResult();
print("after callback result = $result");
free(returnStruct8BytesIntResult.addressOf);
calloc.free(returnStruct8BytesIntResult.addressOf);
}
typedef ReturnStruct8BytesHomogeneousFloatType = Struct8BytesHomogeneousFloat
@@ -5856,7 +5857,7 @@ Struct8BytesHomogeneousFloat returnStruct8BytesHomogeneousFloatResult =
Struct8BytesHomogeneousFloat
returnStruct8BytesHomogeneousFloatCalculateResult() {
Struct8BytesHomogeneousFloat result =
allocate<Struct8BytesHomogeneousFloat>().ref;
calloc<Struct8BytesHomogeneousFloat>().ref;
result.a0 = returnStruct8BytesHomogeneousFloat_a0;
result.a1 = returnStruct8BytesHomogeneousFloat_a1;
@@ -5894,13 +5895,13 @@ Struct8BytesHomogeneousFloat returnStruct8BytesHomogeneousFloat(
}
void returnStruct8BytesHomogeneousFloatAfterCallback() {
free(returnStruct8BytesHomogeneousFloatResult.addressOf);
calloc.free(returnStruct8BytesHomogeneousFloatResult.addressOf);
final result = returnStruct8BytesHomogeneousFloatCalculateResult();
print("after callback result = $result");
free(returnStruct8BytesHomogeneousFloatResult.addressOf);
calloc.free(returnStruct8BytesHomogeneousFloatResult.addressOf);
}
typedef ReturnStruct8BytesMixedType = Struct8BytesMixed Function(
@@ -5915,7 +5916,7 @@ int returnStruct8BytesMixed_a2 = 0;
Struct8BytesMixed returnStruct8BytesMixedResult = Struct8BytesMixed();
Struct8BytesMixed returnStruct8BytesMixedCalculateResult() {
Struct8BytesMixed result = allocate<Struct8BytesMixed>().ref;
Struct8BytesMixed result = calloc<Struct8BytesMixed>().ref;
result.a0 = returnStruct8BytesMixed_a0;
result.a1 = returnStruct8BytesMixed_a1;
@@ -5954,13 +5955,13 @@ Struct8BytesMixed returnStruct8BytesMixed(double a0, int a1, int a2) {
}
void returnStruct8BytesMixedAfterCallback() {
free(returnStruct8BytesMixedResult.addressOf);
calloc.free(returnStruct8BytesMixedResult.addressOf);
final result = returnStruct8BytesMixedCalculateResult();
print("after callback result = $result");
free(returnStruct8BytesMixedResult.addressOf);
calloc.free(returnStruct8BytesMixedResult.addressOf);
}
typedef ReturnStruct9BytesHomogeneousUint8Type = Struct9BytesHomogeneousUint8
@@ -5984,7 +5985,7 @@ Struct9BytesHomogeneousUint8 returnStruct9BytesHomogeneousUint8Result =
Struct9BytesHomogeneousUint8
returnStruct9BytesHomogeneousUint8CalculateResult() {
Struct9BytesHomogeneousUint8 result =
allocate<Struct9BytesHomogeneousUint8>().ref;
calloc<Struct9BytesHomogeneousUint8>().ref;
result.a0 = returnStruct9BytesHomogeneousUint8_a0;
result.a1 = returnStruct9BytesHomogeneousUint8_a1;
@@ -6039,13 +6040,13 @@ Struct9BytesHomogeneousUint8 returnStruct9BytesHomogeneousUint8(
}
void returnStruct9BytesHomogeneousUint8AfterCallback() {
free(returnStruct9BytesHomogeneousUint8Result.addressOf);
calloc.free(returnStruct9BytesHomogeneousUint8Result.addressOf);
final result = returnStruct9BytesHomogeneousUint8CalculateResult();
print("after callback result = $result");
free(returnStruct9BytesHomogeneousUint8Result.addressOf);
calloc.free(returnStruct9BytesHomogeneousUint8Result.addressOf);
}
typedef ReturnStruct9BytesInt4Or8ByteAlignedType
@@ -6062,7 +6063,7 @@ Struct9BytesInt4Or8ByteAligned returnStruct9BytesInt4Or8ByteAlignedResult =
Struct9BytesInt4Or8ByteAligned
returnStruct9BytesInt4Or8ByteAlignedCalculateResult() {
Struct9BytesInt4Or8ByteAligned result =
allocate<Struct9BytesInt4Or8ByteAligned>().ref;
calloc<Struct9BytesInt4Or8ByteAligned>().ref;
result.a0 = returnStruct9BytesInt4Or8ByteAligned_a0;
result.a1 = returnStruct9BytesInt4Or8ByteAligned_a1;
@@ -6102,13 +6103,13 @@ Struct9BytesInt4Or8ByteAligned returnStruct9BytesInt4Or8ByteAligned(
}
void returnStruct9BytesInt4Or8ByteAlignedAfterCallback() {
free(returnStruct9BytesInt4Or8ByteAlignedResult.addressOf);
calloc.free(returnStruct9BytesInt4Or8ByteAlignedResult.addressOf);
final result = returnStruct9BytesInt4Or8ByteAlignedCalculateResult();
print("after callback result = $result");
free(returnStruct9BytesInt4Or8ByteAlignedResult.addressOf);
calloc.free(returnStruct9BytesInt4Or8ByteAlignedResult.addressOf);
}
typedef ReturnStruct12BytesHomogeneousFloatType = Struct12BytesHomogeneousFloat
@@ -6126,7 +6127,7 @@ Struct12BytesHomogeneousFloat returnStruct12BytesHomogeneousFloatResult =
Struct12BytesHomogeneousFloat
returnStruct12BytesHomogeneousFloatCalculateResult() {
Struct12BytesHomogeneousFloat result =
allocate<Struct12BytesHomogeneousFloat>().ref;
calloc<Struct12BytesHomogeneousFloat>().ref;
result.a0 = returnStruct12BytesHomogeneousFloat_a0;
result.a1 = returnStruct12BytesHomogeneousFloat_a1;
@@ -6167,13 +6168,13 @@ Struct12BytesHomogeneousFloat returnStruct12BytesHomogeneousFloat(
}
void returnStruct12BytesHomogeneousFloatAfterCallback() {
free(returnStruct12BytesHomogeneousFloatResult.addressOf);
calloc.free(returnStruct12BytesHomogeneousFloatResult.addressOf);
final result = returnStruct12BytesHomogeneousFloatCalculateResult();
print("after callback result = $result");
free(returnStruct12BytesHomogeneousFloatResult.addressOf);
calloc.free(returnStruct12BytesHomogeneousFloatResult.addressOf);
}
typedef ReturnStruct16BytesHomogeneousFloatType = Struct16BytesHomogeneousFloat
@@ -6192,7 +6193,7 @@ Struct16BytesHomogeneousFloat returnStruct16BytesHomogeneousFloatResult =
Struct16BytesHomogeneousFloat
returnStruct16BytesHomogeneousFloatCalculateResult() {
Struct16BytesHomogeneousFloat result =
allocate<Struct16BytesHomogeneousFloat>().ref;
calloc<Struct16BytesHomogeneousFloat>().ref;
result.a0 = returnStruct16BytesHomogeneousFloat_a0;
result.a1 = returnStruct16BytesHomogeneousFloat_a1;
@@ -6234,13 +6235,13 @@ Struct16BytesHomogeneousFloat returnStruct16BytesHomogeneousFloat(
}
void returnStruct16BytesHomogeneousFloatAfterCallback() {
free(returnStruct16BytesHomogeneousFloatResult.addressOf);
calloc.free(returnStruct16BytesHomogeneousFloatResult.addressOf);
final result = returnStruct16BytesHomogeneousFloatCalculateResult();
print("after callback result = $result");
free(returnStruct16BytesHomogeneousFloatResult.addressOf);
calloc.free(returnStruct16BytesHomogeneousFloatResult.addressOf);
}
typedef ReturnStruct16BytesMixedType = Struct16BytesMixed Function(
@@ -6254,7 +6255,7 @@ int returnStruct16BytesMixed_a1 = 0;
Struct16BytesMixed returnStruct16BytesMixedResult = Struct16BytesMixed();
Struct16BytesMixed returnStruct16BytesMixedCalculateResult() {
Struct16BytesMixed result = allocate<Struct16BytesMixed>().ref;
Struct16BytesMixed result = calloc<Struct16BytesMixed>().ref;
result.a0 = returnStruct16BytesMixed_a0;
result.a1 = returnStruct16BytesMixed_a1;
@@ -6291,13 +6292,13 @@ Struct16BytesMixed returnStruct16BytesMixed(double a0, int a1) {
}
void returnStruct16BytesMixedAfterCallback() {
free(returnStruct16BytesMixedResult.addressOf);
calloc.free(returnStruct16BytesMixedResult.addressOf);
final result = returnStruct16BytesMixedCalculateResult();
print("after callback result = $result");
free(returnStruct16BytesMixedResult.addressOf);
calloc.free(returnStruct16BytesMixedResult.addressOf);
}
typedef ReturnStruct16BytesMixed2Type = Struct16BytesMixed2 Function(
@@ -6313,7 +6314,7 @@ int returnStruct16BytesMixed2_a3 = 0;
Struct16BytesMixed2 returnStruct16BytesMixed2Result = Struct16BytesMixed2();
Struct16BytesMixed2 returnStruct16BytesMixed2CalculateResult() {
Struct16BytesMixed2 result = allocate<Struct16BytesMixed2>().ref;
Struct16BytesMixed2 result = calloc<Struct16BytesMixed2>().ref;
result.a0 = returnStruct16BytesMixed2_a0;
result.a1 = returnStruct16BytesMixed2_a1;
@@ -6356,13 +6357,13 @@ Struct16BytesMixed2 returnStruct16BytesMixed2(
}
void returnStruct16BytesMixed2AfterCallback() {
free(returnStruct16BytesMixed2Result.addressOf);
calloc.free(returnStruct16BytesMixed2Result.addressOf);
final result = returnStruct16BytesMixed2CalculateResult();
print("after callback result = $result");
free(returnStruct16BytesMixed2Result.addressOf);
calloc.free(returnStruct16BytesMixed2Result.addressOf);
}
typedef ReturnStruct17BytesIntType = Struct17BytesInt Function(
@@ -6377,7 +6378,7 @@ int returnStruct17BytesInt_a2 = 0;
Struct17BytesInt returnStruct17BytesIntResult = Struct17BytesInt();
Struct17BytesInt returnStruct17BytesIntCalculateResult() {
Struct17BytesInt result = allocate<Struct17BytesInt>().ref;
Struct17BytesInt result = calloc<Struct17BytesInt>().ref;
result.a0 = returnStruct17BytesInt_a0;
result.a1 = returnStruct17BytesInt_a1;
@@ -6418,13 +6419,13 @@ Struct17BytesInt returnStruct17BytesInt(int a0, int a1, int a2) {
}
void returnStruct17BytesIntAfterCallback() {
free(returnStruct17BytesIntResult.addressOf);
calloc.free(returnStruct17BytesIntResult.addressOf);
final result = returnStruct17BytesIntCalculateResult();
print("after callback result = $result");
free(returnStruct17BytesIntResult.addressOf);
calloc.free(returnStruct17BytesIntResult.addressOf);
}
typedef ReturnStruct19BytesHomogeneousUint8Type
@@ -6477,7 +6478,7 @@ Struct19BytesHomogeneousUint8 returnStruct19BytesHomogeneousUint8Result =
Struct19BytesHomogeneousUint8
returnStruct19BytesHomogeneousUint8CalculateResult() {
Struct19BytesHomogeneousUint8 result =
allocate<Struct19BytesHomogeneousUint8>().ref;
calloc<Struct19BytesHomogeneousUint8>().ref;
result.a0 = returnStruct19BytesHomogeneousUint8_a0;
result.a1 = returnStruct19BytesHomogeneousUint8_a1;
@@ -6570,13 +6571,13 @@ Struct19BytesHomogeneousUint8 returnStruct19BytesHomogeneousUint8(
}
void returnStruct19BytesHomogeneousUint8AfterCallback() {
free(returnStruct19BytesHomogeneousUint8Result.addressOf);
calloc.free(returnStruct19BytesHomogeneousUint8Result.addressOf);
final result = returnStruct19BytesHomogeneousUint8CalculateResult();
print("after callback result = $result");
free(returnStruct19BytesHomogeneousUint8Result.addressOf);
calloc.free(returnStruct19BytesHomogeneousUint8Result.addressOf);
}
typedef ReturnStruct20BytesHomogeneousInt32Type = Struct20BytesHomogeneousInt32
@@ -6596,7 +6597,7 @@ Struct20BytesHomogeneousInt32 returnStruct20BytesHomogeneousInt32Result =
Struct20BytesHomogeneousInt32
returnStruct20BytesHomogeneousInt32CalculateResult() {
Struct20BytesHomogeneousInt32 result =
allocate<Struct20BytesHomogeneousInt32>().ref;
calloc<Struct20BytesHomogeneousInt32>().ref;
result.a0 = returnStruct20BytesHomogeneousInt32_a0;
result.a1 = returnStruct20BytesHomogeneousInt32_a1;
@@ -6641,13 +6642,13 @@ Struct20BytesHomogeneousInt32 returnStruct20BytesHomogeneousInt32(
}
void returnStruct20BytesHomogeneousInt32AfterCallback() {
free(returnStruct20BytesHomogeneousInt32Result.addressOf);
calloc.free(returnStruct20BytesHomogeneousInt32Result.addressOf);
final result = returnStruct20BytesHomogeneousInt32CalculateResult();
print("after callback result = $result");
free(returnStruct20BytesHomogeneousInt32Result.addressOf);
calloc.free(returnStruct20BytesHomogeneousInt32Result.addressOf);
}
typedef ReturnStruct20BytesHomogeneousFloatType = Struct20BytesHomogeneousFloat
@@ -6667,7 +6668,7 @@ Struct20BytesHomogeneousFloat returnStruct20BytesHomogeneousFloatResult =
Struct20BytesHomogeneousFloat
returnStruct20BytesHomogeneousFloatCalculateResult() {
Struct20BytesHomogeneousFloat result =
allocate<Struct20BytesHomogeneousFloat>().ref;
calloc<Struct20BytesHomogeneousFloat>().ref;
result.a0 = returnStruct20BytesHomogeneousFloat_a0;
result.a1 = returnStruct20BytesHomogeneousFloat_a1;
@@ -6712,13 +6713,13 @@ Struct20BytesHomogeneousFloat returnStruct20BytesHomogeneousFloat(
}
void returnStruct20BytesHomogeneousFloatAfterCallback() {
free(returnStruct20BytesHomogeneousFloatResult.addressOf);
calloc.free(returnStruct20BytesHomogeneousFloatResult.addressOf);
final result = returnStruct20BytesHomogeneousFloatCalculateResult();
print("after callback result = $result");
free(returnStruct20BytesHomogeneousFloatResult.addressOf);
calloc.free(returnStruct20BytesHomogeneousFloatResult.addressOf);
}
typedef ReturnStruct32BytesHomogeneousDoubleType
@@ -6737,7 +6738,7 @@ Struct32BytesHomogeneousDouble returnStruct32BytesHomogeneousDoubleResult =
Struct32BytesHomogeneousDouble
returnStruct32BytesHomogeneousDoubleCalculateResult() {
Struct32BytesHomogeneousDouble result =
allocate<Struct32BytesHomogeneousDouble>().ref;
calloc<Struct32BytesHomogeneousDouble>().ref;
result.a0 = returnStruct32BytesHomogeneousDouble_a0;
result.a1 = returnStruct32BytesHomogeneousDouble_a1;
@@ -6780,13 +6781,13 @@ Struct32BytesHomogeneousDouble returnStruct32BytesHomogeneousDouble(
}
void returnStruct32BytesHomogeneousDoubleAfterCallback() {
free(returnStruct32BytesHomogeneousDoubleResult.addressOf);
calloc.free(returnStruct32BytesHomogeneousDoubleResult.addressOf);
final result = returnStruct32BytesHomogeneousDoubleCalculateResult();
print("after callback result = $result");
free(returnStruct32BytesHomogeneousDoubleResult.addressOf);
calloc.free(returnStruct32BytesHomogeneousDoubleResult.addressOf);
}
typedef ReturnStruct40BytesHomogeneousDoubleType
@@ -6807,7 +6808,7 @@ Struct40BytesHomogeneousDouble returnStruct40BytesHomogeneousDoubleResult =
Struct40BytesHomogeneousDouble
returnStruct40BytesHomogeneousDoubleCalculateResult() {
Struct40BytesHomogeneousDouble result =
allocate<Struct40BytesHomogeneousDouble>().ref;
calloc<Struct40BytesHomogeneousDouble>().ref;
result.a0 = returnStruct40BytesHomogeneousDouble_a0;
result.a1 = returnStruct40BytesHomogeneousDouble_a1;
@@ -6853,13 +6854,13 @@ Struct40BytesHomogeneousDouble returnStruct40BytesHomogeneousDouble(
}
void returnStruct40BytesHomogeneousDoubleAfterCallback() {
free(returnStruct40BytesHomogeneousDoubleResult.addressOf);
calloc.free(returnStruct40BytesHomogeneousDoubleResult.addressOf);
final result = returnStruct40BytesHomogeneousDoubleCalculateResult();
print("after callback result = $result");
free(returnStruct40BytesHomogeneousDoubleResult.addressOf);
calloc.free(returnStruct40BytesHomogeneousDoubleResult.addressOf);
}
typedef ReturnStruct1024BytesHomogeneousUint64Type
@@ -7130,7 +7131,7 @@ Struct1024BytesHomogeneousUint64 returnStruct1024BytesHomogeneousUint64Result =
Struct1024BytesHomogeneousUint64
returnStruct1024BytesHomogeneousUint64CalculateResult() {
Struct1024BytesHomogeneousUint64 result =
allocate<Struct1024BytesHomogeneousUint64>().ref;
calloc<Struct1024BytesHomogeneousUint64>().ref;
result.a0 = returnStruct1024BytesHomogeneousUint64_a0;
result.a1 = returnStruct1024BytesHomogeneousUint64_a1;
@@ -7549,13 +7550,13 @@ Struct1024BytesHomogeneousUint64 returnStruct1024BytesHomogeneousUint64(
}
void returnStruct1024BytesHomogeneousUint64AfterCallback() {
free(returnStruct1024BytesHomogeneousUint64Result.addressOf);
calloc.free(returnStruct1024BytesHomogeneousUint64Result.addressOf);
final result = returnStruct1024BytesHomogeneousUint64CalculateResult();
print("after callback result = $result");
free(returnStruct1024BytesHomogeneousUint64Result.addressOf);
calloc.free(returnStruct1024BytesHomogeneousUint64Result.addressOf);
}
typedef ReturnStructArgumentStruct1ByteIntType = Struct1ByteInt Function(
@@ -7894,7 +7895,7 @@ int returnStructAlignmentInt16_a2 = 0;
StructAlignmentInt16 returnStructAlignmentInt16Result = StructAlignmentInt16();
StructAlignmentInt16 returnStructAlignmentInt16CalculateResult() {
StructAlignmentInt16 result = allocate<StructAlignmentInt16>().ref;
StructAlignmentInt16 result = calloc<StructAlignmentInt16>().ref;
result.a0 = returnStructAlignmentInt16_a0;
result.a1 = returnStructAlignmentInt16_a1;
@@ -7933,13 +7934,13 @@ StructAlignmentInt16 returnStructAlignmentInt16(int a0, int a1, int a2) {
}
void returnStructAlignmentInt16AfterCallback() {
free(returnStructAlignmentInt16Result.addressOf);
calloc.free(returnStructAlignmentInt16Result.addressOf);
final result = returnStructAlignmentInt16CalculateResult();
print("after callback result = $result");
free(returnStructAlignmentInt16Result.addressOf);
calloc.free(returnStructAlignmentInt16Result.addressOf);
}
typedef ReturnStructAlignmentInt32Type = StructAlignmentInt32 Function(
@@ -7954,7 +7955,7 @@ int returnStructAlignmentInt32_a2 = 0;
StructAlignmentInt32 returnStructAlignmentInt32Result = StructAlignmentInt32();
StructAlignmentInt32 returnStructAlignmentInt32CalculateResult() {
StructAlignmentInt32 result = allocate<StructAlignmentInt32>().ref;
StructAlignmentInt32 result = calloc<StructAlignmentInt32>().ref;
result.a0 = returnStructAlignmentInt32_a0;
result.a1 = returnStructAlignmentInt32_a1;
@@ -7993,13 +7994,13 @@ StructAlignmentInt32 returnStructAlignmentInt32(int a0, int a1, int a2) {
}
void returnStructAlignmentInt32AfterCallback() {
free(returnStructAlignmentInt32Result.addressOf);
calloc.free(returnStructAlignmentInt32Result.addressOf);
final result = returnStructAlignmentInt32CalculateResult();
print("after callback result = $result");
free(returnStructAlignmentInt32Result.addressOf);
calloc.free(returnStructAlignmentInt32Result.addressOf);
}
typedef ReturnStructAlignmentInt64Type = StructAlignmentInt64 Function(
@@ -8014,7 +8015,7 @@ int returnStructAlignmentInt64_a2 = 0;
StructAlignmentInt64 returnStructAlignmentInt64Result = StructAlignmentInt64();
StructAlignmentInt64 returnStructAlignmentInt64CalculateResult() {
StructAlignmentInt64 result = allocate<StructAlignmentInt64>().ref;
StructAlignmentInt64 result = calloc<StructAlignmentInt64>().ref;
result.a0 = returnStructAlignmentInt64_a0;
result.a1 = returnStructAlignmentInt64_a1;
@@ -8053,13 +8054,13 @@ StructAlignmentInt64 returnStructAlignmentInt64(int a0, int a1, int a2) {
}
void returnStructAlignmentInt64AfterCallback() {
free(returnStructAlignmentInt64Result.addressOf);
calloc.free(returnStructAlignmentInt64Result.addressOf);
final result = returnStructAlignmentInt64CalculateResult();
print("after callback result = $result");
free(returnStructAlignmentInt64Result.addressOf);
calloc.free(returnStructAlignmentInt64Result.addressOf);
}
typedef ReturnStruct8BytesNestedIntType = Struct8BytesNestedInt Function(
@@ -8076,7 +8077,7 @@ Struct8BytesNestedInt returnStruct8BytesNestedIntResult =
Struct8BytesNestedInt();
Struct8BytesNestedInt returnStruct8BytesNestedIntCalculateResult() {
Struct8BytesNestedInt result = allocate<Struct8BytesNestedInt>().ref;
Struct8BytesNestedInt result = calloc<Struct8BytesNestedInt>().ref;
result.a0.a0 = returnStruct8BytesNestedInt_a0.a0;
result.a0.a1 = returnStruct8BytesNestedInt_a0.a1;
@@ -8116,13 +8117,13 @@ Struct8BytesNestedInt returnStruct8BytesNestedInt(
}
void returnStruct8BytesNestedIntAfterCallback() {
free(returnStruct8BytesNestedIntResult.addressOf);
calloc.free(returnStruct8BytesNestedIntResult.addressOf);
final result = returnStruct8BytesNestedIntCalculateResult();
print("after callback result = $result");
free(returnStruct8BytesNestedIntResult.addressOf);
calloc.free(returnStruct8BytesNestedIntResult.addressOf);
}
typedef ReturnStruct8BytesNestedFloatType = Struct8BytesNestedFloat Function(
@@ -8137,7 +8138,7 @@ Struct8BytesNestedFloat returnStruct8BytesNestedFloatResult =
Struct8BytesNestedFloat();
Struct8BytesNestedFloat returnStruct8BytesNestedFloatCalculateResult() {
Struct8BytesNestedFloat result = allocate<Struct8BytesNestedFloat>().ref;
Struct8BytesNestedFloat result = calloc<Struct8BytesNestedFloat>().ref;
result.a0.a0 = returnStruct8BytesNestedFloat_a0.a0;
result.a1.a0 = returnStruct8BytesNestedFloat_a1.a0;
@@ -8175,13 +8176,13 @@ Struct8BytesNestedFloat returnStruct8BytesNestedFloat(
}
void returnStruct8BytesNestedFloatAfterCallback() {
free(returnStruct8BytesNestedFloatResult.addressOf);
calloc.free(returnStruct8BytesNestedFloatResult.addressOf);
final result = returnStruct8BytesNestedFloatCalculateResult();
print("after callback result = $result");
free(returnStruct8BytesNestedFloatResult.addressOf);
calloc.free(returnStruct8BytesNestedFloatResult.addressOf);
}
typedef ReturnStruct8BytesNestedFloat2Type = Struct8BytesNestedFloat2 Function(
@@ -8196,7 +8197,7 @@ Struct8BytesNestedFloat2 returnStruct8BytesNestedFloat2Result =
Struct8BytesNestedFloat2();
Struct8BytesNestedFloat2 returnStruct8BytesNestedFloat2CalculateResult() {
Struct8BytesNestedFloat2 result = allocate<Struct8BytesNestedFloat2>().ref;
Struct8BytesNestedFloat2 result = calloc<Struct8BytesNestedFloat2>().ref;
result.a0.a0 = returnStruct8BytesNestedFloat2_a0.a0;
result.a1 = returnStruct8BytesNestedFloat2_a1;
@@ -8235,13 +8236,13 @@ Struct8BytesNestedFloat2 returnStruct8BytesNestedFloat2(
}
void returnStruct8BytesNestedFloat2AfterCallback() {
free(returnStruct8BytesNestedFloat2Result.addressOf);
calloc.free(returnStruct8BytesNestedFloat2Result.addressOf);
final result = returnStruct8BytesNestedFloat2CalculateResult();
print("after callback result = $result");
free(returnStruct8BytesNestedFloat2Result.addressOf);
calloc.free(returnStruct8BytesNestedFloat2Result.addressOf);
}
typedef ReturnStruct8BytesNestedMixedType = Struct8BytesNestedMixed Function(
@@ -8257,7 +8258,7 @@ Struct8BytesNestedMixed returnStruct8BytesNestedMixedResult =
Struct8BytesNestedMixed();
Struct8BytesNestedMixed returnStruct8BytesNestedMixedCalculateResult() {
Struct8BytesNestedMixed result = allocate<Struct8BytesNestedMixed>().ref;
Struct8BytesNestedMixed result = calloc<Struct8BytesNestedMixed>().ref;
result.a0.a0 = returnStruct8BytesNestedMixed_a0.a0;
result.a0.a1 = returnStruct8BytesNestedMixed_a0.a1;
@@ -8296,13 +8297,13 @@ Struct8BytesNestedMixed returnStruct8BytesNestedMixed(
}
void returnStruct8BytesNestedMixedAfterCallback() {
free(returnStruct8BytesNestedMixedResult.addressOf);
calloc.free(returnStruct8BytesNestedMixedResult.addressOf);
final result = returnStruct8BytesNestedMixedCalculateResult();
print("after callback result = $result");
free(returnStruct8BytesNestedMixedResult.addressOf);
calloc.free(returnStruct8BytesNestedMixedResult.addressOf);
}
typedef ReturnStruct16BytesNestedIntType = Struct16BytesNestedInt Function(
@@ -8317,7 +8318,7 @@ Struct16BytesNestedInt returnStruct16BytesNestedIntResult =
Struct16BytesNestedInt();
Struct16BytesNestedInt returnStruct16BytesNestedIntCalculateResult() {
Struct16BytesNestedInt result = allocate<Struct16BytesNestedInt>().ref;
Struct16BytesNestedInt result = calloc<Struct16BytesNestedInt>().ref;
result.a0.a0.a0 = returnStruct16BytesNestedInt_a0.a0.a0;
result.a0.a0.a1 = returnStruct16BytesNestedInt_a0.a0.a1;
@@ -8361,13 +8362,13 @@ Struct16BytesNestedInt returnStruct16BytesNestedInt(
}
void returnStruct16BytesNestedIntAfterCallback() {
free(returnStruct16BytesNestedIntResult.addressOf);
calloc.free(returnStruct16BytesNestedIntResult.addressOf);
final result = returnStruct16BytesNestedIntCalculateResult();
print("after callback result = $result");
free(returnStruct16BytesNestedIntResult.addressOf);
calloc.free(returnStruct16BytesNestedIntResult.addressOf);
}
typedef ReturnStruct32BytesNestedIntType = Struct32BytesNestedInt Function(
@@ -8384,7 +8385,7 @@ Struct32BytesNestedInt returnStruct32BytesNestedIntResult =
Struct32BytesNestedInt();
Struct32BytesNestedInt returnStruct32BytesNestedIntCalculateResult() {
Struct32BytesNestedInt result = allocate<Struct32BytesNestedInt>().ref;
Struct32BytesNestedInt result = calloc<Struct32BytesNestedInt>().ref;
result.a0.a0.a0.a0 = returnStruct32BytesNestedInt_a0.a0.a0.a0;
result.a0.a0.a0.a1 = returnStruct32BytesNestedInt_a0.a0.a0.a1;
@@ -8436,13 +8437,13 @@ Struct32BytesNestedInt returnStruct32BytesNestedInt(
}
void returnStruct32BytesNestedIntAfterCallback() {
free(returnStruct32BytesNestedIntResult.addressOf);
calloc.free(returnStruct32BytesNestedIntResult.addressOf);
final result = returnStruct32BytesNestedIntCalculateResult();
print("after callback result = $result");
free(returnStruct32BytesNestedIntResult.addressOf);
calloc.free(returnStruct32BytesNestedIntResult.addressOf);
}
typedef ReturnStructNestedIntStructAlignmentInt16Type
@@ -8463,7 +8464,7 @@ StructNestedIntStructAlignmentInt16
StructNestedIntStructAlignmentInt16
returnStructNestedIntStructAlignmentInt16CalculateResult() {
StructNestedIntStructAlignmentInt16 result =
allocate<StructNestedIntStructAlignmentInt16>().ref;
calloc<StructNestedIntStructAlignmentInt16>().ref;
result.a0.a0 = returnStructNestedIntStructAlignmentInt16_a0.a0;
result.a0.a1 = returnStructNestedIntStructAlignmentInt16_a0.a1;
@@ -8506,13 +8507,13 @@ StructNestedIntStructAlignmentInt16 returnStructNestedIntStructAlignmentInt16(
}
void returnStructNestedIntStructAlignmentInt16AfterCallback() {
free(returnStructNestedIntStructAlignmentInt16Result.addressOf);
calloc.free(returnStructNestedIntStructAlignmentInt16Result.addressOf);
final result = returnStructNestedIntStructAlignmentInt16CalculateResult();
print("after callback result = $result");
free(returnStructNestedIntStructAlignmentInt16Result.addressOf);
calloc.free(returnStructNestedIntStructAlignmentInt16Result.addressOf);
}
typedef ReturnStructNestedIntStructAlignmentInt32Type
@@ -8533,7 +8534,7 @@ StructNestedIntStructAlignmentInt32
StructNestedIntStructAlignmentInt32
returnStructNestedIntStructAlignmentInt32CalculateResult() {
StructNestedIntStructAlignmentInt32 result =
allocate<StructNestedIntStructAlignmentInt32>().ref;
calloc<StructNestedIntStructAlignmentInt32>().ref;
result.a0.a0 = returnStructNestedIntStructAlignmentInt32_a0.a0;
result.a0.a1 = returnStructNestedIntStructAlignmentInt32_a0.a1;
@@ -8576,13 +8577,13 @@ StructNestedIntStructAlignmentInt32 returnStructNestedIntStructAlignmentInt32(
}
void returnStructNestedIntStructAlignmentInt32AfterCallback() {
free(returnStructNestedIntStructAlignmentInt32Result.addressOf);
calloc.free(returnStructNestedIntStructAlignmentInt32Result.addressOf);
final result = returnStructNestedIntStructAlignmentInt32CalculateResult();
print("after callback result = $result");
free(returnStructNestedIntStructAlignmentInt32Result.addressOf);
calloc.free(returnStructNestedIntStructAlignmentInt32Result.addressOf);
}
typedef ReturnStructNestedIntStructAlignmentInt64Type
@@ -8603,7 +8604,7 @@ StructNestedIntStructAlignmentInt64
StructNestedIntStructAlignmentInt64
returnStructNestedIntStructAlignmentInt64CalculateResult() {
StructNestedIntStructAlignmentInt64 result =
allocate<StructNestedIntStructAlignmentInt64>().ref;
calloc<StructNestedIntStructAlignmentInt64>().ref;
result.a0.a0 = returnStructNestedIntStructAlignmentInt64_a0.a0;
result.a0.a1 = returnStructNestedIntStructAlignmentInt64_a0.a1;
@@ -8646,13 +8647,13 @@ StructNestedIntStructAlignmentInt64 returnStructNestedIntStructAlignmentInt64(
}
void returnStructNestedIntStructAlignmentInt64AfterCallback() {
free(returnStructNestedIntStructAlignmentInt64Result.addressOf);
calloc.free(returnStructNestedIntStructAlignmentInt64Result.addressOf);
final result = returnStructNestedIntStructAlignmentInt64CalculateResult();
print("after callback result = $result");
free(returnStructNestedIntStructAlignmentInt64Result.addressOf);
calloc.free(returnStructNestedIntStructAlignmentInt64Result.addressOf);
}
typedef ReturnStructNestedIrregularEvenBiggerType
@@ -8674,7 +8675,7 @@ StructNestedIrregularEvenBigger returnStructNestedIrregularEvenBiggerResult =
StructNestedIrregularEvenBigger
returnStructNestedIrregularEvenBiggerCalculateResult() {
StructNestedIrregularEvenBigger result =
allocate<StructNestedIrregularEvenBigger>().ref;
calloc<StructNestedIrregularEvenBigger>().ref;
result.a0 = returnStructNestedIrregularEvenBigger_a0;
result.a1.a0.a0 = returnStructNestedIrregularEvenBigger_a1.a0.a0;
@@ -8747,11 +8748,11 @@ StructNestedIrregularEvenBigger returnStructNestedIrregularEvenBigger(int a0,
}
void returnStructNestedIrregularEvenBiggerAfterCallback() {
free(returnStructNestedIrregularEvenBiggerResult.addressOf);
calloc.free(returnStructNestedIrregularEvenBiggerResult.addressOf);
final result = returnStructNestedIrregularEvenBiggerCalculateResult();
print("after callback result = $result");
free(returnStructNestedIrregularEvenBiggerResult.addressOf);
calloc.free(returnStructNestedIrregularEvenBiggerResult.addressOf);
}
@@ -11,6 +11,7 @@ import 'dart:ffi';
import "package:expect/expect.dart";
import "package:ffi/ffi.dart";
import 'calloc.dart';
// Reuse the struct classes.
import 'function_structs_by_value_generated_test.dart';
@@ -23,7 +24,7 @@ void main() {
}
void recursiveTest(int recursionCounter) {
final struct = allocate<Struct20BytesHomogeneousInt32>().ref;
final struct = calloc<Struct20BytesHomogeneousInt32>().ref;
struct.a0 = 1;
struct.a1 = 2;
struct.a2 = 3;
@@ -35,7 +36,7 @@ void recursiveTest(int recursionCounter) {
Expect.equals(struct.a2, result.a2);
Expect.equals(struct.a3, result.a3);
Expect.equals(struct.a4, result.a4);
free(struct.addressOf);
calloc.free(struct.addressOf);
}
Struct20BytesHomogeneousInt32 dartPassStructRecursive(
@@ -93,7 +94,7 @@ void testCopyLogic() {
_invokeReceiveStructByValue(_receiveStructByValuePointer);
Expect.isTrue(typedDataBackedStructSet);
final pointerBackedStruct = allocate<Struct8BytesNestedInt>().ref;
final pointerBackedStruct = calloc<Struct8BytesNestedInt>().ref;
void reset() {
pointerBackedStruct.a0.a0 = 1;
@@ -130,5 +131,5 @@ void testCopyLogic() {
Expect.equals(5, typedDataBackedStruct.a1.a0);
Expect.equals(6, typedDataBackedStruct.a1.a1);
free(pointerBackedStruct.addressOf);
calloc.free(pointerBackedStruct.addressOf);
}
File diff suppressed because it is too large Load Diff
+12 -10
View File
@@ -9,12 +9,12 @@
import 'dart:ffi';
import 'dylib_utils.dart';
import "package:expect/expect.dart";
import "package:ffi/ffi.dart";
import 'calloc.dart';
import 'coordinate.dart';
import 'dylib_utils.dart';
import 'very_large_struct.dart';
typedef NativeCoordinateOp = Pointer<Coordinate> Function(Pointer<Coordinate>);
@@ -33,8 +33,10 @@ void testFunctionWithStruct() {
ffiTestFunctions.lookup("TransposeCoordinate");
NativeCoordinateOp f1 = p1.asFunction();
Pointer<Coordinate> c1 = Coordinate.allocate(10.0, 20.0, nullptr).addressOf;
Pointer<Coordinate> c2 = Coordinate.allocate(42.0, 84.0, c1).addressOf;
Pointer<Coordinate> c1 =
Coordinate.allocate(calloc, 10.0, 20.0, nullptr).addressOf;
Pointer<Coordinate> c2 =
Coordinate.allocate(calloc, 42.0, 84.0, c1).addressOf;
c1.ref.next = c2;
Coordinate result = f1(c1).ref;
@@ -45,8 +47,8 @@ void testFunctionWithStruct() {
Expect.approxEquals(42.0, result.x);
Expect.approxEquals(84.0, result.y);
free(c1);
free(c2);
calloc.free(c1);
calloc.free(c2);
}
/// pass an array of structs to a c funtion
@@ -55,7 +57,7 @@ void testFunctionWithStructArray() {
ffiTestFunctions.lookup("CoordinateElemAt1");
NativeCoordinateOp f1 = p1.asFunction();
Coordinate c1 = allocate<Coordinate>(count: 3).ref;
Coordinate c1 = calloc<Coordinate>(3).ref;
Coordinate c2 = c1.addressOf[1];
Coordinate c3 = c1.addressOf[2];
c1.x = 10.0;
@@ -72,7 +74,7 @@ void testFunctionWithStructArray() {
Expect.approxEquals(20.0, result.x);
Expect.approxEquals(20.0, result.y);
free(c1.addressOf);
calloc.free(c1.addressOf);
}
typedef VeryLargeStructSum = int Function(Pointer<VeryLargeStruct>);
@@ -83,7 +85,7 @@ void testFunctionWithVeryLargeStruct() {
ffiTestFunctions.lookup("SumVeryLargeStruct");
VeryLargeStructSum f = p1.asFunction();
VeryLargeStruct vls1 = allocate<VeryLargeStruct>(count: 2).ref;
VeryLargeStruct vls1 = calloc<VeryLargeStruct>(2).ref;
VeryLargeStruct vls2 = vls1.addressOf[1];
List<VeryLargeStruct> structs = [vls1, vls2];
for (VeryLargeStruct struct in structs) {
@@ -114,5 +116,5 @@ void testFunctionWithVeryLargeStruct() {
result = f(vls2.addressOf);
Expect.equals(2048, result);
free(vls1.addressOf);
calloc.free(vls1.addressOf);
}
+11 -10
View File
@@ -15,11 +15,12 @@
import 'dart:ffi';
import 'dylib_utils.dart';
import "package:ffi/ffi.dart";
import "package:expect/expect.dart";
import 'dylib_utils.dart';
import 'calloc.dart';
void main() {
for (int i = 0; i < 100; ++i) {
testNativeFunctionFromCast();
@@ -50,11 +51,11 @@ typedef BinaryOp = int Function(int, int);
typedef GenericBinaryOp<T> = int Function(int, T);
void testNativeFunctionFromCast() {
Pointer<IntPtr> p1 = allocate();
Pointer<IntPtr> p1 = calloc();
Pointer<NativeFunction<NativeBinaryOp>> p2 = p1.cast();
p2.asFunction<BinaryOp>();
p2.asFunction<GenericBinaryOp<int>>();
free(p1);
calloc.free(p1);
}
typedef NativeQuadOpSigned = Int64 Function(Int8, Int16, Int32, Int64);
@@ -394,14 +395,14 @@ Int64PointerUnOp assign1337Index1 = ffiTestFunctions
.lookupFunction<Int64PointerUnOp, Int64PointerUnOp>("Assign1337Index1");
void testNativeFunctionPointer() {
Pointer<Int64> p2 = allocate(count: 2);
Pointer<Int64> p2 = calloc(2);
p2.value = 42;
p2[1] = 1000;
Pointer<Int64> result = assign1337Index1(p2);
Expect.equals(1337, result.value);
Expect.equals(1337, p2[1]);
Expect.equals(p2.elementAt(1).address, result.address);
free(p2);
calloc.free(p2);
}
Int64PointerUnOp nullableInt64ElemAt1 = ffiTestFunctions
@@ -411,10 +412,10 @@ void testNullPointers() {
Pointer<Int64> result = nullableInt64ElemAt1(nullptr);
Expect.equals(result, nullptr);
Pointer<Int64> p2 = allocate(count: 2);
Pointer<Int64> p2 = calloc(2);
result = nullableInt64ElemAt1(p2);
Expect.notEquals(result, nullptr);
free(p2);
calloc.free(p2);
}
typedef NativeFloatPointerToBool = Uint8 Function(Pointer<Float>);
@@ -424,13 +425,13 @@ FloatPointerToBool isRoughly1337 = ffiTestFunctions.lookupFunction<
NativeFloatPointerToBool, FloatPointerToBool>("IsRoughly1337");
void testFloatRounding() {
Pointer<Float> p2 = allocate();
Pointer<Float> p2 = calloc();
p2.value = 1337.0;
int result = isRoughly1337(p2);
Expect.equals(1, result);
free(p2);
calloc.free(p2);
}
typedef NativeFloatToVoid = Void Function(Float);
@@ -197,7 +197,7 @@ extension on CType {
return "${dartType} ${variableName};\n";
case StructType:
return "${dartType} ${variableName} = allocate<$dartType>().ref;\n";
return "${dartType} ${variableName} = calloc<$dartType>().ref;\n";
}
throw Exception("Not implemented for ${this.runtimeType}");
@@ -243,7 +243,7 @@ extension on CType {
return "";
case StructType:
return "free($variableName.addressOf);\n";
return "calloc.free($variableName.addressOf);\n";
}
throw Exception("Not implemented for ${this.runtimeType}");
@@ -485,7 +485,7 @@ extension on FunctionType {
case TestType.structReturn:
// Allocate a struct.
buildReturnValue = """
${returnValue.dartType} result = allocate<${returnValue.dartType}>().ref;
${returnValue.dartType} result = calloc<${returnValue.dartType}>().ref;
${arguments.copyValueStatements("${dartName}_", "result.")}
""";
@@ -749,6 +749,7 @@ import 'dart:ffi';
import "package:expect/expect.dart";
import "package:ffi/ffi.dart";
import 'calloc.dart';
import 'dylib_utils.dart';
final ffiTestFunctions = dlopenPlatformSpecific("ffi_test_functions");
@@ -801,6 +802,7 @@ import "package:expect/expect.dart";
import "package:ffi/ffi.dart";
import 'callback_tests_utils.dart';
import 'calloc.dart';
// Reuse the struct classes.
import 'function_structs_by_value_generated_test.dart';
+13 -12
View File
@@ -20,6 +20,7 @@ import 'dart:ffi';
import "package:expect/expect.dart";
import "package:ffi/ffi.dart";
import 'calloc.dart';
import 'dylib_utils.dart';
import 'ffi_test_helpers.dart';
@@ -40,17 +41,17 @@ void main() {
void testPointerStoreNull() {
int i = null;
Pointer<Int8> p = allocate();
Pointer<Int8> p = calloc();
Expect.throws(() => p.value = i);
free(p);
calloc.free(p);
double d = null;
Pointer<Float> p2 = allocate();
Pointer<Float> p2 = calloc();
Expect.throws(() => p2.value = d);
free(p2);
calloc.free(p2);
Pointer<Void> x = null;
Pointer<Pointer<Void>> p3 = allocate();
Pointer<Pointer<Void>> p3 = calloc();
Expect.throws(() => p3.value = x);
free(p3);
calloc.free(p3);
}
void testEquality() {
@@ -61,7 +62,7 @@ void testEquality() {
/// With extension methods, the receiver position can be null.
testNullReceivers() {
Pointer<Int8> p = allocate();
Pointer<Int8> p = calloc();
Pointer<Int8> p4 = null;
Expect.throws(() => Expect.equals(10, p4.value));
@@ -74,11 +75,11 @@ testNullReceivers() {
Pointer<Foo> p6 = null;
Expect.throws(() => Expect.equals(10, p6.ref));
free(p);
calloc.free(p);
}
testNullIndices() {
Pointer<Int8> p = allocate();
Pointer<Int8> p = calloc();
Expect.throws(() => Expect.equals(10, p[null]));
Expect.throws(() => p[null] = 10);
@@ -90,13 +91,13 @@ testNullIndices() {
Pointer<Foo> p6 = p.cast();
Expect.throws(() => Expect.equals(10, p6[null]));
free(p);
calloc.free(p);
}
testNullArguments() {
Pointer<Int8> p = allocate();
Pointer<Int8> p = calloc();
Expect.throws(() => p.value = null);
free(p);
calloc.free(p);
}
class Foo extends Struct {
+50 -48
View File
@@ -65,34 +65,36 @@ import 'dart:ffi';
import "package:expect/expect.dart";
import "package:ffi/ffi.dart";
import 'calloc.dart';
// ===== a.value = b ======
// The tests follow table cells left to right, top to bottom.
void store1() {
final Pointer<Pointer<Int8>> a = allocate<Pointer<Int8>>();
final Pointer<Int8> b = allocate<Int8>();
final Pointer<Pointer<Int8>> a = calloc<Pointer<Int8>>();
final Pointer<Int8> b = calloc<Int8>();
a.value = b;
free(a);
free(b);
calloc.free(a);
calloc.free(b);
}
void store2() {
final Pointer<Pointer<Int8>> a = allocate<Pointer<Int8>>();
final Pointer<Pointer<Int8>> a = calloc<Pointer<Int8>>();
final Pointer<NativeType> b =
allocate<Int8>(); // Reified Pointer<Int8> at runtime.
calloc<Int8>(); // Reified Pointer<Int8> at runtime.
// Successful implicit downcast of argument at runtime.
// Should succeed now, should statically be rejected when NNBD lands.
a.value = b;
free(a);
free(b);
calloc.free(a);
calloc.free(b);
}
void store3() {
final Pointer<Pointer<Int8>> a = allocate<Pointer<Int8>>();
final Pointer<NativeType> b = allocate<Int8>().cast<Pointer<NativeType>>();
final Pointer<Pointer<Int8>> a = calloc<Pointer<Int8>>();
final Pointer<NativeType> b = calloc<Int8>().cast<Pointer<NativeType>>();
// Failing implicit downcast of argument at runtime.
// Should fail now at runtime, should statically be rejected when NNBD lands.
@@ -100,124 +102,124 @@ void store3() {
a.value = b;
});
free(a);
free(b);
calloc.free(a);
calloc.free(b);
}
void store4() {
// Reified as Pointer<Pointer<Int8>> at runtime.
final Pointer<Pointer<NativeType>> a = allocate<Pointer<Int8>>();
final Pointer<Pointer<NativeType>> a = calloc<Pointer<Int8>>();
final Pointer<Int8> b = allocate<Int8>();
final Pointer<Int8> b = calloc<Int8>();
a.value = b;
free(a);
free(b);
calloc.free(a);
calloc.free(b);
}
void store5() {
// Reified as Pointer<Pointer<Int8>> at runtime.
final Pointer<Pointer<NativeType>> a = allocate<Pointer<Int8>>();
final Pointer<Pointer<NativeType>> a = calloc<Pointer<Int8>>();
final Pointer<NativeType> b =
allocate<Int8>(); // Reified as Pointer<Int8> at runtime.
calloc<Int8>(); // Reified as Pointer<Int8> at runtime.
a.value = b;
free(a);
free(b);
calloc.free(a);
calloc.free(b);
}
void store6() {
// Reified as Pointer<Pointer<Int8>> at runtime.
final Pointer<Pointer<NativeType>> a = allocate<Pointer<Int8>>();
final Pointer<NativeType> b = allocate<Int8>().cast<Pointer<NativeType>>();
final Pointer<Pointer<NativeType>> a = calloc<Pointer<Int8>>();
final Pointer<NativeType> b = calloc<Int8>().cast<Pointer<NativeType>>();
// Fails on type check of argument.
Expect.throws(() {
a.value = b;
});
free(a);
free(b);
calloc.free(a);
calloc.free(b);
}
void store7() {
final Pointer<Pointer<NativeType>> a = allocate<Pointer<NativeType>>();
final Pointer<Int8> b = allocate<Int8>();
final Pointer<Pointer<NativeType>> a = calloc<Pointer<NativeType>>();
final Pointer<Int8> b = calloc<Int8>();
a.value = b;
free(a);
free(b);
calloc.free(a);
calloc.free(b);
}
void store8() {
final Pointer<Pointer<NativeType>> a = allocate<Pointer<NativeType>>();
final Pointer<Pointer<NativeType>> a = calloc<Pointer<NativeType>>();
// Reified as Pointer<Int8> at runtime.
final Pointer<NativeType> b = allocate<Int8>();
final Pointer<NativeType> b = calloc<Int8>();
a.value = b;
free(a);
free(b);
calloc.free(a);
calloc.free(b);
}
void store9() {
final Pointer<Pointer<NativeType>> a = allocate<Pointer<NativeType>>();
final Pointer<NativeType> b = allocate<Int8>().cast<Pointer<NativeType>>();
final Pointer<Pointer<NativeType>> a = calloc<Pointer<NativeType>>();
final Pointer<NativeType> b = calloc<Int8>().cast<Pointer<NativeType>>();
a.value = b;
free(a);
free(b);
calloc.free(a);
calloc.free(b);
}
// ====== b = a.value ======
// The tests follow table cells left to right, top to bottom.
void load1() {
final Pointer<Pointer<Int8>> a = allocate<Pointer<Int8>>();
final Pointer<Pointer<Int8>> a = calloc<Pointer<Int8>>();
Pointer<Int8> b = a.value;
Expect.type<Pointer<Int8>>(b);
free(a);
calloc.free(a);
}
void load2() {
final Pointer<Pointer<Int8>> a = allocate<Pointer<Int8>>();
final Pointer<Pointer<Int8>> a = calloc<Pointer<Int8>>();
Pointer<NativeType> b = a.value;
Expect.type<Pointer<Int8>>(b);
free(a);
calloc.free(a);
}
void load3() {
// Reified as Pointer<Pointer<Int8>> at runtime.
final Pointer<Pointer<NativeType>> a = allocate<Pointer<Int8>>();
final Pointer<Pointer<NativeType>> a = calloc<Pointer<Int8>>();
Pointer<Int8> b = a.value;
Expect.type<Pointer<Int8>>(b);
free(a);
calloc.free(a);
}
void load4() {
// Reified as Pointer<Pointer<Int8>> at runtime.
final Pointer<Pointer<NativeType>> a = allocate<Pointer<Int8>>();
final Pointer<Pointer<NativeType>> a = calloc<Pointer<Int8>>();
// Return value runtime type is Pointer<Int8>.
Pointer<NativeType> b = a.value;
Expect.type<Pointer<Int8>>(b);
free(a);
calloc.free(a);
}
void load5() {
final Pointer<Pointer<NativeType>> a = allocate<Pointer<NativeType>>();
final Pointer<Pointer<NativeType>> a = calloc<Pointer<NativeType>>();
// Failing implicit downcast of return value at runtime.
// Should fail now at runtime, should statically be rejected when NNBD lands.
@@ -225,16 +227,16 @@ void load5() {
Pointer<Int8> b = a.value;
});
free(a);
calloc.free(a);
}
void load6() {
final Pointer<Pointer<NativeType>> a = allocate<Pointer<NativeType>>();
final Pointer<Pointer<NativeType>> a = calloc<Pointer<NativeType>>();
Pointer<NativeType> b = a.value;
Expect.type<Pointer<NativeType>>(b);
free(a);
calloc.free(a);
}
void main() {
+6 -3
View File
@@ -3,12 +3,15 @@
// BSD-style license that can be found in the LICENSE file.
import 'dart:ffi';
import "package:ffi/ffi.dart" show allocate, free;
import "package:ffi/ffi.dart";
import 'calloc.dart';
main() {
final data = allocate<Uint8>(count: 3);
final data = calloc<Uint8>(3);
for (int i = 0; i < 3; ++i) {
data.elementAt(i).value = 1;
}
free(data);
calloc.free(data);
}
+3 -2
View File
@@ -9,6 +9,7 @@ import 'dart:ffi';
import 'package:ffi/ffi.dart';
import 'package:expect/expect.dart';
import 'calloc.dart';
import 'dylib_utils.dart';
class Struct43693 extends Struct {
@@ -27,10 +28,10 @@ final int Function(Pointer<Struct43693>) readMyStructSomeValue =
final ffiTestFunctions = dlopenPlatformSpecific("ffi_test_functions");
void main() {
final myStructs = allocate<Struct43693>();
final myStructs = calloc<Struct43693>();
myStructs[0].somePtr = nullptr;
myStructs[0].someValue = 0xAAAAAAAABBBBBBBB;
final result = readMyStructSomeValue(myStructs);
Expect.equals(0xAAAAAAAABBBBBBBB, result);
free(myStructs);
calloc.free(myStructs);
}
+9 -8
View File
@@ -11,6 +11,7 @@ import 'dart:ffi';
import "package:expect/expect.dart";
import "package:ffi/ffi.dart";
import 'calloc.dart';
import 'dylib_utils.dart';
final ffiTestFunctions = dlopenPlatformSpecific("ffi_test_functions");
@@ -48,16 +49,16 @@ void testSizeOf() {
}
void testAllocate() {
final p = allocate<Struct8BytesNestedInt>();
final p = calloc<Struct8BytesNestedInt>();
Expect.type<Pointer<Struct8BytesNestedInt>>(p);
print(p);
free(p);
calloc.free(p);
}
/// Test that reading does not segfault, even uninitialized.
void testRead() {
print("read");
final p = allocate<Struct8BytesNestedInt>();
final p = calloc<Struct8BytesNestedInt>();
print(p);
print(p.ref.runtimeType);
print(p.ref.addressOf);
@@ -65,13 +66,13 @@ void testRead() {
print(p.ref.a0.runtimeType);
print(p.ref.a0.addressOf);
print(p.ref.a0.a0);
free(p);
calloc.free(p);
print("read");
}
void testWrite() {
print("write");
final p = allocate<Struct8BytesNestedInt>(count: 2);
final p = calloc<Struct8BytesNestedInt>(2);
p[0].a0.a0 = 12;
p[0].a0.a1 = 13;
p[0].a1.a0 = 14;
@@ -88,18 +89,18 @@ void testWrite() {
Expect.equals(17, p[1].a0.a1);
Expect.equals(18, p[1].a1.a0);
Expect.equals(19, p[1].a1.a1);
free(p);
calloc.free(p);
print("written");
}
void testCopy() {
print("copy");
final p = allocate<Struct8BytesNestedInt>();
final p = calloc<Struct8BytesNestedInt>();
p.ref.a0.a0 = 12;
p.ref.a0.a1 = 13;
p.ref.a1 = p.ref.a0;
Expect.equals(12, p.ref.a1.a0);
Expect.equals(13, p.ref.a1.a1);
free(p);
calloc.free(p);
print("copied");
}
+20 -16
View File
@@ -11,9 +11,10 @@ import 'dart:ffi';
import "package:expect/expect.dart";
import "package:ffi/ffi.dart";
import 'ffi_test_helpers.dart';
import 'calloc.dart';
import 'coordinate_bare.dart' as bare;
import 'coordinate.dart';
import 'ffi_test_helpers.dart';
void main() {
for (int i = 0; i < 100; i++) {
@@ -28,9 +29,12 @@ void main() {
/// allocates each coordinate separately in c memory
void testStructAllocate() {
Pointer<Coordinate> c1 = Coordinate.allocate(10.0, 10.0, nullptr).addressOf;
Pointer<Coordinate> c2 = Coordinate.allocate(20.0, 20.0, c1).addressOf;
Pointer<Coordinate> c3 = Coordinate.allocate(30.0, 30.0, c2).addressOf;
Pointer<Coordinate> c1 =
Coordinate.allocate(calloc, 10.0, 10.0, nullptr).addressOf;
Pointer<Coordinate> c2 =
Coordinate.allocate(calloc, 20.0, 20.0, c1).addressOf;
Pointer<Coordinate> c3 =
Coordinate.allocate(calloc, 30.0, 30.0, c2).addressOf;
c1.ref.next = c3;
Coordinate currentCoordinate = c1.ref;
@@ -42,14 +46,14 @@ void testStructAllocate() {
currentCoordinate = currentCoordinate.next.ref;
Expect.equals(10.0, currentCoordinate.x);
free(c1);
free(c2);
free(c3);
calloc.free(c1);
calloc.free(c2);
calloc.free(c3);
}
/// allocates coordinates consecutively in c memory
void testStructFromAddress() {
Pointer<Coordinate> c1 = allocate(count: 3);
Pointer<Coordinate> c1 = calloc(3);
Pointer<Coordinate> c2 = c1.elementAt(1);
Pointer<Coordinate> c3 = c1.elementAt(2);
c1.ref
@@ -74,24 +78,24 @@ void testStructFromAddress() {
currentCoordinate = currentCoordinate.next.ref;
Expect.equals(10.0, currentCoordinate.x);
free(c1);
calloc.free(c1);
}
void testStructWithNulls() {
Pointer<Coordinate> coordinate =
Coordinate.allocate(10.0, 10.0, nullptr).addressOf;
Coordinate.allocate(calloc, 10.0, 10.0, nullptr).addressOf;
Expect.equals(coordinate.ref.next, nullptr);
coordinate.ref.next = coordinate;
Expect.notEquals(coordinate.ref.next, nullptr);
coordinate.ref.next = nullptr;
Expect.equals(coordinate.ref.next, nullptr);
free(coordinate);
calloc.free(coordinate);
}
void testBareStruct() {
int structSize = sizeOf<Double>() * 2 + sizeOf<IntPtr>();
bare.Coordinate c1 =
allocate<Uint8>(count: structSize * 3).cast<bare.Coordinate>().ref;
calloc<Uint8>(structSize * 3).cast<bare.Coordinate>().ref;
bare.Coordinate c2 =
c1.addressOf.offsetBy(structSize).cast<bare.Coordinate>().ref;
bare.Coordinate c3 =
@@ -115,19 +119,19 @@ void testBareStruct() {
currentCoordinate = currentCoordinate.next.ref;
Expect.equals(10.0, currentCoordinate.x);
free(c1.addressOf);
calloc.free(c1.addressOf);
}
void testTypeTest() {
Coordinate c = Coordinate.allocate(10, 10, nullptr);
Coordinate c = Coordinate.allocate(calloc, 10, 10, nullptr);
Expect.isTrue(c is Struct);
Expect.isTrue(c.addressOf is Pointer<Coordinate>);
free(c.addressOf);
calloc.free(c.addressOf);
}
void testUtf8() {
final String test = 'Hasta Mañana';
final Pointer<Utf8> medium = Utf8.toUtf8(test);
Expect.equals(test, Utf8.fromUtf8(medium));
free(medium);
calloc.free(medium);
}
+13 -12
View File
@@ -12,11 +12,12 @@
import 'dart:ffi';
import 'dylib_utils.dart';
import "package:expect/expect.dart";
import "package:ffi/ffi.dart";
import 'calloc.dart';
import 'dylib_utils.dart';
typedef Int64PointerParamOpDart = void Function(Pointer<Int64>);
typedef Int64PointerParamOp = Void Function(Pointer<Int64>);
typedef NaTyPointerParamOpDart = void Function(Pointer<NativeType>);
@@ -38,19 +39,19 @@ void paramInvariant1() {
final fp =
ffiTestFunctions.lookup<NativeFunction<Int64PointerParamOp>>(paramOpName);
final f = fp.asFunction<Int64PointerParamOpDart>();
final arg = allocate<Int64>();
final arg = calloc<Int64>();
f(arg);
free(arg);
calloc.free(arg);
}
void paramInvariant2() {
final fp =
ffiTestFunctions.lookup<NativeFunction<NaTyPointerParamOp>>(paramOpName);
final f = fp.asFunction<NaTyPointerParamOpDart>();
final arg = allocate<Int64>().cast<NativeType>();
final arg = calloc<Int64>().cast<NativeType>();
Expect.type<Pointer<NativeType>>(arg);
f(arg);
free(arg);
calloc.free(arg);
}
// Pass a statically and dynamically subtyped argument.
@@ -58,10 +59,10 @@ void paramSubtype1() {
final fp =
ffiTestFunctions.lookup<NativeFunction<NaTyPointerParamOp>>(paramOpName);
final f = fp.asFunction<NaTyPointerParamOpDart>();
final arg = allocate<Int64>();
final arg = calloc<Int64>();
Expect.type<Pointer<Int64>>(arg);
f(arg);
free(arg);
calloc.free(arg);
}
// Pass a statically subtyped but dynamically invariant argument.
@@ -69,10 +70,10 @@ void paramSubtype2() {
final fp =
ffiTestFunctions.lookup<NativeFunction<NaTyPointerParamOp>>(paramOpName);
final f = fp.asFunction<NaTyPointerParamOpDart>();
final Pointer<NativeType> arg = allocate<Int64>();
final Pointer<NativeType> arg = calloc<Int64>();
Expect.type<Pointer<Int64>>(arg);
f(arg);
free(arg);
calloc.free(arg);
}
void returnInvariant1() {
@@ -220,7 +221,7 @@ void callbackReturnInvariant2() {
}
void fromFunctionTests() {
data = allocate();
data = calloc();
for (int i = 0; i < 100; ++i) {
callbackParamInvariant1(); // Pointer<Int64> invariant
callbackParamInvariant2(); // Pointer<NativeType> invariant
@@ -229,7 +230,7 @@ void fromFunctionTests() {
callbackReturnInvariant1(); // Pointer<Int64> invariant
callbackReturnInvariant2(); // Pointer<NativeType> invariant
}
free(data);
calloc.free(data);
}
void main() {
+5 -2
View File
@@ -7,11 +7,14 @@
// VMOptions=--enable-ffi=false
import 'dart:ffi'; //# 01: compile-time error
import 'package:ffi/ffi.dart'; //# 01: compile-time error
import 'calloc.dart'; //# 01: compile-time error
void main() {
Pointer<Int8> p = //# 01: compile-time error
allocate(); //# 01: compile-time error
calloc(); //# 01: compile-time error
print(p.address); //# 01: compile-time error
free(p); //# 01: compile-time error
calloc.free(p); //# 01: compile-time error
}
+21 -20
View File
@@ -10,6 +10,7 @@ import 'dart:ffi';
import "package:ffi/ffi.dart";
import 'calloc.dart';
import 'dylib_utils.dart';
void main() {
@@ -67,20 +68,20 @@ void testGetGeneric() {
return result;
}
Pointer<Int8> p = allocate();
Pointer<Int8> p = calloc();
p.value = 123;
Pointer loseType = p;
generic(loseType);
free(p);
calloc.free(p);
}
void testGetGeneric2() {
T generic<T extends Object>() {
Pointer<Int8> p = allocate();
Pointer<Int8> p = calloc();
p.value = 123;
T result;
result = p.value; //# 21: compile-time error
free(p);
calloc.free(p);
return result;
}
@@ -88,12 +89,12 @@ void testGetGeneric2() {
}
void testGetVoid() {
Pointer<IntPtr> p1 = allocate();
Pointer<IntPtr> p1 = calloc();
Pointer<Void> p2 = p1.cast();
p2.value; //# 22: compile-time error
free(p1);
calloc.free(p1);
}
void testGetNativeFunction() {
@@ -106,14 +107,14 @@ void testGetNativeType() {
}
void testGetTypeMismatch() {
Pointer<Pointer<Int16>> p = allocate();
Pointer<Pointer<Int16>> p = calloc();
Pointer<Int16> typedNull = nullptr;
p.value = typedNull;
// this fails to compile due to type mismatch
Pointer<Int8> p2 = p.value; //# 25: compile-time error
free(p);
calloc.free(p);
}
void testSetGeneric() {
@@ -121,30 +122,30 @@ void testSetGeneric() {
p.value = 123; //# 26: compile-time error
}
Pointer<Int8> p = allocate();
Pointer<Int8> p = calloc();
p.value = 123;
Pointer loseType = p;
generic(loseType);
free(p);
calloc.free(p);
}
void testSetGeneric2() {
void generic<T extends Object>(T arg) {
Pointer<Int8> p = allocate();
Pointer<Int8> p = calloc();
p.value = arg; //# 27: compile-time error
free(p);
calloc.free(p);
}
generic<int>(123);
}
void testSetVoid() {
Pointer<IntPtr> p1 = allocate();
Pointer<IntPtr> p1 = calloc();
Pointer<Void> p2 = p1.cast();
p2.value = 1234; //# 28: compile-time error
free(p1);
calloc.free(p1);
}
void testSetNativeFunction() {
@@ -159,16 +160,16 @@ void testSetNativeType() {
void testSetTypeMismatch() {
// the pointer to pointer types must match up
Pointer<Int8> pHelper = allocate();
Pointer<Int8> pHelper = calloc();
pHelper.value = 123;
Pointer<Pointer<Int16>> p = allocate();
Pointer<Pointer<Int16>> p = calloc();
// this fails to compile due to type mismatch
p.value = pHelper; //# 40: compile-time error
free(pHelper);
free(p);
calloc.free(pHelper);
calloc.free(p);
}
void testAsFunctionGeneric() {
@@ -558,7 +559,7 @@ class HasNestedEmptyStruct extends Struct {
void testAllocateGeneric() {
Pointer<T> generic<T extends NativeType>() {
Pointer<T> pointer = nullptr;
pointer = malloc(); //# 1320: compile-time error
pointer = calloc(); //# 1320: compile-time error
return pointer;
}
@@ -566,5 +567,5 @@ void testAllocateGeneric() {
}
void testAllocateNativeType() {
malloc(); //# 1321: compile-time error
calloc(); //# 1321: compile-time error
}