diff --git a/tests/ffi/aliasing_test.dart b/tests/ffi/aliasing_test.dart index 6c2f698c0e2..946e1e4b05d 100644 --- a/tests/ffi/aliasing_test.dart +++ b/tests/ffi/aliasing_test.dart @@ -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(); + final source = calloc(); 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(); + final source = calloc(); final alias = source.cast().cast(); 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(); + final source = calloc(); final alias = source.cast().cast(); final alias2 = source.cast().cast(); 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(count: 2); + final source = calloc(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(count: 3); + final source = calloc(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(count: 2); + final source = calloc(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(count: 3); + final source = calloc(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(); + final source = calloc(); final alias = Pointer.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(); + final source = calloc(); final alias = Pointer.fromAddress(source.address); final alias2 = Pointer.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(); - final source = allocate(); + final helper = calloc(); + final source = calloc(); helper.value = source.address; final alias = Pointer.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(); - final source = allocate(); + final helper = calloc(); + final source = calloc(); helper.value = source.address; final alias = Pointer.fromAddress(helper.value); final alias2 = Pointer.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("IntComputation"); void testAliasFromAddressViaNativeFunction() { - final source = allocate(); + final source = calloc(); final alias = Pointer.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(); + final source = calloc(); final alias = Pointer.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 makeDerived(Pointer source) => source.offsetBy(7).cast(); testPartialOverlap() { - final source = allocate(count: 2); + final source = calloc(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); } diff --git a/tests/ffi/calloc.dart b/tests/ffi/calloc.dart index f76e9cb23e0..e17238a91b1 100644 --- a/tests/ffi/calloc.dart +++ b/tests/ffi/calloc.dart @@ -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 diff --git a/tests/ffi/coordinate.dart b/tests/ffi/coordinate.dart index 950731296fe..abd6ecdfcef 100644 --- a/tests/ffi/coordinate.dart +++ b/tests/ffi/coordinate.dart @@ -17,8 +17,9 @@ class Coordinate extends Struct { external Pointer next; - factory Coordinate.allocate(double x, double y, Pointer next) { - return allocate().ref + factory Coordinate.allocate( + Allocator allocator, double x, double y, Pointer next) { + return allocator().ref ..x = x ..y = y ..next = next; diff --git a/tests/ffi/coordinate_nnbd_workaround.dart b/tests/ffi/coordinate_nnbd_workaround.dart index 515badd22d8..abd8dba96f0 100644 --- a/tests/ffi/coordinate_nnbd_workaround.dart +++ b/tests/ffi/coordinate_nnbd_workaround.dart @@ -20,8 +20,9 @@ class Coordinate extends Struct { external Pointer get next; external set next(Pointer v); - factory Coordinate.allocate(double x, double y, Pointer next) { - return allocate().ref + factory Coordinate.allocate( + Allocator allocator, double x, double y, Pointer next) { + return allocator().ref ..x = x ..y = y ..next = next; diff --git a/tests/ffi/data_not_asan_test.dart b/tests/ffi/data_not_asan_test.dart index e95658f2fd1..69257d6cb28 100644 --- a/tests/ffi/data_not_asan_test.dart +++ b/tests/ffi/data_not_asan_test.dart @@ -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(count: maxInt)); + Expect.throws(() => calloc(maxInt)); // Try to allocate almost the full 64 bit address space. int maxInt1_8 = 1152921504606846975; // 2^60 -1 - Expect.throws(() => allocate(count: maxInt1_8)); + Expect.throws(() => calloc(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(count: -1)); + Expect.throws(() => calloc(-1)); } diff --git a/tests/ffi/data_test.dart b/tests/ffi/data_test.dart index 0dd067042bc..47b88c50e00 100644 --- a/tests/ffi/data_test.dart +++ b/tests/ffi/data_test.dart @@ -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 p = allocate(); + Pointer p = calloc(); p.value = 42; Expect.equals(42, p.value); - free(p); + calloc.free(p); } void testPointerFromPointer() { - Pointer p = allocate(); + Pointer p = calloc(); p.value = 1337; int ptr = p.address; Pointer p2 = Pointer.fromAddress(ptr); Expect.equals(1337, p2.value); - free(p); + calloc.free(p); } void testPointerPointerArithmetic() { - Pointer p = allocate(count: 2); + Pointer p = calloc(2); Pointer p2 = p.elementAt(1); p2.value = 100; Pointer p3 = p.offsetBy(8); Expect.equals(100, p3.value); - free(p); + calloc.free(p); } void testPointerPointerArithmeticSizes() { - Pointer p = allocate(count: 2); + Pointer p = calloc(2); Pointer p2 = p.elementAt(1); int addr = p.address; Expect.equals(addr + 8, p2.address); - free(p); + calloc.free(p); - Pointer p3 = allocate(count: 2); + Pointer p3 = calloc(2); Pointer 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 p = nullptr; try { - p = allocate(count: 0); + p = calloc(0); } on Exception { returnedNullPointer = true; } if (!returnedNullPointer) { - free(p); + calloc.free(p); } } void testPointerCast() { - Pointer p = allocate(); + Pointer p = calloc(); p.cast(); // gets the correct type args back - free(p); + calloc.free(p); } void testCastGeneric() { @@ -123,9 +124,9 @@ void testCastGeneric() { return p.cast(); } - Pointer p = allocate(); + Pointer p = calloc(); Pointer p2 = generic(p); - free(p); + calloc.free(p); } void testCastGeneric2() { @@ -133,41 +134,41 @@ void testCastGeneric2() { return p.cast(); } - Pointer p = allocate(); + Pointer p = calloc(); Pointer p2 = generic(p); - free(p); + calloc.free(p); } void testCastNativeType() { - Pointer p = allocate(); + Pointer p = calloc(); p.cast(); - free(p); + calloc.free(p); } void testCondensedNumbersInt8() { - Pointer p = allocate(count: 8); + Pointer 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 p = allocate(count: 8); + Pointer 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 p = allocate(); + Pointer 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 p = allocate(); + Pointer 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 p = allocate(); + Pointer 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 p = allocate(); + Pointer 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 p = allocate(); + Pointer 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 p = allocate(); + Pointer 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 p = allocate(); + Pointer 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 p = allocate(); + Pointer 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 p = allocate(); + Pointer 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 p = allocate(); + Pointer 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 p = allocate(); + Pointer p = calloc(); p.value = 1.4260258159703532e-105; Expect.equals(1.4260258159703532e-105, p.value); - free(p); + calloc.free(p); } void testVoid() { - Pointer p1 = allocate(); + Pointer p1 = calloc(); Pointer p2 = p1.cast(); // make this dart pointer opaque p2.address; // we can print the address - free(p2); + calloc.free(p2); } void testPointerPointer() { - Pointer p = allocate(); + Pointer p = calloc(); p.value = 17; - Pointer> p2 = allocate(); + Pointer> p2 = calloc(); p2.value = p; Expect.equals(17, p2.value.value); - free(p2); - free(p); + calloc.free(p2); + calloc.free(p); } void testPointerPointerNull() { - Pointer> pointerToPointer = allocate(); + Pointer> pointerToPointer = calloc(); Pointer 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 next = allocate(); + Pointer next = calloc(); head.value = next.address; createChain(next, length - 1, value); } @@ -378,14 +379,14 @@ void testPointerChain(int length) { void freeChain(Pointer head, int length) { Pointer next = Pointer.fromAddress(head.value); - free(head); + calloc.free(head); if (length == 0) { return; } freeChain(next, length - 1); } - Pointer head = allocate(); + Pointer 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 p = allocate(); + Pointer p = calloc(); Expect.isTrue(p is Pointer); - free(p); + calloc.free(p); } void testToString() { - Pointer p = allocate(); + Pointer p = calloc(); Expect.stringEquals( "Pointer: address=0x", p.toString().substring(0, 26)); - free(p); + calloc.free(p); Pointer p2 = Pointer.fromAddress(0x123abc); Expect.stringEquals("Pointer: address=0x123abc", p2.toString()); } @@ -423,13 +424,13 @@ typedef Int8UnOp = Int8 Function(Int8); void testAllocateVoid() { Expect.throws(() { - Pointer p = allocate(); + Pointer p = calloc(); }); } void testAllocateNativeFunction() { Expect.throws(() { - Pointer> p = allocate(); + Pointer> p = calloc(); }); } @@ -463,7 +464,7 @@ void testSizeOfNativeType() { } void testDynamicInvocation() { - dynamic p = allocate(); + dynamic p = calloc(); 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 p2 = p.cast(); - free(p); + calloc.free(p); } final nullableInt64ElementAt1 = ffiTestFunctions.lookupFunction< diff --git a/tests/ffi/extension_methods_test.dart b/tests/ffi/extension_methods_test.dart index d4e8e4af35f..5c688e0e938 100644 --- a/tests/ffi/extension_methods_test.dart +++ b/tests/ffi/extension_methods_test.dart @@ -7,6 +7,8 @@ import 'dart:ffi'; import "package:expect/expect.dart"; import "package:ffi/ffi.dart"; +import 'calloc.dart'; + main(List arguments) { for (int i = 0; i < 100; i++) { testStoreLoad(); @@ -15,7 +17,7 @@ main(List arguments) { } testStoreLoad() { - final p = allocate(count: 2); + final p = calloc(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(count: 2); + final p1 = calloc(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>(count: 2); + final p2 = calloc>(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(); + final p3 = calloc(); Foo foo = p3.ref; foo.a = 1; Expect.equals(1, foo.a); - free(p3); + calloc.free(p3); } testReifiedGeneric() { - final p = allocate>(); + final p = calloc>(); Pointer> p2 = p; Expect.isTrue(p2.value is Pointer); - free(p); + calloc.free(p); } class Foo extends Struct { diff --git a/tests/ffi/external_typed_data_test.dart b/tests/ffi/external_typed_data_test.dart index 2b584b4b7ab..1327dea6fbd 100644 --- a/tests/ffi/external_typed_data_test.dart +++ b/tests/ffi/external_typed_data_test.dart @@ -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 ptr = allocate(); + Pointer 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 ptr = allocate(); + Pointer 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 ptr = allocate(); + Pointer 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 ptr = allocate(); + Pointer 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 ptr = allocate(); + Pointer 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 ptr = allocate(); + Pointer 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 ptr = allocate(); + Pointer 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 ptr = allocate(); + Pointer 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 ptr = allocate(); + Pointer 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 ptr = allocate(); + Pointer 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 ptr = allocate(); + Pointer 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 ptr = allocate(); + Pointer 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 ptr = allocate(); + Pointer 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 ptr = allocate(); + Pointer 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 ptr = allocate(); + Pointer 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 ptr = allocate(); + Pointer 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 ptr = allocate(); + Pointer 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 ptr = allocate(); + Pointer 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 ptr = allocate(); + Pointer 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 ptr = allocate(); + Pointer 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 ptr = allocate(count: count); + Pointer 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 ptr = allocate(count: count); + Pointer 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() { diff --git a/tests/ffi/function_callbacks_structs_by_value_generated_test.dart b/tests/ffi/function_callbacks_structs_by_value_generated_test.dart index 75ef76f1e2c..785f03acd2b 100644 --- a/tests/ffi/function_callbacks_structs_by_value_generated_test.dart +++ b/tests/ffi/function_callbacks_structs_by_value_generated_test.dart @@ -16,6 +16,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().ref; + Struct1ByteInt result = calloc().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().ref; + calloc().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().ref; + calloc().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().ref; + calloc().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().ref; + calloc().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().ref; + calloc().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().ref; + Struct8BytesInt result = calloc().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().ref; + calloc().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().ref; + Struct8BytesMixed result = calloc().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().ref; + calloc().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().ref; + calloc().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().ref; + calloc().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().ref; + calloc().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().ref; + Struct16BytesMixed result = calloc().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().ref; + Struct16BytesMixed2 result = calloc().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().ref; + Struct17BytesInt result = calloc().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().ref; + calloc().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().ref; + calloc().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().ref; + calloc().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().ref; + calloc().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().ref; + calloc().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().ref; + calloc().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().ref; + StructAlignmentInt16 result = calloc().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().ref; + StructAlignmentInt32 result = calloc().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().ref; + StructAlignmentInt64 result = calloc().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().ref; + Struct8BytesNestedInt result = calloc().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().ref; + Struct8BytesNestedFloat result = calloc().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().ref; + Struct8BytesNestedFloat2 result = calloc().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().ref; + Struct8BytesNestedMixed result = calloc().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().ref; + Struct16BytesNestedInt result = calloc().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().ref; + Struct32BytesNestedInt result = calloc().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().ref; + calloc().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().ref; + calloc().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().ref; + calloc().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().ref; + calloc().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); } diff --git a/tests/ffi/function_callbacks_structs_by_value_test.dart b/tests/ffi/function_callbacks_structs_by_value_test.dart index 23c9946e0d7..5e9399a547d 100644 --- a/tests/ffi/function_callbacks_structs_by_value_test.dart +++ b/tests/ffi/function_callbacks_structs_by_value_test.dart @@ -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().ref; + final struct = calloc().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().ref; + final pointerBackedStruct = calloc().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); } diff --git a/tests/ffi/function_structs_by_value_generated_test.dart b/tests/ffi/function_structs_by_value_generated_test.dart index 8e800fccec5..c8b91cb0372 100644 --- a/tests/ffi/function_structs_by_value_generated_test.dart +++ b/tests/ffi/function_structs_by_value_generated_test.dart @@ -15,6 +15,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"); @@ -1053,16 +1054,16 @@ final passStruct1ByteIntx10 = ffiTestFunctions.lookupFunction< /// Smallest struct with data. /// 10 struct arguments will exhaust available registers. void testPassStruct1ByteIntx10() { - Struct1ByteInt a0 = allocate().ref; - Struct1ByteInt a1 = allocate().ref; - Struct1ByteInt a2 = allocate().ref; - Struct1ByteInt a3 = allocate().ref; - Struct1ByteInt a4 = allocate().ref; - Struct1ByteInt a5 = allocate().ref; - Struct1ByteInt a6 = allocate().ref; - Struct1ByteInt a7 = allocate().ref; - Struct1ByteInt a8 = allocate().ref; - Struct1ByteInt a9 = allocate().ref; + Struct1ByteInt a0 = calloc().ref; + Struct1ByteInt a1 = calloc().ref; + Struct1ByteInt a2 = calloc().ref; + Struct1ByteInt a3 = calloc().ref; + Struct1ByteInt a4 = calloc().ref; + Struct1ByteInt a5 = calloc().ref; + Struct1ByteInt a6 = calloc().ref; + Struct1ByteInt a7 = calloc().ref; + Struct1ByteInt a8 = calloc().ref; + Struct1ByteInt a9 = calloc().ref; a0.a0 = -1; a1.a0 = 2; @@ -1081,16 +1082,16 @@ void testPassStruct1ByteIntx10() { Expect.equals(5, result); - free(a0.addressOf); - free(a1.addressOf); - free(a2.addressOf); - free(a3.addressOf); - free(a4.addressOf); - free(a5.addressOf); - free(a6.addressOf); - free(a7.addressOf); - free(a8.addressOf); - free(a9.addressOf); + calloc.free(a0.addressOf); + calloc.free(a1.addressOf); + calloc.free(a2.addressOf); + calloc.free(a3.addressOf); + calloc.free(a4.addressOf); + calloc.free(a5.addressOf); + calloc.free(a6.addressOf); + calloc.free(a7.addressOf); + calloc.free(a8.addressOf); + calloc.free(a9.addressOf); } final passStruct3BytesHomogeneousUint8x10 = ffiTestFunctions.lookupFunction< @@ -1120,26 +1121,16 @@ final passStruct3BytesHomogeneousUint8x10 = ffiTestFunctions.lookupFunction< /// Not a multiple of word size, not a power of two. /// 10 struct arguments will exhaust available registers. void testPassStruct3BytesHomogeneousUint8x10() { - Struct3BytesHomogeneousUint8 a0 = - allocate().ref; - Struct3BytesHomogeneousUint8 a1 = - allocate().ref; - Struct3BytesHomogeneousUint8 a2 = - allocate().ref; - Struct3BytesHomogeneousUint8 a3 = - allocate().ref; - Struct3BytesHomogeneousUint8 a4 = - allocate().ref; - Struct3BytesHomogeneousUint8 a5 = - allocate().ref; - Struct3BytesHomogeneousUint8 a6 = - allocate().ref; - Struct3BytesHomogeneousUint8 a7 = - allocate().ref; - Struct3BytesHomogeneousUint8 a8 = - allocate().ref; - Struct3BytesHomogeneousUint8 a9 = - allocate().ref; + Struct3BytesHomogeneousUint8 a0 = calloc().ref; + Struct3BytesHomogeneousUint8 a1 = calloc().ref; + Struct3BytesHomogeneousUint8 a2 = calloc().ref; + Struct3BytesHomogeneousUint8 a3 = calloc().ref; + Struct3BytesHomogeneousUint8 a4 = calloc().ref; + Struct3BytesHomogeneousUint8 a5 = calloc().ref; + Struct3BytesHomogeneousUint8 a6 = calloc().ref; + Struct3BytesHomogeneousUint8 a7 = calloc().ref; + Struct3BytesHomogeneousUint8 a8 = calloc().ref; + Struct3BytesHomogeneousUint8 a9 = calloc().ref; a0.a0 = 1; a0.a1 = 2; @@ -1179,16 +1170,16 @@ void testPassStruct3BytesHomogeneousUint8x10() { Expect.equals(465, result); - free(a0.addressOf); - free(a1.addressOf); - free(a2.addressOf); - free(a3.addressOf); - free(a4.addressOf); - free(a5.addressOf); - free(a6.addressOf); - free(a7.addressOf); - free(a8.addressOf); - free(a9.addressOf); + calloc.free(a0.addressOf); + calloc.free(a1.addressOf); + calloc.free(a2.addressOf); + calloc.free(a3.addressOf); + calloc.free(a4.addressOf); + calloc.free(a5.addressOf); + calloc.free(a6.addressOf); + calloc.free(a7.addressOf); + calloc.free(a8.addressOf); + calloc.free(a9.addressOf); } final passStruct3BytesInt2ByteAlignedx10 = ffiTestFunctions.lookupFunction< @@ -1219,16 +1210,16 @@ final passStruct3BytesInt2ByteAlignedx10 = ffiTestFunctions.lookupFunction< /// With alignment rules taken into account size is 4 bytes. /// 10 struct arguments will exhaust available registers. void testPassStruct3BytesInt2ByteAlignedx10() { - Struct3BytesInt2ByteAligned a0 = allocate().ref; - Struct3BytesInt2ByteAligned a1 = allocate().ref; - Struct3BytesInt2ByteAligned a2 = allocate().ref; - Struct3BytesInt2ByteAligned a3 = allocate().ref; - Struct3BytesInt2ByteAligned a4 = allocate().ref; - Struct3BytesInt2ByteAligned a5 = allocate().ref; - Struct3BytesInt2ByteAligned a6 = allocate().ref; - Struct3BytesInt2ByteAligned a7 = allocate().ref; - Struct3BytesInt2ByteAligned a8 = allocate().ref; - Struct3BytesInt2ByteAligned a9 = allocate().ref; + Struct3BytesInt2ByteAligned a0 = calloc().ref; + Struct3BytesInt2ByteAligned a1 = calloc().ref; + Struct3BytesInt2ByteAligned a2 = calloc().ref; + Struct3BytesInt2ByteAligned a3 = calloc().ref; + Struct3BytesInt2ByteAligned a4 = calloc().ref; + Struct3BytesInt2ByteAligned a5 = calloc().ref; + Struct3BytesInt2ByteAligned a6 = calloc().ref; + Struct3BytesInt2ByteAligned a7 = calloc().ref; + Struct3BytesInt2ByteAligned a8 = calloc().ref; + Struct3BytesInt2ByteAligned a9 = calloc().ref; a0.a0 = -1; a0.a1 = 2; @@ -1258,16 +1249,16 @@ void testPassStruct3BytesInt2ByteAlignedx10() { Expect.equals(10, result); - free(a0.addressOf); - free(a1.addressOf); - free(a2.addressOf); - free(a3.addressOf); - free(a4.addressOf); - free(a5.addressOf); - free(a6.addressOf); - free(a7.addressOf); - free(a8.addressOf); - free(a9.addressOf); + calloc.free(a0.addressOf); + calloc.free(a1.addressOf); + calloc.free(a2.addressOf); + calloc.free(a3.addressOf); + calloc.free(a4.addressOf); + calloc.free(a5.addressOf); + calloc.free(a6.addressOf); + calloc.free(a7.addressOf); + calloc.free(a8.addressOf); + calloc.free(a9.addressOf); } final passStruct4BytesHomogeneousInt16x10 = ffiTestFunctions.lookupFunction< @@ -1297,26 +1288,16 @@ final passStruct4BytesHomogeneousInt16x10 = ffiTestFunctions.lookupFunction< /// Exactly word size on 32-bit architectures. /// 10 struct arguments will exhaust available registers. void testPassStruct4BytesHomogeneousInt16x10() { - Struct4BytesHomogeneousInt16 a0 = - allocate().ref; - Struct4BytesHomogeneousInt16 a1 = - allocate().ref; - Struct4BytesHomogeneousInt16 a2 = - allocate().ref; - Struct4BytesHomogeneousInt16 a3 = - allocate().ref; - Struct4BytesHomogeneousInt16 a4 = - allocate().ref; - Struct4BytesHomogeneousInt16 a5 = - allocate().ref; - Struct4BytesHomogeneousInt16 a6 = - allocate().ref; - Struct4BytesHomogeneousInt16 a7 = - allocate().ref; - Struct4BytesHomogeneousInt16 a8 = - allocate().ref; - Struct4BytesHomogeneousInt16 a9 = - allocate().ref; + Struct4BytesHomogeneousInt16 a0 = calloc().ref; + Struct4BytesHomogeneousInt16 a1 = calloc().ref; + Struct4BytesHomogeneousInt16 a2 = calloc().ref; + Struct4BytesHomogeneousInt16 a3 = calloc().ref; + Struct4BytesHomogeneousInt16 a4 = calloc().ref; + Struct4BytesHomogeneousInt16 a5 = calloc().ref; + Struct4BytesHomogeneousInt16 a6 = calloc().ref; + Struct4BytesHomogeneousInt16 a7 = calloc().ref; + Struct4BytesHomogeneousInt16 a8 = calloc().ref; + Struct4BytesHomogeneousInt16 a9 = calloc().ref; a0.a0 = -1; a0.a1 = 2; @@ -1346,16 +1327,16 @@ void testPassStruct4BytesHomogeneousInt16x10() { Expect.equals(10, result); - free(a0.addressOf); - free(a1.addressOf); - free(a2.addressOf); - free(a3.addressOf); - free(a4.addressOf); - free(a5.addressOf); - free(a6.addressOf); - free(a7.addressOf); - free(a8.addressOf); - free(a9.addressOf); + calloc.free(a0.addressOf); + calloc.free(a1.addressOf); + calloc.free(a2.addressOf); + calloc.free(a3.addressOf); + calloc.free(a4.addressOf); + calloc.free(a5.addressOf); + calloc.free(a6.addressOf); + calloc.free(a7.addressOf); + calloc.free(a8.addressOf); + calloc.free(a9.addressOf); } final passStruct7BytesHomogeneousUint8x10 = ffiTestFunctions.lookupFunction< @@ -1385,26 +1366,16 @@ final passStruct7BytesHomogeneousUint8x10 = ffiTestFunctions.lookupFunction< /// Sub word size on 64 bit architectures. /// 10 struct arguments will exhaust available registers. void testPassStruct7BytesHomogeneousUint8x10() { - Struct7BytesHomogeneousUint8 a0 = - allocate().ref; - Struct7BytesHomogeneousUint8 a1 = - allocate().ref; - Struct7BytesHomogeneousUint8 a2 = - allocate().ref; - Struct7BytesHomogeneousUint8 a3 = - allocate().ref; - Struct7BytesHomogeneousUint8 a4 = - allocate().ref; - Struct7BytesHomogeneousUint8 a5 = - allocate().ref; - Struct7BytesHomogeneousUint8 a6 = - allocate().ref; - Struct7BytesHomogeneousUint8 a7 = - allocate().ref; - Struct7BytesHomogeneousUint8 a8 = - allocate().ref; - Struct7BytesHomogeneousUint8 a9 = - allocate().ref; + Struct7BytesHomogeneousUint8 a0 = calloc().ref; + Struct7BytesHomogeneousUint8 a1 = calloc().ref; + Struct7BytesHomogeneousUint8 a2 = calloc().ref; + Struct7BytesHomogeneousUint8 a3 = calloc().ref; + Struct7BytesHomogeneousUint8 a4 = calloc().ref; + Struct7BytesHomogeneousUint8 a5 = calloc().ref; + Struct7BytesHomogeneousUint8 a6 = calloc().ref; + Struct7BytesHomogeneousUint8 a7 = calloc().ref; + Struct7BytesHomogeneousUint8 a8 = calloc().ref; + Struct7BytesHomogeneousUint8 a9 = calloc().ref; a0.a0 = 1; a0.a1 = 2; @@ -1484,16 +1455,16 @@ void testPassStruct7BytesHomogeneousUint8x10() { Expect.equals(2485, result); - free(a0.addressOf); - free(a1.addressOf); - free(a2.addressOf); - free(a3.addressOf); - free(a4.addressOf); - free(a5.addressOf); - free(a6.addressOf); - free(a7.addressOf); - free(a8.addressOf); - free(a9.addressOf); + calloc.free(a0.addressOf); + calloc.free(a1.addressOf); + calloc.free(a2.addressOf); + calloc.free(a3.addressOf); + calloc.free(a4.addressOf); + calloc.free(a5.addressOf); + calloc.free(a6.addressOf); + calloc.free(a7.addressOf); + calloc.free(a8.addressOf); + calloc.free(a9.addressOf); } final passStruct7BytesInt4ByteAlignedx10 = ffiTestFunctions.lookupFunction< @@ -1524,16 +1495,16 @@ final passStruct7BytesInt4ByteAlignedx10 = ffiTestFunctions.lookupFunction< /// With alignment rules taken into account size is 8 bytes. /// 10 struct arguments will exhaust available registers. void testPassStruct7BytesInt4ByteAlignedx10() { - Struct7BytesInt4ByteAligned a0 = allocate().ref; - Struct7BytesInt4ByteAligned a1 = allocate().ref; - Struct7BytesInt4ByteAligned a2 = allocate().ref; - Struct7BytesInt4ByteAligned a3 = allocate().ref; - Struct7BytesInt4ByteAligned a4 = allocate().ref; - Struct7BytesInt4ByteAligned a5 = allocate().ref; - Struct7BytesInt4ByteAligned a6 = allocate().ref; - Struct7BytesInt4ByteAligned a7 = allocate().ref; - Struct7BytesInt4ByteAligned a8 = allocate().ref; - Struct7BytesInt4ByteAligned a9 = allocate().ref; + Struct7BytesInt4ByteAligned a0 = calloc().ref; + Struct7BytesInt4ByteAligned a1 = calloc().ref; + Struct7BytesInt4ByteAligned a2 = calloc().ref; + Struct7BytesInt4ByteAligned a3 = calloc().ref; + Struct7BytesInt4ByteAligned a4 = calloc().ref; + Struct7BytesInt4ByteAligned a5 = calloc().ref; + Struct7BytesInt4ByteAligned a6 = calloc().ref; + Struct7BytesInt4ByteAligned a7 = calloc().ref; + Struct7BytesInt4ByteAligned a8 = calloc().ref; + Struct7BytesInt4ByteAligned a9 = calloc().ref; a0.a0 = -1; a0.a1 = 2; @@ -1573,16 +1544,16 @@ void testPassStruct7BytesInt4ByteAlignedx10() { Expect.equals(15, result); - free(a0.addressOf); - free(a1.addressOf); - free(a2.addressOf); - free(a3.addressOf); - free(a4.addressOf); - free(a5.addressOf); - free(a6.addressOf); - free(a7.addressOf); - free(a8.addressOf); - free(a9.addressOf); + calloc.free(a0.addressOf); + calloc.free(a1.addressOf); + calloc.free(a2.addressOf); + calloc.free(a3.addressOf); + calloc.free(a4.addressOf); + calloc.free(a5.addressOf); + calloc.free(a6.addressOf); + calloc.free(a7.addressOf); + calloc.free(a8.addressOf); + calloc.free(a9.addressOf); } final passStruct8BytesIntx10 = ffiTestFunctions.lookupFunction< @@ -1612,16 +1583,16 @@ final passStruct8BytesIntx10 = ffiTestFunctions.lookupFunction< /// Exactly word size struct on 64bit architectures. /// 10 struct arguments will exhaust available registers. void testPassStruct8BytesIntx10() { - Struct8BytesInt a0 = allocate().ref; - Struct8BytesInt a1 = allocate().ref; - Struct8BytesInt a2 = allocate().ref; - Struct8BytesInt a3 = allocate().ref; - Struct8BytesInt a4 = allocate().ref; - Struct8BytesInt a5 = allocate().ref; - Struct8BytesInt a6 = allocate().ref; - Struct8BytesInt a7 = allocate().ref; - Struct8BytesInt a8 = allocate().ref; - Struct8BytesInt a9 = allocate().ref; + Struct8BytesInt a0 = calloc().ref; + Struct8BytesInt a1 = calloc().ref; + Struct8BytesInt a2 = calloc().ref; + Struct8BytesInt a3 = calloc().ref; + Struct8BytesInt a4 = calloc().ref; + Struct8BytesInt a5 = calloc().ref; + Struct8BytesInt a6 = calloc().ref; + Struct8BytesInt a7 = calloc().ref; + Struct8BytesInt a8 = calloc().ref; + Struct8BytesInt a9 = calloc().ref; a0.a0 = -1; a0.a1 = 2; @@ -1660,16 +1631,16 @@ void testPassStruct8BytesIntx10() { Expect.equals(15, result); - free(a0.addressOf); - free(a1.addressOf); - free(a2.addressOf); - free(a3.addressOf); - free(a4.addressOf); - free(a5.addressOf); - free(a6.addressOf); - free(a7.addressOf); - free(a8.addressOf); - free(a9.addressOf); + calloc.free(a0.addressOf); + calloc.free(a1.addressOf); + calloc.free(a2.addressOf); + calloc.free(a3.addressOf); + calloc.free(a4.addressOf); + calloc.free(a5.addressOf); + calloc.free(a6.addressOf); + calloc.free(a7.addressOf); + calloc.free(a8.addressOf); + calloc.free(a9.addressOf); } final passStruct8BytesHomogeneousFloatx10 = ffiTestFunctions.lookupFunction< @@ -1699,26 +1670,16 @@ final passStruct8BytesHomogeneousFloatx10 = ffiTestFunctions.lookupFunction< /// Arguments passed in FP registers as long as they fit. /// 10 struct arguments will exhaust available registers. void testPassStruct8BytesHomogeneousFloatx10() { - Struct8BytesHomogeneousFloat a0 = - allocate().ref; - Struct8BytesHomogeneousFloat a1 = - allocate().ref; - Struct8BytesHomogeneousFloat a2 = - allocate().ref; - Struct8BytesHomogeneousFloat a3 = - allocate().ref; - Struct8BytesHomogeneousFloat a4 = - allocate().ref; - Struct8BytesHomogeneousFloat a5 = - allocate().ref; - Struct8BytesHomogeneousFloat a6 = - allocate().ref; - Struct8BytesHomogeneousFloat a7 = - allocate().ref; - Struct8BytesHomogeneousFloat a8 = - allocate().ref; - Struct8BytesHomogeneousFloat a9 = - allocate().ref; + Struct8BytesHomogeneousFloat a0 = calloc().ref; + Struct8BytesHomogeneousFloat a1 = calloc().ref; + Struct8BytesHomogeneousFloat a2 = calloc().ref; + Struct8BytesHomogeneousFloat a3 = calloc().ref; + Struct8BytesHomogeneousFloat a4 = calloc().ref; + Struct8BytesHomogeneousFloat a5 = calloc().ref; + Struct8BytesHomogeneousFloat a6 = calloc().ref; + Struct8BytesHomogeneousFloat a7 = calloc().ref; + Struct8BytesHomogeneousFloat a8 = calloc().ref; + Struct8BytesHomogeneousFloat a9 = calloc().ref; a0.a0 = -1.0; a0.a1 = 2.0; @@ -1748,16 +1709,16 @@ void testPassStruct8BytesHomogeneousFloatx10() { Expect.approxEquals(10.0, result); - free(a0.addressOf); - free(a1.addressOf); - free(a2.addressOf); - free(a3.addressOf); - free(a4.addressOf); - free(a5.addressOf); - free(a6.addressOf); - free(a7.addressOf); - free(a8.addressOf); - free(a9.addressOf); + calloc.free(a0.addressOf); + calloc.free(a1.addressOf); + calloc.free(a2.addressOf); + calloc.free(a3.addressOf); + calloc.free(a4.addressOf); + calloc.free(a5.addressOf); + calloc.free(a6.addressOf); + calloc.free(a7.addressOf); + calloc.free(a8.addressOf); + calloc.free(a9.addressOf); } final passStruct8BytesMixedx10 = ffiTestFunctions.lookupFunction< @@ -1787,16 +1748,16 @@ final passStruct8BytesMixedx10 = ffiTestFunctions.lookupFunction< /// On x64, arguments go in int registers because it is not only float. /// 10 struct arguments will exhaust available registers. void testPassStruct8BytesMixedx10() { - Struct8BytesMixed a0 = allocate().ref; - Struct8BytesMixed a1 = allocate().ref; - Struct8BytesMixed a2 = allocate().ref; - Struct8BytesMixed a3 = allocate().ref; - Struct8BytesMixed a4 = allocate().ref; - Struct8BytesMixed a5 = allocate().ref; - Struct8BytesMixed a6 = allocate().ref; - Struct8BytesMixed a7 = allocate().ref; - Struct8BytesMixed a8 = allocate().ref; - Struct8BytesMixed a9 = allocate().ref; + Struct8BytesMixed a0 = calloc().ref; + Struct8BytesMixed a1 = calloc().ref; + Struct8BytesMixed a2 = calloc().ref; + Struct8BytesMixed a3 = calloc().ref; + Struct8BytesMixed a4 = calloc().ref; + Struct8BytesMixed a5 = calloc().ref; + Struct8BytesMixed a6 = calloc().ref; + Struct8BytesMixed a7 = calloc().ref; + Struct8BytesMixed a8 = calloc().ref; + Struct8BytesMixed a9 = calloc().ref; a0.a0 = -1.0; a0.a1 = 2; @@ -1836,16 +1797,16 @@ void testPassStruct8BytesMixedx10() { Expect.approxEquals(15.0, result); - free(a0.addressOf); - free(a1.addressOf); - free(a2.addressOf); - free(a3.addressOf); - free(a4.addressOf); - free(a5.addressOf); - free(a6.addressOf); - free(a7.addressOf); - free(a8.addressOf); - free(a9.addressOf); + calloc.free(a0.addressOf); + calloc.free(a1.addressOf); + calloc.free(a2.addressOf); + calloc.free(a3.addressOf); + calloc.free(a4.addressOf); + calloc.free(a5.addressOf); + calloc.free(a6.addressOf); + calloc.free(a7.addressOf); + calloc.free(a8.addressOf); + calloc.free(a9.addressOf); } final passStruct9BytesHomogeneousUint8x10 = ffiTestFunctions.lookupFunction< @@ -1878,26 +1839,16 @@ final passStruct9BytesHomogeneousUint8x10 = ffiTestFunctions.lookupFunction< /// Tests upper bytes in the integer registers that are partly filled. /// Tests stack alignment of non word size stack arguments. void testPassStruct9BytesHomogeneousUint8x10() { - Struct9BytesHomogeneousUint8 a0 = - allocate().ref; - Struct9BytesHomogeneousUint8 a1 = - allocate().ref; - Struct9BytesHomogeneousUint8 a2 = - allocate().ref; - Struct9BytesHomogeneousUint8 a3 = - allocate().ref; - Struct9BytesHomogeneousUint8 a4 = - allocate().ref; - Struct9BytesHomogeneousUint8 a5 = - allocate().ref; - Struct9BytesHomogeneousUint8 a6 = - allocate().ref; - Struct9BytesHomogeneousUint8 a7 = - allocate().ref; - Struct9BytesHomogeneousUint8 a8 = - allocate().ref; - Struct9BytesHomogeneousUint8 a9 = - allocate().ref; + Struct9BytesHomogeneousUint8 a0 = calloc().ref; + Struct9BytesHomogeneousUint8 a1 = calloc().ref; + Struct9BytesHomogeneousUint8 a2 = calloc().ref; + Struct9BytesHomogeneousUint8 a3 = calloc().ref; + Struct9BytesHomogeneousUint8 a4 = calloc().ref; + Struct9BytesHomogeneousUint8 a5 = calloc().ref; + Struct9BytesHomogeneousUint8 a6 = calloc().ref; + Struct9BytesHomogeneousUint8 a7 = calloc().ref; + Struct9BytesHomogeneousUint8 a8 = calloc().ref; + Struct9BytesHomogeneousUint8 a9 = calloc().ref; a0.a0 = 1; a0.a1 = 2; @@ -1997,16 +1948,16 @@ void testPassStruct9BytesHomogeneousUint8x10() { Expect.equals(4095, result); - free(a0.addressOf); - free(a1.addressOf); - free(a2.addressOf); - free(a3.addressOf); - free(a4.addressOf); - free(a5.addressOf); - free(a6.addressOf); - free(a7.addressOf); - free(a8.addressOf); - free(a9.addressOf); + calloc.free(a0.addressOf); + calloc.free(a1.addressOf); + calloc.free(a2.addressOf); + calloc.free(a3.addressOf); + calloc.free(a4.addressOf); + calloc.free(a5.addressOf); + calloc.free(a6.addressOf); + calloc.free(a7.addressOf); + calloc.free(a8.addressOf); + calloc.free(a9.addressOf); } final passStruct9BytesInt4Or8ByteAlignedx10 = ffiTestFunctions.lookupFunction< @@ -2040,25 +1991,25 @@ final passStruct9BytesInt4Or8ByteAlignedx10 = ffiTestFunctions.lookupFunction< /// void testPassStruct9BytesInt4Or8ByteAlignedx10() { Struct9BytesInt4Or8ByteAligned a0 = - allocate().ref; + calloc().ref; Struct9BytesInt4Or8ByteAligned a1 = - allocate().ref; + calloc().ref; Struct9BytesInt4Or8ByteAligned a2 = - allocate().ref; + calloc().ref; Struct9BytesInt4Or8ByteAligned a3 = - allocate().ref; + calloc().ref; Struct9BytesInt4Or8ByteAligned a4 = - allocate().ref; + calloc().ref; Struct9BytesInt4Or8ByteAligned a5 = - allocate().ref; + calloc().ref; Struct9BytesInt4Or8ByteAligned a6 = - allocate().ref; + calloc().ref; Struct9BytesInt4Or8ByteAligned a7 = - allocate().ref; + calloc().ref; Struct9BytesInt4Or8ByteAligned a8 = - allocate().ref; + calloc().ref; Struct9BytesInt4Or8ByteAligned a9 = - allocate().ref; + calloc().ref; a0.a0 = -1; a0.a1 = 2; @@ -2088,16 +2039,16 @@ void testPassStruct9BytesInt4Or8ByteAlignedx10() { Expect.equals(10, result); - free(a0.addressOf); - free(a1.addressOf); - free(a2.addressOf); - free(a3.addressOf); - free(a4.addressOf); - free(a5.addressOf); - free(a6.addressOf); - free(a7.addressOf); - free(a8.addressOf); - free(a9.addressOf); + calloc.free(a0.addressOf); + calloc.free(a1.addressOf); + calloc.free(a2.addressOf); + calloc.free(a3.addressOf); + calloc.free(a4.addressOf); + calloc.free(a5.addressOf); + calloc.free(a6.addressOf); + calloc.free(a7.addressOf); + calloc.free(a8.addressOf); + calloc.free(a9.addressOf); } final passStruct12BytesHomogeneousFloatx6 = ffiTestFunctions.lookupFunction< @@ -2121,17 +2072,17 @@ final passStruct12BytesHomogeneousFloatx6 = ffiTestFunctions.lookupFunction< /// The last argument is to test whether arguments are backfilled. void testPassStruct12BytesHomogeneousFloatx6() { Struct12BytesHomogeneousFloat a0 = - allocate().ref; + calloc().ref; Struct12BytesHomogeneousFloat a1 = - allocate().ref; + calloc().ref; Struct12BytesHomogeneousFloat a2 = - allocate().ref; + calloc().ref; Struct12BytesHomogeneousFloat a3 = - allocate().ref; + calloc().ref; Struct12BytesHomogeneousFloat a4 = - allocate().ref; + calloc().ref; Struct12BytesHomogeneousFloat a5 = - allocate().ref; + calloc().ref; a0.a0 = -1.0; a0.a1 = 2.0; @@ -2158,12 +2109,12 @@ void testPassStruct12BytesHomogeneousFloatx6() { Expect.approxEquals(9.0, result); - free(a0.addressOf); - free(a1.addressOf); - free(a2.addressOf); - free(a3.addressOf); - free(a4.addressOf); - free(a5.addressOf); + calloc.free(a0.addressOf); + calloc.free(a1.addressOf); + calloc.free(a2.addressOf); + calloc.free(a3.addressOf); + calloc.free(a4.addressOf); + calloc.free(a5.addressOf); } final passStruct16BytesHomogeneousFloatx5 = ffiTestFunctions.lookupFunction< @@ -2185,15 +2136,15 @@ final passStruct16BytesHomogeneousFloatx5 = ffiTestFunctions.lookupFunction< /// 5 struct arguments will exhaust available registers. void testPassStruct16BytesHomogeneousFloatx5() { Struct16BytesHomogeneousFloat a0 = - allocate().ref; + calloc().ref; Struct16BytesHomogeneousFloat a1 = - allocate().ref; + calloc().ref; Struct16BytesHomogeneousFloat a2 = - allocate().ref; + calloc().ref; Struct16BytesHomogeneousFloat a3 = - allocate().ref; + calloc().ref; Struct16BytesHomogeneousFloat a4 = - allocate().ref; + calloc().ref; a0.a0 = -1.0; a0.a1 = 2.0; @@ -2222,11 +2173,11 @@ void testPassStruct16BytesHomogeneousFloatx5() { Expect.approxEquals(10.0, result); - free(a0.addressOf); - free(a1.addressOf); - free(a2.addressOf); - free(a3.addressOf); - free(a4.addressOf); + calloc.free(a0.addressOf); + calloc.free(a1.addressOf); + calloc.free(a2.addressOf); + calloc.free(a3.addressOf); + calloc.free(a4.addressOf); } final passStruct16BytesMixedx10 = ffiTestFunctions.lookupFunction< @@ -2258,16 +2209,16 @@ final passStruct16BytesMixedx10 = ffiTestFunctions.lookupFunction< /// The rest goes on the stack. /// On arm, arguments are 8 byte aligned. void testPassStruct16BytesMixedx10() { - Struct16BytesMixed a0 = allocate().ref; - Struct16BytesMixed a1 = allocate().ref; - Struct16BytesMixed a2 = allocate().ref; - Struct16BytesMixed a3 = allocate().ref; - Struct16BytesMixed a4 = allocate().ref; - Struct16BytesMixed a5 = allocate().ref; - Struct16BytesMixed a6 = allocate().ref; - Struct16BytesMixed a7 = allocate().ref; - Struct16BytesMixed a8 = allocate().ref; - Struct16BytesMixed a9 = allocate().ref; + Struct16BytesMixed a0 = calloc().ref; + Struct16BytesMixed a1 = calloc().ref; + Struct16BytesMixed a2 = calloc().ref; + Struct16BytesMixed a3 = calloc().ref; + Struct16BytesMixed a4 = calloc().ref; + Struct16BytesMixed a5 = calloc().ref; + Struct16BytesMixed a6 = calloc().ref; + Struct16BytesMixed a7 = calloc().ref; + Struct16BytesMixed a8 = calloc().ref; + Struct16BytesMixed a9 = calloc().ref; a0.a0 = -1.0; a0.a1 = 2; @@ -2297,16 +2248,16 @@ void testPassStruct16BytesMixedx10() { Expect.approxEquals(10.0, result); - free(a0.addressOf); - free(a1.addressOf); - free(a2.addressOf); - free(a3.addressOf); - free(a4.addressOf); - free(a5.addressOf); - free(a6.addressOf); - free(a7.addressOf); - free(a8.addressOf); - free(a9.addressOf); + calloc.free(a0.addressOf); + calloc.free(a1.addressOf); + calloc.free(a2.addressOf); + calloc.free(a3.addressOf); + calloc.free(a4.addressOf); + calloc.free(a5.addressOf); + calloc.free(a6.addressOf); + calloc.free(a7.addressOf); + calloc.free(a8.addressOf); + calloc.free(a9.addressOf); } final passStruct16BytesMixed2x10 = ffiTestFunctions.lookupFunction< @@ -2338,16 +2289,16 @@ final passStruct16BytesMixed2x10 = ffiTestFunctions.lookupFunction< /// The rest goes on the stack. /// On arm, arguments are 4 byte aligned. void testPassStruct16BytesMixed2x10() { - Struct16BytesMixed2 a0 = allocate().ref; - Struct16BytesMixed2 a1 = allocate().ref; - Struct16BytesMixed2 a2 = allocate().ref; - Struct16BytesMixed2 a3 = allocate().ref; - Struct16BytesMixed2 a4 = allocate().ref; - Struct16BytesMixed2 a5 = allocate().ref; - Struct16BytesMixed2 a6 = allocate().ref; - Struct16BytesMixed2 a7 = allocate().ref; - Struct16BytesMixed2 a8 = allocate().ref; - Struct16BytesMixed2 a9 = allocate().ref; + Struct16BytesMixed2 a0 = calloc().ref; + Struct16BytesMixed2 a1 = calloc().ref; + Struct16BytesMixed2 a2 = calloc().ref; + Struct16BytesMixed2 a3 = calloc().ref; + Struct16BytesMixed2 a4 = calloc().ref; + Struct16BytesMixed2 a5 = calloc().ref; + Struct16BytesMixed2 a6 = calloc().ref; + Struct16BytesMixed2 a7 = calloc().ref; + Struct16BytesMixed2 a8 = calloc().ref; + Struct16BytesMixed2 a9 = calloc().ref; a0.a0 = -1.0; a0.a1 = 2.0; @@ -2397,16 +2348,16 @@ void testPassStruct16BytesMixed2x10() { Expect.approxEquals(20.0, result); - free(a0.addressOf); - free(a1.addressOf); - free(a2.addressOf); - free(a3.addressOf); - free(a4.addressOf); - free(a5.addressOf); - free(a6.addressOf); - free(a7.addressOf); - free(a8.addressOf); - free(a9.addressOf); + calloc.free(a0.addressOf); + calloc.free(a1.addressOf); + calloc.free(a2.addressOf); + calloc.free(a3.addressOf); + calloc.free(a4.addressOf); + calloc.free(a5.addressOf); + calloc.free(a6.addressOf); + calloc.free(a7.addressOf); + calloc.free(a8.addressOf); + calloc.free(a9.addressOf); } final passStruct17BytesIntx10 = ffiTestFunctions.lookupFunction< @@ -2436,16 +2387,16 @@ final passStruct17BytesIntx10 = ffiTestFunctions.lookupFunction< /// Arguments are passed as pointer to copy on arm64. /// Tests that the memory allocated for copies are rounded up to word size. void testPassStruct17BytesIntx10() { - Struct17BytesInt a0 = allocate().ref; - Struct17BytesInt a1 = allocate().ref; - Struct17BytesInt a2 = allocate().ref; - Struct17BytesInt a3 = allocate().ref; - Struct17BytesInt a4 = allocate().ref; - Struct17BytesInt a5 = allocate().ref; - Struct17BytesInt a6 = allocate().ref; - Struct17BytesInt a7 = allocate().ref; - Struct17BytesInt a8 = allocate().ref; - Struct17BytesInt a9 = allocate().ref; + Struct17BytesInt a0 = calloc().ref; + Struct17BytesInt a1 = calloc().ref; + Struct17BytesInt a2 = calloc().ref; + Struct17BytesInt a3 = calloc().ref; + Struct17BytesInt a4 = calloc().ref; + Struct17BytesInt a5 = calloc().ref; + Struct17BytesInt a6 = calloc().ref; + Struct17BytesInt a7 = calloc().ref; + Struct17BytesInt a8 = calloc().ref; + Struct17BytesInt a9 = calloc().ref; a0.a0 = -1; a0.a1 = 2; @@ -2485,16 +2436,16 @@ void testPassStruct17BytesIntx10() { Expect.equals(15, result); - free(a0.addressOf); - free(a1.addressOf); - free(a2.addressOf); - free(a3.addressOf); - free(a4.addressOf); - free(a5.addressOf); - free(a6.addressOf); - free(a7.addressOf); - free(a8.addressOf); - free(a9.addressOf); + calloc.free(a0.addressOf); + calloc.free(a1.addressOf); + calloc.free(a2.addressOf); + calloc.free(a3.addressOf); + calloc.free(a4.addressOf); + calloc.free(a5.addressOf); + calloc.free(a6.addressOf); + calloc.free(a7.addressOf); + calloc.free(a8.addressOf); + calloc.free(a9.addressOf); } final passStruct19BytesHomogeneousUint8x10 = ffiTestFunctions.lookupFunction< @@ -2526,25 +2477,25 @@ final passStruct19BytesHomogeneousUint8x10 = ffiTestFunctions.lookupFunction< /// void testPassStruct19BytesHomogeneousUint8x10() { Struct19BytesHomogeneousUint8 a0 = - allocate().ref; + calloc().ref; Struct19BytesHomogeneousUint8 a1 = - allocate().ref; + calloc().ref; Struct19BytesHomogeneousUint8 a2 = - allocate().ref; + calloc().ref; Struct19BytesHomogeneousUint8 a3 = - allocate().ref; + calloc().ref; Struct19BytesHomogeneousUint8 a4 = - allocate().ref; + calloc().ref; Struct19BytesHomogeneousUint8 a5 = - allocate().ref; + calloc().ref; Struct19BytesHomogeneousUint8 a6 = - allocate().ref; + calloc().ref; Struct19BytesHomogeneousUint8 a7 = - allocate().ref; + calloc().ref; Struct19BytesHomogeneousUint8 a8 = - allocate().ref; + calloc().ref; Struct19BytesHomogeneousUint8 a9 = - allocate().ref; + calloc().ref; a0.a0 = 1; a0.a1 = 2; @@ -2744,16 +2695,16 @@ void testPassStruct19BytesHomogeneousUint8x10() { Expect.equals(18145, result); - free(a0.addressOf); - free(a1.addressOf); - free(a2.addressOf); - free(a3.addressOf); - free(a4.addressOf); - free(a5.addressOf); - free(a6.addressOf); - free(a7.addressOf); - free(a8.addressOf); - free(a9.addressOf); + calloc.free(a0.addressOf); + calloc.free(a1.addressOf); + calloc.free(a2.addressOf); + calloc.free(a3.addressOf); + calloc.free(a4.addressOf); + calloc.free(a5.addressOf); + calloc.free(a6.addressOf); + calloc.free(a7.addressOf); + calloc.free(a8.addressOf); + calloc.free(a9.addressOf); } final passStruct20BytesHomogeneousInt32x10 = ffiTestFunctions.lookupFunction< @@ -2786,25 +2737,25 @@ final passStruct20BytesHomogeneousInt32x10 = ffiTestFunctions.lookupFunction< /// pointers to copies are also passed on the stack. void testPassStruct20BytesHomogeneousInt32x10() { Struct20BytesHomogeneousInt32 a0 = - allocate().ref; + calloc().ref; Struct20BytesHomogeneousInt32 a1 = - allocate().ref; + calloc().ref; Struct20BytesHomogeneousInt32 a2 = - allocate().ref; + calloc().ref; Struct20BytesHomogeneousInt32 a3 = - allocate().ref; + calloc().ref; Struct20BytesHomogeneousInt32 a4 = - allocate().ref; + calloc().ref; Struct20BytesHomogeneousInt32 a5 = - allocate().ref; + calloc().ref; Struct20BytesHomogeneousInt32 a6 = - allocate().ref; + calloc().ref; Struct20BytesHomogeneousInt32 a7 = - allocate().ref; + calloc().ref; Struct20BytesHomogeneousInt32 a8 = - allocate().ref; + calloc().ref; Struct20BytesHomogeneousInt32 a9 = - allocate().ref; + calloc().ref; a0.a0 = -1; a0.a1 = 2; @@ -2864,16 +2815,16 @@ void testPassStruct20BytesHomogeneousInt32x10() { Expect.equals(25, result); - free(a0.addressOf); - free(a1.addressOf); - free(a2.addressOf); - free(a3.addressOf); - free(a4.addressOf); - free(a5.addressOf); - free(a6.addressOf); - free(a7.addressOf); - free(a8.addressOf); - free(a9.addressOf); + calloc.free(a0.addressOf); + calloc.free(a1.addressOf); + calloc.free(a2.addressOf); + calloc.free(a3.addressOf); + calloc.free(a4.addressOf); + calloc.free(a5.addressOf); + calloc.free(a6.addressOf); + calloc.free(a7.addressOf); + calloc.free(a8.addressOf); + calloc.free(a9.addressOf); } final passStruct20BytesHomogeneousFloat = ffiTestFunctions.lookupFunction< @@ -2884,7 +2835,7 @@ final passStruct20BytesHomogeneousFloat = ffiTestFunctions.lookupFunction< /// Argument too big to go into FPU registers in hardfp and arm64. void testPassStruct20BytesHomogeneousFloat() { Struct20BytesHomogeneousFloat a0 = - allocate().ref; + calloc().ref; a0.a0 = -1.0; a0.a1 = 2.0; @@ -2898,7 +2849,7 @@ void testPassStruct20BytesHomogeneousFloat() { Expect.approxEquals(-3.0, result); - free(a0.addressOf); + calloc.free(a0.addressOf); } final passStruct32BytesHomogeneousDoublex5 = ffiTestFunctions.lookupFunction< @@ -2920,15 +2871,15 @@ final passStruct32BytesHomogeneousDoublex5 = ffiTestFunctions.lookupFunction< /// 5 struct arguments will exhaust available registers. void testPassStruct32BytesHomogeneousDoublex5() { Struct32BytesHomogeneousDouble a0 = - allocate().ref; + calloc().ref; Struct32BytesHomogeneousDouble a1 = - allocate().ref; + calloc().ref; Struct32BytesHomogeneousDouble a2 = - allocate().ref; + calloc().ref; Struct32BytesHomogeneousDouble a3 = - allocate().ref; + calloc().ref; Struct32BytesHomogeneousDouble a4 = - allocate().ref; + calloc().ref; a0.a0 = -1.0; a0.a1 = 2.0; @@ -2957,11 +2908,11 @@ void testPassStruct32BytesHomogeneousDoublex5() { Expect.approxEquals(10.0, result); - free(a0.addressOf); - free(a1.addressOf); - free(a2.addressOf); - free(a3.addressOf); - free(a4.addressOf); + calloc.free(a0.addressOf); + calloc.free(a1.addressOf); + calloc.free(a2.addressOf); + calloc.free(a3.addressOf); + calloc.free(a4.addressOf); } final passStruct40BytesHomogeneousDouble = ffiTestFunctions.lookupFunction< @@ -2972,7 +2923,7 @@ final passStruct40BytesHomogeneousDouble = ffiTestFunctions.lookupFunction< /// Argument too big to go into FPU registers in arm64. void testPassStruct40BytesHomogeneousDouble() { Struct40BytesHomogeneousDouble a0 = - allocate().ref; + calloc().ref; a0.a0 = -1.0; a0.a1 = 2.0; @@ -2986,7 +2937,7 @@ void testPassStruct40BytesHomogeneousDouble() { Expect.approxEquals(-3.0, result); - free(a0.addressOf); + calloc.free(a0.addressOf); } final passStruct1024BytesHomogeneousUint64 = ffiTestFunctions.lookupFunction< @@ -2997,7 +2948,7 @@ final passStruct1024BytesHomogeneousUint64 = ffiTestFunctions.lookupFunction< /// Test 1kb struct. void testPassStruct1024BytesHomogeneousUint64() { Struct1024BytesHomogeneousUint64 a0 = - allocate().ref; + calloc().ref; a0.a0 = 1; a0.a1 = 2; @@ -3134,7 +3085,7 @@ void testPassStruct1024BytesHomogeneousUint64() { Expect.equals(8256, result); - free(a0.addressOf); + calloc.free(a0.addressOf); } final passFloatStruct16BytesHomogeneousFloatFloatStruct1 = @@ -3164,16 +3115,16 @@ final passFloatStruct16BytesHomogeneousFloatFloatStruct1 = void testPassFloatStruct16BytesHomogeneousFloatFloatStruct1() { double a0; Struct16BytesHomogeneousFloat a1 = - allocate().ref; + calloc().ref; double a2; Struct16BytesHomogeneousFloat a3 = - allocate().ref; + calloc().ref; double a4; Struct16BytesHomogeneousFloat a5 = - allocate().ref; + calloc().ref; double a6; Struct16BytesHomogeneousFloat a7 = - allocate().ref; + calloc().ref; double a8; a0 = -1.0; @@ -3205,10 +3156,10 @@ void testPassFloatStruct16BytesHomogeneousFloatFloatStruct1() { Expect.approxEquals(-11.0, result); - free(a1.addressOf); - free(a3.addressOf); - free(a5.addressOf); - free(a7.addressOf); + calloc.free(a1.addressOf); + calloc.free(a3.addressOf); + calloc.free(a5.addressOf); + calloc.free(a7.addressOf); } final passFloatStruct32BytesHomogeneousDoubleFloatStruct = @@ -3238,16 +3189,16 @@ final passFloatStruct32BytesHomogeneousDoubleFloatStruct = void testPassFloatStruct32BytesHomogeneousDoubleFloatStruct() { double a0; Struct32BytesHomogeneousDouble a1 = - allocate().ref; + calloc().ref; double a2; Struct32BytesHomogeneousDouble a3 = - allocate().ref; + calloc().ref; double a4; Struct32BytesHomogeneousDouble a5 = - allocate().ref; + calloc().ref; double a6; Struct32BytesHomogeneousDouble a7 = - allocate().ref; + calloc().ref; double a8; a0 = -1.0; @@ -3279,10 +3230,10 @@ void testPassFloatStruct32BytesHomogeneousDoubleFloatStruct() { Expect.approxEquals(-11.0, result); - free(a1.addressOf); - free(a3.addressOf); - free(a5.addressOf); - free(a7.addressOf); + calloc.free(a1.addressOf); + calloc.free(a3.addressOf); + calloc.free(a5.addressOf); + calloc.free(a7.addressOf); } final passInt8Struct16BytesMixedInt8Struct16BytesMixedIn = @@ -3307,13 +3258,13 @@ final passInt8Struct16BytesMixedInt8Struct16BytesMixedIn = /// Test backfilling of integer registers. void testPassInt8Struct16BytesMixedInt8Struct16BytesMixedIn() { int a0; - Struct16BytesMixed a1 = allocate().ref; + Struct16BytesMixed a1 = calloc().ref; int a2; - Struct16BytesMixed a3 = allocate().ref; + Struct16BytesMixed a3 = calloc().ref; int a4; - Struct16BytesMixed a5 = allocate().ref; + Struct16BytesMixed a5 = calloc().ref; int a6; - Struct16BytesMixed a7 = allocate().ref; + Struct16BytesMixed a7 = calloc().ref; int a8; a0 = -1; @@ -3337,10 +3288,10 @@ void testPassInt8Struct16BytesMixedInt8Struct16BytesMixedIn() { Expect.approxEquals(-7.0, result); - free(a1.addressOf); - free(a3.addressOf); - free(a5.addressOf); - free(a7.addressOf); + calloc.free(a1.addressOf); + calloc.free(a3.addressOf); + calloc.free(a5.addressOf); + calloc.free(a7.addressOf); } final passDoublex6Struct16BytesMixedx4Int32 = ffiTestFunctions.lookupFunction< @@ -3379,10 +3330,10 @@ void testPassDoublex6Struct16BytesMixedx4Int32() { double a3; double a4; double a5; - Struct16BytesMixed a6 = allocate().ref; - Struct16BytesMixed a7 = allocate().ref; - Struct16BytesMixed a8 = allocate().ref; - Struct16BytesMixed a9 = allocate().ref; + Struct16BytesMixed a6 = calloc().ref; + Struct16BytesMixed a7 = calloc().ref; + Struct16BytesMixed a8 = calloc().ref; + Struct16BytesMixed a9 = calloc().ref; int a10; a0 = -1.0; @@ -3408,10 +3359,10 @@ void testPassDoublex6Struct16BytesMixedx4Int32() { Expect.approxEquals(-8.0, result); - free(a6.addressOf); - free(a7.addressOf); - free(a8.addressOf); - free(a9.addressOf); + calloc.free(a6.addressOf); + calloc.free(a7.addressOf); + calloc.free(a8.addressOf); + calloc.free(a9.addressOf); } final passInt32x4Struct16BytesMixedx4Double = ffiTestFunctions.lookupFunction< @@ -3436,10 +3387,10 @@ void testPassInt32x4Struct16BytesMixedx4Double() { int a1; int a2; int a3; - Struct16BytesMixed a4 = allocate().ref; - Struct16BytesMixed a5 = allocate().ref; - Struct16BytesMixed a6 = allocate().ref; - Struct16BytesMixed a7 = allocate().ref; + Struct16BytesMixed a4 = calloc().ref; + Struct16BytesMixed a5 = calloc().ref; + Struct16BytesMixed a6 = calloc().ref; + Struct16BytesMixed a7 = calloc().ref; double a8; a0 = -1; @@ -3463,10 +3414,10 @@ void testPassInt32x4Struct16BytesMixedx4Double() { Expect.approxEquals(-7.0, result); - free(a4.addressOf); - free(a5.addressOf); - free(a6.addressOf); - free(a7.addressOf); + calloc.free(a4.addressOf); + calloc.free(a5.addressOf); + calloc.free(a6.addressOf); + calloc.free(a7.addressOf); } final passStruct40BytesHomogeneousDoubleStruct4BytesHomo = @@ -3481,11 +3432,9 @@ final passStruct40BytesHomogeneousDoubleStruct4BytesHomo = /// Check that the other two arguments are allocated on registers. void testPassStruct40BytesHomogeneousDoubleStruct4BytesHomo() { Struct40BytesHomogeneousDouble a0 = - allocate().ref; - Struct4BytesHomogeneousInt16 a1 = - allocate().ref; - Struct8BytesHomogeneousFloat a2 = - allocate().ref; + calloc().ref; + Struct4BytesHomogeneousInt16 a1 = calloc().ref; + Struct8BytesHomogeneousFloat a2 = calloc().ref; a0.a0 = -1.0; a0.a1 = 2.0; @@ -3503,9 +3452,9 @@ void testPassStruct40BytesHomogeneousDoubleStruct4BytesHomo() { Expect.approxEquals(-5.0, result); - free(a0.addressOf); - free(a1.addressOf); - free(a2.addressOf); + calloc.free(a0.addressOf); + calloc.free(a1.addressOf); + calloc.free(a2.addressOf); } final passInt32x8Doublex8Int64Int8Struct1ByteIntInt64Int = @@ -3613,30 +3562,28 @@ void testPassInt32x8Doublex8Int64Int8Struct1ByteIntInt64Int() { double a15; int a16; int a17; - Struct1ByteInt a18 = allocate().ref; + Struct1ByteInt a18 = calloc().ref; int a19; int a20; - Struct4BytesHomogeneousInt16 a21 = - allocate().ref; + Struct4BytesHomogeneousInt16 a21 = calloc().ref; int a22; int a23; - Struct8BytesInt a24 = allocate().ref; + Struct8BytesInt a24 = calloc().ref; int a25; int a26; - Struct8BytesHomogeneousFloat a27 = - allocate().ref; + Struct8BytesHomogeneousFloat a27 = calloc().ref; int a28; int a29; - Struct8BytesMixed a30 = allocate().ref; + Struct8BytesMixed a30 = calloc().ref; int a31; int a32; - StructAlignmentInt16 a33 = allocate().ref; + StructAlignmentInt16 a33 = calloc().ref; int a34; int a35; - StructAlignmentInt32 a36 = allocate().ref; + StructAlignmentInt32 a36 = calloc().ref; int a37; int a38; - StructAlignmentInt64 a39 = allocate().ref; + StructAlignmentInt64 a39 = calloc().ref; a0 = -1; a1 = 2; @@ -3737,14 +3684,14 @@ void testPassInt32x8Doublex8Int64Int8Struct1ByteIntInt64Int() { Expect.approxEquals(26.0, result); - free(a18.addressOf); - free(a21.addressOf); - free(a24.addressOf); - free(a27.addressOf); - free(a30.addressOf); - free(a33.addressOf); - free(a36.addressOf); - free(a39.addressOf); + calloc.free(a18.addressOf); + calloc.free(a21.addressOf); + calloc.free(a24.addressOf); + calloc.free(a27.addressOf); + calloc.free(a30.addressOf); + calloc.free(a33.addressOf); + calloc.free(a36.addressOf); + calloc.free(a39.addressOf); } final passStructAlignmentInt16 = ffiTestFunctions.lookupFunction< @@ -3753,7 +3700,7 @@ final passStructAlignmentInt16 = ffiTestFunctions.lookupFunction< /// Test alignment and padding of 16 byte int within struct. void testPassStructAlignmentInt16() { - StructAlignmentInt16 a0 = allocate().ref; + StructAlignmentInt16 a0 = calloc().ref; a0.a0 = -1; a0.a1 = 2; @@ -3765,7 +3712,7 @@ void testPassStructAlignmentInt16() { Expect.equals(-2, result); - free(a0.addressOf); + calloc.free(a0.addressOf); } final passStructAlignmentInt32 = ffiTestFunctions.lookupFunction< @@ -3774,7 +3721,7 @@ final passStructAlignmentInt32 = ffiTestFunctions.lookupFunction< /// Test alignment and padding of 32 byte int within struct. void testPassStructAlignmentInt32() { - StructAlignmentInt32 a0 = allocate().ref; + StructAlignmentInt32 a0 = calloc().ref; a0.a0 = -1; a0.a1 = 2; @@ -3786,7 +3733,7 @@ void testPassStructAlignmentInt32() { Expect.equals(-2, result); - free(a0.addressOf); + calloc.free(a0.addressOf); } final passStructAlignmentInt64 = ffiTestFunctions.lookupFunction< @@ -3795,7 +3742,7 @@ final passStructAlignmentInt64 = ffiTestFunctions.lookupFunction< /// Test alignment and padding of 64 byte int within struct. void testPassStructAlignmentInt64() { - StructAlignmentInt64 a0 = allocate().ref; + StructAlignmentInt64 a0 = calloc().ref; a0.a0 = -1; a0.a1 = 2; @@ -3807,7 +3754,7 @@ void testPassStructAlignmentInt64() { Expect.equals(-2, result); - free(a0.addressOf); + calloc.free(a0.addressOf); } final passStruct8BytesNestedIntx10 = ffiTestFunctions.lookupFunction< @@ -3837,16 +3784,16 @@ final passStruct8BytesNestedIntx10 = ffiTestFunctions.lookupFunction< /// Simple nested struct. No alignment gaps on any architectures. /// 10 arguments exhaust registers on all platforms. void testPassStruct8BytesNestedIntx10() { - Struct8BytesNestedInt a0 = allocate().ref; - Struct8BytesNestedInt a1 = allocate().ref; - Struct8BytesNestedInt a2 = allocate().ref; - Struct8BytesNestedInt a3 = allocate().ref; - Struct8BytesNestedInt a4 = allocate().ref; - Struct8BytesNestedInt a5 = allocate().ref; - Struct8BytesNestedInt a6 = allocate().ref; - Struct8BytesNestedInt a7 = allocate().ref; - Struct8BytesNestedInt a8 = allocate().ref; - Struct8BytesNestedInt a9 = allocate().ref; + Struct8BytesNestedInt a0 = calloc().ref; + Struct8BytesNestedInt a1 = calloc().ref; + Struct8BytesNestedInt a2 = calloc().ref; + Struct8BytesNestedInt a3 = calloc().ref; + Struct8BytesNestedInt a4 = calloc().ref; + Struct8BytesNestedInt a5 = calloc().ref; + Struct8BytesNestedInt a6 = calloc().ref; + Struct8BytesNestedInt a7 = calloc().ref; + Struct8BytesNestedInt a8 = calloc().ref; + Struct8BytesNestedInt a9 = calloc().ref; a0.a0.a0 = -1; a0.a0.a1 = 2; @@ -3896,16 +3843,16 @@ void testPassStruct8BytesNestedIntx10() { Expect.equals(20, result); - free(a0.addressOf); - free(a1.addressOf); - free(a2.addressOf); - free(a3.addressOf); - free(a4.addressOf); - free(a5.addressOf); - free(a6.addressOf); - free(a7.addressOf); - free(a8.addressOf); - free(a9.addressOf); + calloc.free(a0.addressOf); + calloc.free(a1.addressOf); + calloc.free(a2.addressOf); + calloc.free(a3.addressOf); + calloc.free(a4.addressOf); + calloc.free(a5.addressOf); + calloc.free(a6.addressOf); + calloc.free(a7.addressOf); + calloc.free(a8.addressOf); + calloc.free(a9.addressOf); } final passStruct8BytesNestedFloatx10 = ffiTestFunctions.lookupFunction< @@ -3935,16 +3882,16 @@ final passStruct8BytesNestedFloatx10 = ffiTestFunctions.lookupFunction< /// Simple nested struct. No alignment gaps on any architectures. /// 10 arguments exhaust fpu registers on all platforms. void testPassStruct8BytesNestedFloatx10() { - Struct8BytesNestedFloat a0 = allocate().ref; - Struct8BytesNestedFloat a1 = allocate().ref; - Struct8BytesNestedFloat a2 = allocate().ref; - Struct8BytesNestedFloat a3 = allocate().ref; - Struct8BytesNestedFloat a4 = allocate().ref; - Struct8BytesNestedFloat a5 = allocate().ref; - Struct8BytesNestedFloat a6 = allocate().ref; - Struct8BytesNestedFloat a7 = allocate().ref; - Struct8BytesNestedFloat a8 = allocate().ref; - Struct8BytesNestedFloat a9 = allocate().ref; + Struct8BytesNestedFloat a0 = calloc().ref; + Struct8BytesNestedFloat a1 = calloc().ref; + Struct8BytesNestedFloat a2 = calloc().ref; + Struct8BytesNestedFloat a3 = calloc().ref; + Struct8BytesNestedFloat a4 = calloc().ref; + Struct8BytesNestedFloat a5 = calloc().ref; + Struct8BytesNestedFloat a6 = calloc().ref; + Struct8BytesNestedFloat a7 = calloc().ref; + Struct8BytesNestedFloat a8 = calloc().ref; + Struct8BytesNestedFloat a9 = calloc().ref; a0.a0.a0 = -1.0; a0.a1.a0 = 2.0; @@ -3974,16 +3921,16 @@ void testPassStruct8BytesNestedFloatx10() { Expect.approxEquals(10.0, result); - free(a0.addressOf); - free(a1.addressOf); - free(a2.addressOf); - free(a3.addressOf); - free(a4.addressOf); - free(a5.addressOf); - free(a6.addressOf); - free(a7.addressOf); - free(a8.addressOf); - free(a9.addressOf); + calloc.free(a0.addressOf); + calloc.free(a1.addressOf); + calloc.free(a2.addressOf); + calloc.free(a3.addressOf); + calloc.free(a4.addressOf); + calloc.free(a5.addressOf); + calloc.free(a6.addressOf); + calloc.free(a7.addressOf); + calloc.free(a8.addressOf); + calloc.free(a9.addressOf); } final passStruct8BytesNestedFloat2x10 = ffiTestFunctions.lookupFunction< @@ -4015,16 +3962,16 @@ final passStruct8BytesNestedFloat2x10 = ffiTestFunctions.lookupFunction< /// The nesting is irregular, testing homogenous float rules on arm and arm64, /// and the fpu register usage on x64. void testPassStruct8BytesNestedFloat2x10() { - Struct8BytesNestedFloat2 a0 = allocate().ref; - Struct8BytesNestedFloat2 a1 = allocate().ref; - Struct8BytesNestedFloat2 a2 = allocate().ref; - Struct8BytesNestedFloat2 a3 = allocate().ref; - Struct8BytesNestedFloat2 a4 = allocate().ref; - Struct8BytesNestedFloat2 a5 = allocate().ref; - Struct8BytesNestedFloat2 a6 = allocate().ref; - Struct8BytesNestedFloat2 a7 = allocate().ref; - Struct8BytesNestedFloat2 a8 = allocate().ref; - Struct8BytesNestedFloat2 a9 = allocate().ref; + Struct8BytesNestedFloat2 a0 = calloc().ref; + Struct8BytesNestedFloat2 a1 = calloc().ref; + Struct8BytesNestedFloat2 a2 = calloc().ref; + Struct8BytesNestedFloat2 a3 = calloc().ref; + Struct8BytesNestedFloat2 a4 = calloc().ref; + Struct8BytesNestedFloat2 a5 = calloc().ref; + Struct8BytesNestedFloat2 a6 = calloc().ref; + Struct8BytesNestedFloat2 a7 = calloc().ref; + Struct8BytesNestedFloat2 a8 = calloc().ref; + Struct8BytesNestedFloat2 a9 = calloc().ref; a0.a0.a0 = -1.0; a0.a1 = 2.0; @@ -4054,16 +4001,16 @@ void testPassStruct8BytesNestedFloat2x10() { Expect.approxEquals(10.0, result); - free(a0.addressOf); - free(a1.addressOf); - free(a2.addressOf); - free(a3.addressOf); - free(a4.addressOf); - free(a5.addressOf); - free(a6.addressOf); - free(a7.addressOf); - free(a8.addressOf); - free(a9.addressOf); + calloc.free(a0.addressOf); + calloc.free(a1.addressOf); + calloc.free(a2.addressOf); + calloc.free(a3.addressOf); + calloc.free(a4.addressOf); + calloc.free(a5.addressOf); + calloc.free(a6.addressOf); + calloc.free(a7.addressOf); + calloc.free(a8.addressOf); + calloc.free(a9.addressOf); } final passStruct8BytesNestedMixedx10 = ffiTestFunctions.lookupFunction< @@ -4093,16 +4040,16 @@ final passStruct8BytesNestedMixedx10 = ffiTestFunctions.lookupFunction< /// Simple nested struct. No alignment gaps on any architectures. /// 10 arguments exhaust all registers on all platforms. void testPassStruct8BytesNestedMixedx10() { - Struct8BytesNestedMixed a0 = allocate().ref; - Struct8BytesNestedMixed a1 = allocate().ref; - Struct8BytesNestedMixed a2 = allocate().ref; - Struct8BytesNestedMixed a3 = allocate().ref; - Struct8BytesNestedMixed a4 = allocate().ref; - Struct8BytesNestedMixed a5 = allocate().ref; - Struct8BytesNestedMixed a6 = allocate().ref; - Struct8BytesNestedMixed a7 = allocate().ref; - Struct8BytesNestedMixed a8 = allocate().ref; - Struct8BytesNestedMixed a9 = allocate().ref; + Struct8BytesNestedMixed a0 = calloc().ref; + Struct8BytesNestedMixed a1 = calloc().ref; + Struct8BytesNestedMixed a2 = calloc().ref; + Struct8BytesNestedMixed a3 = calloc().ref; + Struct8BytesNestedMixed a4 = calloc().ref; + Struct8BytesNestedMixed a5 = calloc().ref; + Struct8BytesNestedMixed a6 = calloc().ref; + Struct8BytesNestedMixed a7 = calloc().ref; + Struct8BytesNestedMixed a8 = calloc().ref; + Struct8BytesNestedMixed a9 = calloc().ref; a0.a0.a0 = -1; a0.a0.a1 = 2; @@ -4142,16 +4089,16 @@ void testPassStruct8BytesNestedMixedx10() { Expect.approxEquals(15.0, result); - free(a0.addressOf); - free(a1.addressOf); - free(a2.addressOf); - free(a3.addressOf); - free(a4.addressOf); - free(a5.addressOf); - free(a6.addressOf); - free(a7.addressOf); - free(a8.addressOf); - free(a9.addressOf); + calloc.free(a0.addressOf); + calloc.free(a1.addressOf); + calloc.free(a2.addressOf); + calloc.free(a3.addressOf); + calloc.free(a4.addressOf); + calloc.free(a5.addressOf); + calloc.free(a6.addressOf); + calloc.free(a7.addressOf); + calloc.free(a8.addressOf); + calloc.free(a9.addressOf); } final passStruct16BytesNestedIntx2 = ffiTestFunctions.lookupFunction< @@ -4161,8 +4108,8 @@ final passStruct16BytesNestedIntx2 = ffiTestFunctions.lookupFunction< /// Deeper nested struct to test recursive member access. void testPassStruct16BytesNestedIntx2() { - Struct16BytesNestedInt a0 = allocate().ref; - Struct16BytesNestedInt a1 = allocate().ref; + Struct16BytesNestedInt a0 = calloc().ref; + Struct16BytesNestedInt a1 = calloc().ref; a0.a0.a0.a0 = -1; a0.a0.a0.a1 = 2; @@ -4187,8 +4134,8 @@ void testPassStruct16BytesNestedIntx2() { Expect.equals(8, result); - free(a0.addressOf); - free(a1.addressOf); + calloc.free(a0.addressOf); + calloc.free(a1.addressOf); } final passStruct32BytesNestedIntx2 = ffiTestFunctions.lookupFunction< @@ -4198,8 +4145,8 @@ final passStruct32BytesNestedIntx2 = ffiTestFunctions.lookupFunction< /// Even deeper nested struct to test recursive member access. void testPassStruct32BytesNestedIntx2() { - Struct32BytesNestedInt a0 = allocate().ref; - Struct32BytesNestedInt a1 = allocate().ref; + Struct32BytesNestedInt a0 = calloc().ref; + Struct32BytesNestedInt a1 = calloc().ref; a0.a0.a0.a0.a0 = -1; a0.a0.a0.a0.a1 = 2; @@ -4240,8 +4187,8 @@ void testPassStruct32BytesNestedIntx2() { Expect.equals(16, result); - free(a0.addressOf); - free(a1.addressOf); + calloc.free(a0.addressOf); + calloc.free(a1.addressOf); } final passStructNestedIntStructAlignmentInt16 = ffiTestFunctions.lookupFunction< @@ -4252,7 +4199,7 @@ final passStructNestedIntStructAlignmentInt16 = ffiTestFunctions.lookupFunction< /// Test alignment and padding of nested struct with 16 byte int. void testPassStructNestedIntStructAlignmentInt16() { StructNestedIntStructAlignmentInt16 a0 = - allocate().ref; + calloc().ref; a0.a0.a0 = -1; a0.a0.a1 = 2; @@ -4267,7 +4214,7 @@ void testPassStructNestedIntStructAlignmentInt16() { Expect.equals(3, result); - free(a0.addressOf); + calloc.free(a0.addressOf); } final passStructNestedIntStructAlignmentInt32 = ffiTestFunctions.lookupFunction< @@ -4278,7 +4225,7 @@ final passStructNestedIntStructAlignmentInt32 = ffiTestFunctions.lookupFunction< /// Test alignment and padding of nested struct with 32 byte int. void testPassStructNestedIntStructAlignmentInt32() { StructNestedIntStructAlignmentInt32 a0 = - allocate().ref; + calloc().ref; a0.a0.a0 = -1; a0.a0.a1 = 2; @@ -4293,7 +4240,7 @@ void testPassStructNestedIntStructAlignmentInt32() { Expect.equals(3, result); - free(a0.addressOf); + calloc.free(a0.addressOf); } final passStructNestedIntStructAlignmentInt64 = ffiTestFunctions.lookupFunction< @@ -4304,7 +4251,7 @@ final passStructNestedIntStructAlignmentInt64 = ffiTestFunctions.lookupFunction< /// Test alignment and padding of nested struct with 64 byte int. void testPassStructNestedIntStructAlignmentInt64() { StructNestedIntStructAlignmentInt64 a0 = - allocate().ref; + calloc().ref; a0.a0.a0 = -1; a0.a0.a1 = 2; @@ -4319,7 +4266,7 @@ void testPassStructNestedIntStructAlignmentInt64() { Expect.equals(3, result); - free(a0.addressOf); + calloc.free(a0.addressOf); } final passStructNestedIrregularEvenBiggerx4 = ffiTestFunctions.lookupFunction< @@ -4338,13 +4285,13 @@ final passStructNestedIrregularEvenBiggerx4 = ffiTestFunctions.lookupFunction< /// Return big irregular struct as smoke test. void testPassStructNestedIrregularEvenBiggerx4() { StructNestedIrregularEvenBigger a0 = - allocate().ref; + calloc().ref; StructNestedIrregularEvenBigger a1 = - allocate().ref; + calloc().ref; StructNestedIrregularEvenBigger a2 = - allocate().ref; + calloc().ref; StructNestedIrregularEvenBigger a3 = - allocate().ref; + calloc().ref; a0.a0 = 1; a0.a1.a0.a0 = 2; @@ -4489,10 +4436,10 @@ void testPassStructNestedIrregularEvenBiggerx4() { Expect.approxEquals(1572.0, result); - free(a0.addressOf); - free(a1.addressOf); - free(a2.addressOf); - free(a3.addressOf); + calloc.free(a0.addressOf); + calloc.free(a1.addressOf); + calloc.free(a2.addressOf); + calloc.free(a3.addressOf); } final returnStruct1ByteInt = ffiTestFunctions.lookupFunction< @@ -5922,7 +5869,7 @@ final returnStructArgumentStruct1ByteInt = ffiTestFunctions.lookupFunction< /// Especially for ffi callbacks. /// Struct is passed in int registers in most ABIs. void testReturnStructArgumentStruct1ByteInt() { - Struct1ByteInt a0 = allocate().ref; + Struct1ByteInt a0 = calloc().ref; a0.a0 = -1; @@ -5932,7 +5879,7 @@ void testReturnStructArgumentStruct1ByteInt() { Expect.equals(a0.a0, result.a0); - free(a0.addressOf); + calloc.free(a0.addressOf); } final returnStructArgumentInt32x8Struct1ByteInt = @@ -5954,7 +5901,7 @@ void testReturnStructArgumentInt32x8Struct1ByteInt() { int a5; int a6; int a7; - Struct1ByteInt a8 = allocate().ref; + Struct1ByteInt a8 = calloc().ref; a0 = -1; a1 = 2; @@ -5973,7 +5920,7 @@ void testReturnStructArgumentInt32x8Struct1ByteInt() { Expect.equals(a8.a0, result.a0); - free(a8.addressOf); + calloc.free(a8.addressOf); } final returnStructArgumentStruct8BytesHomogeneousFloat = @@ -5987,8 +5934,7 @@ final returnStructArgumentStruct8BytesHomogeneousFloat = /// Especially for ffi callbacks. /// Struct is passed in float registers in most ABIs. void testReturnStructArgumentStruct8BytesHomogeneousFloat() { - Struct8BytesHomogeneousFloat a0 = - allocate().ref; + Struct8BytesHomogeneousFloat a0 = calloc().ref; a0.a0 = -1.0; a0.a1 = 2.0; @@ -6000,7 +5946,7 @@ void testReturnStructArgumentStruct8BytesHomogeneousFloat() { Expect.approxEquals(a0.a0, result.a0); Expect.approxEquals(a0.a1, result.a1); - free(a0.addressOf); + calloc.free(a0.addressOf); } final returnStructArgumentStruct20BytesHomogeneousInt32 = @@ -6015,7 +5961,7 @@ final returnStructArgumentStruct20BytesHomogeneousInt32 = /// On arm64, both argument and return value are passed in by pointer. void testReturnStructArgumentStruct20BytesHomogeneousInt32() { Struct20BytesHomogeneousInt32 a0 = - allocate().ref; + calloc().ref; a0.a0 = -1; a0.a1 = 2; @@ -6033,7 +5979,7 @@ void testReturnStructArgumentStruct20BytesHomogeneousInt32() { Expect.equals(a0.a3, result.a3); Expect.equals(a0.a4, result.a4); - free(a0.addressOf); + calloc.free(a0.addressOf); } final returnStructArgumentInt32x8Struct20BytesHomogeneou = @@ -6056,7 +6002,7 @@ void testReturnStructArgumentInt32x8Struct20BytesHomogeneou() { int a6; int a7; Struct20BytesHomogeneousInt32 a8 = - allocate().ref; + calloc().ref; a0 = -1; a1 = 2; @@ -6083,7 +6029,7 @@ void testReturnStructArgumentInt32x8Struct20BytesHomogeneou() { Expect.equals(a8.a3, result.a3); Expect.equals(a8.a4, result.a4); - free(a8.addressOf); + calloc.free(a8.addressOf); } final returnStructAlignmentInt16 = ffiTestFunctions.lookupFunction< @@ -6163,10 +6109,8 @@ final returnStruct8BytesNestedInt = ffiTestFunctions.lookupFunction< /// Simple nested struct. void testReturnStruct8BytesNestedInt() { - Struct4BytesHomogeneousInt16 a0 = - allocate().ref; - Struct4BytesHomogeneousInt16 a1 = - allocate().ref; + Struct4BytesHomogeneousInt16 a0 = calloc().ref; + Struct4BytesHomogeneousInt16 a1 = calloc().ref; a0.a0 = -1; a0.a1 = 2; @@ -6182,8 +6126,8 @@ void testReturnStruct8BytesNestedInt() { Expect.equals(a1.a0, result.a1.a0); Expect.equals(a1.a1, result.a1.a1); - free(a0.addressOf); - free(a1.addressOf); + calloc.free(a0.addressOf); + calloc.free(a1.addressOf); } final returnStruct8BytesNestedFloat = ffiTestFunctions.lookupFunction< @@ -6193,8 +6137,8 @@ final returnStruct8BytesNestedFloat = ffiTestFunctions.lookupFunction< /// Simple nested struct with floats. void testReturnStruct8BytesNestedFloat() { - Struct4BytesFloat a0 = allocate().ref; - Struct4BytesFloat a1 = allocate().ref; + Struct4BytesFloat a0 = calloc().ref; + Struct4BytesFloat a1 = calloc().ref; a0.a0 = -1.0; a1.a0 = 2.0; @@ -6206,8 +6150,8 @@ void testReturnStruct8BytesNestedFloat() { Expect.approxEquals(a0.a0, result.a0.a0); Expect.approxEquals(a1.a0, result.a1.a0); - free(a0.addressOf); - free(a1.addressOf); + calloc.free(a0.addressOf); + calloc.free(a1.addressOf); } final returnStruct8BytesNestedFloat2 = ffiTestFunctions.lookupFunction< @@ -6218,7 +6162,7 @@ final returnStruct8BytesNestedFloat2 = ffiTestFunctions.lookupFunction< /// The nesting is irregular, testing homogenous float rules on arm and arm64, /// and the fpu register usage on x64. void testReturnStruct8BytesNestedFloat2() { - Struct4BytesFloat a0 = allocate().ref; + Struct4BytesFloat a0 = calloc().ref; double a1; a0.a0 = -1.0; @@ -6231,7 +6175,7 @@ void testReturnStruct8BytesNestedFloat2() { Expect.approxEquals(a0.a0, result.a0.a0); Expect.approxEquals(a1, result.a1); - free(a0.addressOf); + calloc.free(a0.addressOf); } final returnStruct8BytesNestedMixed = ffiTestFunctions.lookupFunction< @@ -6242,9 +6186,8 @@ final returnStruct8BytesNestedMixed = ffiTestFunctions.lookupFunction< /// Simple nested struct with mixed members. void testReturnStruct8BytesNestedMixed() { - Struct4BytesHomogeneousInt16 a0 = - allocate().ref; - Struct4BytesFloat a1 = allocate().ref; + Struct4BytesHomogeneousInt16 a0 = calloc().ref; + Struct4BytesFloat a1 = calloc().ref; a0.a0 = -1; a0.a1 = 2; @@ -6258,8 +6201,8 @@ void testReturnStruct8BytesNestedMixed() { Expect.equals(a0.a1, result.a0.a1); Expect.approxEquals(a1.a0, result.a1.a0); - free(a0.addressOf); - free(a1.addressOf); + calloc.free(a0.addressOf); + calloc.free(a1.addressOf); } final returnStruct16BytesNestedInt = ffiTestFunctions.lookupFunction< @@ -6270,8 +6213,8 @@ final returnStruct16BytesNestedInt = ffiTestFunctions.lookupFunction< /// Deeper nested struct to test recursive member access. void testReturnStruct16BytesNestedInt() { - Struct8BytesNestedInt a0 = allocate().ref; - Struct8BytesNestedInt a1 = allocate().ref; + Struct8BytesNestedInt a0 = calloc().ref; + Struct8BytesNestedInt a1 = calloc().ref; a0.a0.a0 = -1; a0.a0.a1 = 2; @@ -6295,8 +6238,8 @@ void testReturnStruct16BytesNestedInt() { Expect.equals(a1.a1.a0, result.a1.a1.a0); Expect.equals(a1.a1.a1, result.a1.a1.a1); - free(a0.addressOf); - free(a1.addressOf); + calloc.free(a0.addressOf); + calloc.free(a1.addressOf); } final returnStruct32BytesNestedInt = ffiTestFunctions.lookupFunction< @@ -6307,8 +6250,8 @@ final returnStruct32BytesNestedInt = ffiTestFunctions.lookupFunction< /// Even deeper nested struct to test recursive member access. void testReturnStruct32BytesNestedInt() { - Struct16BytesNestedInt a0 = allocate().ref; - Struct16BytesNestedInt a1 = allocate().ref; + Struct16BytesNestedInt a0 = calloc().ref; + Struct16BytesNestedInt a1 = calloc().ref; a0.a0.a0.a0 = -1; a0.a0.a0.a1 = 2; @@ -6348,8 +6291,8 @@ void testReturnStruct32BytesNestedInt() { Expect.equals(a1.a1.a1.a0, result.a1.a1.a1.a0); Expect.equals(a1.a1.a1.a1, result.a1.a1.a1.a1); - free(a0.addressOf); - free(a1.addressOf); + calloc.free(a0.addressOf); + calloc.free(a1.addressOf); } final returnStructNestedIntStructAlignmentInt16 = @@ -6361,8 +6304,8 @@ final returnStructNestedIntStructAlignmentInt16 = /// Test alignment and padding of nested struct with 16 byte int. void testReturnStructNestedIntStructAlignmentInt16() { - StructAlignmentInt16 a0 = allocate().ref; - StructAlignmentInt16 a1 = allocate().ref; + StructAlignmentInt16 a0 = calloc().ref; + StructAlignmentInt16 a1 = calloc().ref; a0.a0 = -1; a0.a1 = 2; @@ -6382,8 +6325,8 @@ void testReturnStructNestedIntStructAlignmentInt16() { Expect.equals(a1.a1, result.a1.a1); Expect.equals(a1.a2, result.a1.a2); - free(a0.addressOf); - free(a1.addressOf); + calloc.free(a0.addressOf); + calloc.free(a1.addressOf); } final returnStructNestedIntStructAlignmentInt32 = @@ -6395,8 +6338,8 @@ final returnStructNestedIntStructAlignmentInt32 = /// Test alignment and padding of nested struct with 32 byte int. void testReturnStructNestedIntStructAlignmentInt32() { - StructAlignmentInt32 a0 = allocate().ref; - StructAlignmentInt32 a1 = allocate().ref; + StructAlignmentInt32 a0 = calloc().ref; + StructAlignmentInt32 a1 = calloc().ref; a0.a0 = -1; a0.a1 = 2; @@ -6416,8 +6359,8 @@ void testReturnStructNestedIntStructAlignmentInt32() { Expect.equals(a1.a1, result.a1.a1); Expect.equals(a1.a2, result.a1.a2); - free(a0.addressOf); - free(a1.addressOf); + calloc.free(a0.addressOf); + calloc.free(a1.addressOf); } final returnStructNestedIntStructAlignmentInt64 = @@ -6429,8 +6372,8 @@ final returnStructNestedIntStructAlignmentInt64 = /// Test alignment and padding of nested struct with 64 byte int. void testReturnStructNestedIntStructAlignmentInt64() { - StructAlignmentInt64 a0 = allocate().ref; - StructAlignmentInt64 a1 = allocate().ref; + StructAlignmentInt64 a0 = calloc().ref; + StructAlignmentInt64 a1 = calloc().ref; a0.a0 = -1; a0.a1 = 2; @@ -6450,8 +6393,8 @@ void testReturnStructNestedIntStructAlignmentInt64() { Expect.equals(a1.a1, result.a1.a1); Expect.equals(a1.a2, result.a1.a2); - free(a0.addressOf); - free(a1.addressOf); + calloc.free(a0.addressOf); + calloc.free(a1.addressOf); } final returnStructNestedIrregularEvenBigger = ffiTestFunctions.lookupFunction< @@ -6466,8 +6409,8 @@ final returnStructNestedIrregularEvenBigger = ffiTestFunctions.lookupFunction< /// Return big irregular struct as smoke test. void testReturnStructNestedIrregularEvenBigger() { int a0; - StructNestedIrregularBigger a1 = allocate().ref; - StructNestedIrregularBigger a2 = allocate().ref; + StructNestedIrregularBigger a1 = calloc().ref; + StructNestedIrregularBigger a2 = calloc().ref; double a3; a0 = 1; @@ -6544,6 +6487,6 @@ void testReturnStructNestedIrregularEvenBigger() { Expect.approxEquals(a2.a3, result.a2.a3); Expect.approxEquals(a3, result.a3); - free(a1.addressOf); - free(a2.addressOf); + calloc.free(a1.addressOf); + calloc.free(a2.addressOf); } diff --git a/tests/ffi/function_structs_test.dart b/tests/ffi/function_structs_test.dart index bf9ea5f86b9..ade55fb8e1f 100644 --- a/tests/ffi/function_structs_test.dart +++ b/tests/ffi/function_structs_test.dart @@ -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 c1 = Coordinate.allocate(10.0, 20.0, nullptr).addressOf; - Pointer c2 = Coordinate.allocate(42.0, 84.0, c1).addressOf; + Pointer c1 = + Coordinate.allocate(calloc, 10.0, 20.0, nullptr).addressOf; + Pointer 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(count: 3).ref; + Coordinate c1 = calloc(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); @@ -83,7 +86,7 @@ void testFunctionWithVeryLargeStruct() { ffiTestFunctions.lookup("SumVeryLargeStruct"); VeryLargeStructSum f = p1.asFunction(); - VeryLargeStruct vls1 = allocate(count: 2).ref; + VeryLargeStruct vls1 = calloc(2).ref; VeryLargeStruct vls2 = vls1.addressOf[1]; List 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); } diff --git a/tests/ffi/function_test.dart b/tests/ffi/function_test.dart index bff456e49b1..077be64c23f 100644 --- a/tests/ffi/function_test.dart +++ b/tests/ffi/function_test.dart @@ -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 = int Function(int, T); void testNativeFunctionFromCast() { - Pointer p1 = allocate(); + Pointer p1 = calloc(); Pointer> p2 = p1.cast(); p2.asFunction(); p2.asFunction>(); - free(p1); + calloc.free(p1); } typedef NativeQuadOpSigned = Int64 Function(Int8, Int16, Int32, Int64); @@ -394,14 +395,14 @@ Int64PointerUnOp assign1337Index1 = ffiTestFunctions .lookupFunction("Assign1337Index1"); void testNativeFunctionPointer() { - Pointer p2 = allocate(count: 2); + Pointer p2 = calloc(2); p2.value = 42; p2[1] = 1000; Pointer 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 result = nullableInt64ElemAt1(nullptr); Expect.equals(result, nullptr); - Pointer p2 = allocate(count: 2); + Pointer p2 = calloc(2); result = nullableInt64ElemAt1(p2); Expect.notEquals(result, nullptr); - free(p2); + calloc.free(p2); } typedef NativeFloatPointerToBool = Uint8 Function(Pointer); @@ -424,13 +425,13 @@ FloatPointerToBool isRoughly1337 = ffiTestFunctions.lookupFunction< NativeFloatPointerToBool, FloatPointerToBool>("IsRoughly1337"); void testFloatRounding() { - Pointer p2 = allocate(); + Pointer p2 = calloc(); p2.value = 1337.0; int result = isRoughly1337(p2); Expect.equals(1, result); - free(p2); + calloc.free(p2); } typedef NativeFloatToVoid = Void Function(Float); diff --git a/tests/ffi/generator/structs_by_value_tests_generator.dart b/tests/ffi/generator/structs_by_value_tests_generator.dart index f3f9f02a32b..7bd7c83c363 100644 --- a/tests/ffi/generator/structs_by_value_tests_generator.dart +++ b/tests/ffi/generator/structs_by_value_tests_generator.dart @@ -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'; diff --git a/tests/ffi/regress_37254_test.dart b/tests/ffi/regress_37254_test.dart index ce696af95cf..62c71dbcc1b 100644 --- a/tests/ffi/regress_37254_test.dart +++ b/tests/ffi/regress_37254_test.dart @@ -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> a = allocate>(); - final Pointer b = allocate(); + final Pointer> a = calloc>(); + final Pointer b = calloc(); a.value = b; - free(a); - free(b); + calloc.free(a); + calloc.free(b); } void store2() { - final Pointer> a = allocate>(); + final Pointer> a = calloc>(); final Pointer b = - allocate(); // Reified Pointer at runtime. + calloc(); // Reified Pointer at runtime. // Successful implicit downcast of argument at runtime. // Should succeed now, should statically be rejected when NNBD lands. a.value = b as Pointer; - free(a); - free(b); + calloc.free(a); + calloc.free(b); } void store3() { - final Pointer> a = allocate>(); - final Pointer b = allocate().cast>(); + final Pointer> a = calloc>(); + final Pointer b = calloc().cast>(); // 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; }); - free(a); - free(b); + calloc.free(a); + calloc.free(b); } void store4() { // Reified as Pointer> at runtime. - final Pointer> a = allocate>(); + final Pointer> a = calloc>(); - final Pointer b = allocate(); + final Pointer b = calloc(); a.value = b; - free(a); - free(b); + calloc.free(a); + calloc.free(b); } void store5() { // Reified as Pointer> at runtime. - final Pointer> a = allocate>(); + final Pointer> a = calloc>(); final Pointer b = - allocate(); // Reified as Pointer at runtime. + calloc(); // Reified as Pointer at runtime. a.value = b; - free(a); - free(b); + calloc.free(a); + calloc.free(b); } void store6() { // Reified as Pointer> at runtime. - final Pointer> a = allocate>(); - final Pointer b = allocate().cast>(); + final Pointer> a = calloc>(); + final Pointer b = calloc().cast>(); // 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> a = allocate>(); - final Pointer b = allocate(); + final Pointer> a = calloc>(); + final Pointer b = calloc(); a.value = b; - free(a); - free(b); + calloc.free(a); + calloc.free(b); } void store8() { - final Pointer> a = allocate>(); + final Pointer> a = calloc>(); // Reified as Pointer at runtime. - final Pointer b = allocate(); + final Pointer b = calloc(); a.value = b; - free(a); - free(b); + calloc.free(a); + calloc.free(b); } void store9() { - final Pointer> a = allocate>(); - final Pointer b = allocate().cast>(); + final Pointer> a = calloc>(); + final Pointer b = calloc().cast>(); 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> a = allocate>(); + final Pointer> a = calloc>(); Pointer b = a.value; Expect.type>(b); - free(a); + calloc.free(a); } void load2() { - final Pointer> a = allocate>(); + final Pointer> a = calloc>(); Pointer b = a.value; Expect.type>(b); - free(a); + calloc.free(a); } void load3() { // Reified as Pointer> at runtime. - final Pointer> a = allocate>(); + final Pointer> a = calloc>(); Pointer b = a.value as Pointer; Expect.type>(b); - free(a); + calloc.free(a); } void load4() { // Reified as Pointer> at runtime. - final Pointer> a = allocate>(); + final Pointer> a = calloc>(); // Return value runtime type is Pointer. Pointer b = a.value; Expect.type>(b); - free(a); + calloc.free(a); } void load5() { - final Pointer> a = allocate>(); + final Pointer> a = calloc>(); // 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 b = a.value as Pointer; }); - free(a); + calloc.free(a); } void load6() { - final Pointer> a = allocate>(); + final Pointer> a = calloc>(); Pointer b = a.value; Expect.type>(b); - free(a); + calloc.free(a); } void main() { diff --git a/tests/ffi/regress_39885_test.dart b/tests/ffi/regress_39885_test.dart index 7d960f26671..ef73ca75cfc 100644 --- a/tests/ffi/regress_39885_test.dart +++ b/tests/ffi/regress_39885_test.dart @@ -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(count: 3); + final data = calloc(3); for (int i = 0; i < 3; ++i) { data.elementAt(i).value = 1; } - free(data); + calloc.free(data); } diff --git a/tests/ffi/regress_43693_test.dart b/tests/ffi/regress_43693_test.dart index a34e8f8343d..64b48bfa275 100644 --- a/tests/ffi/regress_43693_test.dart +++ b/tests/ffi/regress_43693_test.dart @@ -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) readMyStructSomeValue = final ffiTestFunctions = dlopenPlatformSpecific("ffi_test_functions"); void main() { - final myStructs = allocate(); + final myStructs = calloc(); myStructs[0].somePtr = nullptr; myStructs[0].someValue = 0xAAAAAAAABBBBBBBB; final result = readMyStructSomeValue(myStructs); Expect.equals(0xAAAAAAAABBBBBBBB, result); - free(myStructs); + calloc.free(myStructs); } diff --git a/tests/ffi/structs_nested_test.dart b/tests/ffi/structs_nested_test.dart index ea4b6dbbe5f..2d5208d97a2 100644 --- a/tests/ffi/structs_nested_test.dart +++ b/tests/ffi/structs_nested_test.dart @@ -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(); + final p = calloc(); Expect.type>(p); print(p); - free(p); + calloc.free(p); } /// Test that reading does not segfault, even uninitialized. void testRead() { print("read"); - final p = allocate(); + final p = calloc(); 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(count: 2); + final p = calloc(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(); + final p = calloc(); 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"); } diff --git a/tests/ffi/structs_nnbd_workaround_test.dart b/tests/ffi/structs_nnbd_workaround_test.dart index 6501faf251b..06c6f29d1d3 100644 --- a/tests/ffi/structs_nnbd_workaround_test.dart +++ b/tests/ffi/structs_nnbd_workaround_test.dart @@ -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 c1 = Coordinate.allocate(10.0, 10.0, nullptr).addressOf; - Pointer c2 = Coordinate.allocate(20.0, 20.0, c1).addressOf; - Pointer c3 = Coordinate.allocate(30.0, 30.0, c2).addressOf; + Pointer c1 = + Coordinate.allocate(calloc, 10.0, 10.0, nullptr).addressOf; + Pointer c2 = + Coordinate.allocate(calloc, 20.0, 20.0, c1).addressOf; + Pointer 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 c1 = allocate(count: 3); + Pointer c1 = calloc(3); Pointer c2 = c1.elementAt(1); Pointer 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.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); - free(c.addressOf); + calloc.free(c.addressOf); } void testUtf8() { final String test = 'Hasta MaƱana'; final Pointer medium = Utf8.toUtf8(test); Expect.equals(test, Utf8.fromUtf8(medium)); - free(medium); + calloc.free(medium); } diff --git a/tests/ffi/structs_test.dart b/tests/ffi/structs_test.dart index 83e617dff7b..6bc1ed1a7a7 100644 --- a/tests/ffi/structs_test.dart +++ b/tests/ffi/structs_test.dart @@ -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 c1 = Coordinate.allocate(10.0, 10.0, nullptr).addressOf; - Pointer c2 = Coordinate.allocate(20.0, 20.0, c1).addressOf; - Pointer c3 = Coordinate.allocate(30.0, 30.0, c2).addressOf; + Pointer c1 = + Coordinate.allocate(calloc, 10.0, 10.0, nullptr).addressOf; + Pointer c2 = + Coordinate.allocate(calloc, 20.0, 20.0, c1).addressOf; + Pointer 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 c1 = allocate(count: 3); + Pointer c1 = calloc(3); Pointer c2 = c1.elementAt(1); Pointer 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.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() * 2 + sizeOf(); bare.Coordinate c1 = - allocate(count: structSize * 3).cast().ref; + calloc(structSize * 3).cast().ref; bare.Coordinate c2 = c1.addressOf.offsetBy(structSize).cast().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); - free(c.addressOf); + calloc.free(c.addressOf); } void testUtf8() { final String test = 'Hasta MaƱana'; final Pointer medium = Utf8.toUtf8(test); Expect.equals(test, Utf8.fromUtf8(medium)); - free(medium); + calloc.free(medium); } diff --git a/tests/ffi/variance_function_test.dart b/tests/ffi/variance_function_test.dart index 539c245266e..3db0147abad 100644 --- a/tests/ffi/variance_function_test.dart +++ b/tests/ffi/variance_function_test.dart @@ -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); typedef Int64PointerParamOp = Void Function(Pointer); typedef NaTyPointerParamOpDart = void Function(Pointer); @@ -38,19 +39,19 @@ void paramInvariant1() { final fp = ffiTestFunctions.lookup>(paramOpName); final f = fp.asFunction(); - final arg = allocate(); + final arg = calloc(); f(arg); - free(arg); + calloc.free(arg); } void paramInvariant2() { final fp = ffiTestFunctions.lookup>(paramOpName); final f = fp.asFunction(); - final arg = allocate().cast(); + final arg = calloc().cast(); Expect.type>(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>(paramOpName); final f = fp.asFunction(); - final arg = allocate(); + final arg = calloc(); Expect.type>(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>(paramOpName); final f = fp.asFunction(); - final Pointer arg = allocate(); + final Pointer arg = calloc(); Expect.type>(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 invariant callbackParamInvariant2(); // Pointer invariant @@ -229,7 +230,7 @@ void fromFunctionTests() { callbackReturnInvariant1(); // Pointer invariant callbackReturnInvariant2(); // Pointer invariant } - free(data); + calloc.free(data); } void main() { diff --git a/tests/ffi/vmspecific_enable_ffi_test.dart b/tests/ffi/vmspecific_enable_ffi_test.dart index f44753d7315..ce906071f16 100644 --- a/tests/ffi/vmspecific_enable_ffi_test.dart +++ b/tests/ffi/vmspecific_enable_ffi_test.dart @@ -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 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 } diff --git a/tests/ffi/vmspecific_static_checks_test.dart b/tests/ffi/vmspecific_static_checks_test.dart index 02819f675ed..cbce8e6fb22 100644 --- a/tests/ffi/vmspecific_static_checks_test.dart +++ b/tests/ffi/vmspecific_static_checks_test.dart @@ -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 p = allocate(); + Pointer p = calloc(); p.value = 123; Pointer loseType = p; generic(loseType); - free(p); + calloc.free(p); } void testGetGeneric2() { T? generic() { - Pointer p = allocate(); + Pointer 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 p1 = allocate(); + Pointer p1 = calloc(); Pointer 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> p = allocate(); + Pointer> p = calloc(); Pointer typedNull = nullptr; p.value = typedNull; // this fails to compile due to type mismatch Pointer 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 p = allocate(); + Pointer p = calloc(); p.value = 123; Pointer loseType = p; generic(loseType); - free(p); + calloc.free(p); } void testSetGeneric2() { void generic(T arg) { - Pointer p = allocate(); + Pointer p = calloc(); p.value = arg; //# 27: compile-time error - free(p); + calloc.free(p); } generic(123); } void testSetVoid() { - Pointer p1 = allocate(); + Pointer p1 = calloc(); Pointer 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 pHelper = allocate(); + Pointer pHelper = calloc(); pHelper.value = 123; - Pointer> p = allocate(); + Pointer> 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 generic() { Pointer 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 } diff --git a/tests/ffi_2/aliasing_test.dart b/tests/ffi_2/aliasing_test.dart index 6c2f698c0e2..946e1e4b05d 100644 --- a/tests/ffi_2/aliasing_test.dart +++ b/tests/ffi_2/aliasing_test.dart @@ -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(); + final source = calloc(); 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(); + final source = calloc(); final alias = source.cast().cast(); 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(); + final source = calloc(); final alias = source.cast().cast(); final alias2 = source.cast().cast(); 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(count: 2); + final source = calloc(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(count: 3); + final source = calloc(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(count: 2); + final source = calloc(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(count: 3); + final source = calloc(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(); + final source = calloc(); final alias = Pointer.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(); + final source = calloc(); final alias = Pointer.fromAddress(source.address); final alias2 = Pointer.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(); - final source = allocate(); + final helper = calloc(); + final source = calloc(); helper.value = source.address; final alias = Pointer.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(); - final source = allocate(); + final helper = calloc(); + final source = calloc(); helper.value = source.address; final alias = Pointer.fromAddress(helper.value); final alias2 = Pointer.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("IntComputation"); void testAliasFromAddressViaNativeFunction() { - final source = allocate(); + final source = calloc(); final alias = Pointer.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(); + final source = calloc(); final alias = Pointer.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 makeDerived(Pointer source) => source.offsetBy(7).cast(); testPartialOverlap() { - final source = allocate(count: 2); + final source = calloc(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); } diff --git a/tests/ffi_2/calloc.dart b/tests/ffi_2/calloc.dart index a0599157c79..a433e39cd9a 100644 --- a/tests/ffi_2/calloc.dart +++ b/tests/ffi_2/calloc.dart @@ -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 diff --git a/tests/ffi_2/coordinate.dart b/tests/ffi_2/coordinate.dart index 92dd9d4599c..92dfbf030df 100644 --- a/tests/ffi_2/coordinate.dart +++ b/tests/ffi_2/coordinate.dart @@ -17,8 +17,9 @@ class Coordinate extends Struct { Pointer next; - factory Coordinate.allocate(double x, double y, Pointer next) { - return allocate().ref + factory Coordinate.allocate( + Allocator allocator, double x, double y, Pointer next) { + return allocator().ref ..x = x ..y = y ..next = next; diff --git a/tests/ffi_2/data_not_asan_test.dart b/tests/ffi_2/data_not_asan_test.dart index e95658f2fd1..69257d6cb28 100644 --- a/tests/ffi_2/data_not_asan_test.dart +++ b/tests/ffi_2/data_not_asan_test.dart @@ -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(count: maxInt)); + Expect.throws(() => calloc(maxInt)); // Try to allocate almost the full 64 bit address space. int maxInt1_8 = 1152921504606846975; // 2^60 -1 - Expect.throws(() => allocate(count: maxInt1_8)); + Expect.throws(() => calloc(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(count: -1)); + Expect.throws(() => calloc(-1)); } diff --git a/tests/ffi_2/data_test.dart b/tests/ffi_2/data_test.dart index 35f9c5e0449..8fca1a1b28b 100644 --- a/tests/ffi_2/data_test.dart +++ b/tests/ffi_2/data_test.dart @@ -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 p = allocate(); + Pointer p = calloc(); p.value = 42; Expect.equals(42, p.value); - free(p); + calloc.free(p); } void testPointerFromPointer() { - Pointer p = allocate(); + Pointer p = calloc(); p.value = 1337; int ptr = p.address; Pointer p2 = Pointer.fromAddress(ptr); Expect.equals(1337, p2.value); - free(p); + calloc.free(p); } void testPointerPointerArithmetic() { - Pointer p = allocate(count: 2); + Pointer p = calloc(2); Pointer p2 = p.elementAt(1); p2.value = 100; Pointer p3 = p.offsetBy(8); Expect.equals(100, p3.value); - free(p); + calloc.free(p); } void testPointerPointerArithmeticSizes() { - Pointer p = allocate(count: 2); + Pointer p = calloc(2); Pointer p2 = p.elementAt(1); int addr = p.address; Expect.equals(addr + 8, p2.address); - free(p); + calloc.free(p); - Pointer p3 = allocate(count: 2); + Pointer p3 = calloc(2); Pointer 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 p; try { - p = allocate(count: 0); + p = calloc(0); } on Exception { returnedNullPointer = true; } if (!returnedNullPointer) { - free(p); + calloc.free(p); } } void testPointerCast() { - Pointer p = allocate(); + Pointer p = calloc(); p.cast(); // gets the correct type args back - free(p); + calloc.free(p); } void testCastGeneric() { @@ -123,9 +124,9 @@ void testCastGeneric() { return p.cast(); } - Pointer p = allocate(); + Pointer p = calloc(); Pointer p2 = generic(p); - free(p); + calloc.free(p); } void testCastGeneric2() { @@ -133,41 +134,41 @@ void testCastGeneric2() { return p.cast(); } - Pointer p = allocate(); + Pointer p = calloc(); Pointer p2 = generic(p); - free(p); + calloc.free(p); } void testCastNativeType() { - Pointer p = allocate(); + Pointer p = calloc(); p.cast(); - free(p); + calloc.free(p); } void testCondensedNumbersInt8() { - Pointer p = allocate(count: 8); + Pointer 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 p = allocate(count: 8); + Pointer 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 p = allocate(); + Pointer 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 p = allocate(); + Pointer 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 p = allocate(); + Pointer 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 p = allocate(); + Pointer 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 p = allocate(); + Pointer 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 p = allocate(); + Pointer 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 p = allocate(); + Pointer 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 p = allocate(); + Pointer 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 p = allocate(); + Pointer 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 p = allocate(); + Pointer 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 p = allocate(); + Pointer p = calloc(); p.value = 1.4260258159703532e-105; Expect.equals(1.4260258159703532e-105, p.value); - free(p); + calloc.free(p); } void testVoid() { - Pointer p1 = allocate(); + Pointer p1 = calloc(); Pointer p2 = p1.cast(); // make this dart pointer opaque p2.address; // we can print the address - free(p2); + calloc.free(p2); } void testPointerPointer() { - Pointer p = allocate(); + Pointer p = calloc(); p.value = 17; - Pointer> p2 = allocate(); + Pointer> p2 = calloc(); p2.value = p; Expect.equals(17, p2.value.value); - free(p2); - free(p); + calloc.free(p2); + calloc.free(p); } void testPointerPointerNull() { - Pointer> pointerToPointer = allocate(); + Pointer> pointerToPointer = calloc(); Pointer 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 next = allocate(); + Pointer next = calloc(); head.value = next.address; createChain(next, length - 1, value); } @@ -378,14 +379,14 @@ void testPointerChain(int length) { void freeChain(Pointer head, int length) { Pointer next = Pointer.fromAddress(head.value); - free(head); + calloc.free(head); if (length == 0) { return; } freeChain(next, length - 1); } - Pointer head = allocate(); + Pointer 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 p = allocate(); + Pointer p = calloc(); Expect.isTrue(p is Pointer); - free(p); + calloc.free(p); } void testToString() { - Pointer p = allocate(); + Pointer p = calloc(); Expect.stringEquals( "Pointer: address=0x", p.toString().substring(0, 26)); - free(p); + calloc.free(p); Pointer p2 = Pointer.fromAddress(0x123abc); Expect.stringEquals("Pointer: address=0x123abc", p2.toString()); } @@ -423,13 +424,13 @@ typedef Int8UnOp = Int8 Function(Int8); void testAllocateVoid() { Expect.throws(() { - Pointer p = allocate(); + Pointer p = calloc(); }); } void testAllocateNativeFunction() { Expect.throws(() { - Pointer> p = allocate(); + Pointer> p = calloc(); }); } @@ -463,7 +464,7 @@ void testSizeOfNativeType() { } void testDynamicInvocation() { - dynamic p = allocate(); + dynamic p = calloc(); 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 p2 = p.cast(); - free(p); + calloc.free(p); } final nullableInt64ElementAt1 = ffiTestFunctions.lookupFunction< diff --git a/tests/ffi_2/extension_methods_test.dart b/tests/ffi_2/extension_methods_test.dart index 19bc44b4c70..3524a7f646b 100644 --- a/tests/ffi_2/extension_methods_test.dart +++ b/tests/ffi_2/extension_methods_test.dart @@ -7,6 +7,8 @@ import 'dart:ffi'; import "package:expect/expect.dart"; import "package:ffi/ffi.dart"; +import 'calloc.dart'; + main(List arguments) { for (int i = 0; i < 100; i++) { testStoreLoad(); @@ -15,7 +17,7 @@ main(List arguments) { } testStoreLoad() { - final p = allocate(count: 2); + final p = calloc(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(count: 2); + final p1 = calloc(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>(count: 2); + final p2 = calloc>(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(); + final p3 = calloc(); Foo foo = p3.ref; foo.a = 1; Expect.equals(1, foo.a); - free(p3); + calloc.free(p3); } testReifiedGeneric() { - final p = allocate>(); + final p = calloc>(); Pointer> p2 = p; Expect.isTrue(p2.value is Pointer); - free(p); + calloc.free(p); } class Foo extends Struct { diff --git a/tests/ffi_2/external_typed_data_test.dart b/tests/ffi_2/external_typed_data_test.dart index 8d19f79a37f..18e8e3c61f5 100644 --- a/tests/ffi_2/external_typed_data_test.dart +++ b/tests/ffi_2/external_typed_data_test.dart @@ -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 ptr = allocate(); + Pointer 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 ptr = allocate(); + Pointer 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 ptr = allocate(); + Pointer 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 ptr = allocate(); + Pointer 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 ptr = allocate(); + Pointer 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 ptr = allocate(); + Pointer 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 ptr = allocate(); + Pointer 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 ptr = allocate(); + Pointer 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 ptr = allocate(); + Pointer 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 ptr = allocate(); + Pointer 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 ptr = allocate(); + Pointer 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 ptr = allocate(); + Pointer 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 ptr = allocate(); + Pointer 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 ptr = allocate(); + Pointer 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 ptr = allocate(); + Pointer 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 ptr = allocate(); + Pointer 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 ptr = allocate(); + Pointer 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 ptr = allocate(); + Pointer 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 ptr = allocate(); + Pointer 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 ptr = allocate(); + Pointer 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 ptr = allocate(count: count); + Pointer 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 ptr = allocate(count: count); + Pointer 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() { diff --git a/tests/ffi_2/function_callbacks_structs_by_value_generated_test.dart b/tests/ffi_2/function_callbacks_structs_by_value_generated_test.dart index bebd119df7f..e11d9629007 100644 --- a/tests/ffi_2/function_callbacks_structs_by_value_generated_test.dart +++ b/tests/ffi_2/function_callbacks_structs_by_value_generated_test.dart @@ -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().ref; + Struct1ByteInt result = calloc().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().ref; + calloc().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().ref; + calloc().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().ref; + calloc().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().ref; + calloc().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().ref; + calloc().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().ref; + Struct8BytesInt result = calloc().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().ref; + calloc().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().ref; + Struct8BytesMixed result = calloc().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().ref; + calloc().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().ref; + calloc().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().ref; + calloc().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().ref; + calloc().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().ref; + Struct16BytesMixed result = calloc().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().ref; + Struct16BytesMixed2 result = calloc().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().ref; + Struct17BytesInt result = calloc().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().ref; + calloc().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().ref; + calloc().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().ref; + calloc().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().ref; + calloc().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().ref; + calloc().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().ref; + calloc().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().ref; + StructAlignmentInt16 result = calloc().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().ref; + StructAlignmentInt32 result = calloc().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().ref; + StructAlignmentInt64 result = calloc().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().ref; + Struct8BytesNestedInt result = calloc().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().ref; + Struct8BytesNestedFloat result = calloc().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().ref; + Struct8BytesNestedFloat2 result = calloc().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().ref; + Struct8BytesNestedMixed result = calloc().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().ref; + Struct16BytesNestedInt result = calloc().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().ref; + Struct32BytesNestedInt result = calloc().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().ref; + calloc().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().ref; + calloc().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().ref; + calloc().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().ref; + calloc().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); } diff --git a/tests/ffi_2/function_callbacks_structs_by_value_test.dart b/tests/ffi_2/function_callbacks_structs_by_value_test.dart index 23c9946e0d7..5e9399a547d 100644 --- a/tests/ffi_2/function_callbacks_structs_by_value_test.dart +++ b/tests/ffi_2/function_callbacks_structs_by_value_test.dart @@ -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().ref; + final struct = calloc().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().ref; + final pointerBackedStruct = calloc().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); } diff --git a/tests/ffi_2/function_structs_by_value_generated_test.dart b/tests/ffi_2/function_structs_by_value_generated_test.dart index d8ed635d4a4..e00f3fa4739 100644 --- a/tests/ffi_2/function_structs_by_value_generated_test.dart +++ b/tests/ffi_2/function_structs_by_value_generated_test.dart @@ -15,6 +15,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"); @@ -1053,16 +1054,16 @@ final passStruct1ByteIntx10 = ffiTestFunctions.lookupFunction< /// Smallest struct with data. /// 10 struct arguments will exhaust available registers. void testPassStruct1ByteIntx10() { - Struct1ByteInt a0 = allocate().ref; - Struct1ByteInt a1 = allocate().ref; - Struct1ByteInt a2 = allocate().ref; - Struct1ByteInt a3 = allocate().ref; - Struct1ByteInt a4 = allocate().ref; - Struct1ByteInt a5 = allocate().ref; - Struct1ByteInt a6 = allocate().ref; - Struct1ByteInt a7 = allocate().ref; - Struct1ByteInt a8 = allocate().ref; - Struct1ByteInt a9 = allocate().ref; + Struct1ByteInt a0 = calloc().ref; + Struct1ByteInt a1 = calloc().ref; + Struct1ByteInt a2 = calloc().ref; + Struct1ByteInt a3 = calloc().ref; + Struct1ByteInt a4 = calloc().ref; + Struct1ByteInt a5 = calloc().ref; + Struct1ByteInt a6 = calloc().ref; + Struct1ByteInt a7 = calloc().ref; + Struct1ByteInt a8 = calloc().ref; + Struct1ByteInt a9 = calloc().ref; a0.a0 = -1; a1.a0 = 2; @@ -1081,16 +1082,16 @@ void testPassStruct1ByteIntx10() { Expect.equals(5, result); - free(a0.addressOf); - free(a1.addressOf); - free(a2.addressOf); - free(a3.addressOf); - free(a4.addressOf); - free(a5.addressOf); - free(a6.addressOf); - free(a7.addressOf); - free(a8.addressOf); - free(a9.addressOf); + calloc.free(a0.addressOf); + calloc.free(a1.addressOf); + calloc.free(a2.addressOf); + calloc.free(a3.addressOf); + calloc.free(a4.addressOf); + calloc.free(a5.addressOf); + calloc.free(a6.addressOf); + calloc.free(a7.addressOf); + calloc.free(a8.addressOf); + calloc.free(a9.addressOf); } final passStruct3BytesHomogeneousUint8x10 = ffiTestFunctions.lookupFunction< @@ -1120,26 +1121,16 @@ final passStruct3BytesHomogeneousUint8x10 = ffiTestFunctions.lookupFunction< /// Not a multiple of word size, not a power of two. /// 10 struct arguments will exhaust available registers. void testPassStruct3BytesHomogeneousUint8x10() { - Struct3BytesHomogeneousUint8 a0 = - allocate().ref; - Struct3BytesHomogeneousUint8 a1 = - allocate().ref; - Struct3BytesHomogeneousUint8 a2 = - allocate().ref; - Struct3BytesHomogeneousUint8 a3 = - allocate().ref; - Struct3BytesHomogeneousUint8 a4 = - allocate().ref; - Struct3BytesHomogeneousUint8 a5 = - allocate().ref; - Struct3BytesHomogeneousUint8 a6 = - allocate().ref; - Struct3BytesHomogeneousUint8 a7 = - allocate().ref; - Struct3BytesHomogeneousUint8 a8 = - allocate().ref; - Struct3BytesHomogeneousUint8 a9 = - allocate().ref; + Struct3BytesHomogeneousUint8 a0 = calloc().ref; + Struct3BytesHomogeneousUint8 a1 = calloc().ref; + Struct3BytesHomogeneousUint8 a2 = calloc().ref; + Struct3BytesHomogeneousUint8 a3 = calloc().ref; + Struct3BytesHomogeneousUint8 a4 = calloc().ref; + Struct3BytesHomogeneousUint8 a5 = calloc().ref; + Struct3BytesHomogeneousUint8 a6 = calloc().ref; + Struct3BytesHomogeneousUint8 a7 = calloc().ref; + Struct3BytesHomogeneousUint8 a8 = calloc().ref; + Struct3BytesHomogeneousUint8 a9 = calloc().ref; a0.a0 = 1; a0.a1 = 2; @@ -1179,16 +1170,16 @@ void testPassStruct3BytesHomogeneousUint8x10() { Expect.equals(465, result); - free(a0.addressOf); - free(a1.addressOf); - free(a2.addressOf); - free(a3.addressOf); - free(a4.addressOf); - free(a5.addressOf); - free(a6.addressOf); - free(a7.addressOf); - free(a8.addressOf); - free(a9.addressOf); + calloc.free(a0.addressOf); + calloc.free(a1.addressOf); + calloc.free(a2.addressOf); + calloc.free(a3.addressOf); + calloc.free(a4.addressOf); + calloc.free(a5.addressOf); + calloc.free(a6.addressOf); + calloc.free(a7.addressOf); + calloc.free(a8.addressOf); + calloc.free(a9.addressOf); } final passStruct3BytesInt2ByteAlignedx10 = ffiTestFunctions.lookupFunction< @@ -1219,16 +1210,16 @@ final passStruct3BytesInt2ByteAlignedx10 = ffiTestFunctions.lookupFunction< /// With alignment rules taken into account size is 4 bytes. /// 10 struct arguments will exhaust available registers. void testPassStruct3BytesInt2ByteAlignedx10() { - Struct3BytesInt2ByteAligned a0 = allocate().ref; - Struct3BytesInt2ByteAligned a1 = allocate().ref; - Struct3BytesInt2ByteAligned a2 = allocate().ref; - Struct3BytesInt2ByteAligned a3 = allocate().ref; - Struct3BytesInt2ByteAligned a4 = allocate().ref; - Struct3BytesInt2ByteAligned a5 = allocate().ref; - Struct3BytesInt2ByteAligned a6 = allocate().ref; - Struct3BytesInt2ByteAligned a7 = allocate().ref; - Struct3BytesInt2ByteAligned a8 = allocate().ref; - Struct3BytesInt2ByteAligned a9 = allocate().ref; + Struct3BytesInt2ByteAligned a0 = calloc().ref; + Struct3BytesInt2ByteAligned a1 = calloc().ref; + Struct3BytesInt2ByteAligned a2 = calloc().ref; + Struct3BytesInt2ByteAligned a3 = calloc().ref; + Struct3BytesInt2ByteAligned a4 = calloc().ref; + Struct3BytesInt2ByteAligned a5 = calloc().ref; + Struct3BytesInt2ByteAligned a6 = calloc().ref; + Struct3BytesInt2ByteAligned a7 = calloc().ref; + Struct3BytesInt2ByteAligned a8 = calloc().ref; + Struct3BytesInt2ByteAligned a9 = calloc().ref; a0.a0 = -1; a0.a1 = 2; @@ -1258,16 +1249,16 @@ void testPassStruct3BytesInt2ByteAlignedx10() { Expect.equals(10, result); - free(a0.addressOf); - free(a1.addressOf); - free(a2.addressOf); - free(a3.addressOf); - free(a4.addressOf); - free(a5.addressOf); - free(a6.addressOf); - free(a7.addressOf); - free(a8.addressOf); - free(a9.addressOf); + calloc.free(a0.addressOf); + calloc.free(a1.addressOf); + calloc.free(a2.addressOf); + calloc.free(a3.addressOf); + calloc.free(a4.addressOf); + calloc.free(a5.addressOf); + calloc.free(a6.addressOf); + calloc.free(a7.addressOf); + calloc.free(a8.addressOf); + calloc.free(a9.addressOf); } final passStruct4BytesHomogeneousInt16x10 = ffiTestFunctions.lookupFunction< @@ -1297,26 +1288,16 @@ final passStruct4BytesHomogeneousInt16x10 = ffiTestFunctions.lookupFunction< /// Exactly word size on 32-bit architectures. /// 10 struct arguments will exhaust available registers. void testPassStruct4BytesHomogeneousInt16x10() { - Struct4BytesHomogeneousInt16 a0 = - allocate().ref; - Struct4BytesHomogeneousInt16 a1 = - allocate().ref; - Struct4BytesHomogeneousInt16 a2 = - allocate().ref; - Struct4BytesHomogeneousInt16 a3 = - allocate().ref; - Struct4BytesHomogeneousInt16 a4 = - allocate().ref; - Struct4BytesHomogeneousInt16 a5 = - allocate().ref; - Struct4BytesHomogeneousInt16 a6 = - allocate().ref; - Struct4BytesHomogeneousInt16 a7 = - allocate().ref; - Struct4BytesHomogeneousInt16 a8 = - allocate().ref; - Struct4BytesHomogeneousInt16 a9 = - allocate().ref; + Struct4BytesHomogeneousInt16 a0 = calloc().ref; + Struct4BytesHomogeneousInt16 a1 = calloc().ref; + Struct4BytesHomogeneousInt16 a2 = calloc().ref; + Struct4BytesHomogeneousInt16 a3 = calloc().ref; + Struct4BytesHomogeneousInt16 a4 = calloc().ref; + Struct4BytesHomogeneousInt16 a5 = calloc().ref; + Struct4BytesHomogeneousInt16 a6 = calloc().ref; + Struct4BytesHomogeneousInt16 a7 = calloc().ref; + Struct4BytesHomogeneousInt16 a8 = calloc().ref; + Struct4BytesHomogeneousInt16 a9 = calloc().ref; a0.a0 = -1; a0.a1 = 2; @@ -1346,16 +1327,16 @@ void testPassStruct4BytesHomogeneousInt16x10() { Expect.equals(10, result); - free(a0.addressOf); - free(a1.addressOf); - free(a2.addressOf); - free(a3.addressOf); - free(a4.addressOf); - free(a5.addressOf); - free(a6.addressOf); - free(a7.addressOf); - free(a8.addressOf); - free(a9.addressOf); + calloc.free(a0.addressOf); + calloc.free(a1.addressOf); + calloc.free(a2.addressOf); + calloc.free(a3.addressOf); + calloc.free(a4.addressOf); + calloc.free(a5.addressOf); + calloc.free(a6.addressOf); + calloc.free(a7.addressOf); + calloc.free(a8.addressOf); + calloc.free(a9.addressOf); } final passStruct7BytesHomogeneousUint8x10 = ffiTestFunctions.lookupFunction< @@ -1385,26 +1366,16 @@ final passStruct7BytesHomogeneousUint8x10 = ffiTestFunctions.lookupFunction< /// Sub word size on 64 bit architectures. /// 10 struct arguments will exhaust available registers. void testPassStruct7BytesHomogeneousUint8x10() { - Struct7BytesHomogeneousUint8 a0 = - allocate().ref; - Struct7BytesHomogeneousUint8 a1 = - allocate().ref; - Struct7BytesHomogeneousUint8 a2 = - allocate().ref; - Struct7BytesHomogeneousUint8 a3 = - allocate().ref; - Struct7BytesHomogeneousUint8 a4 = - allocate().ref; - Struct7BytesHomogeneousUint8 a5 = - allocate().ref; - Struct7BytesHomogeneousUint8 a6 = - allocate().ref; - Struct7BytesHomogeneousUint8 a7 = - allocate().ref; - Struct7BytesHomogeneousUint8 a8 = - allocate().ref; - Struct7BytesHomogeneousUint8 a9 = - allocate().ref; + Struct7BytesHomogeneousUint8 a0 = calloc().ref; + Struct7BytesHomogeneousUint8 a1 = calloc().ref; + Struct7BytesHomogeneousUint8 a2 = calloc().ref; + Struct7BytesHomogeneousUint8 a3 = calloc().ref; + Struct7BytesHomogeneousUint8 a4 = calloc().ref; + Struct7BytesHomogeneousUint8 a5 = calloc().ref; + Struct7BytesHomogeneousUint8 a6 = calloc().ref; + Struct7BytesHomogeneousUint8 a7 = calloc().ref; + Struct7BytesHomogeneousUint8 a8 = calloc().ref; + Struct7BytesHomogeneousUint8 a9 = calloc().ref; a0.a0 = 1; a0.a1 = 2; @@ -1484,16 +1455,16 @@ void testPassStruct7BytesHomogeneousUint8x10() { Expect.equals(2485, result); - free(a0.addressOf); - free(a1.addressOf); - free(a2.addressOf); - free(a3.addressOf); - free(a4.addressOf); - free(a5.addressOf); - free(a6.addressOf); - free(a7.addressOf); - free(a8.addressOf); - free(a9.addressOf); + calloc.free(a0.addressOf); + calloc.free(a1.addressOf); + calloc.free(a2.addressOf); + calloc.free(a3.addressOf); + calloc.free(a4.addressOf); + calloc.free(a5.addressOf); + calloc.free(a6.addressOf); + calloc.free(a7.addressOf); + calloc.free(a8.addressOf); + calloc.free(a9.addressOf); } final passStruct7BytesInt4ByteAlignedx10 = ffiTestFunctions.lookupFunction< @@ -1524,16 +1495,16 @@ final passStruct7BytesInt4ByteAlignedx10 = ffiTestFunctions.lookupFunction< /// With alignment rules taken into account size is 8 bytes. /// 10 struct arguments will exhaust available registers. void testPassStruct7BytesInt4ByteAlignedx10() { - Struct7BytesInt4ByteAligned a0 = allocate().ref; - Struct7BytesInt4ByteAligned a1 = allocate().ref; - Struct7BytesInt4ByteAligned a2 = allocate().ref; - Struct7BytesInt4ByteAligned a3 = allocate().ref; - Struct7BytesInt4ByteAligned a4 = allocate().ref; - Struct7BytesInt4ByteAligned a5 = allocate().ref; - Struct7BytesInt4ByteAligned a6 = allocate().ref; - Struct7BytesInt4ByteAligned a7 = allocate().ref; - Struct7BytesInt4ByteAligned a8 = allocate().ref; - Struct7BytesInt4ByteAligned a9 = allocate().ref; + Struct7BytesInt4ByteAligned a0 = calloc().ref; + Struct7BytesInt4ByteAligned a1 = calloc().ref; + Struct7BytesInt4ByteAligned a2 = calloc().ref; + Struct7BytesInt4ByteAligned a3 = calloc().ref; + Struct7BytesInt4ByteAligned a4 = calloc().ref; + Struct7BytesInt4ByteAligned a5 = calloc().ref; + Struct7BytesInt4ByteAligned a6 = calloc().ref; + Struct7BytesInt4ByteAligned a7 = calloc().ref; + Struct7BytesInt4ByteAligned a8 = calloc().ref; + Struct7BytesInt4ByteAligned a9 = calloc().ref; a0.a0 = -1; a0.a1 = 2; @@ -1573,16 +1544,16 @@ void testPassStruct7BytesInt4ByteAlignedx10() { Expect.equals(15, result); - free(a0.addressOf); - free(a1.addressOf); - free(a2.addressOf); - free(a3.addressOf); - free(a4.addressOf); - free(a5.addressOf); - free(a6.addressOf); - free(a7.addressOf); - free(a8.addressOf); - free(a9.addressOf); + calloc.free(a0.addressOf); + calloc.free(a1.addressOf); + calloc.free(a2.addressOf); + calloc.free(a3.addressOf); + calloc.free(a4.addressOf); + calloc.free(a5.addressOf); + calloc.free(a6.addressOf); + calloc.free(a7.addressOf); + calloc.free(a8.addressOf); + calloc.free(a9.addressOf); } final passStruct8BytesIntx10 = ffiTestFunctions.lookupFunction< @@ -1612,16 +1583,16 @@ final passStruct8BytesIntx10 = ffiTestFunctions.lookupFunction< /// Exactly word size struct on 64bit architectures. /// 10 struct arguments will exhaust available registers. void testPassStruct8BytesIntx10() { - Struct8BytesInt a0 = allocate().ref; - Struct8BytesInt a1 = allocate().ref; - Struct8BytesInt a2 = allocate().ref; - Struct8BytesInt a3 = allocate().ref; - Struct8BytesInt a4 = allocate().ref; - Struct8BytesInt a5 = allocate().ref; - Struct8BytesInt a6 = allocate().ref; - Struct8BytesInt a7 = allocate().ref; - Struct8BytesInt a8 = allocate().ref; - Struct8BytesInt a9 = allocate().ref; + Struct8BytesInt a0 = calloc().ref; + Struct8BytesInt a1 = calloc().ref; + Struct8BytesInt a2 = calloc().ref; + Struct8BytesInt a3 = calloc().ref; + Struct8BytesInt a4 = calloc().ref; + Struct8BytesInt a5 = calloc().ref; + Struct8BytesInt a6 = calloc().ref; + Struct8BytesInt a7 = calloc().ref; + Struct8BytesInt a8 = calloc().ref; + Struct8BytesInt a9 = calloc().ref; a0.a0 = -1; a0.a1 = 2; @@ -1660,16 +1631,16 @@ void testPassStruct8BytesIntx10() { Expect.equals(15, result); - free(a0.addressOf); - free(a1.addressOf); - free(a2.addressOf); - free(a3.addressOf); - free(a4.addressOf); - free(a5.addressOf); - free(a6.addressOf); - free(a7.addressOf); - free(a8.addressOf); - free(a9.addressOf); + calloc.free(a0.addressOf); + calloc.free(a1.addressOf); + calloc.free(a2.addressOf); + calloc.free(a3.addressOf); + calloc.free(a4.addressOf); + calloc.free(a5.addressOf); + calloc.free(a6.addressOf); + calloc.free(a7.addressOf); + calloc.free(a8.addressOf); + calloc.free(a9.addressOf); } final passStruct8BytesHomogeneousFloatx10 = ffiTestFunctions.lookupFunction< @@ -1699,26 +1670,16 @@ final passStruct8BytesHomogeneousFloatx10 = ffiTestFunctions.lookupFunction< /// Arguments passed in FP registers as long as they fit. /// 10 struct arguments will exhaust available registers. void testPassStruct8BytesHomogeneousFloatx10() { - Struct8BytesHomogeneousFloat a0 = - allocate().ref; - Struct8BytesHomogeneousFloat a1 = - allocate().ref; - Struct8BytesHomogeneousFloat a2 = - allocate().ref; - Struct8BytesHomogeneousFloat a3 = - allocate().ref; - Struct8BytesHomogeneousFloat a4 = - allocate().ref; - Struct8BytesHomogeneousFloat a5 = - allocate().ref; - Struct8BytesHomogeneousFloat a6 = - allocate().ref; - Struct8BytesHomogeneousFloat a7 = - allocate().ref; - Struct8BytesHomogeneousFloat a8 = - allocate().ref; - Struct8BytesHomogeneousFloat a9 = - allocate().ref; + Struct8BytesHomogeneousFloat a0 = calloc().ref; + Struct8BytesHomogeneousFloat a1 = calloc().ref; + Struct8BytesHomogeneousFloat a2 = calloc().ref; + Struct8BytesHomogeneousFloat a3 = calloc().ref; + Struct8BytesHomogeneousFloat a4 = calloc().ref; + Struct8BytesHomogeneousFloat a5 = calloc().ref; + Struct8BytesHomogeneousFloat a6 = calloc().ref; + Struct8BytesHomogeneousFloat a7 = calloc().ref; + Struct8BytesHomogeneousFloat a8 = calloc().ref; + Struct8BytesHomogeneousFloat a9 = calloc().ref; a0.a0 = -1.0; a0.a1 = 2.0; @@ -1748,16 +1709,16 @@ void testPassStruct8BytesHomogeneousFloatx10() { Expect.approxEquals(10.0, result); - free(a0.addressOf); - free(a1.addressOf); - free(a2.addressOf); - free(a3.addressOf); - free(a4.addressOf); - free(a5.addressOf); - free(a6.addressOf); - free(a7.addressOf); - free(a8.addressOf); - free(a9.addressOf); + calloc.free(a0.addressOf); + calloc.free(a1.addressOf); + calloc.free(a2.addressOf); + calloc.free(a3.addressOf); + calloc.free(a4.addressOf); + calloc.free(a5.addressOf); + calloc.free(a6.addressOf); + calloc.free(a7.addressOf); + calloc.free(a8.addressOf); + calloc.free(a9.addressOf); } final passStruct8BytesMixedx10 = ffiTestFunctions.lookupFunction< @@ -1787,16 +1748,16 @@ final passStruct8BytesMixedx10 = ffiTestFunctions.lookupFunction< /// On x64, arguments go in int registers because it is not only float. /// 10 struct arguments will exhaust available registers. void testPassStruct8BytesMixedx10() { - Struct8BytesMixed a0 = allocate().ref; - Struct8BytesMixed a1 = allocate().ref; - Struct8BytesMixed a2 = allocate().ref; - Struct8BytesMixed a3 = allocate().ref; - Struct8BytesMixed a4 = allocate().ref; - Struct8BytesMixed a5 = allocate().ref; - Struct8BytesMixed a6 = allocate().ref; - Struct8BytesMixed a7 = allocate().ref; - Struct8BytesMixed a8 = allocate().ref; - Struct8BytesMixed a9 = allocate().ref; + Struct8BytesMixed a0 = calloc().ref; + Struct8BytesMixed a1 = calloc().ref; + Struct8BytesMixed a2 = calloc().ref; + Struct8BytesMixed a3 = calloc().ref; + Struct8BytesMixed a4 = calloc().ref; + Struct8BytesMixed a5 = calloc().ref; + Struct8BytesMixed a6 = calloc().ref; + Struct8BytesMixed a7 = calloc().ref; + Struct8BytesMixed a8 = calloc().ref; + Struct8BytesMixed a9 = calloc().ref; a0.a0 = -1.0; a0.a1 = 2; @@ -1836,16 +1797,16 @@ void testPassStruct8BytesMixedx10() { Expect.approxEquals(15.0, result); - free(a0.addressOf); - free(a1.addressOf); - free(a2.addressOf); - free(a3.addressOf); - free(a4.addressOf); - free(a5.addressOf); - free(a6.addressOf); - free(a7.addressOf); - free(a8.addressOf); - free(a9.addressOf); + calloc.free(a0.addressOf); + calloc.free(a1.addressOf); + calloc.free(a2.addressOf); + calloc.free(a3.addressOf); + calloc.free(a4.addressOf); + calloc.free(a5.addressOf); + calloc.free(a6.addressOf); + calloc.free(a7.addressOf); + calloc.free(a8.addressOf); + calloc.free(a9.addressOf); } final passStruct9BytesHomogeneousUint8x10 = ffiTestFunctions.lookupFunction< @@ -1878,26 +1839,16 @@ final passStruct9BytesHomogeneousUint8x10 = ffiTestFunctions.lookupFunction< /// Tests upper bytes in the integer registers that are partly filled. /// Tests stack alignment of non word size stack arguments. void testPassStruct9BytesHomogeneousUint8x10() { - Struct9BytesHomogeneousUint8 a0 = - allocate().ref; - Struct9BytesHomogeneousUint8 a1 = - allocate().ref; - Struct9BytesHomogeneousUint8 a2 = - allocate().ref; - Struct9BytesHomogeneousUint8 a3 = - allocate().ref; - Struct9BytesHomogeneousUint8 a4 = - allocate().ref; - Struct9BytesHomogeneousUint8 a5 = - allocate().ref; - Struct9BytesHomogeneousUint8 a6 = - allocate().ref; - Struct9BytesHomogeneousUint8 a7 = - allocate().ref; - Struct9BytesHomogeneousUint8 a8 = - allocate().ref; - Struct9BytesHomogeneousUint8 a9 = - allocate().ref; + Struct9BytesHomogeneousUint8 a0 = calloc().ref; + Struct9BytesHomogeneousUint8 a1 = calloc().ref; + Struct9BytesHomogeneousUint8 a2 = calloc().ref; + Struct9BytesHomogeneousUint8 a3 = calloc().ref; + Struct9BytesHomogeneousUint8 a4 = calloc().ref; + Struct9BytesHomogeneousUint8 a5 = calloc().ref; + Struct9BytesHomogeneousUint8 a6 = calloc().ref; + Struct9BytesHomogeneousUint8 a7 = calloc().ref; + Struct9BytesHomogeneousUint8 a8 = calloc().ref; + Struct9BytesHomogeneousUint8 a9 = calloc().ref; a0.a0 = 1; a0.a1 = 2; @@ -1997,16 +1948,16 @@ void testPassStruct9BytesHomogeneousUint8x10() { Expect.equals(4095, result); - free(a0.addressOf); - free(a1.addressOf); - free(a2.addressOf); - free(a3.addressOf); - free(a4.addressOf); - free(a5.addressOf); - free(a6.addressOf); - free(a7.addressOf); - free(a8.addressOf); - free(a9.addressOf); + calloc.free(a0.addressOf); + calloc.free(a1.addressOf); + calloc.free(a2.addressOf); + calloc.free(a3.addressOf); + calloc.free(a4.addressOf); + calloc.free(a5.addressOf); + calloc.free(a6.addressOf); + calloc.free(a7.addressOf); + calloc.free(a8.addressOf); + calloc.free(a9.addressOf); } final passStruct9BytesInt4Or8ByteAlignedx10 = ffiTestFunctions.lookupFunction< @@ -2040,25 +1991,25 @@ final passStruct9BytesInt4Or8ByteAlignedx10 = ffiTestFunctions.lookupFunction< /// void testPassStruct9BytesInt4Or8ByteAlignedx10() { Struct9BytesInt4Or8ByteAligned a0 = - allocate().ref; + calloc().ref; Struct9BytesInt4Or8ByteAligned a1 = - allocate().ref; + calloc().ref; Struct9BytesInt4Or8ByteAligned a2 = - allocate().ref; + calloc().ref; Struct9BytesInt4Or8ByteAligned a3 = - allocate().ref; + calloc().ref; Struct9BytesInt4Or8ByteAligned a4 = - allocate().ref; + calloc().ref; Struct9BytesInt4Or8ByteAligned a5 = - allocate().ref; + calloc().ref; Struct9BytesInt4Or8ByteAligned a6 = - allocate().ref; + calloc().ref; Struct9BytesInt4Or8ByteAligned a7 = - allocate().ref; + calloc().ref; Struct9BytesInt4Or8ByteAligned a8 = - allocate().ref; + calloc().ref; Struct9BytesInt4Or8ByteAligned a9 = - allocate().ref; + calloc().ref; a0.a0 = -1; a0.a1 = 2; @@ -2088,16 +2039,16 @@ void testPassStruct9BytesInt4Or8ByteAlignedx10() { Expect.equals(10, result); - free(a0.addressOf); - free(a1.addressOf); - free(a2.addressOf); - free(a3.addressOf); - free(a4.addressOf); - free(a5.addressOf); - free(a6.addressOf); - free(a7.addressOf); - free(a8.addressOf); - free(a9.addressOf); + calloc.free(a0.addressOf); + calloc.free(a1.addressOf); + calloc.free(a2.addressOf); + calloc.free(a3.addressOf); + calloc.free(a4.addressOf); + calloc.free(a5.addressOf); + calloc.free(a6.addressOf); + calloc.free(a7.addressOf); + calloc.free(a8.addressOf); + calloc.free(a9.addressOf); } final passStruct12BytesHomogeneousFloatx6 = ffiTestFunctions.lookupFunction< @@ -2121,17 +2072,17 @@ final passStruct12BytesHomogeneousFloatx6 = ffiTestFunctions.lookupFunction< /// The last argument is to test whether arguments are backfilled. void testPassStruct12BytesHomogeneousFloatx6() { Struct12BytesHomogeneousFloat a0 = - allocate().ref; + calloc().ref; Struct12BytesHomogeneousFloat a1 = - allocate().ref; + calloc().ref; Struct12BytesHomogeneousFloat a2 = - allocate().ref; + calloc().ref; Struct12BytesHomogeneousFloat a3 = - allocate().ref; + calloc().ref; Struct12BytesHomogeneousFloat a4 = - allocate().ref; + calloc().ref; Struct12BytesHomogeneousFloat a5 = - allocate().ref; + calloc().ref; a0.a0 = -1.0; a0.a1 = 2.0; @@ -2158,12 +2109,12 @@ void testPassStruct12BytesHomogeneousFloatx6() { Expect.approxEquals(9.0, result); - free(a0.addressOf); - free(a1.addressOf); - free(a2.addressOf); - free(a3.addressOf); - free(a4.addressOf); - free(a5.addressOf); + calloc.free(a0.addressOf); + calloc.free(a1.addressOf); + calloc.free(a2.addressOf); + calloc.free(a3.addressOf); + calloc.free(a4.addressOf); + calloc.free(a5.addressOf); } final passStruct16BytesHomogeneousFloatx5 = ffiTestFunctions.lookupFunction< @@ -2185,15 +2136,15 @@ final passStruct16BytesHomogeneousFloatx5 = ffiTestFunctions.lookupFunction< /// 5 struct arguments will exhaust available registers. void testPassStruct16BytesHomogeneousFloatx5() { Struct16BytesHomogeneousFloat a0 = - allocate().ref; + calloc().ref; Struct16BytesHomogeneousFloat a1 = - allocate().ref; + calloc().ref; Struct16BytesHomogeneousFloat a2 = - allocate().ref; + calloc().ref; Struct16BytesHomogeneousFloat a3 = - allocate().ref; + calloc().ref; Struct16BytesHomogeneousFloat a4 = - allocate().ref; + calloc().ref; a0.a0 = -1.0; a0.a1 = 2.0; @@ -2222,11 +2173,11 @@ void testPassStruct16BytesHomogeneousFloatx5() { Expect.approxEquals(10.0, result); - free(a0.addressOf); - free(a1.addressOf); - free(a2.addressOf); - free(a3.addressOf); - free(a4.addressOf); + calloc.free(a0.addressOf); + calloc.free(a1.addressOf); + calloc.free(a2.addressOf); + calloc.free(a3.addressOf); + calloc.free(a4.addressOf); } final passStruct16BytesMixedx10 = ffiTestFunctions.lookupFunction< @@ -2258,16 +2209,16 @@ final passStruct16BytesMixedx10 = ffiTestFunctions.lookupFunction< /// The rest goes on the stack. /// On arm, arguments are 8 byte aligned. void testPassStruct16BytesMixedx10() { - Struct16BytesMixed a0 = allocate().ref; - Struct16BytesMixed a1 = allocate().ref; - Struct16BytesMixed a2 = allocate().ref; - Struct16BytesMixed a3 = allocate().ref; - Struct16BytesMixed a4 = allocate().ref; - Struct16BytesMixed a5 = allocate().ref; - Struct16BytesMixed a6 = allocate().ref; - Struct16BytesMixed a7 = allocate().ref; - Struct16BytesMixed a8 = allocate().ref; - Struct16BytesMixed a9 = allocate().ref; + Struct16BytesMixed a0 = calloc().ref; + Struct16BytesMixed a1 = calloc().ref; + Struct16BytesMixed a2 = calloc().ref; + Struct16BytesMixed a3 = calloc().ref; + Struct16BytesMixed a4 = calloc().ref; + Struct16BytesMixed a5 = calloc().ref; + Struct16BytesMixed a6 = calloc().ref; + Struct16BytesMixed a7 = calloc().ref; + Struct16BytesMixed a8 = calloc().ref; + Struct16BytesMixed a9 = calloc().ref; a0.a0 = -1.0; a0.a1 = 2; @@ -2297,16 +2248,16 @@ void testPassStruct16BytesMixedx10() { Expect.approxEquals(10.0, result); - free(a0.addressOf); - free(a1.addressOf); - free(a2.addressOf); - free(a3.addressOf); - free(a4.addressOf); - free(a5.addressOf); - free(a6.addressOf); - free(a7.addressOf); - free(a8.addressOf); - free(a9.addressOf); + calloc.free(a0.addressOf); + calloc.free(a1.addressOf); + calloc.free(a2.addressOf); + calloc.free(a3.addressOf); + calloc.free(a4.addressOf); + calloc.free(a5.addressOf); + calloc.free(a6.addressOf); + calloc.free(a7.addressOf); + calloc.free(a8.addressOf); + calloc.free(a9.addressOf); } final passStruct16BytesMixed2x10 = ffiTestFunctions.lookupFunction< @@ -2338,16 +2289,16 @@ final passStruct16BytesMixed2x10 = ffiTestFunctions.lookupFunction< /// The rest goes on the stack. /// On arm, arguments are 4 byte aligned. void testPassStruct16BytesMixed2x10() { - Struct16BytesMixed2 a0 = allocate().ref; - Struct16BytesMixed2 a1 = allocate().ref; - Struct16BytesMixed2 a2 = allocate().ref; - Struct16BytesMixed2 a3 = allocate().ref; - Struct16BytesMixed2 a4 = allocate().ref; - Struct16BytesMixed2 a5 = allocate().ref; - Struct16BytesMixed2 a6 = allocate().ref; - Struct16BytesMixed2 a7 = allocate().ref; - Struct16BytesMixed2 a8 = allocate().ref; - Struct16BytesMixed2 a9 = allocate().ref; + Struct16BytesMixed2 a0 = calloc().ref; + Struct16BytesMixed2 a1 = calloc().ref; + Struct16BytesMixed2 a2 = calloc().ref; + Struct16BytesMixed2 a3 = calloc().ref; + Struct16BytesMixed2 a4 = calloc().ref; + Struct16BytesMixed2 a5 = calloc().ref; + Struct16BytesMixed2 a6 = calloc().ref; + Struct16BytesMixed2 a7 = calloc().ref; + Struct16BytesMixed2 a8 = calloc().ref; + Struct16BytesMixed2 a9 = calloc().ref; a0.a0 = -1.0; a0.a1 = 2.0; @@ -2397,16 +2348,16 @@ void testPassStruct16BytesMixed2x10() { Expect.approxEquals(20.0, result); - free(a0.addressOf); - free(a1.addressOf); - free(a2.addressOf); - free(a3.addressOf); - free(a4.addressOf); - free(a5.addressOf); - free(a6.addressOf); - free(a7.addressOf); - free(a8.addressOf); - free(a9.addressOf); + calloc.free(a0.addressOf); + calloc.free(a1.addressOf); + calloc.free(a2.addressOf); + calloc.free(a3.addressOf); + calloc.free(a4.addressOf); + calloc.free(a5.addressOf); + calloc.free(a6.addressOf); + calloc.free(a7.addressOf); + calloc.free(a8.addressOf); + calloc.free(a9.addressOf); } final passStruct17BytesIntx10 = ffiTestFunctions.lookupFunction< @@ -2436,16 +2387,16 @@ final passStruct17BytesIntx10 = ffiTestFunctions.lookupFunction< /// Arguments are passed as pointer to copy on arm64. /// Tests that the memory allocated for copies are rounded up to word size. void testPassStruct17BytesIntx10() { - Struct17BytesInt a0 = allocate().ref; - Struct17BytesInt a1 = allocate().ref; - Struct17BytesInt a2 = allocate().ref; - Struct17BytesInt a3 = allocate().ref; - Struct17BytesInt a4 = allocate().ref; - Struct17BytesInt a5 = allocate().ref; - Struct17BytesInt a6 = allocate().ref; - Struct17BytesInt a7 = allocate().ref; - Struct17BytesInt a8 = allocate().ref; - Struct17BytesInt a9 = allocate().ref; + Struct17BytesInt a0 = calloc().ref; + Struct17BytesInt a1 = calloc().ref; + Struct17BytesInt a2 = calloc().ref; + Struct17BytesInt a3 = calloc().ref; + Struct17BytesInt a4 = calloc().ref; + Struct17BytesInt a5 = calloc().ref; + Struct17BytesInt a6 = calloc().ref; + Struct17BytesInt a7 = calloc().ref; + Struct17BytesInt a8 = calloc().ref; + Struct17BytesInt a9 = calloc().ref; a0.a0 = -1; a0.a1 = 2; @@ -2485,16 +2436,16 @@ void testPassStruct17BytesIntx10() { Expect.equals(15, result); - free(a0.addressOf); - free(a1.addressOf); - free(a2.addressOf); - free(a3.addressOf); - free(a4.addressOf); - free(a5.addressOf); - free(a6.addressOf); - free(a7.addressOf); - free(a8.addressOf); - free(a9.addressOf); + calloc.free(a0.addressOf); + calloc.free(a1.addressOf); + calloc.free(a2.addressOf); + calloc.free(a3.addressOf); + calloc.free(a4.addressOf); + calloc.free(a5.addressOf); + calloc.free(a6.addressOf); + calloc.free(a7.addressOf); + calloc.free(a8.addressOf); + calloc.free(a9.addressOf); } final passStruct19BytesHomogeneousUint8x10 = ffiTestFunctions.lookupFunction< @@ -2526,25 +2477,25 @@ final passStruct19BytesHomogeneousUint8x10 = ffiTestFunctions.lookupFunction< /// void testPassStruct19BytesHomogeneousUint8x10() { Struct19BytesHomogeneousUint8 a0 = - allocate().ref; + calloc().ref; Struct19BytesHomogeneousUint8 a1 = - allocate().ref; + calloc().ref; Struct19BytesHomogeneousUint8 a2 = - allocate().ref; + calloc().ref; Struct19BytesHomogeneousUint8 a3 = - allocate().ref; + calloc().ref; Struct19BytesHomogeneousUint8 a4 = - allocate().ref; + calloc().ref; Struct19BytesHomogeneousUint8 a5 = - allocate().ref; + calloc().ref; Struct19BytesHomogeneousUint8 a6 = - allocate().ref; + calloc().ref; Struct19BytesHomogeneousUint8 a7 = - allocate().ref; + calloc().ref; Struct19BytesHomogeneousUint8 a8 = - allocate().ref; + calloc().ref; Struct19BytesHomogeneousUint8 a9 = - allocate().ref; + calloc().ref; a0.a0 = 1; a0.a1 = 2; @@ -2744,16 +2695,16 @@ void testPassStruct19BytesHomogeneousUint8x10() { Expect.equals(18145, result); - free(a0.addressOf); - free(a1.addressOf); - free(a2.addressOf); - free(a3.addressOf); - free(a4.addressOf); - free(a5.addressOf); - free(a6.addressOf); - free(a7.addressOf); - free(a8.addressOf); - free(a9.addressOf); + calloc.free(a0.addressOf); + calloc.free(a1.addressOf); + calloc.free(a2.addressOf); + calloc.free(a3.addressOf); + calloc.free(a4.addressOf); + calloc.free(a5.addressOf); + calloc.free(a6.addressOf); + calloc.free(a7.addressOf); + calloc.free(a8.addressOf); + calloc.free(a9.addressOf); } final passStruct20BytesHomogeneousInt32x10 = ffiTestFunctions.lookupFunction< @@ -2786,25 +2737,25 @@ final passStruct20BytesHomogeneousInt32x10 = ffiTestFunctions.lookupFunction< /// pointers to copies are also passed on the stack. void testPassStruct20BytesHomogeneousInt32x10() { Struct20BytesHomogeneousInt32 a0 = - allocate().ref; + calloc().ref; Struct20BytesHomogeneousInt32 a1 = - allocate().ref; + calloc().ref; Struct20BytesHomogeneousInt32 a2 = - allocate().ref; + calloc().ref; Struct20BytesHomogeneousInt32 a3 = - allocate().ref; + calloc().ref; Struct20BytesHomogeneousInt32 a4 = - allocate().ref; + calloc().ref; Struct20BytesHomogeneousInt32 a5 = - allocate().ref; + calloc().ref; Struct20BytesHomogeneousInt32 a6 = - allocate().ref; + calloc().ref; Struct20BytesHomogeneousInt32 a7 = - allocate().ref; + calloc().ref; Struct20BytesHomogeneousInt32 a8 = - allocate().ref; + calloc().ref; Struct20BytesHomogeneousInt32 a9 = - allocate().ref; + calloc().ref; a0.a0 = -1; a0.a1 = 2; @@ -2864,16 +2815,16 @@ void testPassStruct20BytesHomogeneousInt32x10() { Expect.equals(25, result); - free(a0.addressOf); - free(a1.addressOf); - free(a2.addressOf); - free(a3.addressOf); - free(a4.addressOf); - free(a5.addressOf); - free(a6.addressOf); - free(a7.addressOf); - free(a8.addressOf); - free(a9.addressOf); + calloc.free(a0.addressOf); + calloc.free(a1.addressOf); + calloc.free(a2.addressOf); + calloc.free(a3.addressOf); + calloc.free(a4.addressOf); + calloc.free(a5.addressOf); + calloc.free(a6.addressOf); + calloc.free(a7.addressOf); + calloc.free(a8.addressOf); + calloc.free(a9.addressOf); } final passStruct20BytesHomogeneousFloat = ffiTestFunctions.lookupFunction< @@ -2884,7 +2835,7 @@ final passStruct20BytesHomogeneousFloat = ffiTestFunctions.lookupFunction< /// Argument too big to go into FPU registers in hardfp and arm64. void testPassStruct20BytesHomogeneousFloat() { Struct20BytesHomogeneousFloat a0 = - allocate().ref; + calloc().ref; a0.a0 = -1.0; a0.a1 = 2.0; @@ -2898,7 +2849,7 @@ void testPassStruct20BytesHomogeneousFloat() { Expect.approxEquals(-3.0, result); - free(a0.addressOf); + calloc.free(a0.addressOf); } final passStruct32BytesHomogeneousDoublex5 = ffiTestFunctions.lookupFunction< @@ -2920,15 +2871,15 @@ final passStruct32BytesHomogeneousDoublex5 = ffiTestFunctions.lookupFunction< /// 5 struct arguments will exhaust available registers. void testPassStruct32BytesHomogeneousDoublex5() { Struct32BytesHomogeneousDouble a0 = - allocate().ref; + calloc().ref; Struct32BytesHomogeneousDouble a1 = - allocate().ref; + calloc().ref; Struct32BytesHomogeneousDouble a2 = - allocate().ref; + calloc().ref; Struct32BytesHomogeneousDouble a3 = - allocate().ref; + calloc().ref; Struct32BytesHomogeneousDouble a4 = - allocate().ref; + calloc().ref; a0.a0 = -1.0; a0.a1 = 2.0; @@ -2957,11 +2908,11 @@ void testPassStruct32BytesHomogeneousDoublex5() { Expect.approxEquals(10.0, result); - free(a0.addressOf); - free(a1.addressOf); - free(a2.addressOf); - free(a3.addressOf); - free(a4.addressOf); + calloc.free(a0.addressOf); + calloc.free(a1.addressOf); + calloc.free(a2.addressOf); + calloc.free(a3.addressOf); + calloc.free(a4.addressOf); } final passStruct40BytesHomogeneousDouble = ffiTestFunctions.lookupFunction< @@ -2972,7 +2923,7 @@ final passStruct40BytesHomogeneousDouble = ffiTestFunctions.lookupFunction< /// Argument too big to go into FPU registers in arm64. void testPassStruct40BytesHomogeneousDouble() { Struct40BytesHomogeneousDouble a0 = - allocate().ref; + calloc().ref; a0.a0 = -1.0; a0.a1 = 2.0; @@ -2986,7 +2937,7 @@ void testPassStruct40BytesHomogeneousDouble() { Expect.approxEquals(-3.0, result); - free(a0.addressOf); + calloc.free(a0.addressOf); } final passStruct1024BytesHomogeneousUint64 = ffiTestFunctions.lookupFunction< @@ -2997,7 +2948,7 @@ final passStruct1024BytesHomogeneousUint64 = ffiTestFunctions.lookupFunction< /// Test 1kb struct. void testPassStruct1024BytesHomogeneousUint64() { Struct1024BytesHomogeneousUint64 a0 = - allocate().ref; + calloc().ref; a0.a0 = 1; a0.a1 = 2; @@ -3134,7 +3085,7 @@ void testPassStruct1024BytesHomogeneousUint64() { Expect.equals(8256, result); - free(a0.addressOf); + calloc.free(a0.addressOf); } final passFloatStruct16BytesHomogeneousFloatFloatStruct1 = @@ -3164,16 +3115,16 @@ final passFloatStruct16BytesHomogeneousFloatFloatStruct1 = void testPassFloatStruct16BytesHomogeneousFloatFloatStruct1() { double a0; Struct16BytesHomogeneousFloat a1 = - allocate().ref; + calloc().ref; double a2; Struct16BytesHomogeneousFloat a3 = - allocate().ref; + calloc().ref; double a4; Struct16BytesHomogeneousFloat a5 = - allocate().ref; + calloc().ref; double a6; Struct16BytesHomogeneousFloat a7 = - allocate().ref; + calloc().ref; double a8; a0 = -1.0; @@ -3205,10 +3156,10 @@ void testPassFloatStruct16BytesHomogeneousFloatFloatStruct1() { Expect.approxEquals(-11.0, result); - free(a1.addressOf); - free(a3.addressOf); - free(a5.addressOf); - free(a7.addressOf); + calloc.free(a1.addressOf); + calloc.free(a3.addressOf); + calloc.free(a5.addressOf); + calloc.free(a7.addressOf); } final passFloatStruct32BytesHomogeneousDoubleFloatStruct = @@ -3238,16 +3189,16 @@ final passFloatStruct32BytesHomogeneousDoubleFloatStruct = void testPassFloatStruct32BytesHomogeneousDoubleFloatStruct() { double a0; Struct32BytesHomogeneousDouble a1 = - allocate().ref; + calloc().ref; double a2; Struct32BytesHomogeneousDouble a3 = - allocate().ref; + calloc().ref; double a4; Struct32BytesHomogeneousDouble a5 = - allocate().ref; + calloc().ref; double a6; Struct32BytesHomogeneousDouble a7 = - allocate().ref; + calloc().ref; double a8; a0 = -1.0; @@ -3279,10 +3230,10 @@ void testPassFloatStruct32BytesHomogeneousDoubleFloatStruct() { Expect.approxEquals(-11.0, result); - free(a1.addressOf); - free(a3.addressOf); - free(a5.addressOf); - free(a7.addressOf); + calloc.free(a1.addressOf); + calloc.free(a3.addressOf); + calloc.free(a5.addressOf); + calloc.free(a7.addressOf); } final passInt8Struct16BytesMixedInt8Struct16BytesMixedIn = @@ -3307,13 +3258,13 @@ final passInt8Struct16BytesMixedInt8Struct16BytesMixedIn = /// Test backfilling of integer registers. void testPassInt8Struct16BytesMixedInt8Struct16BytesMixedIn() { int a0; - Struct16BytesMixed a1 = allocate().ref; + Struct16BytesMixed a1 = calloc().ref; int a2; - Struct16BytesMixed a3 = allocate().ref; + Struct16BytesMixed a3 = calloc().ref; int a4; - Struct16BytesMixed a5 = allocate().ref; + Struct16BytesMixed a5 = calloc().ref; int a6; - Struct16BytesMixed a7 = allocate().ref; + Struct16BytesMixed a7 = calloc().ref; int a8; a0 = -1; @@ -3337,10 +3288,10 @@ void testPassInt8Struct16BytesMixedInt8Struct16BytesMixedIn() { Expect.approxEquals(-7.0, result); - free(a1.addressOf); - free(a3.addressOf); - free(a5.addressOf); - free(a7.addressOf); + calloc.free(a1.addressOf); + calloc.free(a3.addressOf); + calloc.free(a5.addressOf); + calloc.free(a7.addressOf); } final passDoublex6Struct16BytesMixedx4Int32 = ffiTestFunctions.lookupFunction< @@ -3379,10 +3330,10 @@ void testPassDoublex6Struct16BytesMixedx4Int32() { double a3; double a4; double a5; - Struct16BytesMixed a6 = allocate().ref; - Struct16BytesMixed a7 = allocate().ref; - Struct16BytesMixed a8 = allocate().ref; - Struct16BytesMixed a9 = allocate().ref; + Struct16BytesMixed a6 = calloc().ref; + Struct16BytesMixed a7 = calloc().ref; + Struct16BytesMixed a8 = calloc().ref; + Struct16BytesMixed a9 = calloc().ref; int a10; a0 = -1.0; @@ -3408,10 +3359,10 @@ void testPassDoublex6Struct16BytesMixedx4Int32() { Expect.approxEquals(-8.0, result); - free(a6.addressOf); - free(a7.addressOf); - free(a8.addressOf); - free(a9.addressOf); + calloc.free(a6.addressOf); + calloc.free(a7.addressOf); + calloc.free(a8.addressOf); + calloc.free(a9.addressOf); } final passInt32x4Struct16BytesMixedx4Double = ffiTestFunctions.lookupFunction< @@ -3436,10 +3387,10 @@ void testPassInt32x4Struct16BytesMixedx4Double() { int a1; int a2; int a3; - Struct16BytesMixed a4 = allocate().ref; - Struct16BytesMixed a5 = allocate().ref; - Struct16BytesMixed a6 = allocate().ref; - Struct16BytesMixed a7 = allocate().ref; + Struct16BytesMixed a4 = calloc().ref; + Struct16BytesMixed a5 = calloc().ref; + Struct16BytesMixed a6 = calloc().ref; + Struct16BytesMixed a7 = calloc().ref; double a8; a0 = -1; @@ -3463,10 +3414,10 @@ void testPassInt32x4Struct16BytesMixedx4Double() { Expect.approxEquals(-7.0, result); - free(a4.addressOf); - free(a5.addressOf); - free(a6.addressOf); - free(a7.addressOf); + calloc.free(a4.addressOf); + calloc.free(a5.addressOf); + calloc.free(a6.addressOf); + calloc.free(a7.addressOf); } final passStruct40BytesHomogeneousDoubleStruct4BytesHomo = @@ -3481,11 +3432,9 @@ final passStruct40BytesHomogeneousDoubleStruct4BytesHomo = /// Check that the other two arguments are allocated on registers. void testPassStruct40BytesHomogeneousDoubleStruct4BytesHomo() { Struct40BytesHomogeneousDouble a0 = - allocate().ref; - Struct4BytesHomogeneousInt16 a1 = - allocate().ref; - Struct8BytesHomogeneousFloat a2 = - allocate().ref; + calloc().ref; + Struct4BytesHomogeneousInt16 a1 = calloc().ref; + Struct8BytesHomogeneousFloat a2 = calloc().ref; a0.a0 = -1.0; a0.a1 = 2.0; @@ -3503,9 +3452,9 @@ void testPassStruct40BytesHomogeneousDoubleStruct4BytesHomo() { Expect.approxEquals(-5.0, result); - free(a0.addressOf); - free(a1.addressOf); - free(a2.addressOf); + calloc.free(a0.addressOf); + calloc.free(a1.addressOf); + calloc.free(a2.addressOf); } final passInt32x8Doublex8Int64Int8Struct1ByteIntInt64Int = @@ -3613,30 +3562,28 @@ void testPassInt32x8Doublex8Int64Int8Struct1ByteIntInt64Int() { double a15; int a16; int a17; - Struct1ByteInt a18 = allocate().ref; + Struct1ByteInt a18 = calloc().ref; int a19; int a20; - Struct4BytesHomogeneousInt16 a21 = - allocate().ref; + Struct4BytesHomogeneousInt16 a21 = calloc().ref; int a22; int a23; - Struct8BytesInt a24 = allocate().ref; + Struct8BytesInt a24 = calloc().ref; int a25; int a26; - Struct8BytesHomogeneousFloat a27 = - allocate().ref; + Struct8BytesHomogeneousFloat a27 = calloc().ref; int a28; int a29; - Struct8BytesMixed a30 = allocate().ref; + Struct8BytesMixed a30 = calloc().ref; int a31; int a32; - StructAlignmentInt16 a33 = allocate().ref; + StructAlignmentInt16 a33 = calloc().ref; int a34; int a35; - StructAlignmentInt32 a36 = allocate().ref; + StructAlignmentInt32 a36 = calloc().ref; int a37; int a38; - StructAlignmentInt64 a39 = allocate().ref; + StructAlignmentInt64 a39 = calloc().ref; a0 = -1; a1 = 2; @@ -3737,14 +3684,14 @@ void testPassInt32x8Doublex8Int64Int8Struct1ByteIntInt64Int() { Expect.approxEquals(26.0, result); - free(a18.addressOf); - free(a21.addressOf); - free(a24.addressOf); - free(a27.addressOf); - free(a30.addressOf); - free(a33.addressOf); - free(a36.addressOf); - free(a39.addressOf); + calloc.free(a18.addressOf); + calloc.free(a21.addressOf); + calloc.free(a24.addressOf); + calloc.free(a27.addressOf); + calloc.free(a30.addressOf); + calloc.free(a33.addressOf); + calloc.free(a36.addressOf); + calloc.free(a39.addressOf); } final passStructAlignmentInt16 = ffiTestFunctions.lookupFunction< @@ -3753,7 +3700,7 @@ final passStructAlignmentInt16 = ffiTestFunctions.lookupFunction< /// Test alignment and padding of 16 byte int within struct. void testPassStructAlignmentInt16() { - StructAlignmentInt16 a0 = allocate().ref; + StructAlignmentInt16 a0 = calloc().ref; a0.a0 = -1; a0.a1 = 2; @@ -3765,7 +3712,7 @@ void testPassStructAlignmentInt16() { Expect.equals(-2, result); - free(a0.addressOf); + calloc.free(a0.addressOf); } final passStructAlignmentInt32 = ffiTestFunctions.lookupFunction< @@ -3774,7 +3721,7 @@ final passStructAlignmentInt32 = ffiTestFunctions.lookupFunction< /// Test alignment and padding of 32 byte int within struct. void testPassStructAlignmentInt32() { - StructAlignmentInt32 a0 = allocate().ref; + StructAlignmentInt32 a0 = calloc().ref; a0.a0 = -1; a0.a1 = 2; @@ -3786,7 +3733,7 @@ void testPassStructAlignmentInt32() { Expect.equals(-2, result); - free(a0.addressOf); + calloc.free(a0.addressOf); } final passStructAlignmentInt64 = ffiTestFunctions.lookupFunction< @@ -3795,7 +3742,7 @@ final passStructAlignmentInt64 = ffiTestFunctions.lookupFunction< /// Test alignment and padding of 64 byte int within struct. void testPassStructAlignmentInt64() { - StructAlignmentInt64 a0 = allocate().ref; + StructAlignmentInt64 a0 = calloc().ref; a0.a0 = -1; a0.a1 = 2; @@ -3807,7 +3754,7 @@ void testPassStructAlignmentInt64() { Expect.equals(-2, result); - free(a0.addressOf); + calloc.free(a0.addressOf); } final passStruct8BytesNestedIntx10 = ffiTestFunctions.lookupFunction< @@ -3837,16 +3784,16 @@ final passStruct8BytesNestedIntx10 = ffiTestFunctions.lookupFunction< /// Simple nested struct. No alignment gaps on any architectures. /// 10 arguments exhaust registers on all platforms. void testPassStruct8BytesNestedIntx10() { - Struct8BytesNestedInt a0 = allocate().ref; - Struct8BytesNestedInt a1 = allocate().ref; - Struct8BytesNestedInt a2 = allocate().ref; - Struct8BytesNestedInt a3 = allocate().ref; - Struct8BytesNestedInt a4 = allocate().ref; - Struct8BytesNestedInt a5 = allocate().ref; - Struct8BytesNestedInt a6 = allocate().ref; - Struct8BytesNestedInt a7 = allocate().ref; - Struct8BytesNestedInt a8 = allocate().ref; - Struct8BytesNestedInt a9 = allocate().ref; + Struct8BytesNestedInt a0 = calloc().ref; + Struct8BytesNestedInt a1 = calloc().ref; + Struct8BytesNestedInt a2 = calloc().ref; + Struct8BytesNestedInt a3 = calloc().ref; + Struct8BytesNestedInt a4 = calloc().ref; + Struct8BytesNestedInt a5 = calloc().ref; + Struct8BytesNestedInt a6 = calloc().ref; + Struct8BytesNestedInt a7 = calloc().ref; + Struct8BytesNestedInt a8 = calloc().ref; + Struct8BytesNestedInt a9 = calloc().ref; a0.a0.a0 = -1; a0.a0.a1 = 2; @@ -3896,16 +3843,16 @@ void testPassStruct8BytesNestedIntx10() { Expect.equals(20, result); - free(a0.addressOf); - free(a1.addressOf); - free(a2.addressOf); - free(a3.addressOf); - free(a4.addressOf); - free(a5.addressOf); - free(a6.addressOf); - free(a7.addressOf); - free(a8.addressOf); - free(a9.addressOf); + calloc.free(a0.addressOf); + calloc.free(a1.addressOf); + calloc.free(a2.addressOf); + calloc.free(a3.addressOf); + calloc.free(a4.addressOf); + calloc.free(a5.addressOf); + calloc.free(a6.addressOf); + calloc.free(a7.addressOf); + calloc.free(a8.addressOf); + calloc.free(a9.addressOf); } final passStruct8BytesNestedFloatx10 = ffiTestFunctions.lookupFunction< @@ -3935,16 +3882,16 @@ final passStruct8BytesNestedFloatx10 = ffiTestFunctions.lookupFunction< /// Simple nested struct. No alignment gaps on any architectures. /// 10 arguments exhaust fpu registers on all platforms. void testPassStruct8BytesNestedFloatx10() { - Struct8BytesNestedFloat a0 = allocate().ref; - Struct8BytesNestedFloat a1 = allocate().ref; - Struct8BytesNestedFloat a2 = allocate().ref; - Struct8BytesNestedFloat a3 = allocate().ref; - Struct8BytesNestedFloat a4 = allocate().ref; - Struct8BytesNestedFloat a5 = allocate().ref; - Struct8BytesNestedFloat a6 = allocate().ref; - Struct8BytesNestedFloat a7 = allocate().ref; - Struct8BytesNestedFloat a8 = allocate().ref; - Struct8BytesNestedFloat a9 = allocate().ref; + Struct8BytesNestedFloat a0 = calloc().ref; + Struct8BytesNestedFloat a1 = calloc().ref; + Struct8BytesNestedFloat a2 = calloc().ref; + Struct8BytesNestedFloat a3 = calloc().ref; + Struct8BytesNestedFloat a4 = calloc().ref; + Struct8BytesNestedFloat a5 = calloc().ref; + Struct8BytesNestedFloat a6 = calloc().ref; + Struct8BytesNestedFloat a7 = calloc().ref; + Struct8BytesNestedFloat a8 = calloc().ref; + Struct8BytesNestedFloat a9 = calloc().ref; a0.a0.a0 = -1.0; a0.a1.a0 = 2.0; @@ -3974,16 +3921,16 @@ void testPassStruct8BytesNestedFloatx10() { Expect.approxEquals(10.0, result); - free(a0.addressOf); - free(a1.addressOf); - free(a2.addressOf); - free(a3.addressOf); - free(a4.addressOf); - free(a5.addressOf); - free(a6.addressOf); - free(a7.addressOf); - free(a8.addressOf); - free(a9.addressOf); + calloc.free(a0.addressOf); + calloc.free(a1.addressOf); + calloc.free(a2.addressOf); + calloc.free(a3.addressOf); + calloc.free(a4.addressOf); + calloc.free(a5.addressOf); + calloc.free(a6.addressOf); + calloc.free(a7.addressOf); + calloc.free(a8.addressOf); + calloc.free(a9.addressOf); } final passStruct8BytesNestedFloat2x10 = ffiTestFunctions.lookupFunction< @@ -4015,16 +3962,16 @@ final passStruct8BytesNestedFloat2x10 = ffiTestFunctions.lookupFunction< /// The nesting is irregular, testing homogenous float rules on arm and arm64, /// and the fpu register usage on x64. void testPassStruct8BytesNestedFloat2x10() { - Struct8BytesNestedFloat2 a0 = allocate().ref; - Struct8BytesNestedFloat2 a1 = allocate().ref; - Struct8BytesNestedFloat2 a2 = allocate().ref; - Struct8BytesNestedFloat2 a3 = allocate().ref; - Struct8BytesNestedFloat2 a4 = allocate().ref; - Struct8BytesNestedFloat2 a5 = allocate().ref; - Struct8BytesNestedFloat2 a6 = allocate().ref; - Struct8BytesNestedFloat2 a7 = allocate().ref; - Struct8BytesNestedFloat2 a8 = allocate().ref; - Struct8BytesNestedFloat2 a9 = allocate().ref; + Struct8BytesNestedFloat2 a0 = calloc().ref; + Struct8BytesNestedFloat2 a1 = calloc().ref; + Struct8BytesNestedFloat2 a2 = calloc().ref; + Struct8BytesNestedFloat2 a3 = calloc().ref; + Struct8BytesNestedFloat2 a4 = calloc().ref; + Struct8BytesNestedFloat2 a5 = calloc().ref; + Struct8BytesNestedFloat2 a6 = calloc().ref; + Struct8BytesNestedFloat2 a7 = calloc().ref; + Struct8BytesNestedFloat2 a8 = calloc().ref; + Struct8BytesNestedFloat2 a9 = calloc().ref; a0.a0.a0 = -1.0; a0.a1 = 2.0; @@ -4054,16 +4001,16 @@ void testPassStruct8BytesNestedFloat2x10() { Expect.approxEquals(10.0, result); - free(a0.addressOf); - free(a1.addressOf); - free(a2.addressOf); - free(a3.addressOf); - free(a4.addressOf); - free(a5.addressOf); - free(a6.addressOf); - free(a7.addressOf); - free(a8.addressOf); - free(a9.addressOf); + calloc.free(a0.addressOf); + calloc.free(a1.addressOf); + calloc.free(a2.addressOf); + calloc.free(a3.addressOf); + calloc.free(a4.addressOf); + calloc.free(a5.addressOf); + calloc.free(a6.addressOf); + calloc.free(a7.addressOf); + calloc.free(a8.addressOf); + calloc.free(a9.addressOf); } final passStruct8BytesNestedMixedx10 = ffiTestFunctions.lookupFunction< @@ -4093,16 +4040,16 @@ final passStruct8BytesNestedMixedx10 = ffiTestFunctions.lookupFunction< /// Simple nested struct. No alignment gaps on any architectures. /// 10 arguments exhaust all registers on all platforms. void testPassStruct8BytesNestedMixedx10() { - Struct8BytesNestedMixed a0 = allocate().ref; - Struct8BytesNestedMixed a1 = allocate().ref; - Struct8BytesNestedMixed a2 = allocate().ref; - Struct8BytesNestedMixed a3 = allocate().ref; - Struct8BytesNestedMixed a4 = allocate().ref; - Struct8BytesNestedMixed a5 = allocate().ref; - Struct8BytesNestedMixed a6 = allocate().ref; - Struct8BytesNestedMixed a7 = allocate().ref; - Struct8BytesNestedMixed a8 = allocate().ref; - Struct8BytesNestedMixed a9 = allocate().ref; + Struct8BytesNestedMixed a0 = calloc().ref; + Struct8BytesNestedMixed a1 = calloc().ref; + Struct8BytesNestedMixed a2 = calloc().ref; + Struct8BytesNestedMixed a3 = calloc().ref; + Struct8BytesNestedMixed a4 = calloc().ref; + Struct8BytesNestedMixed a5 = calloc().ref; + Struct8BytesNestedMixed a6 = calloc().ref; + Struct8BytesNestedMixed a7 = calloc().ref; + Struct8BytesNestedMixed a8 = calloc().ref; + Struct8BytesNestedMixed a9 = calloc().ref; a0.a0.a0 = -1; a0.a0.a1 = 2; @@ -4142,16 +4089,16 @@ void testPassStruct8BytesNestedMixedx10() { Expect.approxEquals(15.0, result); - free(a0.addressOf); - free(a1.addressOf); - free(a2.addressOf); - free(a3.addressOf); - free(a4.addressOf); - free(a5.addressOf); - free(a6.addressOf); - free(a7.addressOf); - free(a8.addressOf); - free(a9.addressOf); + calloc.free(a0.addressOf); + calloc.free(a1.addressOf); + calloc.free(a2.addressOf); + calloc.free(a3.addressOf); + calloc.free(a4.addressOf); + calloc.free(a5.addressOf); + calloc.free(a6.addressOf); + calloc.free(a7.addressOf); + calloc.free(a8.addressOf); + calloc.free(a9.addressOf); } final passStruct16BytesNestedIntx2 = ffiTestFunctions.lookupFunction< @@ -4161,8 +4108,8 @@ final passStruct16BytesNestedIntx2 = ffiTestFunctions.lookupFunction< /// Deeper nested struct to test recursive member access. void testPassStruct16BytesNestedIntx2() { - Struct16BytesNestedInt a0 = allocate().ref; - Struct16BytesNestedInt a1 = allocate().ref; + Struct16BytesNestedInt a0 = calloc().ref; + Struct16BytesNestedInt a1 = calloc().ref; a0.a0.a0.a0 = -1; a0.a0.a0.a1 = 2; @@ -4187,8 +4134,8 @@ void testPassStruct16BytesNestedIntx2() { Expect.equals(8, result); - free(a0.addressOf); - free(a1.addressOf); + calloc.free(a0.addressOf); + calloc.free(a1.addressOf); } final passStruct32BytesNestedIntx2 = ffiTestFunctions.lookupFunction< @@ -4198,8 +4145,8 @@ final passStruct32BytesNestedIntx2 = ffiTestFunctions.lookupFunction< /// Even deeper nested struct to test recursive member access. void testPassStruct32BytesNestedIntx2() { - Struct32BytesNestedInt a0 = allocate().ref; - Struct32BytesNestedInt a1 = allocate().ref; + Struct32BytesNestedInt a0 = calloc().ref; + Struct32BytesNestedInt a1 = calloc().ref; a0.a0.a0.a0.a0 = -1; a0.a0.a0.a0.a1 = 2; @@ -4240,8 +4187,8 @@ void testPassStruct32BytesNestedIntx2() { Expect.equals(16, result); - free(a0.addressOf); - free(a1.addressOf); + calloc.free(a0.addressOf); + calloc.free(a1.addressOf); } final passStructNestedIntStructAlignmentInt16 = ffiTestFunctions.lookupFunction< @@ -4252,7 +4199,7 @@ final passStructNestedIntStructAlignmentInt16 = ffiTestFunctions.lookupFunction< /// Test alignment and padding of nested struct with 16 byte int. void testPassStructNestedIntStructAlignmentInt16() { StructNestedIntStructAlignmentInt16 a0 = - allocate().ref; + calloc().ref; a0.a0.a0 = -1; a0.a0.a1 = 2; @@ -4267,7 +4214,7 @@ void testPassStructNestedIntStructAlignmentInt16() { Expect.equals(3, result); - free(a0.addressOf); + calloc.free(a0.addressOf); } final passStructNestedIntStructAlignmentInt32 = ffiTestFunctions.lookupFunction< @@ -4278,7 +4225,7 @@ final passStructNestedIntStructAlignmentInt32 = ffiTestFunctions.lookupFunction< /// Test alignment and padding of nested struct with 32 byte int. void testPassStructNestedIntStructAlignmentInt32() { StructNestedIntStructAlignmentInt32 a0 = - allocate().ref; + calloc().ref; a0.a0.a0 = -1; a0.a0.a1 = 2; @@ -4293,7 +4240,7 @@ void testPassStructNestedIntStructAlignmentInt32() { Expect.equals(3, result); - free(a0.addressOf); + calloc.free(a0.addressOf); } final passStructNestedIntStructAlignmentInt64 = ffiTestFunctions.lookupFunction< @@ -4304,7 +4251,7 @@ final passStructNestedIntStructAlignmentInt64 = ffiTestFunctions.lookupFunction< /// Test alignment and padding of nested struct with 64 byte int. void testPassStructNestedIntStructAlignmentInt64() { StructNestedIntStructAlignmentInt64 a0 = - allocate().ref; + calloc().ref; a0.a0.a0 = -1; a0.a0.a1 = 2; @@ -4319,7 +4266,7 @@ void testPassStructNestedIntStructAlignmentInt64() { Expect.equals(3, result); - free(a0.addressOf); + calloc.free(a0.addressOf); } final passStructNestedIrregularEvenBiggerx4 = ffiTestFunctions.lookupFunction< @@ -4338,13 +4285,13 @@ final passStructNestedIrregularEvenBiggerx4 = ffiTestFunctions.lookupFunction< /// Return big irregular struct as smoke test. void testPassStructNestedIrregularEvenBiggerx4() { StructNestedIrregularEvenBigger a0 = - allocate().ref; + calloc().ref; StructNestedIrregularEvenBigger a1 = - allocate().ref; + calloc().ref; StructNestedIrregularEvenBigger a2 = - allocate().ref; + calloc().ref; StructNestedIrregularEvenBigger a3 = - allocate().ref; + calloc().ref; a0.a0 = 1; a0.a1.a0.a0 = 2; @@ -4489,10 +4436,10 @@ void testPassStructNestedIrregularEvenBiggerx4() { Expect.approxEquals(1572.0, result); - free(a0.addressOf); - free(a1.addressOf); - free(a2.addressOf); - free(a3.addressOf); + calloc.free(a0.addressOf); + calloc.free(a1.addressOf); + calloc.free(a2.addressOf); + calloc.free(a3.addressOf); } final returnStruct1ByteInt = ffiTestFunctions.lookupFunction< @@ -5922,7 +5869,7 @@ final returnStructArgumentStruct1ByteInt = ffiTestFunctions.lookupFunction< /// Especially for ffi callbacks. /// Struct is passed in int registers in most ABIs. void testReturnStructArgumentStruct1ByteInt() { - Struct1ByteInt a0 = allocate().ref; + Struct1ByteInt a0 = calloc().ref; a0.a0 = -1; @@ -5932,7 +5879,7 @@ void testReturnStructArgumentStruct1ByteInt() { Expect.equals(a0.a0, result.a0); - free(a0.addressOf); + calloc.free(a0.addressOf); } final returnStructArgumentInt32x8Struct1ByteInt = @@ -5954,7 +5901,7 @@ void testReturnStructArgumentInt32x8Struct1ByteInt() { int a5; int a6; int a7; - Struct1ByteInt a8 = allocate().ref; + Struct1ByteInt a8 = calloc().ref; a0 = -1; a1 = 2; @@ -5973,7 +5920,7 @@ void testReturnStructArgumentInt32x8Struct1ByteInt() { Expect.equals(a8.a0, result.a0); - free(a8.addressOf); + calloc.free(a8.addressOf); } final returnStructArgumentStruct8BytesHomogeneousFloat = @@ -5987,8 +5934,7 @@ final returnStructArgumentStruct8BytesHomogeneousFloat = /// Especially for ffi callbacks. /// Struct is passed in float registers in most ABIs. void testReturnStructArgumentStruct8BytesHomogeneousFloat() { - Struct8BytesHomogeneousFloat a0 = - allocate().ref; + Struct8BytesHomogeneousFloat a0 = calloc().ref; a0.a0 = -1.0; a0.a1 = 2.0; @@ -6000,7 +5946,7 @@ void testReturnStructArgumentStruct8BytesHomogeneousFloat() { Expect.approxEquals(a0.a0, result.a0); Expect.approxEquals(a0.a1, result.a1); - free(a0.addressOf); + calloc.free(a0.addressOf); } final returnStructArgumentStruct20BytesHomogeneousInt32 = @@ -6015,7 +5961,7 @@ final returnStructArgumentStruct20BytesHomogeneousInt32 = /// On arm64, both argument and return value are passed in by pointer. void testReturnStructArgumentStruct20BytesHomogeneousInt32() { Struct20BytesHomogeneousInt32 a0 = - allocate().ref; + calloc().ref; a0.a0 = -1; a0.a1 = 2; @@ -6033,7 +5979,7 @@ void testReturnStructArgumentStruct20BytesHomogeneousInt32() { Expect.equals(a0.a3, result.a3); Expect.equals(a0.a4, result.a4); - free(a0.addressOf); + calloc.free(a0.addressOf); } final returnStructArgumentInt32x8Struct20BytesHomogeneou = @@ -6056,7 +6002,7 @@ void testReturnStructArgumentInt32x8Struct20BytesHomogeneou() { int a6; int a7; Struct20BytesHomogeneousInt32 a8 = - allocate().ref; + calloc().ref; a0 = -1; a1 = 2; @@ -6083,7 +6029,7 @@ void testReturnStructArgumentInt32x8Struct20BytesHomogeneou() { Expect.equals(a8.a3, result.a3); Expect.equals(a8.a4, result.a4); - free(a8.addressOf); + calloc.free(a8.addressOf); } final returnStructAlignmentInt16 = ffiTestFunctions.lookupFunction< @@ -6163,10 +6109,8 @@ final returnStruct8BytesNestedInt = ffiTestFunctions.lookupFunction< /// Simple nested struct. void testReturnStruct8BytesNestedInt() { - Struct4BytesHomogeneousInt16 a0 = - allocate().ref; - Struct4BytesHomogeneousInt16 a1 = - allocate().ref; + Struct4BytesHomogeneousInt16 a0 = calloc().ref; + Struct4BytesHomogeneousInt16 a1 = calloc().ref; a0.a0 = -1; a0.a1 = 2; @@ -6182,8 +6126,8 @@ void testReturnStruct8BytesNestedInt() { Expect.equals(a1.a0, result.a1.a0); Expect.equals(a1.a1, result.a1.a1); - free(a0.addressOf); - free(a1.addressOf); + calloc.free(a0.addressOf); + calloc.free(a1.addressOf); } final returnStruct8BytesNestedFloat = ffiTestFunctions.lookupFunction< @@ -6193,8 +6137,8 @@ final returnStruct8BytesNestedFloat = ffiTestFunctions.lookupFunction< /// Simple nested struct with floats. void testReturnStruct8BytesNestedFloat() { - Struct4BytesFloat a0 = allocate().ref; - Struct4BytesFloat a1 = allocate().ref; + Struct4BytesFloat a0 = calloc().ref; + Struct4BytesFloat a1 = calloc().ref; a0.a0 = -1.0; a1.a0 = 2.0; @@ -6206,8 +6150,8 @@ void testReturnStruct8BytesNestedFloat() { Expect.approxEquals(a0.a0, result.a0.a0); Expect.approxEquals(a1.a0, result.a1.a0); - free(a0.addressOf); - free(a1.addressOf); + calloc.free(a0.addressOf); + calloc.free(a1.addressOf); } final returnStruct8BytesNestedFloat2 = ffiTestFunctions.lookupFunction< @@ -6218,7 +6162,7 @@ final returnStruct8BytesNestedFloat2 = ffiTestFunctions.lookupFunction< /// The nesting is irregular, testing homogenous float rules on arm and arm64, /// and the fpu register usage on x64. void testReturnStruct8BytesNestedFloat2() { - Struct4BytesFloat a0 = allocate().ref; + Struct4BytesFloat a0 = calloc().ref; double a1; a0.a0 = -1.0; @@ -6231,7 +6175,7 @@ void testReturnStruct8BytesNestedFloat2() { Expect.approxEquals(a0.a0, result.a0.a0); Expect.approxEquals(a1, result.a1); - free(a0.addressOf); + calloc.free(a0.addressOf); } final returnStruct8BytesNestedMixed = ffiTestFunctions.lookupFunction< @@ -6242,9 +6186,8 @@ final returnStruct8BytesNestedMixed = ffiTestFunctions.lookupFunction< /// Simple nested struct with mixed members. void testReturnStruct8BytesNestedMixed() { - Struct4BytesHomogeneousInt16 a0 = - allocate().ref; - Struct4BytesFloat a1 = allocate().ref; + Struct4BytesHomogeneousInt16 a0 = calloc().ref; + Struct4BytesFloat a1 = calloc().ref; a0.a0 = -1; a0.a1 = 2; @@ -6258,8 +6201,8 @@ void testReturnStruct8BytesNestedMixed() { Expect.equals(a0.a1, result.a0.a1); Expect.approxEquals(a1.a0, result.a1.a0); - free(a0.addressOf); - free(a1.addressOf); + calloc.free(a0.addressOf); + calloc.free(a1.addressOf); } final returnStruct16BytesNestedInt = ffiTestFunctions.lookupFunction< @@ -6270,8 +6213,8 @@ final returnStruct16BytesNestedInt = ffiTestFunctions.lookupFunction< /// Deeper nested struct to test recursive member access. void testReturnStruct16BytesNestedInt() { - Struct8BytesNestedInt a0 = allocate().ref; - Struct8BytesNestedInt a1 = allocate().ref; + Struct8BytesNestedInt a0 = calloc().ref; + Struct8BytesNestedInt a1 = calloc().ref; a0.a0.a0 = -1; a0.a0.a1 = 2; @@ -6295,8 +6238,8 @@ void testReturnStruct16BytesNestedInt() { Expect.equals(a1.a1.a0, result.a1.a1.a0); Expect.equals(a1.a1.a1, result.a1.a1.a1); - free(a0.addressOf); - free(a1.addressOf); + calloc.free(a0.addressOf); + calloc.free(a1.addressOf); } final returnStruct32BytesNestedInt = ffiTestFunctions.lookupFunction< @@ -6307,8 +6250,8 @@ final returnStruct32BytesNestedInt = ffiTestFunctions.lookupFunction< /// Even deeper nested struct to test recursive member access. void testReturnStruct32BytesNestedInt() { - Struct16BytesNestedInt a0 = allocate().ref; - Struct16BytesNestedInt a1 = allocate().ref; + Struct16BytesNestedInt a0 = calloc().ref; + Struct16BytesNestedInt a1 = calloc().ref; a0.a0.a0.a0 = -1; a0.a0.a0.a1 = 2; @@ -6348,8 +6291,8 @@ void testReturnStruct32BytesNestedInt() { Expect.equals(a1.a1.a1.a0, result.a1.a1.a1.a0); Expect.equals(a1.a1.a1.a1, result.a1.a1.a1.a1); - free(a0.addressOf); - free(a1.addressOf); + calloc.free(a0.addressOf); + calloc.free(a1.addressOf); } final returnStructNestedIntStructAlignmentInt16 = @@ -6361,8 +6304,8 @@ final returnStructNestedIntStructAlignmentInt16 = /// Test alignment and padding of nested struct with 16 byte int. void testReturnStructNestedIntStructAlignmentInt16() { - StructAlignmentInt16 a0 = allocate().ref; - StructAlignmentInt16 a1 = allocate().ref; + StructAlignmentInt16 a0 = calloc().ref; + StructAlignmentInt16 a1 = calloc().ref; a0.a0 = -1; a0.a1 = 2; @@ -6382,8 +6325,8 @@ void testReturnStructNestedIntStructAlignmentInt16() { Expect.equals(a1.a1, result.a1.a1); Expect.equals(a1.a2, result.a1.a2); - free(a0.addressOf); - free(a1.addressOf); + calloc.free(a0.addressOf); + calloc.free(a1.addressOf); } final returnStructNestedIntStructAlignmentInt32 = @@ -6395,8 +6338,8 @@ final returnStructNestedIntStructAlignmentInt32 = /// Test alignment and padding of nested struct with 32 byte int. void testReturnStructNestedIntStructAlignmentInt32() { - StructAlignmentInt32 a0 = allocate().ref; - StructAlignmentInt32 a1 = allocate().ref; + StructAlignmentInt32 a0 = calloc().ref; + StructAlignmentInt32 a1 = calloc().ref; a0.a0 = -1; a0.a1 = 2; @@ -6416,8 +6359,8 @@ void testReturnStructNestedIntStructAlignmentInt32() { Expect.equals(a1.a1, result.a1.a1); Expect.equals(a1.a2, result.a1.a2); - free(a0.addressOf); - free(a1.addressOf); + calloc.free(a0.addressOf); + calloc.free(a1.addressOf); } final returnStructNestedIntStructAlignmentInt64 = @@ -6429,8 +6372,8 @@ final returnStructNestedIntStructAlignmentInt64 = /// Test alignment and padding of nested struct with 64 byte int. void testReturnStructNestedIntStructAlignmentInt64() { - StructAlignmentInt64 a0 = allocate().ref; - StructAlignmentInt64 a1 = allocate().ref; + StructAlignmentInt64 a0 = calloc().ref; + StructAlignmentInt64 a1 = calloc().ref; a0.a0 = -1; a0.a1 = 2; @@ -6450,8 +6393,8 @@ void testReturnStructNestedIntStructAlignmentInt64() { Expect.equals(a1.a1, result.a1.a1); Expect.equals(a1.a2, result.a1.a2); - free(a0.addressOf); - free(a1.addressOf); + calloc.free(a0.addressOf); + calloc.free(a1.addressOf); } final returnStructNestedIrregularEvenBigger = ffiTestFunctions.lookupFunction< @@ -6466,8 +6409,8 @@ final returnStructNestedIrregularEvenBigger = ffiTestFunctions.lookupFunction< /// Return big irregular struct as smoke test. void testReturnStructNestedIrregularEvenBigger() { int a0; - StructNestedIrregularBigger a1 = allocate().ref; - StructNestedIrregularBigger a2 = allocate().ref; + StructNestedIrregularBigger a1 = calloc().ref; + StructNestedIrregularBigger a2 = calloc().ref; double a3; a0 = 1; @@ -6544,6 +6487,6 @@ void testReturnStructNestedIrregularEvenBigger() { Expect.approxEquals(a2.a3, result.a2.a3); Expect.approxEquals(a3, result.a3); - free(a1.addressOf); - free(a2.addressOf); + calloc.free(a1.addressOf); + calloc.free(a2.addressOf); } diff --git a/tests/ffi_2/function_structs_test.dart b/tests/ffi_2/function_structs_test.dart index bf9ea5f86b9..6bb3e56b5f6 100644 --- a/tests/ffi_2/function_structs_test.dart +++ b/tests/ffi_2/function_structs_test.dart @@ -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 Function(Pointer); @@ -33,8 +33,10 @@ void testFunctionWithStruct() { ffiTestFunctions.lookup("TransposeCoordinate"); NativeCoordinateOp f1 = p1.asFunction(); - Pointer c1 = Coordinate.allocate(10.0, 20.0, nullptr).addressOf; - Pointer c2 = Coordinate.allocate(42.0, 84.0, c1).addressOf; + Pointer c1 = + Coordinate.allocate(calloc, 10.0, 20.0, nullptr).addressOf; + Pointer 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(count: 3).ref; + Coordinate c1 = calloc(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); @@ -83,7 +85,7 @@ void testFunctionWithVeryLargeStruct() { ffiTestFunctions.lookup("SumVeryLargeStruct"); VeryLargeStructSum f = p1.asFunction(); - VeryLargeStruct vls1 = allocate(count: 2).ref; + VeryLargeStruct vls1 = calloc(2).ref; VeryLargeStruct vls2 = vls1.addressOf[1]; List 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); } diff --git a/tests/ffi_2/function_test.dart b/tests/ffi_2/function_test.dart index bff456e49b1..b547ffe6916 100644 --- a/tests/ffi_2/function_test.dart +++ b/tests/ffi_2/function_test.dart @@ -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 = int Function(int, T); void testNativeFunctionFromCast() { - Pointer p1 = allocate(); + Pointer p1 = calloc(); Pointer> p2 = p1.cast(); p2.asFunction(); p2.asFunction>(); - free(p1); + calloc.free(p1); } typedef NativeQuadOpSigned = Int64 Function(Int8, Int16, Int32, Int64); @@ -394,14 +395,14 @@ Int64PointerUnOp assign1337Index1 = ffiTestFunctions .lookupFunction("Assign1337Index1"); void testNativeFunctionPointer() { - Pointer p2 = allocate(count: 2); + Pointer p2 = calloc(2); p2.value = 42; p2[1] = 1000; Pointer 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 result = nullableInt64ElemAt1(nullptr); Expect.equals(result, nullptr); - Pointer p2 = allocate(count: 2); + Pointer p2 = calloc(2); result = nullableInt64ElemAt1(p2); Expect.notEquals(result, nullptr); - free(p2); + calloc.free(p2); } typedef NativeFloatPointerToBool = Uint8 Function(Pointer); @@ -424,13 +425,13 @@ FloatPointerToBool isRoughly1337 = ffiTestFunctions.lookupFunction< NativeFloatPointerToBool, FloatPointerToBool>("IsRoughly1337"); void testFloatRounding() { - Pointer p2 = allocate(); + Pointer p2 = calloc(); p2.value = 1337.0; int result = isRoughly1337(p2); Expect.equals(1, result); - free(p2); + calloc.free(p2); } typedef NativeFloatToVoid = Void Function(Float); diff --git a/tests/ffi_2/generator/structs_by_value_tests_generator.dart b/tests/ffi_2/generator/structs_by_value_tests_generator.dart index f3f9f02a32b..7bd7c83c363 100644 --- a/tests/ffi_2/generator/structs_by_value_tests_generator.dart +++ b/tests/ffi_2/generator/structs_by_value_tests_generator.dart @@ -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'; diff --git a/tests/ffi_2/null_test.dart b/tests/ffi_2/null_test.dart index 303499c59a2..fb51f947f07 100644 --- a/tests/ffi_2/null_test.dart +++ b/tests/ffi_2/null_test.dart @@ -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 p = allocate(); + Pointer p = calloc(); Expect.throws(() => p.value = i); - free(p); + calloc.free(p); double d = null; - Pointer p2 = allocate(); + Pointer p2 = calloc(); Expect.throws(() => p2.value = d); - free(p2); + calloc.free(p2); Pointer x = null; - Pointer> p3 = allocate(); + Pointer> 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 p = allocate(); + Pointer p = calloc(); Pointer p4 = null; Expect.throws(() => Expect.equals(10, p4.value)); @@ -74,11 +75,11 @@ testNullReceivers() { Pointer p6 = null; Expect.throws(() => Expect.equals(10, p6.ref)); - free(p); + calloc.free(p); } testNullIndices() { - Pointer p = allocate(); + Pointer p = calloc(); Expect.throws(() => Expect.equals(10, p[null])); Expect.throws(() => p[null] = 10); @@ -90,13 +91,13 @@ testNullIndices() { Pointer p6 = p.cast(); Expect.throws(() => Expect.equals(10, p6[null])); - free(p); + calloc.free(p); } testNullArguments() { - Pointer p = allocate(); + Pointer p = calloc(); Expect.throws(() => p.value = null); - free(p); + calloc.free(p); } class Foo extends Struct { diff --git a/tests/ffi_2/regress_37254_test.dart b/tests/ffi_2/regress_37254_test.dart index 6ba796f90b5..e73562d8b02 100644 --- a/tests/ffi_2/regress_37254_test.dart +++ b/tests/ffi_2/regress_37254_test.dart @@ -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> a = allocate>(); - final Pointer b = allocate(); + final Pointer> a = calloc>(); + final Pointer b = calloc(); a.value = b; - free(a); - free(b); + calloc.free(a); + calloc.free(b); } void store2() { - final Pointer> a = allocate>(); + final Pointer> a = calloc>(); final Pointer b = - allocate(); // Reified Pointer at runtime. + calloc(); // Reified Pointer 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> a = allocate>(); - final Pointer b = allocate().cast>(); + final Pointer> a = calloc>(); + final Pointer b = calloc().cast>(); // 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> at runtime. - final Pointer> a = allocate>(); + final Pointer> a = calloc>(); - final Pointer b = allocate(); + final Pointer b = calloc(); a.value = b; - free(a); - free(b); + calloc.free(a); + calloc.free(b); } void store5() { // Reified as Pointer> at runtime. - final Pointer> a = allocate>(); + final Pointer> a = calloc>(); final Pointer b = - allocate(); // Reified as Pointer at runtime. + calloc(); // Reified as Pointer at runtime. a.value = b; - free(a); - free(b); + calloc.free(a); + calloc.free(b); } void store6() { // Reified as Pointer> at runtime. - final Pointer> a = allocate>(); - final Pointer b = allocate().cast>(); + final Pointer> a = calloc>(); + final Pointer b = calloc().cast>(); // 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> a = allocate>(); - final Pointer b = allocate(); + final Pointer> a = calloc>(); + final Pointer b = calloc(); a.value = b; - free(a); - free(b); + calloc.free(a); + calloc.free(b); } void store8() { - final Pointer> a = allocate>(); + final Pointer> a = calloc>(); // Reified as Pointer at runtime. - final Pointer b = allocate(); + final Pointer b = calloc(); a.value = b; - free(a); - free(b); + calloc.free(a); + calloc.free(b); } void store9() { - final Pointer> a = allocate>(); - final Pointer b = allocate().cast>(); + final Pointer> a = calloc>(); + final Pointer b = calloc().cast>(); 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> a = allocate>(); + final Pointer> a = calloc>(); Pointer b = a.value; Expect.type>(b); - free(a); + calloc.free(a); } void load2() { - final Pointer> a = allocate>(); + final Pointer> a = calloc>(); Pointer b = a.value; Expect.type>(b); - free(a); + calloc.free(a); } void load3() { // Reified as Pointer> at runtime. - final Pointer> a = allocate>(); + final Pointer> a = calloc>(); Pointer b = a.value; Expect.type>(b); - free(a); + calloc.free(a); } void load4() { // Reified as Pointer> at runtime. - final Pointer> a = allocate>(); + final Pointer> a = calloc>(); // Return value runtime type is Pointer. Pointer b = a.value; Expect.type>(b); - free(a); + calloc.free(a); } void load5() { - final Pointer> a = allocate>(); + final Pointer> a = calloc>(); // 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 b = a.value; }); - free(a); + calloc.free(a); } void load6() { - final Pointer> a = allocate>(); + final Pointer> a = calloc>(); Pointer b = a.value; Expect.type>(b); - free(a); + calloc.free(a); } void main() { diff --git a/tests/ffi_2/regress_39885_test.dart b/tests/ffi_2/regress_39885_test.dart index 7d960f26671..ef73ca75cfc 100644 --- a/tests/ffi_2/regress_39885_test.dart +++ b/tests/ffi_2/regress_39885_test.dart @@ -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(count: 3); + final data = calloc(3); for (int i = 0; i < 3; ++i) { data.elementAt(i).value = 1; } - free(data); + calloc.free(data); } diff --git a/tests/ffi_2/regress_43693_test.dart b/tests/ffi_2/regress_43693_test.dart index a30a11830ae..b589b0c5aed 100644 --- a/tests/ffi_2/regress_43693_test.dart +++ b/tests/ffi_2/regress_43693_test.dart @@ -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) readMyStructSomeValue = final ffiTestFunctions = dlopenPlatformSpecific("ffi_test_functions"); void main() { - final myStructs = allocate(); + final myStructs = calloc(); myStructs[0].somePtr = nullptr; myStructs[0].someValue = 0xAAAAAAAABBBBBBBB; final result = readMyStructSomeValue(myStructs); Expect.equals(0xAAAAAAAABBBBBBBB, result); - free(myStructs); + calloc.free(myStructs); } diff --git a/tests/ffi_2/structs_nested_test.dart b/tests/ffi_2/structs_nested_test.dart index 7083044a213..3a69edbf2c5 100644 --- a/tests/ffi_2/structs_nested_test.dart +++ b/tests/ffi_2/structs_nested_test.dart @@ -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(); + final p = calloc(); Expect.type>(p); print(p); - free(p); + calloc.free(p); } /// Test that reading does not segfault, even uninitialized. void testRead() { print("read"); - final p = allocate(); + final p = calloc(); 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(count: 2); + final p = calloc(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(); + final p = calloc(); 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"); } diff --git a/tests/ffi_2/structs_test.dart b/tests/ffi_2/structs_test.dart index 263d562f870..275905648ec 100644 --- a/tests/ffi_2/structs_test.dart +++ b/tests/ffi_2/structs_test.dart @@ -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 c1 = Coordinate.allocate(10.0, 10.0, nullptr).addressOf; - Pointer c2 = Coordinate.allocate(20.0, 20.0, c1).addressOf; - Pointer c3 = Coordinate.allocate(30.0, 30.0, c2).addressOf; + Pointer c1 = + Coordinate.allocate(calloc, 10.0, 10.0, nullptr).addressOf; + Pointer c2 = + Coordinate.allocate(calloc, 20.0, 20.0, c1).addressOf; + Pointer 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 c1 = allocate(count: 3); + Pointer c1 = calloc(3); Pointer c2 = c1.elementAt(1); Pointer 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.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() * 2 + sizeOf(); bare.Coordinate c1 = - allocate(count: structSize * 3).cast().ref; + calloc(structSize * 3).cast().ref; bare.Coordinate c2 = c1.addressOf.offsetBy(structSize).cast().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); - free(c.addressOf); + calloc.free(c.addressOf); } void testUtf8() { final String test = 'Hasta MaƱana'; final Pointer medium = Utf8.toUtf8(test); Expect.equals(test, Utf8.fromUtf8(medium)); - free(medium); + calloc.free(medium); } diff --git a/tests/ffi_2/variance_function_test.dart b/tests/ffi_2/variance_function_test.dart index d6e63787f59..f53cdfcbf36 100644 --- a/tests/ffi_2/variance_function_test.dart +++ b/tests/ffi_2/variance_function_test.dart @@ -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); typedef Int64PointerParamOp = Void Function(Pointer); typedef NaTyPointerParamOpDart = void Function(Pointer); @@ -38,19 +39,19 @@ void paramInvariant1() { final fp = ffiTestFunctions.lookup>(paramOpName); final f = fp.asFunction(); - final arg = allocate(); + final arg = calloc(); f(arg); - free(arg); + calloc.free(arg); } void paramInvariant2() { final fp = ffiTestFunctions.lookup>(paramOpName); final f = fp.asFunction(); - final arg = allocate().cast(); + final arg = calloc().cast(); Expect.type>(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>(paramOpName); final f = fp.asFunction(); - final arg = allocate(); + final arg = calloc(); Expect.type>(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>(paramOpName); final f = fp.asFunction(); - final Pointer arg = allocate(); + final Pointer arg = calloc(); Expect.type>(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 invariant callbackParamInvariant2(); // Pointer invariant @@ -229,7 +230,7 @@ void fromFunctionTests() { callbackReturnInvariant1(); // Pointer invariant callbackReturnInvariant2(); // Pointer invariant } - free(data); + calloc.free(data); } void main() { diff --git a/tests/ffi_2/vmspecific_enable_ffi_test.dart b/tests/ffi_2/vmspecific_enable_ffi_test.dart index f44753d7315..ce906071f16 100644 --- a/tests/ffi_2/vmspecific_enable_ffi_test.dart +++ b/tests/ffi_2/vmspecific_enable_ffi_test.dart @@ -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 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 } diff --git a/tests/ffi_2/vmspecific_static_checks_test.dart b/tests/ffi_2/vmspecific_static_checks_test.dart index 46321192c78..f1db86ea5f1 100644 --- a/tests/ffi_2/vmspecific_static_checks_test.dart +++ b/tests/ffi_2/vmspecific_static_checks_test.dart @@ -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 p = allocate(); + Pointer p = calloc(); p.value = 123; Pointer loseType = p; generic(loseType); - free(p); + calloc.free(p); } void testGetGeneric2() { T generic() { - Pointer p = allocate(); + Pointer 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 p1 = allocate(); + Pointer p1 = calloc(); Pointer 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> p = allocate(); + Pointer> p = calloc(); Pointer typedNull = nullptr; p.value = typedNull; // this fails to compile due to type mismatch Pointer 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 p = allocate(); + Pointer p = calloc(); p.value = 123; Pointer loseType = p; generic(loseType); - free(p); + calloc.free(p); } void testSetGeneric2() { void generic(T arg) { - Pointer p = allocate(); + Pointer p = calloc(); p.value = arg; //# 27: compile-time error - free(p); + calloc.free(p); } generic(123); } void testSetVoid() { - Pointer p1 = allocate(); + Pointer p1 = calloc(); Pointer 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 pHelper = allocate(); + Pointer pHelper = calloc(); pHelper.value = 123; - Pointer> p = allocate(); + Pointer> 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 generic() { Pointer 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 }