Skip to content

Commit 8ee8f88

Browse files
dcharkescommit-bot@chromium.org
authored andcommitted
[vm/ffi] Migrate dart:ffi to nnbd
Everything in FFI is nonnullable, because C does not accept null values or return null values (nullptr == 0, not null). The only thing that needed migration in the FFI api is operator == (dynamic other) --> operator == (Object other). This CL does not migrate any tests as the VM cannot run any tests yet. Fixes: #39144 Change-Id: I5efc772b61228bd1bd4d95be1b7bcd969f0c9ac8 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/131380 Commit-Queue: Daco Harkes <[email protected]> Reviewed-by: Leaf Petersen <[email protected]>
1 parent ca565d9 commit 8ee8f88

File tree

8 files changed

+18
-25
lines changed

8 files changed

+18
-25
lines changed

sdk_nnbd/lib/_internal/vm/lib/ffi_dynamic_library_patch.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,10 @@ class DynamicLibrary {
4444
int getHandle() native "Ffi_dl_getHandle";
4545

4646
@patch
47-
bool operator ==(other) {
48-
if (other == null) return false;
49-
return getHandle() == other.getHandle();
47+
bool operator ==(Object other) {
48+
if (other is! DynamicLibrary) return false;
49+
DynamicLibrary otherLib = other;
50+
return getHandle() == otherLib.getHandle();
5051
}
5152

5253
@patch

sdk_nnbd/lib/ffi/annotations.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
// @dart = 2.5
6-
75
part of dart.ffi;
86

97
class DartRepresentationOf {

sdk_nnbd/lib/ffi/dynamic_library.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
// @dart = 2.5
6-
75
part of dart.ffi;
86

97
/// Represents a dynamically loaded C library.
@@ -35,7 +33,7 @@ class DynamicLibrary {
3533
String symbolName);
3634

3735
/// Dynamic libraries are equal if they load the same library.
38-
external bool operator ==(other);
36+
external bool operator ==(Object other);
3937

4038
/// The hash code for a DynamicLibrary only depends on the loaded library
4139
external int get hashCode;

sdk_nnbd/lib/ffi/ffi.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file
44

5-
// @dart = 2.5
6-
75
/**
86
* Foreign Function Interface for interoperability with the C programming language.
97
*
@@ -15,6 +13,7 @@
1513
*/
1614
library dart.ffi;
1715

16+
import 'dart:isolate';
1817
import 'dart:typed_data';
1918

2019
part "native_type.dart";
@@ -75,9 +74,10 @@ class Pointer<T extends NativeType> extends NativeType {
7574
external R asFunction<@DartRepresentationOf("T") R extends Function>();
7675

7776
/// Equality for Pointers only depends on their address.
78-
bool operator ==(other) {
79-
if (other == null) return false;
80-
return address == other.address;
77+
bool operator ==(Object other) {
78+
if (other is! Pointer) return false;
79+
Pointer otherPointer = other;
80+
return address == otherPointer.address;
8181
}
8282

8383
/// The hash code for a Pointer only depends on its address.

sdk_nnbd/lib/ffi/native_type.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
// @dart = 2.5
6-
75
part of dart.ffi;
86

97
/// [NativeType]'s subtypes represent a native type in C.

sdk_nnbd/lib/ffi/struct.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
// @dart = 2.5
6-
75
part of dart.ffi;
86

97
/// This class is extended to define structs.

sdk_nnbd/lib/libraries.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,11 @@
8383
]
8484
},
8585
"ffi": {
86-
"uri": "../../sdk/lib/ffi/ffi.dart",
86+
"uri": "ffi/ffi.dart",
8787
"patches": [
88-
"../../sdk/lib/_internal/vm/lib/ffi_patch.dart",
89-
"../../sdk/lib/_internal/vm/lib/ffi_dynamic_library_patch.dart",
90-
"../../sdk/lib/_internal/vm/lib/ffi_native_type_patch.dart"
88+
"_internal/vm/lib/ffi_patch.dart",
89+
"_internal/vm/lib/ffi_dynamic_library_patch.dart",
90+
"_internal/vm/lib/ffi_native_type_patch.dart"
9191
]
9292
},
9393
"wasm": {

sdk_nnbd/lib/libraries.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,11 @@ vm:
8888
- "../../sdk/lib/_internal/vm/lib/timeline.dart"
8989

9090
ffi:
91-
uri: "../../sdk/lib/ffi/ffi.dart"
91+
uri: "ffi/ffi.dart"
9292
patches:
93-
- "../../sdk/lib/_internal/vm/lib/ffi_patch.dart"
94-
- "../../sdk/lib/_internal/vm/lib/ffi_dynamic_library_patch.dart"
95-
- "../../sdk/lib/_internal/vm/lib/ffi_native_type_patch.dart"
93+
- "_internal/vm/lib/ffi_patch.dart"
94+
- "_internal/vm/lib/ffi_dynamic_library_patch.dart"
95+
- "_internal/vm/lib/ffi_native_type_patch.dart"
9696

9797
wasm:
9898
uri: "wasm/wasm.dart"

0 commit comments

Comments
 (0)