From 35c0ef8410545a44bce142500ecc6fd148dbf44f Mon Sep 17 00:00:00 2001 From: Daco Harkes Date: Thu, 10 Apr 2025 11:14:02 -0700 Subject: [PATCH] [ffi] Remove deprecated `Pointer.elementAt` uses Change-Id: I8ab032442db58f41e474ecfdeace4ff65953c8ca Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/421186 Reviewed-by: Hossein Yousefi --- .../FfiCall/dart/benchmark_generated.dart | 192 +++++++++--------- benchmarks/FfiCall/generate_benchmarks.dart | 5 +- pkg/mmap/lib/src/mmap_impl.dart | 2 +- samples/ffi/sample_ffi_data.dart | 2 +- .../abi_specific_int_incomplete_jit_test.dart | 3 - tests/ffi/abi_specific_int_test.dart | 4 +- tests/ffi/aliasing_test.dart | 14 +- tests/ffi/data_test.dart | 11 +- tests/ffi/extension_methods_test.dart | 10 +- tests/ffi/function_callbacks_test.dart | 4 +- tests/ffi/function_structs_test.dart | 18 +- tests/ffi/function_test.dart | 2 +- tests/ffi/regress_39885_test.dart | 2 +- .../vmspecific_static_checks_test.dart | 28 --- tests/ffi/structs_nnbd_workaround_test.dart | 4 +- tests/ffi/structs_test.dart | 60 ------ tests/ffi/unaligned_test.dart | 2 +- tests/ffi/vmspecific_regress_37511_test.dart | 1 - 18 files changed, 134 insertions(+), 230 deletions(-) diff --git a/benchmarks/FfiCall/dart/benchmark_generated.dart b/benchmarks/FfiCall/dart/benchmark_generated.dart index 814b953eac0..8011e6fc6d6 100644 --- a/benchmarks/FfiCall/dart/benchmark_generated.dart +++ b/benchmarks/FfiCall/dart/benchmark_generated.dart @@ -2830,7 +2830,7 @@ class PointerUint8x02 extends FfiBenchmarkBase { @override void setup() { p1 = calloc(N + 1); - p2 = p1.elementAt(1); + p2 = p1 + 1; } @override @@ -2867,7 +2867,7 @@ class PointerUint8x02Native extends FfiBenchmarkBase { @override void setup() { p1 = calloc(N + 1); - p2 = p1.elementAt(1); + p2 = p1 + 1; } @override @@ -2904,7 +2904,7 @@ class PointerUint8x02NativeLeaf extends FfiBenchmarkBase { @override void setup() { p1 = calloc(N + 1); - p2 = p1.elementAt(1); + p2 = p1 + 1; } @override @@ -2946,9 +2946,9 @@ class PointerUint8x04 extends FfiBenchmarkBase { @override void setup() { p1 = calloc(N + 1); - p2 = p1.elementAt(1); - p3 = p1.elementAt(2); - p4 = p1.elementAt(3); + p2 = p1 + 1; + p3 = p1 + 2; + p4 = p1 + 3; } @override @@ -2989,9 +2989,9 @@ class PointerUint8x04Native extends FfiBenchmarkBase { @override void setup() { p1 = calloc(N + 1); - p2 = p1.elementAt(1); - p3 = p1.elementAt(2); - p4 = p1.elementAt(3); + p2 = p1 + 1; + p3 = p1 + 2; + p4 = p1 + 3; } @override @@ -3032,9 +3032,9 @@ class PointerUint8x04NativeLeaf extends FfiBenchmarkBase { @override void setup() { p1 = calloc(N + 1); - p2 = p1.elementAt(1); - p3 = p1.elementAt(2); - p4 = p1.elementAt(3); + p2 = p1 + 1; + p3 = p1 + 2; + p4 = p1 + 3; } @override @@ -3082,15 +3082,15 @@ class PointerUint8x10 extends FfiBenchmarkBase { @override void setup() { p1 = calloc(N + 1); - p2 = p1.elementAt(1); - p3 = p1.elementAt(2); - p4 = p1.elementAt(3); - p5 = p1.elementAt(4); - p6 = p1.elementAt(5); - p7 = p1.elementAt(6); - p8 = p1.elementAt(7); - p9 = p1.elementAt(8); - p10 = p1.elementAt(9); + p2 = p1 + 1; + p3 = p1 + 2; + p4 = p1 + 3; + p5 = p1 + 4; + p6 = p1 + 5; + p7 = p1 + 6; + p8 = p1 + 7; + p9 = p1 + 8; + p10 = p1 + 9; } @override @@ -3143,15 +3143,15 @@ class PointerUint8x10Native extends FfiBenchmarkBase { @override void setup() { p1 = calloc(N + 1); - p2 = p1.elementAt(1); - p3 = p1.elementAt(2); - p4 = p1.elementAt(3); - p5 = p1.elementAt(4); - p6 = p1.elementAt(5); - p7 = p1.elementAt(6); - p8 = p1.elementAt(7); - p9 = p1.elementAt(8); - p10 = p1.elementAt(9); + p2 = p1 + 1; + p3 = p1 + 2; + p4 = p1 + 3; + p5 = p1 + 4; + p6 = p1 + 5; + p7 = p1 + 6; + p8 = p1 + 7; + p9 = p1 + 8; + p10 = p1 + 9; } @override @@ -3204,15 +3204,15 @@ class PointerUint8x10NativeLeaf extends FfiBenchmarkBase { @override void setup() { p1 = calloc(N + 1); - p2 = p1.elementAt(1); - p3 = p1.elementAt(2); - p4 = p1.elementAt(3); - p5 = p1.elementAt(4); - p6 = p1.elementAt(5); - p7 = p1.elementAt(6); - p8 = p1.elementAt(7); - p9 = p1.elementAt(8); - p10 = p1.elementAt(9); + p2 = p1 + 1; + p3 = p1 + 2; + p4 = p1 + 3; + p5 = p1 + 4; + p6 = p1 + 5; + p7 = p1 + 6; + p8 = p1 + 7; + p9 = p1 + 8; + p10 = p1 + 9; } @override @@ -3270,25 +3270,25 @@ class PointerUint8x20 extends FfiBenchmarkBase { @override void setup() { p1 = calloc(N + 1); - p2 = p1.elementAt(1); - p3 = p1.elementAt(2); - p4 = p1.elementAt(3); - p5 = p1.elementAt(4); - p6 = p1.elementAt(5); - p7 = p1.elementAt(6); - p8 = p1.elementAt(7); - p9 = p1.elementAt(8); - p10 = p1.elementAt(9); - p11 = p1.elementAt(10); - p12 = p1.elementAt(11); - p13 = p1.elementAt(12); - p14 = p1.elementAt(13); - p15 = p1.elementAt(14); - p16 = p1.elementAt(15); - p17 = p1.elementAt(16); - p18 = p1.elementAt(17); - p19 = p1.elementAt(18); - p20 = p1.elementAt(19); + p2 = p1 + 1; + p3 = p1 + 2; + p4 = p1 + 3; + p5 = p1 + 4; + p6 = p1 + 5; + p7 = p1 + 6; + p8 = p1 + 7; + p9 = p1 + 8; + p10 = p1 + 9; + p11 = p1 + 10; + p12 = p1 + 11; + p13 = p1 + 12; + p14 = p1 + 13; + p15 = p1 + 14; + p16 = p1 + 15; + p17 = p1 + 16; + p18 = p1 + 17; + p19 = p1 + 18; + p20 = p1 + 19; } @override @@ -3382,25 +3382,25 @@ class PointerUint8x20Native extends FfiBenchmarkBase { @override void setup() { p1 = calloc(N + 1); - p2 = p1.elementAt(1); - p3 = p1.elementAt(2); - p4 = p1.elementAt(3); - p5 = p1.elementAt(4); - p6 = p1.elementAt(5); - p7 = p1.elementAt(6); - p8 = p1.elementAt(7); - p9 = p1.elementAt(8); - p10 = p1.elementAt(9); - p11 = p1.elementAt(10); - p12 = p1.elementAt(11); - p13 = p1.elementAt(12); - p14 = p1.elementAt(13); - p15 = p1.elementAt(14); - p16 = p1.elementAt(15); - p17 = p1.elementAt(16); - p18 = p1.elementAt(17); - p19 = p1.elementAt(18); - p20 = p1.elementAt(19); + p2 = p1 + 1; + p3 = p1 + 2; + p4 = p1 + 3; + p5 = p1 + 4; + p6 = p1 + 5; + p7 = p1 + 6; + p8 = p1 + 7; + p9 = p1 + 8; + p10 = p1 + 9; + p11 = p1 + 10; + p12 = p1 + 11; + p13 = p1 + 12; + p14 = p1 + 13; + p15 = p1 + 14; + p16 = p1 + 15; + p17 = p1 + 16; + p18 = p1 + 17; + p19 = p1 + 18; + p20 = p1 + 19; } @override @@ -3494,25 +3494,25 @@ class PointerUint8x20NativeLeaf extends FfiBenchmarkBase { @override void setup() { p1 = calloc(N + 1); - p2 = p1.elementAt(1); - p3 = p1.elementAt(2); - p4 = p1.elementAt(3); - p5 = p1.elementAt(4); - p6 = p1.elementAt(5); - p7 = p1.elementAt(6); - p8 = p1.elementAt(7); - p9 = p1.elementAt(8); - p10 = p1.elementAt(9); - p11 = p1.elementAt(10); - p12 = p1.elementAt(11); - p13 = p1.elementAt(12); - p14 = p1.elementAt(13); - p15 = p1.elementAt(14); - p16 = p1.elementAt(15); - p17 = p1.elementAt(16); - p18 = p1.elementAt(17); - p19 = p1.elementAt(18); - p20 = p1.elementAt(19); + p2 = p1 + 1; + p3 = p1 + 2; + p4 = p1 + 3; + p5 = p1 + 4; + p6 = p1 + 5; + p7 = p1 + 6; + p8 = p1 + 7; + p9 = p1 + 8; + p10 = p1 + 9; + p11 = p1 + 10; + p12 = p1 + 11; + p13 = p1 + 12; + p14 = p1 + 13; + p15 = p1 + 14; + p16 = p1 + 15; + p17 = p1 + 16; + p18 = p1 + 17; + p19 = p1 + 18; + p20 = p1 + 19; } @override diff --git a/benchmarks/FfiCall/generate_benchmarks.dart b/benchmarks/FfiCall/generate_benchmarks.dart index 52087a8ca6a..103f15a0437 100644 --- a/benchmarks/FfiCall/generate_benchmarks.dart +++ b/benchmarks/FfiCall/generate_benchmarks.dart @@ -243,10 +243,7 @@ void generateBenchmarkPointer(StringBuffer buffer, List types) { .map((n) => '$type $n = nullptr;') .join('\n'); final String setup = - List.generate( - number - 1, - (i) => 'p${i + 2} = p1.elementAt(${i + 1});', - ).join(); + List.generate(number - 1, (i) => 'p${i + 2} = p1 + ${i + 1};').join(); final String functionType = 'Function$number$dartTypeName'; final String functionNativeType = 'NativeFunction$number$typeName'; final String functionNameC = 'Function$number$typeName'; diff --git a/pkg/mmap/lib/src/mmap_impl.dart b/pkg/mmap/lib/src/mmap_impl.dart index 4081b42487a..721f6f45453 100644 --- a/pkg/mmap/lib/src/mmap_impl.dart +++ b/pkg/mmap/lib/src/mmap_impl.dart @@ -140,7 +140,7 @@ final finalizerAddress = () { throw 'Failed to write executable code to the memory.'; } - return finalizerStub.elementAt(offset).cast(); + return (finalizerStub + offset).cast(); }(); base class PeerData extends Struct { diff --git a/samples/ffi/sample_ffi_data.dart b/samples/ffi/sample_ffi_data.dart index 858d53fb3ac..e57ffc3f0dd 100644 --- a/samples/ffi/sample_ffi_data.dart +++ b/samples/ffi/sample_ffi_data.dart @@ -84,7 +84,7 @@ main() { (p + i).value = i * 3; } for (var i in [0, 1, 2, 3, 4, 5, 6, 7]) { - print('p.elementAt($i) value: ${(p + i).value}'); + print('p + $i value: ${(p + i).value}'); } calloc.free(p); } diff --git a/tests/ffi/abi_specific_int_incomplete_jit_test.dart b/tests/ffi/abi_specific_int_incomplete_jit_test.dart index bb7815bff0a..9689521fa49 100644 --- a/tests/ffi/abi_specific_int_incomplete_jit_test.dart +++ b/tests/ffi/abi_specific_int_incomplete_jit_test.dart @@ -104,9 +104,6 @@ final class IncompleteArrayArrayStruct extends Struct { void testInlineArray2() { final p = calloc(100).cast(); - Expect.throws(() { - p.elementAt(3); - }); Expect.throws(() { (p + 3); }); diff --git a/tests/ffi/abi_specific_int_test.dart b/tests/ffi/abi_specific_int_test.dart index 098cb4cb6ac..d7ccf93c7f2 100644 --- a/tests/ffi/abi_specific_int_test.dart +++ b/tests/ffi/abi_specific_int_test.dart @@ -90,7 +90,7 @@ void testInlineArray2() { int someValue(int a, int b, int c) => a * 1337 + b * 42 + c; final p = calloc(_dim0); for (int i0 = 0; i0 < _dim0; i0++) { - final array = p.elementAt(i0).ref.a0; + final array = (p + i0).ref.a0; for (int i1 = 0; i1 < _dim1; i1++) { final array2 = array[i1]; for (int i2 = 0; i2 < _dim2; i2++) { @@ -99,7 +99,7 @@ void testInlineArray2() { } } for (int i0 = 0; i0 < _dim0; i0++) { - final array = p.elementAt(i0).ref.a0; + final array = (p + i0).ref.a0; for (int i1 = 0; i1 < _dim1; i1++) { final array2 = array[i1]; for (int i2 = 0; i2 < _dim2; i2++) { diff --git a/tests/ffi/aliasing_test.dart b/tests/ffi/aliasing_test.dart index 2325e1e53cc..8ce71f3813f 100644 --- a/tests/ffi/aliasing_test.dart +++ b/tests/ffi/aliasing_test.dart @@ -22,8 +22,8 @@ void main() { testAliasCast2(); testAliasOffsetBy(); testAliasOffsetBy2(); - testAliasElementAt(); - testAliasElementAt2(); + testAliasOperator(); + testAliasOperator2(); testAliasFromAddress(); testAliasFromAddress2(); testAliasFromAddressViaMemory(); @@ -90,9 +90,9 @@ void testAliasOffsetBy2() { calloc.free(source); } -void testAliasElementAt() { +void testAliasOperator() { final source = calloc(2); - final alias = source.elementAt(1).elementAt(-1); + final alias = source + 1 - 1; source.value = 42; final int a = source.value; alias.value = 1984; @@ -101,10 +101,10 @@ void testAliasElementAt() { calloc.free(source); } -void testAliasElementAt2() { +void testAliasOperator2() { final source = calloc(3); - final alias = source.elementAt(2).elementAt(-2); - final alias2 = source.elementAt(1).elementAt(-1); + final alias = source + 2 - 2; + final alias2 = source + 1 - 1; alias.value = 42; final int a = alias.value; alias2.value = 1984; diff --git a/tests/ffi/data_test.dart b/tests/ffi/data_test.dart index 2635cdd922d..2dd2e2a4e15 100644 --- a/tests/ffi/data_test.dart +++ b/tests/ffi/data_test.dart @@ -66,7 +66,7 @@ void testPointerFromPointer() { void testPointerPointerArithmetic() { Pointer p = calloc(2); - Pointer p2 = p.elementAt(1); + Pointer p2 = p + 1; p2.value = 100; Pointer p3 = p.offsetBy(8); Expect.equals(100, p3.value); @@ -82,13 +82,13 @@ void testPointerPointerArithmetic() { void testPointerPointerArithmeticSizes() { Pointer p = calloc(2); - Pointer p2 = p.elementAt(1); + Pointer p2 = p + 1; int addr = p.address; Expect.equals(addr + 8, p2.address); calloc.free(p); Pointer p3 = calloc(2); - Pointer p4 = p3.elementAt(1); + Pointer p4 = p3 + 1; addr = p3.address; Expect.equals(addr + 4, p4.address); calloc.free(p3); @@ -136,8 +136,7 @@ void testCastGeneric() { } Pointer p = calloc(); - // ignore: unused_local_variable - Pointer p2 = generic(p); + generic(p); calloc.free(p); } @@ -434,7 +433,7 @@ void testDynamicInvocation() { p.value; }); Expect.throws(() => p.value = 1); - Expect.throws(() => p.elementAt(5)); + Expect.throws(() => p + 5); Expect.throws(() => p += 5); p.address; p.cast(); diff --git a/tests/ffi/extension_methods_test.dart b/tests/ffi/extension_methods_test.dart index 19c736edbe7..66a09b0f543 100644 --- a/tests/ffi/extension_methods_test.dart +++ b/tests/ffi/extension_methods_test.dart @@ -32,12 +32,12 @@ void testStoreLoad() { Expect.equals(20, p[1]); if (sizeOf() == 4) { // Test round tripping. - Expect.equals(20, p.elementAt(0x100000001).value); + Expect.equals(20, (p + 0x100000001).value); Expect.equals(20, p[0x100000001]); } // Test negative index. - final pUseNegative = p.elementAt(1); + final pUseNegative = p + 1; Expect.equals(10, pUseNegative[-1]); // Test negative index using operators @@ -89,8 +89,8 @@ void testCompoundLoadAndStore() { foos[i] = reference; Expect.isTrue(foos[i].a == 10); - foos.elementAt(i).ref = reference; - Expect.isTrue(foos.elementAt(i).ref.a == 10); + (foos + i).ref = reference; + Expect.isTrue((foos + i).ref.a == 10); } for (var i = 1; i < 9; i++) { @@ -106,7 +106,7 @@ void testCompoundLoadAndStore() { for (var i = 1; i < 9; i++) { bars[i] = bars[0]; - Expect.isTrue(bars.elementAt(i).ref.foo.a == 10); + Expect.isTrue((bars + i).ref.foo.a == 10); Expect.isTrue((bars + i).ref.foo.a == 10); } diff --git a/tests/ffi/function_callbacks_test.dart b/tests/ffi/function_callbacks_test.dart index e8e1dbe0a1f..2770372257f 100644 --- a/tests/ffi/function_callbacks_test.dart +++ b/tests/ffi/function_callbacks_test.dart @@ -185,10 +185,10 @@ double manyArgs( } typedef StoreType = Pointer Function(Pointer); -Pointer store(Pointer ptr) => ptr.elementAt(1)..value = 1337; +Pointer store(Pointer ptr) => (ptr + 1)..value = 1337; typedef NullPointersType = Pointer Function(Pointer); -Pointer nullPointers(Pointer ptr) => ptr.elementAt(1); +Pointer nullPointers(Pointer ptr) => (ptr + 1); typedef ReturnVoid = Void Function(); void returnVoid() {} diff --git a/tests/ffi/function_structs_test.dart b/tests/ffi/function_structs_test.dart index 2ac4ce76fa7..46fd4168105 100644 --- a/tests/ffi/function_structs_test.dart +++ b/tests/ffi/function_structs_test.dart @@ -75,15 +75,15 @@ void testFunctionWithStructArray({bool isLeaf = false}) { Coordinate c3 = coordinateArray[2]; c1.x = 10.0; c1.y = 10.0; - c1.next = coordinateArray.elementAt(2); + c1.next = coordinateArray + 2; c2.x = 20.0; c2.y = 20.0; - c2.next = coordinateArray.elementAt(0); + c2.next = coordinateArray + 0; c3.x = 30.0; c3.y = 30.0; - c3.next = coordinateArray.elementAt(1); + c3.next = coordinateArray + 1; - Coordinate result = f1(coordinateArray.elementAt(0)).ref; + Coordinate result = f1(coordinateArray).ref; Expect.approxEquals(20.0, result.x); Expect.approxEquals(20.0, result.y); @@ -118,18 +118,18 @@ void testFunctionWithVeryLargeStruct({bool isLeaf = false}) { struct.k = 1024; struct.smallLastField = 1; } - vls1.parent = vlsArray.elementAt(1); + vls1.parent = vlsArray + 1; vls1.numChildren = 2; - vls1.children = vlsArray.elementAt(0); - vls2.parent = vlsArray.elementAt(1); + vls1.children = vlsArray; + vls2.parent = vlsArray + 1; vls2.parent = nullptr; vls2.numChildren = 0; vls2.children = nullptr; - int result = f(vlsArray.elementAt(0)); + int result = f(vlsArray); Expect.equals(2051, result); - result = f(vlsArray.elementAt(1)); + result = f(vlsArray + 1); Expect.equals(2048, result); calloc.free(vlsArray); diff --git a/tests/ffi/function_test.dart b/tests/ffi/function_test.dart index 6353ca5dc79..f3998859f2e 100644 --- a/tests/ffi/function_test.dart +++ b/tests/ffi/function_test.dart @@ -536,7 +536,7 @@ void testNativeFunctionPointer() { Pointer result = assign1337Index1(p2); Expect.equals(1337, result.value); Expect.equals(1337, p2[1]); - Expect.equals(p2.elementAt(1).address, result.address); + Expect.equals((p2 + 1).address, result.address); calloc.free(p2); } diff --git a/tests/ffi/regress_39885_test.dart b/tests/ffi/regress_39885_test.dart index 77de64f3ec9..18e664cadd7 100644 --- a/tests/ffi/regress_39885_test.dart +++ b/tests/ffi/regress_39885_test.dart @@ -9,7 +9,7 @@ import "package:ffi/ffi.dart"; main() { final data = calloc(3); for (int i = 0; i < 3; ++i) { - data.elementAt(i).value = 1; + (data + i).value = 1; } calloc.free(data); } diff --git a/tests/ffi/static_checks/vmspecific_static_checks_test.dart b/tests/ffi/static_checks/vmspecific_static_checks_test.dart index 1d01635d748..0d030028c7d 100644 --- a/tests/ffi/static_checks/vmspecific_static_checks_test.dart +++ b/tests/ffi/static_checks/vmspecific_static_checks_test.dart @@ -67,8 +67,6 @@ void main() { testRefStruct(); testSizeOfGeneric(); testSizeOfInvalidType(); - testElementAtGeneric(); - testElementAtNativeType(); testLookupFunctionIsLeafMustBeConst(); testAsFunctionIsLeafMustBeConst(); testLookupFunctionTakesHandle(); @@ -1175,32 +1173,6 @@ void testSizeOfInvalidType() { // [analyzer] COMPILE_TIME_ERROR.NON_CONSTANT_TYPE_ARGUMENT } -void testElementAtGeneric() { - Pointer generic(Pointer pointer) { - Pointer returnValue = pointer; - returnValue = returnValue.elementAt(1); - // ^^^^^^^^^ - // [cfe] The method 'elementAt' isn't defined for the class 'Pointer'. - // [analyzer] COMPILE_TIME_ERROR.UNDEFINED_METHOD - return returnValue; - } - - Pointer p = calloc(); - p.elementAt(1); - generic(p); - calloc.free(p); -} - -void testElementAtNativeType() { - Pointer p = calloc(); - p.elementAt(1); - Pointer p2 = p; - p2.elementAt(1); - // ^^^^^^^^^ - // [cfe] The method 'elementAt' isn't defined for the class 'Pointer'. - // [analyzer] COMPILE_TIME_ERROR.UNDEFINED_METHOD - calloc.free(p); -} final class TestStruct1400 extends Struct { @Array(8) diff --git a/tests/ffi/structs_nnbd_workaround_test.dart b/tests/ffi/structs_nnbd_workaround_test.dart index 240244ad0d2..79c9be191b0 100644 --- a/tests/ffi/structs_nnbd_workaround_test.dart +++ b/tests/ffi/structs_nnbd_workaround_test.dart @@ -58,8 +58,8 @@ void testStructAllocate() { /// allocates coordinates consecutively in c memory void testStructFromAddress() { Pointer c1 = calloc(3); - Pointer c2 = c1.elementAt(1); - Pointer c3 = c1.elementAt(2); + Pointer c2 = c1 + 1; + Pointer c3 = c1 + 2; c1.ref ..x = 10.0 ..y = 10.0 diff --git a/tests/ffi/structs_test.dart b/tests/ffi/structs_test.dart index ab2117f2900..f15f209aa48 100644 --- a/tests/ffi/structs_test.dart +++ b/tests/ffi/structs_test.dart @@ -17,9 +17,7 @@ void main() { for (int i = 0; i < 100; i++) { testStructAllocate(); testStructFromAddress(); - testStructFromAddressWithOperator(); testStructIndexedAccess(); - testStructIndexedAccessWithOperator(); testStructWithNulls(); testUtf8(); testDotDotRef(); @@ -58,37 +56,7 @@ void testStructAllocate() { calloc.free(c3); } -/// Allocates coordinates consecutively in c memory. void testStructFromAddress() { - Pointer c1 = calloc(3); - Pointer c2 = c1.elementAt(1); - Pointer c3 = c1.elementAt(2); - c1.ref - ..x = 10.0 - ..y = 10.0 - ..next = c3; - c2.ref - ..x = 20.0 - ..y = 20.0 - ..next = c1; - c3.ref - ..x = 30.0 - ..y = 30.0 - ..next = c2; - - Coordinate currentCoordinate = c1.ref; - Expect.equals(10.0, currentCoordinate.x); - currentCoordinate = currentCoordinate.next.ref; - Expect.equals(30.0, currentCoordinate.x); - currentCoordinate = currentCoordinate.next.ref; - Expect.equals(20.0, currentCoordinate.x); - currentCoordinate = currentCoordinate.next.ref; - Expect.equals(10.0, currentCoordinate.x); - - calloc.free(c1); -} - -void testStructFromAddressWithOperator() { Pointer c1 = calloc(3); Pointer c2 = c1 + 1; Pointer c3 = c1 + 2; @@ -117,35 +85,7 @@ void testStructFromAddressWithOperator() { calloc.free(c1); } -/// Allocates coordinates consecutively in c memory. void testStructIndexedAccess() { - Pointer cs = calloc(3); - cs[0] - ..x = 10.0 - ..y = 10.0 - ..next = cs.elementAt(2); - cs[1] - ..x = 20.0 - ..y = 20.0 - ..next = cs; - cs[2] - ..x = 30.0 - ..y = 30.0 - ..next = cs.elementAt(1); - - Coordinate currentCoordinate = cs.ref; - Expect.equals(10.0, currentCoordinate.x); - currentCoordinate = currentCoordinate.next.ref; - Expect.equals(30.0, currentCoordinate.x); - currentCoordinate = currentCoordinate.next.ref; - Expect.equals(20.0, currentCoordinate.x); - currentCoordinate = currentCoordinate.next.ref; - Expect.equals(10.0, currentCoordinate.x); - - calloc.free(cs); -} - -void testStructIndexedAccessWithOperator() { Pointer cs = calloc(3); cs[0] ..x = 10.0 diff --git a/tests/ffi/unaligned_test.dart b/tests/ffi/unaligned_test.dart index 537a0fef835..4c21d7319b9 100644 --- a/tests/ffi/unaligned_test.dart +++ b/tests/ffi/unaligned_test.dart @@ -92,7 +92,7 @@ void _freeAll() { Pointer _allocateUnaligned() { final pointer = calloc(16); _pool.add(pointer); - final misaligned = pointer.elementAt(1).cast(); + final misaligned = (pointer + 1).cast(); Expect.equals(1, misaligned.address % 2); return misaligned; } diff --git a/tests/ffi/vmspecific_regress_37511_test.dart b/tests/ffi/vmspecific_regress_37511_test.dart index 75916a1dbe4..2d5dffd25cf 100644 --- a/tests/ffi/vmspecific_regress_37511_test.dart +++ b/tests/ffi/vmspecific_regress_37511_test.dart @@ -32,7 +32,6 @@ final List functionsToTest = [ () => highAddressPointer.cast(), () => Pointer.fromAddress(highAddressPointer.address), () => highAddressPointer.address, - () => highAddressPointer.elementAt(1), () => highAddressPointer + 1, () => highAddressPointer.offsetBy(1), () => highAddressPointer.asTypedList(1),