From c7306aaf41ae712a97b5eccb2edbdac2692b65bf Mon Sep 17 00:00:00 2001 From: Daco Harkes Date: Thu, 14 Jan 2021 12:28:23 +0000 Subject: [PATCH] [vm/ffi] Migrate runtime/tests/vm to `CallocAllocator` This CL does not yet roll `package:ffi` to use `Allocator`, because that breaks the checked in Dart in Flutter in g3. Instead, this uses the copy of `_CallocAllocator` from `package:ffi` in `calloc.dart` in tests/ffi. New API landed in: https://dart-review.googlesource.com/c/sdk/+/177705 Issue: https://github.com/dart-lang/sdk/issues/44621 Issue: https://github.com/dart-lang/sdk/issues/38721 Change-Id: Iedfc4a11d4606915a324c824372bca643016f5a3 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/178994 Commit-Queue: Daco Harkes Reviewed-by: Aske Simon Christensen --- .../dart_api_create_lightweight_isolate_test.dart | 9 +++++---- runtime/tests/vm/dart/regress_41971_test.dart | 6 ++++-- runtime/tests/vm/dart/thread_priority_macos_test.dart | 10 ++++++---- .../dart_api_create_lightweight_isolate_test.dart | 9 +++++---- runtime/tests/vm/dart_2/regress_41971_test.dart | 6 ++++-- .../tests/vm/dart_2/thread_priority_macos_test.dart | 10 ++++++---- 6 files changed, 30 insertions(+), 20 deletions(-) diff --git a/runtime/tests/vm/dart/isolates/dart_api_create_lightweight_isolate_test.dart b/runtime/tests/vm/dart/isolates/dart_api_create_lightweight_isolate_test.dart index f2e8a709bece..25e0199eb00e 100644 --- a/runtime/tests/vm/dart/isolates/dart_api_create_lightweight_isolate_test.dart +++ b/runtime/tests/vm/dart/isolates/dart_api_create_lightweight_isolate_test.dart @@ -14,6 +14,7 @@ import 'dart:isolate'; import 'package:expect/expect.dart'; import 'package:ffi/ffi.dart'; +import '../../../../../tests/ffi/calloc.dart'; import '../../../../../tests/ffi/dylib_utils.dart'; final bool isAOT = Platform.executable.contains('dart_precompiled_runtime'); @@ -62,7 +63,7 @@ abstract class FfiBindings { Expect.isTrue(isolate.address != 0); return isolate; } finally { - free(cname); + calloc.free(cname); } } @@ -86,8 +87,8 @@ abstract class FfiBindings { onError != null ? onError.nativePort : 0, onExit != null ? onExit.nativePort : 0); - free(libraryUri); - free(functionName); + calloc.free(libraryUri); + calloc.free(functionName); } } @@ -120,7 +121,7 @@ Future withPeerPointer(fun(Pointer peer)) async { // wait a little here to ensure the write of the callback has arrived. await Future.delayed(const Duration(milliseconds: 100)); Expect.equals('xbz', Utf8.fromUtf8(peer.cast())); - free(peer); + calloc.free(peer); } } diff --git a/runtime/tests/vm/dart/regress_41971_test.dart b/runtime/tests/vm/dart/regress_41971_test.dart index 28f63ad1d5e9..7979d0d1e592 100644 --- a/runtime/tests/vm/dart/regress_41971_test.dart +++ b/runtime/tests/vm/dart/regress_41971_test.dart @@ -11,6 +11,8 @@ import 'dart:ffi'; import 'package:expect/expect.dart'; import 'package:ffi/ffi.dart'; +import '../../../../tests/ffi/calloc.dart'; + class X { int field; X(this.field); @@ -35,8 +37,8 @@ int loadFrom(Pointer p) { } void main() { - final p = allocate(count: 128); + final p = calloc(128); p[0] = 42; Expect.equals(42, loadFrom(p)); - free(p); + calloc.free(p); } diff --git a/runtime/tests/vm/dart/thread_priority_macos_test.dart b/runtime/tests/vm/dart/thread_priority_macos_test.dart index b7c8280362f5..473c1ce267c0 100644 --- a/runtime/tests/vm/dart/thread_priority_macos_test.dart +++ b/runtime/tests/vm/dart/thread_priority_macos_test.dart @@ -10,6 +10,8 @@ import 'dart:io'; import 'package:expect/expect.dart'; import 'package:ffi/ffi.dart'; +import '../../../../tests/ffi/calloc.dart'; + // pthread_t pthread_self() typedef PthreadSelfFT = int Function(); typedef PthreadSelfNFT = IntPtr Function(); @@ -34,11 +36,11 @@ class SchedParam extends Struct { main(args) { if (Platform.isMacOS) { - final policy = allocate(count: 1); - final param = allocate(count: 1); + final policy = calloc(1); + final param = calloc(1); Expect.equals(0, pthreadGetSchedParam(pthreadSelf(), policy, param)); Expect.equals(15, param.ref.schedPriority); - free(policy); - free(param); + calloc.free(policy); + calloc.free(param); } } diff --git a/runtime/tests/vm/dart_2/isolates/dart_api_create_lightweight_isolate_test.dart b/runtime/tests/vm/dart_2/isolates/dart_api_create_lightweight_isolate_test.dart index 0daead0f8fbe..d35474e27f2b 100644 --- a/runtime/tests/vm/dart_2/isolates/dart_api_create_lightweight_isolate_test.dart +++ b/runtime/tests/vm/dart_2/isolates/dart_api_create_lightweight_isolate_test.dart @@ -14,6 +14,7 @@ import 'dart:isolate'; import 'package:expect/expect.dart'; import 'package:ffi/ffi.dart'; +import '../../../../../tests/ffi/calloc.dart'; import '../../../../../tests/ffi/dylib_utils.dart'; final bool isAOT = Platform.executable.contains('dart_precompiled_runtime'); @@ -62,7 +63,7 @@ abstract class FfiBindings { Expect.isTrue(isolate.address != 0); return isolate; } finally { - free(cname); + calloc.free(cname); } } @@ -86,8 +87,8 @@ abstract class FfiBindings { onError != null ? onError.nativePort : 0, onExit != null ? onExit.nativePort : 0); - free(libraryUri); - free(functionName); + calloc.free(libraryUri); + calloc.free(functionName); } } @@ -120,7 +121,7 @@ Future withPeerPointer(fun(Pointer peer)) async { // wait a little here to ensure the write of the callback has arrived. await Future.delayed(const Duration(milliseconds: 100)); Expect.equals('xbz', Utf8.fromUtf8(peer.cast())); - free(peer); + calloc.free(peer); } } diff --git a/runtime/tests/vm/dart_2/regress_41971_test.dart b/runtime/tests/vm/dart_2/regress_41971_test.dart index 28f63ad1d5e9..7979d0d1e592 100644 --- a/runtime/tests/vm/dart_2/regress_41971_test.dart +++ b/runtime/tests/vm/dart_2/regress_41971_test.dart @@ -11,6 +11,8 @@ import 'dart:ffi'; import 'package:expect/expect.dart'; import 'package:ffi/ffi.dart'; +import '../../../../tests/ffi/calloc.dart'; + class X { int field; X(this.field); @@ -35,8 +37,8 @@ int loadFrom(Pointer p) { } void main() { - final p = allocate(count: 128); + final p = calloc(128); p[0] = 42; Expect.equals(42, loadFrom(p)); - free(p); + calloc.free(p); } diff --git a/runtime/tests/vm/dart_2/thread_priority_macos_test.dart b/runtime/tests/vm/dart_2/thread_priority_macos_test.dart index b466eb0f26fa..fdce726a3629 100644 --- a/runtime/tests/vm/dart_2/thread_priority_macos_test.dart +++ b/runtime/tests/vm/dart_2/thread_priority_macos_test.dart @@ -10,6 +10,8 @@ import 'dart:io'; import 'package:expect/expect.dart'; import 'package:ffi/ffi.dart'; +import '../../../../tests/ffi/calloc.dart'; + // pthread_t pthread_self() typedef PthreadSelfFT = int Function(); typedef PthreadSelfNFT = IntPtr Function(); @@ -34,11 +36,11 @@ class SchedParam extends Struct { main(args) { if (Platform.isMacOS) { - final policy = allocate(count: 1); - final param = allocate(count: 1); + final policy = calloc(1); + final param = calloc(1); Expect.equals(0, pthreadGetSchedParam(pthreadSelf(), policy, param)); Expect.equals(15, param.ref.schedPriority); - free(policy); - free(param); + calloc.free(policy); + calloc.free(param); } }