Skip to content

Commit 8859206

Browse files
sjindel-googlecommit-bot@chromium.org
authored andcommitted
[vm/ffi] Remove Pointer.offsetBy.
Fixes #35883 Change-Id: Idf4b113d655a6cf7063f1ee7732ddd2001247dee Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/121124 Reviewed-by: Martin Kustermann <[email protected]> Reviewed-by: Daco Harkes <[email protected]> Commit-Queue: Samir Jindel <[email protected]>
1 parent cba6c8c commit 8859206

File tree

14 files changed

+20
-39
lines changed

14 files changed

+20
-39
lines changed

pkg/vm/lib/transformations/ffi.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ class FfiTransformer extends Transformer {
229229
castMethod = index.getMember('dart:ffi', 'Pointer', 'cast'),
230230
loadMethod = index.getMember('dart:ffi', 'Pointer', 'load'),
231231
storeMethod = index.getMember('dart:ffi', 'Pointer', 'store'),
232-
offsetByMethod = index.getMember('dart:ffi', 'Pointer', 'offsetBy'),
232+
offsetByMethod = index.getMember('dart:ffi', 'Pointer', '_offsetBy'),
233233
elementAtMethod = index.getMember('dart:ffi', 'Pointer', 'elementAt'),
234234
addressOfField = index.getMember('dart:ffi', 'Struct', 'addressOf'),
235235
structFromPointer =

samples/ffi/sample_ffi_data.dart

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,21 +46,6 @@ main(List<String> arguments) {
4646
print('After free, address is zero: ${p.address}');
4747
}
4848

49-
{
50-
// pointer arithmetic can be done with element offsets or bytes
51-
Pointer<Int64> p1 = allocate<Int64>(count: 2);
52-
print('p1 address: ${p1.address}');
53-
54-
Pointer<Int64> p2 = p1.elementAt(1);
55-
print('p1.elementAt(1) address: ${p2.address}');
56-
p2.value = 100;
57-
58-
Pointer<Int64> p3 = p1.offsetBy(8);
59-
print('p1.offsetBy(8) address: ${p3.address}');
60-
print('p1.offsetBy(8) value: ${p3.value}');
61-
free(p1);
62-
}
63-
6449
{
6550
// allocating too much throws an exception
6651
try {

sdk/lib/_internal/vm/lib/ffi_patch.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ class Pointer<T extends NativeType> {
115115
Pointer.fromAddress(address + sizeOf<T>() * index);
116116

117117
@patch
118-
Pointer<T> offsetBy(int offsetInBytes) =>
118+
Pointer<T> _offsetBy(int offsetInBytes) =>
119119
Pointer.fromAddress(address + offsetInBytes);
120120

121121
@patch

sdk/lib/ffi/ffi.dart

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,6 @@ class Pointer<T extends NativeType> extends NativeType {
9999
/// Pointer arithmetic (takes element size into account).
100100
external Pointer<T> elementAt(int index);
101101

102-
/// Pointer arithmetic (byte offset).
103-
// TODO(dacoharkes): remove this?
104-
// https://github.com/dart-lang/sdk/issues/35883
105-
external Pointer<T> offsetBy(int offsetInBytes);
106-
107102
/// Cast Pointer<T> to a Pointer<V>.
108103
external Pointer<U> cast<U extends NativeType>();
109104

sdk_nnbd/lib/_internal/vm/lib/ffi_patch.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ class Pointer<T extends NativeType> {
117117
Pointer.fromAddress(address + sizeOf<T>() * index);
118118

119119
@patch
120-
Pointer<T> offsetBy(int offsetInBytes) =>
120+
Pointer<T> _offsetBy(int offsetInBytes) =>
121121
Pointer.fromAddress(address + offsetInBytes);
122122

123123
@patch

sdk_nnbd/lib/ffi/ffi.dart

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,6 @@ class Pointer<T extends NativeType> extends NativeType {
100100
/// Pointer arithmetic (takes element size into account).
101101
external Pointer<T> elementAt(int index);
102102

103-
/// Pointer arithmetic (byte offset).
104-
// TODO(dacoharkes): remove this?
105-
// https://github.com/dart-lang/sdk/issues/35883
106-
external Pointer<T> offsetBy(int offsetInBytes);
107-
108103
/// Cast Pointer<T> to a Pointer<V>.
109104
external Pointer<U> cast<U extends NativeType>();
110105

tests/ffi/aliasing_test.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import 'dart:ffi';
1515
import "package:ffi/ffi.dart";
1616
import "package:expect/expect.dart";
1717

18-
import 'dylib_utils.dart';
18+
import 'ffi_test_helpers.dart';
1919

2020
void main() {
2121
for (int i = 0; i < 100; ++i) {
@@ -170,8 +170,6 @@ void testAliasFromAddressViaMemory2() {
170170
typedef NativeQuadOpSigned = Int64 Function(Int8, Int16, Int32, Int64);
171171
typedef QuadOp = int Function(int, int, int, int);
172172

173-
DynamicLibrary ffiTestFunctions = dlopenPlatformSpecific("ffi_test_functions");
174-
175173
QuadOp intComputation = ffiTestFunctions
176174
.lookupFunction<NativeQuadOpSigned, QuadOp>("IntComputation");
177175

tests/ffi/data_test.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import 'dart:ffi';
1111
import "package:expect/expect.dart";
1212
import "package:ffi/ffi.dart";
1313

14+
import 'ffi_test_helpers.dart';
15+
1416
void main() {
1517
testPointerBasic();
1618
testPointerFromPointer();
@@ -114,7 +116,7 @@ void testPointerAllocateZero() {
114116

115117
void testPointerCast() {
116118
Pointer<Int64> p = allocate();
117-
Pointer<Int32> p2 = p.cast(); // gets the correct type args back
119+
p.cast<Int32>(); // gets the correct type args back
118120
free(p);
119121
}
120122

tests/ffi/ffi_test_helpers.dart

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,25 @@
44
//
55
// Helpers for tests which trigger GC in delicate places.
66

7-
import 'dart:ffi' as ffi;
7+
import 'dart:ffi';
88

99
import 'dylib_utils.dart';
1010

11-
typedef NativeNullaryOp = ffi.Void Function();
11+
typedef NativeNullaryOp = Void Function();
1212
typedef NullaryOpVoid = void Function();
1313

14-
typedef NativeUnaryOp = ffi.Void Function(ffi.IntPtr);
14+
typedef NativeUnaryOp = Void Function(IntPtr);
1515
typedef UnaryOpVoid = void Function(int);
1616

17-
final ffi.DynamicLibrary ffiTestFunctions =
17+
final DynamicLibrary ffiTestFunctions =
1818
dlopenPlatformSpecific("ffi_test_functions");
1919

2020
final triggerGc = ffiTestFunctions
2121
.lookupFunction<NativeNullaryOp, NullaryOpVoid>("TriggerGC");
2222

2323
final collectOnNthAllocation = ffiTestFunctions
2424
.lookupFunction<NativeUnaryOp, UnaryOpVoid>("CollectOnNthAllocation");
25+
26+
extension PointerOffsetBy<T extends NativeType> on Pointer<T> {
27+
Pointer<T> offsetBy(int bytes) => Pointer.fromAddress(address + bytes);
28+
}

tests/ffi/function_callbacks_test.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,8 @@ double testExceptionalReturn() {
251251
Pointer.fromFunction<Double Function()>(testExceptionalReturn, "abc"); //# 61: compile-time error
252252
Pointer.fromFunction<Double Function()>(testExceptionalReturn, 0); //# 62: compile-time error
253253
Pointer.fromFunction<Double Function()>(testExceptionalReturn); //# 63: compile-time error
254+
255+
return 0.0; // not used
254256
}
255257

256258
void main() async {

tests/ffi/function_gc_test.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
// SharedObjects=ffi_test_functions
1919

2020
import 'dart:ffi' as ffi;
21-
import 'dylib_utils.dart';
2221
import "package:expect/expect.dart";
2322
import 'ffi_test_helpers.dart';
2423

tests/ffi/highmem_32bit_test.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import 'dart:typed_data';
88

99
import 'package:expect/expect.dart';
1010

11+
import 'ffi_test_helpers.dart';
12+
1113
// void* mmap(void* addr, size_t length,
1214
// int prot, int flags,
1315
// int fd, off_t offset)

tests/ffi/snapshot_test.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
// Checks that the VM throws an appropriate exception when FFI objects are
66
// passed between isolates.
77

8-
import 'dart:async';
98
import 'dart:ffi';
10-
import 'dart:io';
119
import 'dart:isolate';
1210

1311
import 'package:expect/expect.dart';

tests/ffi/structs_test.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import 'dart:ffi';
1313
import "package:expect/expect.dart";
1414
import "package:ffi/ffi.dart";
1515

16+
import 'ffi_test_helpers.dart';
1617
import 'coordinate_bare.dart' as bare;
1718
import 'coordinate.dart';
1819

0 commit comments

Comments
 (0)