diff --git a/DEPS b/DEPS index 87fb10795065..3908cea250cb 100644 --- a/DEPS +++ b/DEPS @@ -102,7 +102,7 @@ vars = { "chromedriver_tag": "83.0.4103.39", "dartdoc_rev" : "9e61a4f11091aaa8998525a2692b14148dc24ab5", - "ffi_rev": "31352979f261f7c6ea88fa0a2cfb0fdd004c38fb", + "ffi_rev": "ad6700de10ca3af16f0c3d9ff8aa15d2bd7cd21c", "fixnum_rev": "16d3890c6dc82ca629659da1934e412292508bba", "file_rev": "0e09370f581ab6388d46fda4cdab66638c0171a1", "glob_rev": "7c0ef8d4fa086f6b185c4dd724b700e7d7ad8f79", @@ -115,7 +115,7 @@ vars = { "http_throttle_tag" : "1.0.2", "icu_rev" : "79326efe26e5440f530963704c3c0ff965b3a4ac", "idl_parser_rev": "5fb1ebf49d235b5a70c9f49047e83b0654031eb7", - "intl_tag": "0.17.0-nullsafety", + "intl_tag": "ade5a936a1de62e7cd04c3ea956c02bd491d7868", "jinja2_rev": "2222b31554f03e62600cd7e383376a7c187967a1", "json_rpc_2_rev": "b8dfe403fd8528fd14399dee3a6527b55802dd4d", "linter_tag": "0.1.128", diff --git a/benchmarks/FfiBoringssl/dart/FfiBoringssl.dart b/benchmarks/FfiBoringssl/dart/FfiBoringssl.dart index 3249be45c400..8781c43542d0 100644 --- a/benchmarks/FfiBoringssl/dart/FfiBoringssl.dart +++ b/benchmarks/FfiBoringssl/dart/FfiBoringssl.dart @@ -11,7 +11,6 @@ import 'dart:typed_data'; import 'package:benchmark_harness/benchmark_harness.dart'; import 'package:ffi/ffi.dart'; -import 'calloc.dart'; import 'digest.dart'; import 'types.dart'; diff --git a/benchmarks/FfiBoringssl/dart/calloc.dart b/benchmarks/FfiBoringssl/dart/calloc.dart deleted file mode 100644 index e17238a91b1b..000000000000 --- a/benchmarks/FfiBoringssl/dart/calloc.dart +++ /dev/null @@ -1,109 +0,0 @@ -// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -// TODO(https://dartbug.com/44621): Remove this copy when package:ffi can be -// rolled. We need to wait until the `Allocator` interface has rolled into -// Flutter. - -import 'dart:ffi'; -import 'dart:io'; - -final DynamicLibrary stdlib = Platform.isWindows - ? DynamicLibrary.open('kernel32.dll') - : DynamicLibrary.process(); - -typedef PosixCallocNative = Pointer Function(IntPtr num, IntPtr size); -typedef PosixCalloc = Pointer Function(int num, int size); -final PosixCalloc posixCalloc = - stdlib.lookupFunction('calloc'); - -typedef PosixFreeNative = Void Function(Pointer); -typedef PosixFree = void Function(Pointer); -final PosixFree posixFree = - stdlib.lookupFunction('free'); - -typedef WinGetProcessHeapFn = Pointer Function(); -final WinGetProcessHeapFn winGetProcessHeap = stdlib - .lookupFunction('GetProcessHeap'); -final Pointer processHeap = winGetProcessHeap(); - -typedef WinHeapAllocNative = Pointer Function(Pointer, Uint32, IntPtr); -typedef WinHeapAlloc = Pointer Function(Pointer, int, int); -final WinHeapAlloc winHeapAlloc = - stdlib.lookupFunction('HeapAlloc'); - -typedef WinHeapFreeNative = Int32 Function( - Pointer heap, Uint32 flags, Pointer memory); -typedef WinHeapFree = int Function(Pointer heap, int flags, Pointer memory); -final WinHeapFree winHeapFree = - stdlib.lookupFunction('HeapFree'); - -const int HEAP_ZERO_MEMORY = 8; - -/// Manages memory on the native heap. -/// -/// Initializes newly allocated memory to zero. -/// -/// For POSIX-based systems, this uses `calloc` and `free`. On Windows, it uses -/// `HeapAlloc` with [HEAP_ZERO_MEMORY] and `HeapFree` against the default -/// public heap. -class _CallocAllocator implements Allocator { - const _CallocAllocator(); - - /// Allocates [byteCount] bytes of zero-initialized of memory on the native - /// heap. - /// - /// 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 - /// satisfied. - // TODO: Stop ignoring alignment if it's large, for example for SSE data. - @override - Pointer allocate(int byteCount, {int? alignment}) { - Pointer result; - if (Platform.isWindows) { - result = winHeapAlloc(processHeap, /*flags=*/ HEAP_ZERO_MEMORY, byteCount) - .cast(); - } else { - result = posixCalloc(byteCount, 1).cast(); - } - if (result.address == 0) { - throw ArgumentError('Could not allocate $byteCount bytes.'); - } - return result; - } - - /// Releases memory allocated on the native heap. - /// - /// For POSIX-based systems, this uses `free`. On Windows, it uses `HeapFree` - /// against the default public heap. It may only be used against pointers - /// allocated in a manner equivalent to [allocate]. - /// - /// Throws an [ArgumentError] if the memory pointed to by [pointer] cannot be - /// freed. - /// - // TODO(dartbug.com/36855): Once we have a ffi.Bool type we can use it instead - // of testing the return integer to be non-zero. - @override - void free(Pointer pointer) { - if (Platform.isWindows) { - if (winHeapFree(processHeap, /*flags=*/ 0, pointer) == 0) { - throw ArgumentError('Could not free $pointer.'); - } - } else { - posixFree(pointer); - } - } -} - -/// Manages memory on the native heap. -/// -/// Initializes newly allocated memory to zero. Use [malloc] for unintialized -/// memory allocation. -/// -/// For POSIX-based systems, this uses `calloc` and `free`. On Windows, it uses -/// `HeapAlloc` with [HEAP_ZERO_MEMORY] and `HeapFree` against the default -/// public heap. -const Allocator calloc = _CallocAllocator(); diff --git a/benchmarks/FfiBoringssl/dart2/FfiBoringssl.dart b/benchmarks/FfiBoringssl/dart2/FfiBoringssl.dart index c749745d7401..635fa574ba6f 100644 --- a/benchmarks/FfiBoringssl/dart2/FfiBoringssl.dart +++ b/benchmarks/FfiBoringssl/dart2/FfiBoringssl.dart @@ -13,7 +13,6 @@ import 'dart:typed_data'; import 'package:benchmark_harness/benchmark_harness.dart'; import 'package:ffi/ffi.dart'; -import 'calloc.dart'; import 'digest.dart'; import 'types.dart'; diff --git a/benchmarks/FfiBoringssl/dart2/calloc.dart b/benchmarks/FfiBoringssl/dart2/calloc.dart deleted file mode 100644 index c6be280de0bc..000000000000 --- a/benchmarks/FfiBoringssl/dart2/calloc.dart +++ /dev/null @@ -1,111 +0,0 @@ -// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -// TODO(https://dartbug.com/44621): Remove this copy when package:ffi can be -// rolled. We need to wait until the `Allocator` interface has rolled into -// Flutter. - -// @dart=2.9 - -import 'dart:ffi'; -import 'dart:io'; - -final DynamicLibrary stdlib = Platform.isWindows - ? DynamicLibrary.open('kernel32.dll') - : DynamicLibrary.process(); - -typedef PosixCallocNative = Pointer Function(IntPtr num, IntPtr size); -typedef PosixCalloc = Pointer Function(int num, int size); -final PosixCalloc posixCalloc = - stdlib.lookupFunction('calloc'); - -typedef PosixFreeNative = Void Function(Pointer); -typedef PosixFree = void Function(Pointer); -final PosixFree posixFree = - stdlib.lookupFunction('free'); - -typedef WinGetProcessHeapFn = Pointer Function(); -final WinGetProcessHeapFn winGetProcessHeap = stdlib - .lookupFunction('GetProcessHeap'); -final Pointer processHeap = winGetProcessHeap(); - -typedef WinHeapAllocNative = Pointer Function(Pointer, Uint32, IntPtr); -typedef WinHeapAlloc = Pointer Function(Pointer, int, int); -final WinHeapAlloc winHeapAlloc = - stdlib.lookupFunction('HeapAlloc'); - -typedef WinHeapFreeNative = Int32 Function( - Pointer heap, Uint32 flags, Pointer memory); -typedef WinHeapFree = int Function(Pointer heap, int flags, Pointer memory); -final WinHeapFree winHeapFree = - stdlib.lookupFunction('HeapFree'); - -const int HEAP_ZERO_MEMORY = 8; - -/// Manages memory on the native heap. -/// -/// Initializes newly allocated memory to zero. -/// -/// For POSIX-based systems, this uses `calloc` and `free`. On Windows, it uses -/// `HeapAlloc` with [HEAP_ZERO_MEMORY] and `HeapFree` against the default -/// public heap. -class _CallocAllocator implements Allocator { - const _CallocAllocator(); - - /// Allocates [byteCount] bytes of zero-initialized of memory on the native - /// heap. - /// - /// 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 - /// satisfied. - // TODO: Stop ignoring alignment if it's large, for example for SSE data. - @override - Pointer allocate(int byteCount, {int alignment}) { - Pointer result; - if (Platform.isWindows) { - result = winHeapAlloc(processHeap, /*flags=*/ HEAP_ZERO_MEMORY, byteCount) - .cast(); - } else { - result = posixCalloc(byteCount, 1).cast(); - } - if (result.address == 0) { - throw ArgumentError('Could not allocate $byteCount bytes.'); - } - return result; - } - - /// Releases memory allocated on the native heap. - /// - /// For POSIX-based systems, this uses `free`. On Windows, it uses `HeapFree` - /// against the default public heap. It may only be used against pointers - /// allocated in a manner equivalent to [allocate]. - /// - /// Throws an [ArgumentError] if the memory pointed to by [pointer] cannot be - /// freed. - /// - // TODO(dartbug.com/36855): Once we have a ffi.Bool type we can use it instead - // of testing the return integer to be non-zero. - @override - void free(Pointer pointer) { - if (Platform.isWindows) { - if (winHeapFree(processHeap, /*flags=*/ 0, pointer) == 0) { - throw ArgumentError('Could not free $pointer.'); - } - } else { - posixFree(pointer); - } - } -} - -/// Manages memory on the native heap. -/// -/// Initializes newly allocated memory to zero. Use [malloc] for unintialized -/// memory allocation. -/// -/// For POSIX-based systems, this uses `calloc` and `free`. On Windows, it uses -/// `HeapAlloc` with [HEAP_ZERO_MEMORY] and `HeapFree` against the default -/// public heap. -const Allocator calloc = _CallocAllocator(); diff --git a/benchmarks/FfiCall/dart/FfiCall.dart b/benchmarks/FfiCall/dart/FfiCall.dart index d33e12093d42..ce48f506aaa8 100644 --- a/benchmarks/FfiCall/dart/FfiCall.dart +++ b/benchmarks/FfiCall/dart/FfiCall.dart @@ -13,7 +13,6 @@ import 'dart:io'; import 'package:ffi/ffi.dart'; import 'package:benchmark_harness/benchmark_harness.dart'; -import 'calloc.dart'; import 'dlopen_helper.dart'; // diff --git a/benchmarks/FfiCall/dart/calloc.dart b/benchmarks/FfiCall/dart/calloc.dart deleted file mode 100644 index e17238a91b1b..000000000000 --- a/benchmarks/FfiCall/dart/calloc.dart +++ /dev/null @@ -1,109 +0,0 @@ -// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -// TODO(https://dartbug.com/44621): Remove this copy when package:ffi can be -// rolled. We need to wait until the `Allocator` interface has rolled into -// Flutter. - -import 'dart:ffi'; -import 'dart:io'; - -final DynamicLibrary stdlib = Platform.isWindows - ? DynamicLibrary.open('kernel32.dll') - : DynamicLibrary.process(); - -typedef PosixCallocNative = Pointer Function(IntPtr num, IntPtr size); -typedef PosixCalloc = Pointer Function(int num, int size); -final PosixCalloc posixCalloc = - stdlib.lookupFunction('calloc'); - -typedef PosixFreeNative = Void Function(Pointer); -typedef PosixFree = void Function(Pointer); -final PosixFree posixFree = - stdlib.lookupFunction('free'); - -typedef WinGetProcessHeapFn = Pointer Function(); -final WinGetProcessHeapFn winGetProcessHeap = stdlib - .lookupFunction('GetProcessHeap'); -final Pointer processHeap = winGetProcessHeap(); - -typedef WinHeapAllocNative = Pointer Function(Pointer, Uint32, IntPtr); -typedef WinHeapAlloc = Pointer Function(Pointer, int, int); -final WinHeapAlloc winHeapAlloc = - stdlib.lookupFunction('HeapAlloc'); - -typedef WinHeapFreeNative = Int32 Function( - Pointer heap, Uint32 flags, Pointer memory); -typedef WinHeapFree = int Function(Pointer heap, int flags, Pointer memory); -final WinHeapFree winHeapFree = - stdlib.lookupFunction('HeapFree'); - -const int HEAP_ZERO_MEMORY = 8; - -/// Manages memory on the native heap. -/// -/// Initializes newly allocated memory to zero. -/// -/// For POSIX-based systems, this uses `calloc` and `free`. On Windows, it uses -/// `HeapAlloc` with [HEAP_ZERO_MEMORY] and `HeapFree` against the default -/// public heap. -class _CallocAllocator implements Allocator { - const _CallocAllocator(); - - /// Allocates [byteCount] bytes of zero-initialized of memory on the native - /// heap. - /// - /// 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 - /// satisfied. - // TODO: Stop ignoring alignment if it's large, for example for SSE data. - @override - Pointer allocate(int byteCount, {int? alignment}) { - Pointer result; - if (Platform.isWindows) { - result = winHeapAlloc(processHeap, /*flags=*/ HEAP_ZERO_MEMORY, byteCount) - .cast(); - } else { - result = posixCalloc(byteCount, 1).cast(); - } - if (result.address == 0) { - throw ArgumentError('Could not allocate $byteCount bytes.'); - } - return result; - } - - /// Releases memory allocated on the native heap. - /// - /// For POSIX-based systems, this uses `free`. On Windows, it uses `HeapFree` - /// against the default public heap. It may only be used against pointers - /// allocated in a manner equivalent to [allocate]. - /// - /// Throws an [ArgumentError] if the memory pointed to by [pointer] cannot be - /// freed. - /// - // TODO(dartbug.com/36855): Once we have a ffi.Bool type we can use it instead - // of testing the return integer to be non-zero. - @override - void free(Pointer pointer) { - if (Platform.isWindows) { - if (winHeapFree(processHeap, /*flags=*/ 0, pointer) == 0) { - throw ArgumentError('Could not free $pointer.'); - } - } else { - posixFree(pointer); - } - } -} - -/// Manages memory on the native heap. -/// -/// Initializes newly allocated memory to zero. Use [malloc] for unintialized -/// memory allocation. -/// -/// For POSIX-based systems, this uses `calloc` and `free`. On Windows, it uses -/// `HeapAlloc` with [HEAP_ZERO_MEMORY] and `HeapFree` against the default -/// public heap. -const Allocator calloc = _CallocAllocator(); diff --git a/benchmarks/FfiCall/dart2/FfiCall.dart b/benchmarks/FfiCall/dart2/FfiCall.dart index 3da29b4a6b34..3e6f29759c7e 100644 --- a/benchmarks/FfiCall/dart2/FfiCall.dart +++ b/benchmarks/FfiCall/dart2/FfiCall.dart @@ -15,7 +15,6 @@ import 'dart:io'; import 'package:ffi/ffi.dart'; import 'package:benchmark_harness/benchmark_harness.dart'; -import 'calloc.dart'; import 'dlopen_helper.dart'; // diff --git a/benchmarks/FfiCall/dart2/calloc.dart b/benchmarks/FfiCall/dart2/calloc.dart deleted file mode 100644 index c6be280de0bc..000000000000 --- a/benchmarks/FfiCall/dart2/calloc.dart +++ /dev/null @@ -1,111 +0,0 @@ -// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -// TODO(https://dartbug.com/44621): Remove this copy when package:ffi can be -// rolled. We need to wait until the `Allocator` interface has rolled into -// Flutter. - -// @dart=2.9 - -import 'dart:ffi'; -import 'dart:io'; - -final DynamicLibrary stdlib = Platform.isWindows - ? DynamicLibrary.open('kernel32.dll') - : DynamicLibrary.process(); - -typedef PosixCallocNative = Pointer Function(IntPtr num, IntPtr size); -typedef PosixCalloc = Pointer Function(int num, int size); -final PosixCalloc posixCalloc = - stdlib.lookupFunction('calloc'); - -typedef PosixFreeNative = Void Function(Pointer); -typedef PosixFree = void Function(Pointer); -final PosixFree posixFree = - stdlib.lookupFunction('free'); - -typedef WinGetProcessHeapFn = Pointer Function(); -final WinGetProcessHeapFn winGetProcessHeap = stdlib - .lookupFunction('GetProcessHeap'); -final Pointer processHeap = winGetProcessHeap(); - -typedef WinHeapAllocNative = Pointer Function(Pointer, Uint32, IntPtr); -typedef WinHeapAlloc = Pointer Function(Pointer, int, int); -final WinHeapAlloc winHeapAlloc = - stdlib.lookupFunction('HeapAlloc'); - -typedef WinHeapFreeNative = Int32 Function( - Pointer heap, Uint32 flags, Pointer memory); -typedef WinHeapFree = int Function(Pointer heap, int flags, Pointer memory); -final WinHeapFree winHeapFree = - stdlib.lookupFunction('HeapFree'); - -const int HEAP_ZERO_MEMORY = 8; - -/// Manages memory on the native heap. -/// -/// Initializes newly allocated memory to zero. -/// -/// For POSIX-based systems, this uses `calloc` and `free`. On Windows, it uses -/// `HeapAlloc` with [HEAP_ZERO_MEMORY] and `HeapFree` against the default -/// public heap. -class _CallocAllocator implements Allocator { - const _CallocAllocator(); - - /// Allocates [byteCount] bytes of zero-initialized of memory on the native - /// heap. - /// - /// 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 - /// satisfied. - // TODO: Stop ignoring alignment if it's large, for example for SSE data. - @override - Pointer allocate(int byteCount, {int alignment}) { - Pointer result; - if (Platform.isWindows) { - result = winHeapAlloc(processHeap, /*flags=*/ HEAP_ZERO_MEMORY, byteCount) - .cast(); - } else { - result = posixCalloc(byteCount, 1).cast(); - } - if (result.address == 0) { - throw ArgumentError('Could not allocate $byteCount bytes.'); - } - return result; - } - - /// Releases memory allocated on the native heap. - /// - /// For POSIX-based systems, this uses `free`. On Windows, it uses `HeapFree` - /// against the default public heap. It may only be used against pointers - /// allocated in a manner equivalent to [allocate]. - /// - /// Throws an [ArgumentError] if the memory pointed to by [pointer] cannot be - /// freed. - /// - // TODO(dartbug.com/36855): Once we have a ffi.Bool type we can use it instead - // of testing the return integer to be non-zero. - @override - void free(Pointer pointer) { - if (Platform.isWindows) { - if (winHeapFree(processHeap, /*flags=*/ 0, pointer) == 0) { - throw ArgumentError('Could not free $pointer.'); - } - } else { - posixFree(pointer); - } - } -} - -/// Manages memory on the native heap. -/// -/// Initializes newly allocated memory to zero. Use [malloc] for unintialized -/// memory allocation. -/// -/// For POSIX-based systems, this uses `calloc` and `free`. On Windows, it uses -/// `HeapAlloc` with [HEAP_ZERO_MEMORY] and `HeapFree` against the default -/// public heap. -const Allocator calloc = _CallocAllocator(); diff --git a/benchmarks/FfiMemory/dart/FfiMemory.dart b/benchmarks/FfiMemory/dart/FfiMemory.dart index 423fa740181a..b776aa877517 100644 --- a/benchmarks/FfiMemory/dart/FfiMemory.dart +++ b/benchmarks/FfiMemory/dart/FfiMemory.dart @@ -14,8 +14,6 @@ import 'dart:ffi'; import 'package:ffi/ffi.dart'; import 'package:benchmark_harness/benchmark_harness.dart'; -import 'calloc.dart'; - // // Pointer store. // diff --git a/benchmarks/FfiMemory/dart/calloc.dart b/benchmarks/FfiMemory/dart/calloc.dart deleted file mode 100644 index e17238a91b1b..000000000000 --- a/benchmarks/FfiMemory/dart/calloc.dart +++ /dev/null @@ -1,109 +0,0 @@ -// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -// TODO(https://dartbug.com/44621): Remove this copy when package:ffi can be -// rolled. We need to wait until the `Allocator` interface has rolled into -// Flutter. - -import 'dart:ffi'; -import 'dart:io'; - -final DynamicLibrary stdlib = Platform.isWindows - ? DynamicLibrary.open('kernel32.dll') - : DynamicLibrary.process(); - -typedef PosixCallocNative = Pointer Function(IntPtr num, IntPtr size); -typedef PosixCalloc = Pointer Function(int num, int size); -final PosixCalloc posixCalloc = - stdlib.lookupFunction('calloc'); - -typedef PosixFreeNative = Void Function(Pointer); -typedef PosixFree = void Function(Pointer); -final PosixFree posixFree = - stdlib.lookupFunction('free'); - -typedef WinGetProcessHeapFn = Pointer Function(); -final WinGetProcessHeapFn winGetProcessHeap = stdlib - .lookupFunction('GetProcessHeap'); -final Pointer processHeap = winGetProcessHeap(); - -typedef WinHeapAllocNative = Pointer Function(Pointer, Uint32, IntPtr); -typedef WinHeapAlloc = Pointer Function(Pointer, int, int); -final WinHeapAlloc winHeapAlloc = - stdlib.lookupFunction('HeapAlloc'); - -typedef WinHeapFreeNative = Int32 Function( - Pointer heap, Uint32 flags, Pointer memory); -typedef WinHeapFree = int Function(Pointer heap, int flags, Pointer memory); -final WinHeapFree winHeapFree = - stdlib.lookupFunction('HeapFree'); - -const int HEAP_ZERO_MEMORY = 8; - -/// Manages memory on the native heap. -/// -/// Initializes newly allocated memory to zero. -/// -/// For POSIX-based systems, this uses `calloc` and `free`. On Windows, it uses -/// `HeapAlloc` with [HEAP_ZERO_MEMORY] and `HeapFree` against the default -/// public heap. -class _CallocAllocator implements Allocator { - const _CallocAllocator(); - - /// Allocates [byteCount] bytes of zero-initialized of memory on the native - /// heap. - /// - /// 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 - /// satisfied. - // TODO: Stop ignoring alignment if it's large, for example for SSE data. - @override - Pointer allocate(int byteCount, {int? alignment}) { - Pointer result; - if (Platform.isWindows) { - result = winHeapAlloc(processHeap, /*flags=*/ HEAP_ZERO_MEMORY, byteCount) - .cast(); - } else { - result = posixCalloc(byteCount, 1).cast(); - } - if (result.address == 0) { - throw ArgumentError('Could not allocate $byteCount bytes.'); - } - return result; - } - - /// Releases memory allocated on the native heap. - /// - /// For POSIX-based systems, this uses `free`. On Windows, it uses `HeapFree` - /// against the default public heap. It may only be used against pointers - /// allocated in a manner equivalent to [allocate]. - /// - /// Throws an [ArgumentError] if the memory pointed to by [pointer] cannot be - /// freed. - /// - // TODO(dartbug.com/36855): Once we have a ffi.Bool type we can use it instead - // of testing the return integer to be non-zero. - @override - void free(Pointer pointer) { - if (Platform.isWindows) { - if (winHeapFree(processHeap, /*flags=*/ 0, pointer) == 0) { - throw ArgumentError('Could not free $pointer.'); - } - } else { - posixFree(pointer); - } - } -} - -/// Manages memory on the native heap. -/// -/// Initializes newly allocated memory to zero. Use [malloc] for unintialized -/// memory allocation. -/// -/// For POSIX-based systems, this uses `calloc` and `free`. On Windows, it uses -/// `HeapAlloc` with [HEAP_ZERO_MEMORY] and `HeapFree` against the default -/// public heap. -const Allocator calloc = _CallocAllocator(); diff --git a/benchmarks/FfiMemory/dart2/FfiMemory.dart b/benchmarks/FfiMemory/dart2/FfiMemory.dart index d8d41e2d387c..5beff0a63560 100644 --- a/benchmarks/FfiMemory/dart2/FfiMemory.dart +++ b/benchmarks/FfiMemory/dart2/FfiMemory.dart @@ -16,8 +16,6 @@ import 'dart:ffi'; import 'package:ffi/ffi.dart'; import 'package:benchmark_harness/benchmark_harness.dart'; -import 'calloc.dart'; - // // Pointer store. // diff --git a/benchmarks/FfiMemory/dart2/calloc.dart b/benchmarks/FfiMemory/dart2/calloc.dart deleted file mode 100644 index c6be280de0bc..000000000000 --- a/benchmarks/FfiMemory/dart2/calloc.dart +++ /dev/null @@ -1,111 +0,0 @@ -// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -// TODO(https://dartbug.com/44621): Remove this copy when package:ffi can be -// rolled. We need to wait until the `Allocator` interface has rolled into -// Flutter. - -// @dart=2.9 - -import 'dart:ffi'; -import 'dart:io'; - -final DynamicLibrary stdlib = Platform.isWindows - ? DynamicLibrary.open('kernel32.dll') - : DynamicLibrary.process(); - -typedef PosixCallocNative = Pointer Function(IntPtr num, IntPtr size); -typedef PosixCalloc = Pointer Function(int num, int size); -final PosixCalloc posixCalloc = - stdlib.lookupFunction('calloc'); - -typedef PosixFreeNative = Void Function(Pointer); -typedef PosixFree = void Function(Pointer); -final PosixFree posixFree = - stdlib.lookupFunction('free'); - -typedef WinGetProcessHeapFn = Pointer Function(); -final WinGetProcessHeapFn winGetProcessHeap = stdlib - .lookupFunction('GetProcessHeap'); -final Pointer processHeap = winGetProcessHeap(); - -typedef WinHeapAllocNative = Pointer Function(Pointer, Uint32, IntPtr); -typedef WinHeapAlloc = Pointer Function(Pointer, int, int); -final WinHeapAlloc winHeapAlloc = - stdlib.lookupFunction('HeapAlloc'); - -typedef WinHeapFreeNative = Int32 Function( - Pointer heap, Uint32 flags, Pointer memory); -typedef WinHeapFree = int Function(Pointer heap, int flags, Pointer memory); -final WinHeapFree winHeapFree = - stdlib.lookupFunction('HeapFree'); - -const int HEAP_ZERO_MEMORY = 8; - -/// Manages memory on the native heap. -/// -/// Initializes newly allocated memory to zero. -/// -/// For POSIX-based systems, this uses `calloc` and `free`. On Windows, it uses -/// `HeapAlloc` with [HEAP_ZERO_MEMORY] and `HeapFree` against the default -/// public heap. -class _CallocAllocator implements Allocator { - const _CallocAllocator(); - - /// Allocates [byteCount] bytes of zero-initialized of memory on the native - /// heap. - /// - /// 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 - /// satisfied. - // TODO: Stop ignoring alignment if it's large, for example for SSE data. - @override - Pointer allocate(int byteCount, {int alignment}) { - Pointer result; - if (Platform.isWindows) { - result = winHeapAlloc(processHeap, /*flags=*/ HEAP_ZERO_MEMORY, byteCount) - .cast(); - } else { - result = posixCalloc(byteCount, 1).cast(); - } - if (result.address == 0) { - throw ArgumentError('Could not allocate $byteCount bytes.'); - } - return result; - } - - /// Releases memory allocated on the native heap. - /// - /// For POSIX-based systems, this uses `free`. On Windows, it uses `HeapFree` - /// against the default public heap. It may only be used against pointers - /// allocated in a manner equivalent to [allocate]. - /// - /// Throws an [ArgumentError] if the memory pointed to by [pointer] cannot be - /// freed. - /// - // TODO(dartbug.com/36855): Once we have a ffi.Bool type we can use it instead - // of testing the return integer to be non-zero. - @override - void free(Pointer pointer) { - if (Platform.isWindows) { - if (winHeapFree(processHeap, /*flags=*/ 0, pointer) == 0) { - throw ArgumentError('Could not free $pointer.'); - } - } else { - posixFree(pointer); - } - } -} - -/// Manages memory on the native heap. -/// -/// Initializes newly allocated memory to zero. Use [malloc] for unintialized -/// memory allocation. -/// -/// For POSIX-based systems, this uses `calloc` and `free`. On Windows, it uses -/// `HeapAlloc` with [HEAP_ZERO_MEMORY] and `HeapFree` against the default -/// public heap. -const Allocator calloc = _CallocAllocator(); diff --git a/benchmarks/FfiStruct/dart/FfiStruct.dart b/benchmarks/FfiStruct/dart/FfiStruct.dart index a4a8f1496308..4fbc61ca7694 100644 --- a/benchmarks/FfiStruct/dart/FfiStruct.dart +++ b/benchmarks/FfiStruct/dart/FfiStruct.dart @@ -12,8 +12,6 @@ import 'dart:ffi'; import 'package:ffi/ffi.dart'; import 'package:benchmark_harness/benchmark_harness.dart'; -import 'calloc.dart'; - // // Struct field store (plus Pointer elementAt and load). // diff --git a/benchmarks/FfiStruct/dart/calloc.dart b/benchmarks/FfiStruct/dart/calloc.dart deleted file mode 100644 index e17238a91b1b..000000000000 --- a/benchmarks/FfiStruct/dart/calloc.dart +++ /dev/null @@ -1,109 +0,0 @@ -// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -// TODO(https://dartbug.com/44621): Remove this copy when package:ffi can be -// rolled. We need to wait until the `Allocator` interface has rolled into -// Flutter. - -import 'dart:ffi'; -import 'dart:io'; - -final DynamicLibrary stdlib = Platform.isWindows - ? DynamicLibrary.open('kernel32.dll') - : DynamicLibrary.process(); - -typedef PosixCallocNative = Pointer Function(IntPtr num, IntPtr size); -typedef PosixCalloc = Pointer Function(int num, int size); -final PosixCalloc posixCalloc = - stdlib.lookupFunction('calloc'); - -typedef PosixFreeNative = Void Function(Pointer); -typedef PosixFree = void Function(Pointer); -final PosixFree posixFree = - stdlib.lookupFunction('free'); - -typedef WinGetProcessHeapFn = Pointer Function(); -final WinGetProcessHeapFn winGetProcessHeap = stdlib - .lookupFunction('GetProcessHeap'); -final Pointer processHeap = winGetProcessHeap(); - -typedef WinHeapAllocNative = Pointer Function(Pointer, Uint32, IntPtr); -typedef WinHeapAlloc = Pointer Function(Pointer, int, int); -final WinHeapAlloc winHeapAlloc = - stdlib.lookupFunction('HeapAlloc'); - -typedef WinHeapFreeNative = Int32 Function( - Pointer heap, Uint32 flags, Pointer memory); -typedef WinHeapFree = int Function(Pointer heap, int flags, Pointer memory); -final WinHeapFree winHeapFree = - stdlib.lookupFunction('HeapFree'); - -const int HEAP_ZERO_MEMORY = 8; - -/// Manages memory on the native heap. -/// -/// Initializes newly allocated memory to zero. -/// -/// For POSIX-based systems, this uses `calloc` and `free`. On Windows, it uses -/// `HeapAlloc` with [HEAP_ZERO_MEMORY] and `HeapFree` against the default -/// public heap. -class _CallocAllocator implements Allocator { - const _CallocAllocator(); - - /// Allocates [byteCount] bytes of zero-initialized of memory on the native - /// heap. - /// - /// 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 - /// satisfied. - // TODO: Stop ignoring alignment if it's large, for example for SSE data. - @override - Pointer allocate(int byteCount, {int? alignment}) { - Pointer result; - if (Platform.isWindows) { - result = winHeapAlloc(processHeap, /*flags=*/ HEAP_ZERO_MEMORY, byteCount) - .cast(); - } else { - result = posixCalloc(byteCount, 1).cast(); - } - if (result.address == 0) { - throw ArgumentError('Could not allocate $byteCount bytes.'); - } - return result; - } - - /// Releases memory allocated on the native heap. - /// - /// For POSIX-based systems, this uses `free`. On Windows, it uses `HeapFree` - /// against the default public heap. It may only be used against pointers - /// allocated in a manner equivalent to [allocate]. - /// - /// Throws an [ArgumentError] if the memory pointed to by [pointer] cannot be - /// freed. - /// - // TODO(dartbug.com/36855): Once we have a ffi.Bool type we can use it instead - // of testing the return integer to be non-zero. - @override - void free(Pointer pointer) { - if (Platform.isWindows) { - if (winHeapFree(processHeap, /*flags=*/ 0, pointer) == 0) { - throw ArgumentError('Could not free $pointer.'); - } - } else { - posixFree(pointer); - } - } -} - -/// Manages memory on the native heap. -/// -/// Initializes newly allocated memory to zero. Use [malloc] for unintialized -/// memory allocation. -/// -/// For POSIX-based systems, this uses `calloc` and `free`. On Windows, it uses -/// `HeapAlloc` with [HEAP_ZERO_MEMORY] and `HeapFree` against the default -/// public heap. -const Allocator calloc = _CallocAllocator(); diff --git a/benchmarks/FfiStruct/dart2/FfiStruct.dart b/benchmarks/FfiStruct/dart2/FfiStruct.dart index 6f4e17ce6bee..87f98de9b3da 100644 --- a/benchmarks/FfiStruct/dart2/FfiStruct.dart +++ b/benchmarks/FfiStruct/dart2/FfiStruct.dart @@ -14,8 +14,6 @@ import 'dart:ffi'; import 'package:ffi/ffi.dart'; import 'package:benchmark_harness/benchmark_harness.dart'; -import 'calloc.dart'; - // // Struct field store (plus Pointer elementAt and load). // diff --git a/benchmarks/FfiStruct/dart2/calloc.dart b/benchmarks/FfiStruct/dart2/calloc.dart deleted file mode 100644 index c6be280de0bc..000000000000 --- a/benchmarks/FfiStruct/dart2/calloc.dart +++ /dev/null @@ -1,111 +0,0 @@ -// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -// TODO(https://dartbug.com/44621): Remove this copy when package:ffi can be -// rolled. We need to wait until the `Allocator` interface has rolled into -// Flutter. - -// @dart=2.9 - -import 'dart:ffi'; -import 'dart:io'; - -final DynamicLibrary stdlib = Platform.isWindows - ? DynamicLibrary.open('kernel32.dll') - : DynamicLibrary.process(); - -typedef PosixCallocNative = Pointer Function(IntPtr num, IntPtr size); -typedef PosixCalloc = Pointer Function(int num, int size); -final PosixCalloc posixCalloc = - stdlib.lookupFunction('calloc'); - -typedef PosixFreeNative = Void Function(Pointer); -typedef PosixFree = void Function(Pointer); -final PosixFree posixFree = - stdlib.lookupFunction('free'); - -typedef WinGetProcessHeapFn = Pointer Function(); -final WinGetProcessHeapFn winGetProcessHeap = stdlib - .lookupFunction('GetProcessHeap'); -final Pointer processHeap = winGetProcessHeap(); - -typedef WinHeapAllocNative = Pointer Function(Pointer, Uint32, IntPtr); -typedef WinHeapAlloc = Pointer Function(Pointer, int, int); -final WinHeapAlloc winHeapAlloc = - stdlib.lookupFunction('HeapAlloc'); - -typedef WinHeapFreeNative = Int32 Function( - Pointer heap, Uint32 flags, Pointer memory); -typedef WinHeapFree = int Function(Pointer heap, int flags, Pointer memory); -final WinHeapFree winHeapFree = - stdlib.lookupFunction('HeapFree'); - -const int HEAP_ZERO_MEMORY = 8; - -/// Manages memory on the native heap. -/// -/// Initializes newly allocated memory to zero. -/// -/// For POSIX-based systems, this uses `calloc` and `free`. On Windows, it uses -/// `HeapAlloc` with [HEAP_ZERO_MEMORY] and `HeapFree` against the default -/// public heap. -class _CallocAllocator implements Allocator { - const _CallocAllocator(); - - /// Allocates [byteCount] bytes of zero-initialized of memory on the native - /// heap. - /// - /// 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 - /// satisfied. - // TODO: Stop ignoring alignment if it's large, for example for SSE data. - @override - Pointer allocate(int byteCount, {int alignment}) { - Pointer result; - if (Platform.isWindows) { - result = winHeapAlloc(processHeap, /*flags=*/ HEAP_ZERO_MEMORY, byteCount) - .cast(); - } else { - result = posixCalloc(byteCount, 1).cast(); - } - if (result.address == 0) { - throw ArgumentError('Could not allocate $byteCount bytes.'); - } - return result; - } - - /// Releases memory allocated on the native heap. - /// - /// For POSIX-based systems, this uses `free`. On Windows, it uses `HeapFree` - /// against the default public heap. It may only be used against pointers - /// allocated in a manner equivalent to [allocate]. - /// - /// Throws an [ArgumentError] if the memory pointed to by [pointer] cannot be - /// freed. - /// - // TODO(dartbug.com/36855): Once we have a ffi.Bool type we can use it instead - // of testing the return integer to be non-zero. - @override - void free(Pointer pointer) { - if (Platform.isWindows) { - if (winHeapFree(processHeap, /*flags=*/ 0, pointer) == 0) { - throw ArgumentError('Could not free $pointer.'); - } - } else { - posixFree(pointer); - } - } -} - -/// Manages memory on the native heap. -/// -/// Initializes newly allocated memory to zero. Use [malloc] for unintialized -/// memory allocation. -/// -/// For POSIX-based systems, this uses `calloc` and `free`. On Windows, it uses -/// `HeapAlloc` with [HEAP_ZERO_MEMORY] and `HeapFree` against the default -/// public heap. -const Allocator calloc = _CallocAllocator(); 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 ecc33a10d645..250b4d92f093 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,7 +14,6 @@ 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'); diff --git a/runtime/tests/vm/dart/regress_41971_test.dart b/runtime/tests/vm/dart/regress_41971_test.dart index 7979d0d1e592..59212add5138 100644 --- a/runtime/tests/vm/dart/regress_41971_test.dart +++ b/runtime/tests/vm/dart/regress_41971_test.dart @@ -11,8 +11,6 @@ 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); diff --git a/runtime/tests/vm/dart/thread_priority_macos_test.dart b/runtime/tests/vm/dart/thread_priority_macos_test.dart index 473c1ce267c0..75e87d47faa7 100644 --- a/runtime/tests/vm/dart/thread_priority_macos_test.dart +++ b/runtime/tests/vm/dart/thread_priority_macos_test.dart @@ -10,8 +10,6 @@ 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(); 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 bcd62700f2be..b92f0432e864 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,7 +14,6 @@ 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'); diff --git a/runtime/tests/vm/dart_2/regress_41971_test.dart b/runtime/tests/vm/dart_2/regress_41971_test.dart index 7979d0d1e592..59212add5138 100644 --- a/runtime/tests/vm/dart_2/regress_41971_test.dart +++ b/runtime/tests/vm/dart_2/regress_41971_test.dart @@ -11,8 +11,6 @@ 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); 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 fdce726a3629..f1574cf9761d 100644 --- a/runtime/tests/vm/dart_2/thread_priority_macos_test.dart +++ b/runtime/tests/vm/dart_2/thread_priority_macos_test.dart @@ -10,8 +10,6 @@ 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(); diff --git a/samples/ffi/calloc.dart b/samples/ffi/calloc.dart deleted file mode 100644 index e17238a91b1b..000000000000 --- a/samples/ffi/calloc.dart +++ /dev/null @@ -1,109 +0,0 @@ -// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -// TODO(https://dartbug.com/44621): Remove this copy when package:ffi can be -// rolled. We need to wait until the `Allocator` interface has rolled into -// Flutter. - -import 'dart:ffi'; -import 'dart:io'; - -final DynamicLibrary stdlib = Platform.isWindows - ? DynamicLibrary.open('kernel32.dll') - : DynamicLibrary.process(); - -typedef PosixCallocNative = Pointer Function(IntPtr num, IntPtr size); -typedef PosixCalloc = Pointer Function(int num, int size); -final PosixCalloc posixCalloc = - stdlib.lookupFunction('calloc'); - -typedef PosixFreeNative = Void Function(Pointer); -typedef PosixFree = void Function(Pointer); -final PosixFree posixFree = - stdlib.lookupFunction('free'); - -typedef WinGetProcessHeapFn = Pointer Function(); -final WinGetProcessHeapFn winGetProcessHeap = stdlib - .lookupFunction('GetProcessHeap'); -final Pointer processHeap = winGetProcessHeap(); - -typedef WinHeapAllocNative = Pointer Function(Pointer, Uint32, IntPtr); -typedef WinHeapAlloc = Pointer Function(Pointer, int, int); -final WinHeapAlloc winHeapAlloc = - stdlib.lookupFunction('HeapAlloc'); - -typedef WinHeapFreeNative = Int32 Function( - Pointer heap, Uint32 flags, Pointer memory); -typedef WinHeapFree = int Function(Pointer heap, int flags, Pointer memory); -final WinHeapFree winHeapFree = - stdlib.lookupFunction('HeapFree'); - -const int HEAP_ZERO_MEMORY = 8; - -/// Manages memory on the native heap. -/// -/// Initializes newly allocated memory to zero. -/// -/// For POSIX-based systems, this uses `calloc` and `free`. On Windows, it uses -/// `HeapAlloc` with [HEAP_ZERO_MEMORY] and `HeapFree` against the default -/// public heap. -class _CallocAllocator implements Allocator { - const _CallocAllocator(); - - /// Allocates [byteCount] bytes of zero-initialized of memory on the native - /// heap. - /// - /// 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 - /// satisfied. - // TODO: Stop ignoring alignment if it's large, for example for SSE data. - @override - Pointer allocate(int byteCount, {int? alignment}) { - Pointer result; - if (Platform.isWindows) { - result = winHeapAlloc(processHeap, /*flags=*/ HEAP_ZERO_MEMORY, byteCount) - .cast(); - } else { - result = posixCalloc(byteCount, 1).cast(); - } - if (result.address == 0) { - throw ArgumentError('Could not allocate $byteCount bytes.'); - } - return result; - } - - /// Releases memory allocated on the native heap. - /// - /// For POSIX-based systems, this uses `free`. On Windows, it uses `HeapFree` - /// against the default public heap. It may only be used against pointers - /// allocated in a manner equivalent to [allocate]. - /// - /// Throws an [ArgumentError] if the memory pointed to by [pointer] cannot be - /// freed. - /// - // TODO(dartbug.com/36855): Once we have a ffi.Bool type we can use it instead - // of testing the return integer to be non-zero. - @override - void free(Pointer pointer) { - if (Platform.isWindows) { - if (winHeapFree(processHeap, /*flags=*/ 0, pointer) == 0) { - throw ArgumentError('Could not free $pointer.'); - } - } else { - posixFree(pointer); - } - } -} - -/// Manages memory on the native heap. -/// -/// Initializes newly allocated memory to zero. Use [malloc] for unintialized -/// memory allocation. -/// -/// For POSIX-based systems, this uses `calloc` and `free`. On Windows, it uses -/// `HeapAlloc` with [HEAP_ZERO_MEMORY] and `HeapFree` against the default -/// public heap. -const Allocator calloc = _CallocAllocator(); diff --git a/samples/ffi/resource_management/pool.dart b/samples/ffi/resource_management/pool.dart index 14e07f4d623c..e37fd227236d 100644 --- a/samples/ffi/resource_management/pool.dart +++ b/samples/ffi/resource_management/pool.dart @@ -9,8 +9,6 @@ import 'dart:ffi'; import 'package:ffi/ffi.dart'; -import '../calloc.dart'; - /// An [Allocator] which frees all allocations at the same time. /// /// The pool allows you to allocate heap memory, but ignores calls to [free]. diff --git a/samples/ffi/resource_management/unmanaged_sample.dart b/samples/ffi/resource_management/unmanaged_sample.dart index 04c20cbd2458..5ddb6aee2b7d 100644 --- a/samples/ffi/resource_management/unmanaged_sample.dart +++ b/samples/ffi/resource_management/unmanaged_sample.dart @@ -10,7 +10,6 @@ import 'package:expect/expect.dart'; import 'package:ffi/ffi.dart'; import 'utf8_helpers.dart'; -import '../calloc.dart'; import '../dylib_utils.dart'; main() { diff --git a/samples/ffi/sample_ffi_bitfield.dart b/samples/ffi/sample_ffi_bitfield.dart index 67ce69e2862a..4508bedc038b 100644 --- a/samples/ffi/sample_ffi_bitfield.dart +++ b/samples/ffi/sample_ffi_bitfield.dart @@ -7,8 +7,6 @@ import 'dart:ffi'; import 'package:ffi/ffi.dart'; import 'package:expect/expect.dart'; -import 'calloc.dart'; - /// typedef struct { /// unsigned int bold : 1; /// unsigned int underline : 2; diff --git a/samples/ffi/sample_ffi_data.dart b/samples/ffi/sample_ffi_data.dart index e5b04970e5c3..fd930f126976 100644 --- a/samples/ffi/sample_ffi_data.dart +++ b/samples/ffi/sample_ffi_data.dart @@ -5,8 +5,6 @@ import 'dart:ffi'; import 'package:ffi/ffi.dart'; -import 'calloc.dart'; - main() { print('start main'); diff --git a/samples/ffi/sample_ffi_functions.dart b/samples/ffi/sample_ffi_functions.dart index 5038ba816dd6..4ff28cd8e90b 100644 --- a/samples/ffi/sample_ffi_functions.dart +++ b/samples/ffi/sample_ffi_functions.dart @@ -6,7 +6,6 @@ import 'dart:ffi'; import 'package:ffi/ffi.dart'; -import 'calloc.dart'; import 'dylib_utils.dart'; typedef NativeUnaryOp = Int32 Function(Int32); diff --git a/samples/ffi/sample_ffi_functions_callbacks.dart b/samples/ffi/sample_ffi_functions_callbacks.dart index de6d05ac9c85..4de68189d006 100644 --- a/samples/ffi/sample_ffi_functions_callbacks.dart +++ b/samples/ffi/sample_ffi_functions_callbacks.dart @@ -6,7 +6,6 @@ import 'dart:ffi'; import 'package:ffi/ffi.dart'; -import 'calloc.dart'; import 'coordinate.dart'; import 'dylib_utils.dart'; diff --git a/samples/ffi/sample_ffi_functions_structs.dart b/samples/ffi/sample_ffi_functions_structs.dart index 918504078d4e..206c925f59f7 100644 --- a/samples/ffi/sample_ffi_functions_structs.dart +++ b/samples/ffi/sample_ffi_functions_structs.dart @@ -6,7 +6,6 @@ import 'dart:ffi'; import 'package:ffi/ffi.dart'; -import 'calloc.dart'; import 'coordinate.dart'; import 'dylib_utils.dart'; diff --git a/samples/ffi/sample_ffi_structs.dart b/samples/ffi/sample_ffi_structs.dart index f6de82cd36ce..0e7858c5eb7c 100644 --- a/samples/ffi/sample_ffi_structs.dart +++ b/samples/ffi/sample_ffi_structs.dart @@ -6,7 +6,6 @@ import 'dart:ffi'; import 'package:ffi/ffi.dart'; -import 'calloc.dart'; import 'coordinate.dart'; main() { diff --git a/samples/ffi/sqlite/lib/sqlite.dart b/samples/ffi/sqlite/lib/sqlite.dart index 1e60f9fec1e5..d6bac5bed63d 100644 --- a/samples/ffi/sqlite/lib/sqlite.dart +++ b/samples/ffi/sqlite/lib/sqlite.dart @@ -8,5 +8,3 @@ library sqlite; export "src/database.dart"; - -export "src/ffi/calloc.dart" show calloc; diff --git a/samples/ffi/sqlite/lib/src/database.dart b/samples/ffi/sqlite/lib/src/database.dart index 5031027f79f4..b98bf250b821 100644 --- a/samples/ffi/sqlite/lib/src/database.dart +++ b/samples/ffi/sqlite/lib/src/database.dart @@ -15,8 +15,6 @@ import "bindings/types.dart" hide Database; import "bindings/constants.dart"; import "collections/closable_iterator.dart"; -import 'ffi/calloc.dart'; - /// [Database] represents an open connection to a SQLite database. /// /// All functions against a database may throw [SQLiteError]. diff --git a/samples/ffi/sqlite/lib/src/ffi/arena.dart b/samples/ffi/sqlite/lib/src/ffi/arena.dart index 5369a22bbaf0..290c2fe88534 100644 --- a/samples/ffi/sqlite/lib/src/ffi/arena.dart +++ b/samples/ffi/sqlite/lib/src/ffi/arena.dart @@ -7,8 +7,6 @@ import "dart:ffi"; import 'package:ffi/ffi.dart'; -import 'calloc.dart'; - /// [Arena] manages allocated C memory. /// /// Arenas are zoned. diff --git a/samples/ffi/sqlite/lib/src/ffi/calloc.dart b/samples/ffi/sqlite/lib/src/ffi/calloc.dart deleted file mode 100644 index e17238a91b1b..000000000000 --- a/samples/ffi/sqlite/lib/src/ffi/calloc.dart +++ /dev/null @@ -1,109 +0,0 @@ -// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -// TODO(https://dartbug.com/44621): Remove this copy when package:ffi can be -// rolled. We need to wait until the `Allocator` interface has rolled into -// Flutter. - -import 'dart:ffi'; -import 'dart:io'; - -final DynamicLibrary stdlib = Platform.isWindows - ? DynamicLibrary.open('kernel32.dll') - : DynamicLibrary.process(); - -typedef PosixCallocNative = Pointer Function(IntPtr num, IntPtr size); -typedef PosixCalloc = Pointer Function(int num, int size); -final PosixCalloc posixCalloc = - stdlib.lookupFunction('calloc'); - -typedef PosixFreeNative = Void Function(Pointer); -typedef PosixFree = void Function(Pointer); -final PosixFree posixFree = - stdlib.lookupFunction('free'); - -typedef WinGetProcessHeapFn = Pointer Function(); -final WinGetProcessHeapFn winGetProcessHeap = stdlib - .lookupFunction('GetProcessHeap'); -final Pointer processHeap = winGetProcessHeap(); - -typedef WinHeapAllocNative = Pointer Function(Pointer, Uint32, IntPtr); -typedef WinHeapAlloc = Pointer Function(Pointer, int, int); -final WinHeapAlloc winHeapAlloc = - stdlib.lookupFunction('HeapAlloc'); - -typedef WinHeapFreeNative = Int32 Function( - Pointer heap, Uint32 flags, Pointer memory); -typedef WinHeapFree = int Function(Pointer heap, int flags, Pointer memory); -final WinHeapFree winHeapFree = - stdlib.lookupFunction('HeapFree'); - -const int HEAP_ZERO_MEMORY = 8; - -/// Manages memory on the native heap. -/// -/// Initializes newly allocated memory to zero. -/// -/// For POSIX-based systems, this uses `calloc` and `free`. On Windows, it uses -/// `HeapAlloc` with [HEAP_ZERO_MEMORY] and `HeapFree` against the default -/// public heap. -class _CallocAllocator implements Allocator { - const _CallocAllocator(); - - /// Allocates [byteCount] bytes of zero-initialized of memory on the native - /// heap. - /// - /// 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 - /// satisfied. - // TODO: Stop ignoring alignment if it's large, for example for SSE data. - @override - Pointer allocate(int byteCount, {int? alignment}) { - Pointer result; - if (Platform.isWindows) { - result = winHeapAlloc(processHeap, /*flags=*/ HEAP_ZERO_MEMORY, byteCount) - .cast(); - } else { - result = posixCalloc(byteCount, 1).cast(); - } - if (result.address == 0) { - throw ArgumentError('Could not allocate $byteCount bytes.'); - } - return result; - } - - /// Releases memory allocated on the native heap. - /// - /// For POSIX-based systems, this uses `free`. On Windows, it uses `HeapFree` - /// against the default public heap. It may only be used against pointers - /// allocated in a manner equivalent to [allocate]. - /// - /// Throws an [ArgumentError] if the memory pointed to by [pointer] cannot be - /// freed. - /// - // TODO(dartbug.com/36855): Once we have a ffi.Bool type we can use it instead - // of testing the return integer to be non-zero. - @override - void free(Pointer pointer) { - if (Platform.isWindows) { - if (winHeapFree(processHeap, /*flags=*/ 0, pointer) == 0) { - throw ArgumentError('Could not free $pointer.'); - } - } else { - posixFree(pointer); - } - } -} - -/// Manages memory on the native heap. -/// -/// Initializes newly allocated memory to zero. Use [malloc] for unintialized -/// memory allocation. -/// -/// For POSIX-based systems, this uses `calloc` and `free`. On Windows, it uses -/// `HeapAlloc` with [HEAP_ZERO_MEMORY] and `HeapFree` against the default -/// public heap. -const Allocator calloc = _CallocAllocator(); diff --git a/samples_2/ffi/calloc.dart b/samples_2/ffi/calloc.dart deleted file mode 100644 index c6be280de0bc..000000000000 --- a/samples_2/ffi/calloc.dart +++ /dev/null @@ -1,111 +0,0 @@ -// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -// TODO(https://dartbug.com/44621): Remove this copy when package:ffi can be -// rolled. We need to wait until the `Allocator` interface has rolled into -// Flutter. - -// @dart=2.9 - -import 'dart:ffi'; -import 'dart:io'; - -final DynamicLibrary stdlib = Platform.isWindows - ? DynamicLibrary.open('kernel32.dll') - : DynamicLibrary.process(); - -typedef PosixCallocNative = Pointer Function(IntPtr num, IntPtr size); -typedef PosixCalloc = Pointer Function(int num, int size); -final PosixCalloc posixCalloc = - stdlib.lookupFunction('calloc'); - -typedef PosixFreeNative = Void Function(Pointer); -typedef PosixFree = void Function(Pointer); -final PosixFree posixFree = - stdlib.lookupFunction('free'); - -typedef WinGetProcessHeapFn = Pointer Function(); -final WinGetProcessHeapFn winGetProcessHeap = stdlib - .lookupFunction('GetProcessHeap'); -final Pointer processHeap = winGetProcessHeap(); - -typedef WinHeapAllocNative = Pointer Function(Pointer, Uint32, IntPtr); -typedef WinHeapAlloc = Pointer Function(Pointer, int, int); -final WinHeapAlloc winHeapAlloc = - stdlib.lookupFunction('HeapAlloc'); - -typedef WinHeapFreeNative = Int32 Function( - Pointer heap, Uint32 flags, Pointer memory); -typedef WinHeapFree = int Function(Pointer heap, int flags, Pointer memory); -final WinHeapFree winHeapFree = - stdlib.lookupFunction('HeapFree'); - -const int HEAP_ZERO_MEMORY = 8; - -/// Manages memory on the native heap. -/// -/// Initializes newly allocated memory to zero. -/// -/// For POSIX-based systems, this uses `calloc` and `free`. On Windows, it uses -/// `HeapAlloc` with [HEAP_ZERO_MEMORY] and `HeapFree` against the default -/// public heap. -class _CallocAllocator implements Allocator { - const _CallocAllocator(); - - /// Allocates [byteCount] bytes of zero-initialized of memory on the native - /// heap. - /// - /// 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 - /// satisfied. - // TODO: Stop ignoring alignment if it's large, for example for SSE data. - @override - Pointer allocate(int byteCount, {int alignment}) { - Pointer result; - if (Platform.isWindows) { - result = winHeapAlloc(processHeap, /*flags=*/ HEAP_ZERO_MEMORY, byteCount) - .cast(); - } else { - result = posixCalloc(byteCount, 1).cast(); - } - if (result.address == 0) { - throw ArgumentError('Could not allocate $byteCount bytes.'); - } - return result; - } - - /// Releases memory allocated on the native heap. - /// - /// For POSIX-based systems, this uses `free`. On Windows, it uses `HeapFree` - /// against the default public heap. It may only be used against pointers - /// allocated in a manner equivalent to [allocate]. - /// - /// Throws an [ArgumentError] if the memory pointed to by [pointer] cannot be - /// freed. - /// - // TODO(dartbug.com/36855): Once we have a ffi.Bool type we can use it instead - // of testing the return integer to be non-zero. - @override - void free(Pointer pointer) { - if (Platform.isWindows) { - if (winHeapFree(processHeap, /*flags=*/ 0, pointer) == 0) { - throw ArgumentError('Could not free $pointer.'); - } - } else { - posixFree(pointer); - } - } -} - -/// Manages memory on the native heap. -/// -/// Initializes newly allocated memory to zero. Use [malloc] for unintialized -/// memory allocation. -/// -/// For POSIX-based systems, this uses `calloc` and `free`. On Windows, it uses -/// `HeapAlloc` with [HEAP_ZERO_MEMORY] and `HeapFree` against the default -/// public heap. -const Allocator calloc = _CallocAllocator(); diff --git a/samples_2/ffi/resource_management/pool.dart b/samples_2/ffi/resource_management/pool.dart index d4610b015028..ddb502677f54 100644 --- a/samples_2/ffi/resource_management/pool.dart +++ b/samples_2/ffi/resource_management/pool.dart @@ -11,8 +11,6 @@ import 'dart:ffi'; import 'package:ffi/ffi.dart'; -import '../calloc.dart'; - /// An [Allocator] which frees all allocations at the same time. /// /// The pool allows you to allocate heap memory, but ignores calls to [free]. diff --git a/samples_2/ffi/resource_management/unmanaged_sample.dart b/samples_2/ffi/resource_management/unmanaged_sample.dart index e73f7cc6a732..fa5a60bb7ce9 100644 --- a/samples_2/ffi/resource_management/unmanaged_sample.dart +++ b/samples_2/ffi/resource_management/unmanaged_sample.dart @@ -12,7 +12,6 @@ import 'package:expect/expect.dart'; import 'package:ffi/ffi.dart'; import 'utf8_helpers.dart'; -import '../calloc.dart'; import '../dylib_utils.dart'; main() { diff --git a/samples_2/ffi/sample_ffi_bitfield.dart b/samples_2/ffi/sample_ffi_bitfield.dart index 78c41dfe526c..43ac4256dc14 100644 --- a/samples_2/ffi/sample_ffi_bitfield.dart +++ b/samples_2/ffi/sample_ffi_bitfield.dart @@ -9,8 +9,6 @@ import 'dart:ffi'; import 'package:ffi/ffi.dart'; import 'package:expect/expect.dart'; -import 'calloc.dart'; - /// typedef struct { /// unsigned int bold : 1; /// unsigned int underline : 2; diff --git a/samples_2/ffi/sample_ffi_data.dart b/samples_2/ffi/sample_ffi_data.dart index 2d22011557d4..ba82bec7c8b3 100644 --- a/samples_2/ffi/sample_ffi_data.dart +++ b/samples_2/ffi/sample_ffi_data.dart @@ -7,8 +7,6 @@ import 'dart:ffi'; import 'package:ffi/ffi.dart'; -import 'calloc.dart'; - main() { print('start main'); diff --git a/samples_2/ffi/sample_ffi_functions.dart b/samples_2/ffi/sample_ffi_functions.dart index 1bf8ecc0063f..02dfc5027806 100644 --- a/samples_2/ffi/sample_ffi_functions.dart +++ b/samples_2/ffi/sample_ffi_functions.dart @@ -8,7 +8,6 @@ import 'dart:ffi'; import 'package:ffi/ffi.dart'; -import 'calloc.dart'; import 'dylib_utils.dart'; typedef NativeUnaryOp = Int32 Function(Int32); diff --git a/samples_2/ffi/sample_ffi_functions_callbacks.dart b/samples_2/ffi/sample_ffi_functions_callbacks.dart index 1d9dc121e517..83d652e8dfad 100644 --- a/samples_2/ffi/sample_ffi_functions_callbacks.dart +++ b/samples_2/ffi/sample_ffi_functions_callbacks.dart @@ -8,7 +8,6 @@ import 'dart:ffi'; import 'package:ffi/ffi.dart'; -import 'calloc.dart'; import 'coordinate.dart'; import 'dylib_utils.dart'; diff --git a/samples_2/ffi/sample_ffi_functions_structs.dart b/samples_2/ffi/sample_ffi_functions_structs.dart index 41b608d7759d..1b780bed4f43 100644 --- a/samples_2/ffi/sample_ffi_functions_structs.dart +++ b/samples_2/ffi/sample_ffi_functions_structs.dart @@ -8,7 +8,6 @@ import 'dart:ffi'; import 'package:ffi/ffi.dart'; -import 'calloc.dart'; import 'coordinate.dart'; import 'dylib_utils.dart'; diff --git a/samples_2/ffi/sample_ffi_structs.dart b/samples_2/ffi/sample_ffi_structs.dart index 94b19cceb4f4..f2ba9166283c 100644 --- a/samples_2/ffi/sample_ffi_structs.dart +++ b/samples_2/ffi/sample_ffi_structs.dart @@ -8,7 +8,6 @@ import 'dart:ffi'; import 'package:ffi/ffi.dart'; -import 'calloc.dart'; import 'coordinate.dart'; main() { diff --git a/samples_2/ffi/sqlite/lib/sqlite.dart b/samples_2/ffi/sqlite/lib/sqlite.dart index 0e0669bfa71a..825e4347f1c9 100644 --- a/samples_2/ffi/sqlite/lib/sqlite.dart +++ b/samples_2/ffi/sqlite/lib/sqlite.dart @@ -10,5 +10,3 @@ library sqlite; export "src/database.dart"; - -export "src/ffi/calloc.dart" show calloc; diff --git a/samples_2/ffi/sqlite/lib/src/database.dart b/samples_2/ffi/sqlite/lib/src/database.dart index 687fea87e99e..91bcfe679213 100644 --- a/samples_2/ffi/sqlite/lib/src/database.dart +++ b/samples_2/ffi/sqlite/lib/src/database.dart @@ -17,8 +17,6 @@ import "bindings/types.dart" hide Database; import "bindings/constants.dart"; import "collections/closable_iterator.dart"; -import 'ffi/calloc.dart'; - /// [Database] represents an open connection to a SQLite database. /// /// All functions against a database may throw [SQLiteError]. diff --git a/samples_2/ffi/sqlite/lib/src/ffi/arena.dart b/samples_2/ffi/sqlite/lib/src/ffi/arena.dart index 39e303558aae..56b6feaae106 100644 --- a/samples_2/ffi/sqlite/lib/src/ffi/arena.dart +++ b/samples_2/ffi/sqlite/lib/src/ffi/arena.dart @@ -9,8 +9,6 @@ import "dart:ffi"; import 'package:ffi/ffi.dart'; -import 'calloc.dart'; - /// [Arena] manages allocated C memory. /// /// Arenas are zoned. diff --git a/samples_2/ffi/sqlite/lib/src/ffi/calloc.dart b/samples_2/ffi/sqlite/lib/src/ffi/calloc.dart deleted file mode 100644 index c6be280de0bc..000000000000 --- a/samples_2/ffi/sqlite/lib/src/ffi/calloc.dart +++ /dev/null @@ -1,111 +0,0 @@ -// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -// TODO(https://dartbug.com/44621): Remove this copy when package:ffi can be -// rolled. We need to wait until the `Allocator` interface has rolled into -// Flutter. - -// @dart=2.9 - -import 'dart:ffi'; -import 'dart:io'; - -final DynamicLibrary stdlib = Platform.isWindows - ? DynamicLibrary.open('kernel32.dll') - : DynamicLibrary.process(); - -typedef PosixCallocNative = Pointer Function(IntPtr num, IntPtr size); -typedef PosixCalloc = Pointer Function(int num, int size); -final PosixCalloc posixCalloc = - stdlib.lookupFunction('calloc'); - -typedef PosixFreeNative = Void Function(Pointer); -typedef PosixFree = void Function(Pointer); -final PosixFree posixFree = - stdlib.lookupFunction('free'); - -typedef WinGetProcessHeapFn = Pointer Function(); -final WinGetProcessHeapFn winGetProcessHeap = stdlib - .lookupFunction('GetProcessHeap'); -final Pointer processHeap = winGetProcessHeap(); - -typedef WinHeapAllocNative = Pointer Function(Pointer, Uint32, IntPtr); -typedef WinHeapAlloc = Pointer Function(Pointer, int, int); -final WinHeapAlloc winHeapAlloc = - stdlib.lookupFunction('HeapAlloc'); - -typedef WinHeapFreeNative = Int32 Function( - Pointer heap, Uint32 flags, Pointer memory); -typedef WinHeapFree = int Function(Pointer heap, int flags, Pointer memory); -final WinHeapFree winHeapFree = - stdlib.lookupFunction('HeapFree'); - -const int HEAP_ZERO_MEMORY = 8; - -/// Manages memory on the native heap. -/// -/// Initializes newly allocated memory to zero. -/// -/// For POSIX-based systems, this uses `calloc` and `free`. On Windows, it uses -/// `HeapAlloc` with [HEAP_ZERO_MEMORY] and `HeapFree` against the default -/// public heap. -class _CallocAllocator implements Allocator { - const _CallocAllocator(); - - /// Allocates [byteCount] bytes of zero-initialized of memory on the native - /// heap. - /// - /// 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 - /// satisfied. - // TODO: Stop ignoring alignment if it's large, for example for SSE data. - @override - Pointer allocate(int byteCount, {int alignment}) { - Pointer result; - if (Platform.isWindows) { - result = winHeapAlloc(processHeap, /*flags=*/ HEAP_ZERO_MEMORY, byteCount) - .cast(); - } else { - result = posixCalloc(byteCount, 1).cast(); - } - if (result.address == 0) { - throw ArgumentError('Could not allocate $byteCount bytes.'); - } - return result; - } - - /// Releases memory allocated on the native heap. - /// - /// For POSIX-based systems, this uses `free`. On Windows, it uses `HeapFree` - /// against the default public heap. It may only be used against pointers - /// allocated in a manner equivalent to [allocate]. - /// - /// Throws an [ArgumentError] if the memory pointed to by [pointer] cannot be - /// freed. - /// - // TODO(dartbug.com/36855): Once we have a ffi.Bool type we can use it instead - // of testing the return integer to be non-zero. - @override - void free(Pointer pointer) { - if (Platform.isWindows) { - if (winHeapFree(processHeap, /*flags=*/ 0, pointer) == 0) { - throw ArgumentError('Could not free $pointer.'); - } - } else { - posixFree(pointer); - } - } -} - -/// Manages memory on the native heap. -/// -/// Initializes newly allocated memory to zero. Use [malloc] for unintialized -/// memory allocation. -/// -/// For POSIX-based systems, this uses `calloc` and `free`. On Windows, it uses -/// `HeapAlloc` with [HEAP_ZERO_MEMORY] and `HeapFree` against the default -/// public heap. -const Allocator calloc = _CallocAllocator(); diff --git a/tests/ffi/aliasing_test.dart b/tests/ffi/aliasing_test.dart index 946e1e4b05d7..5cace63f9fde 100644 --- a/tests/ffi/aliasing_test.dart +++ b/tests/ffi/aliasing_test.dart @@ -13,7 +13,6 @@ import 'dart:ffi'; import "package:ffi/ffi.dart"; import "package:expect/expect.dart"; -import 'calloc.dart'; import 'ffi_test_helpers.dart'; void main() { diff --git a/tests/ffi/calloc.dart b/tests/ffi/calloc.dart deleted file mode 100644 index e17238a91b1b..000000000000 --- a/tests/ffi/calloc.dart +++ /dev/null @@ -1,109 +0,0 @@ -// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -// TODO(https://dartbug.com/44621): Remove this copy when package:ffi can be -// rolled. We need to wait until the `Allocator` interface has rolled into -// Flutter. - -import 'dart:ffi'; -import 'dart:io'; - -final DynamicLibrary stdlib = Platform.isWindows - ? DynamicLibrary.open('kernel32.dll') - : DynamicLibrary.process(); - -typedef PosixCallocNative = Pointer Function(IntPtr num, IntPtr size); -typedef PosixCalloc = Pointer Function(int num, int size); -final PosixCalloc posixCalloc = - stdlib.lookupFunction('calloc'); - -typedef PosixFreeNative = Void Function(Pointer); -typedef PosixFree = void Function(Pointer); -final PosixFree posixFree = - stdlib.lookupFunction('free'); - -typedef WinGetProcessHeapFn = Pointer Function(); -final WinGetProcessHeapFn winGetProcessHeap = stdlib - .lookupFunction('GetProcessHeap'); -final Pointer processHeap = winGetProcessHeap(); - -typedef WinHeapAllocNative = Pointer Function(Pointer, Uint32, IntPtr); -typedef WinHeapAlloc = Pointer Function(Pointer, int, int); -final WinHeapAlloc winHeapAlloc = - stdlib.lookupFunction('HeapAlloc'); - -typedef WinHeapFreeNative = Int32 Function( - Pointer heap, Uint32 flags, Pointer memory); -typedef WinHeapFree = int Function(Pointer heap, int flags, Pointer memory); -final WinHeapFree winHeapFree = - stdlib.lookupFunction('HeapFree'); - -const int HEAP_ZERO_MEMORY = 8; - -/// Manages memory on the native heap. -/// -/// Initializes newly allocated memory to zero. -/// -/// For POSIX-based systems, this uses `calloc` and `free`. On Windows, it uses -/// `HeapAlloc` with [HEAP_ZERO_MEMORY] and `HeapFree` against the default -/// public heap. -class _CallocAllocator implements Allocator { - const _CallocAllocator(); - - /// Allocates [byteCount] bytes of zero-initialized of memory on the native - /// heap. - /// - /// 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 - /// satisfied. - // TODO: Stop ignoring alignment if it's large, for example for SSE data. - @override - Pointer allocate(int byteCount, {int? alignment}) { - Pointer result; - if (Platform.isWindows) { - result = winHeapAlloc(processHeap, /*flags=*/ HEAP_ZERO_MEMORY, byteCount) - .cast(); - } else { - result = posixCalloc(byteCount, 1).cast(); - } - if (result.address == 0) { - throw ArgumentError('Could not allocate $byteCount bytes.'); - } - return result; - } - - /// Releases memory allocated on the native heap. - /// - /// For POSIX-based systems, this uses `free`. On Windows, it uses `HeapFree` - /// against the default public heap. It may only be used against pointers - /// allocated in a manner equivalent to [allocate]. - /// - /// Throws an [ArgumentError] if the memory pointed to by [pointer] cannot be - /// freed. - /// - // TODO(dartbug.com/36855): Once we have a ffi.Bool type we can use it instead - // of testing the return integer to be non-zero. - @override - void free(Pointer pointer) { - if (Platform.isWindows) { - if (winHeapFree(processHeap, /*flags=*/ 0, pointer) == 0) { - throw ArgumentError('Could not free $pointer.'); - } - } else { - posixFree(pointer); - } - } -} - -/// Manages memory on the native heap. -/// -/// Initializes newly allocated memory to zero. Use [malloc] for unintialized -/// memory allocation. -/// -/// For POSIX-based systems, this uses `calloc` and `free`. On Windows, it uses -/// `HeapAlloc` with [HEAP_ZERO_MEMORY] and `HeapFree` against the default -/// public heap. -const Allocator calloc = _CallocAllocator(); diff --git a/tests/ffi/calloc_test.dart b/tests/ffi/calloc_test.dart index b8b9bbff4493..56f1b973a7c5 100644 --- a/tests/ffi/calloc_test.dart +++ b/tests/ffi/calloc_test.dart @@ -5,8 +5,8 @@ import 'dart:ffi'; import 'package:expect/expect.dart'; +import 'package:ffi/ffi.dart'; -import 'calloc.dart'; import 'coordinate.dart'; void main() { diff --git a/tests/ffi/data_not_asan_test.dart b/tests/ffi/data_not_asan_test.dart index 69257d6cb282..b791d7167625 100644 --- a/tests/ffi/data_not_asan_test.dart +++ b/tests/ffi/data_not_asan_test.dart @@ -12,8 +12,6 @@ import 'dart:ffi'; import "package:ffi/ffi.dart"; import "package:expect/expect.dart"; -import 'calloc.dart'; - void main() { testPointerAllocateTooLarge(); testPointerAllocateNegative(); diff --git a/tests/ffi/data_test.dart b/tests/ffi/data_test.dart index 47b88c50e008..49c9f3613d35 100644 --- a/tests/ffi/data_test.dart +++ b/tests/ffi/data_test.dart @@ -11,7 +11,6 @@ import 'dart:ffi'; import "package:expect/expect.dart"; import "package:ffi/ffi.dart"; -import 'calloc.dart'; import 'ffi_test_helpers.dart'; void main() { diff --git a/tests/ffi/extension_methods_test.dart b/tests/ffi/extension_methods_test.dart index 5c688e0e9389..b8f187e8e373 100644 --- a/tests/ffi/extension_methods_test.dart +++ b/tests/ffi/extension_methods_test.dart @@ -7,8 +7,6 @@ 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(); diff --git a/tests/ffi/external_typed_data_test.dart b/tests/ffi/external_typed_data_test.dart index 1327dea6fbd3..17f76eba649a 100644 --- a/tests/ffi/external_typed_data_test.dart +++ b/tests/ffi/external_typed_data_test.dart @@ -9,8 +9,6 @@ import 'dart:typed_data'; import 'package:expect/expect.dart'; import "package:ffi/ffi.dart"; -import 'calloc.dart'; - main() { testInt8Load(); testInt8Store(); 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 785f03acd2bc..b3b6e176e36b 100644 --- a/tests/ffi/function_callbacks_structs_by_value_generated_test.dart +++ b/tests/ffi/function_callbacks_structs_by_value_generated_test.dart @@ -16,7 +16,6 @@ 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/function_callbacks_structs_by_value_test.dart b/tests/ffi/function_callbacks_structs_by_value_test.dart index 5e9399a547df..3273bbd8f692 100644 --- a/tests/ffi/function_callbacks_structs_by_value_test.dart +++ b/tests/ffi/function_callbacks_structs_by_value_test.dart @@ -11,7 +11,6 @@ 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'; diff --git a/tests/ffi/function_structs_by_value_generated_test.dart b/tests/ffi/function_structs_by_value_generated_test.dart index ba988414f572..1cfd869f47aa 100644 --- a/tests/ffi/function_structs_by_value_generated_test.dart +++ b/tests/ffi/function_structs_by_value_generated_test.dart @@ -15,7 +15,6 @@ 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"); diff --git a/tests/ffi/function_structs_test.dart b/tests/ffi/function_structs_test.dart index ade55fb8e1f9..764b644a5ee1 100644 --- a/tests/ffi/function_structs_test.dart +++ b/tests/ffi/function_structs_test.dart @@ -14,7 +14,6 @@ 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'; diff --git a/tests/ffi/function_test.dart b/tests/ffi/function_test.dart index 077be64c23f6..d5fd3c0f1c5d 100644 --- a/tests/ffi/function_test.dart +++ b/tests/ffi/function_test.dart @@ -18,7 +18,6 @@ import 'dart:ffi'; import "package:ffi/ffi.dart"; import "package:expect/expect.dart"; -import 'calloc.dart'; import 'dylib_utils.dart'; void main() { diff --git a/tests/ffi/generator/structs_by_value_tests_generator.dart b/tests/ffi/generator/structs_by_value_tests_generator.dart index 7bd7c83c3638..81118025e428 100644 --- a/tests/ffi/generator/structs_by_value_tests_generator.dart +++ b/tests/ffi/generator/structs_by_value_tests_generator.dart @@ -749,7 +749,6 @@ 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"); @@ -802,7 +801,6 @@ 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 62c71dbcc1b4..0c2829a83d14 100644 --- a/tests/ffi/regress_37254_test.dart +++ b/tests/ffi/regress_37254_test.dart @@ -65,8 +65,6 @@ 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() { diff --git a/tests/ffi/regress_39885_test.dart b/tests/ffi/regress_39885_test.dart index ef73ca75cfcc..77de64f3ec93 100644 --- a/tests/ffi/regress_39885_test.dart +++ b/tests/ffi/regress_39885_test.dart @@ -6,8 +6,6 @@ import 'dart:ffi'; import "package:ffi/ffi.dart"; -import 'calloc.dart'; - main() { final data = calloc(3); for (int i = 0; i < 3; ++i) { diff --git a/tests/ffi/regress_43693_test.dart b/tests/ffi/regress_43693_test.dart index 64b48bfa275e..47e501523607 100644 --- a/tests/ffi/regress_43693_test.dart +++ b/tests/ffi/regress_43693_test.dart @@ -9,7 +9,6 @@ import 'dart:ffi'; import 'package:ffi/ffi.dart'; import 'package:expect/expect.dart'; -import 'calloc.dart'; import 'dylib_utils.dart'; class Struct43693 extends Struct { diff --git a/tests/ffi/structs_nested_test.dart b/tests/ffi/structs_nested_test.dart index 2d5208d97a21..a7c1255e6259 100644 --- a/tests/ffi/structs_nested_test.dart +++ b/tests/ffi/structs_nested_test.dart @@ -11,7 +11,6 @@ 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"); diff --git a/tests/ffi/structs_nnbd_workaround_test.dart b/tests/ffi/structs_nnbd_workaround_test.dart index 06c6f29d1d3f..33f560ea5a0e 100644 --- a/tests/ffi/structs_nnbd_workaround_test.dart +++ b/tests/ffi/structs_nnbd_workaround_test.dart @@ -11,7 +11,6 @@ import 'dart:ffi'; import "package:expect/expect.dart"; import "package:ffi/ffi.dart"; -import 'calloc.dart'; import 'coordinate_nnbd_workaround.dart'; void main() { diff --git a/tests/ffi/structs_test.dart b/tests/ffi/structs_test.dart index 6bc1ed1a7a7c..ede23f99b84f 100644 --- a/tests/ffi/structs_test.dart +++ b/tests/ffi/structs_test.dart @@ -11,7 +11,6 @@ import 'dart:ffi'; import "package:expect/expect.dart"; import "package:ffi/ffi.dart"; -import 'calloc.dart'; import 'coordinate_bare.dart' as bare; import 'coordinate.dart'; import 'ffi_test_helpers.dart'; diff --git a/tests/ffi/variance_function_test.dart b/tests/ffi/variance_function_test.dart index 3db0147abadb..04c812ce27b5 100644 --- a/tests/ffi/variance_function_test.dart +++ b/tests/ffi/variance_function_test.dart @@ -15,7 +15,6 @@ import 'dart:ffi'; import "package:expect/expect.dart"; import "package:ffi/ffi.dart"; -import 'calloc.dart'; import 'dylib_utils.dart'; typedef Int64PointerParamOpDart = void Function(Pointer); diff --git a/tests/ffi/vmspecific_enable_ffi_test.dart b/tests/ffi/vmspecific_enable_ffi_test.dart index ce906071f164..69ae0aaa3645 100644 --- a/tests/ffi/vmspecific_enable_ffi_test.dart +++ b/tests/ffi/vmspecific_enable_ffi_test.dart @@ -10,8 +10,6 @@ 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 calloc(); //# 01: compile-time error diff --git a/tests/ffi/vmspecific_static_checks_test.dart b/tests/ffi/vmspecific_static_checks_test.dart index ff194bdaf70b..117eac7df500 100644 --- a/tests/ffi/vmspecific_static_checks_test.dart +++ b/tests/ffi/vmspecific_static_checks_test.dart @@ -10,7 +10,6 @@ import 'dart:ffi'; import "package:ffi/ffi.dart"; -import 'calloc.dart'; import 'dylib_utils.dart'; void main() { diff --git a/tests/ffi_2/aliasing_test.dart b/tests/ffi_2/aliasing_test.dart index 946e1e4b05d7..5cace63f9fde 100644 --- a/tests/ffi_2/aliasing_test.dart +++ b/tests/ffi_2/aliasing_test.dart @@ -13,7 +13,6 @@ import 'dart:ffi'; import "package:ffi/ffi.dart"; import "package:expect/expect.dart"; -import 'calloc.dart'; import 'ffi_test_helpers.dart'; void main() { diff --git a/tests/ffi_2/calloc.dart b/tests/ffi_2/calloc.dart deleted file mode 100644 index a433e39cd9a8..000000000000 --- a/tests/ffi_2/calloc.dart +++ /dev/null @@ -1,109 +0,0 @@ -// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -// TODO(https://dartbug.com/44621): Remove this copy when package:ffi can be -// rolled. We need to wait until the `Allocator` interface has rolled into -// Flutter. - -import 'dart:ffi'; -import 'dart:io'; - -final DynamicLibrary stdlib = Platform.isWindows - ? DynamicLibrary.open('kernel32.dll') - : DynamicLibrary.process(); - -typedef PosixCallocNative = Pointer Function(IntPtr num, IntPtr size); -typedef PosixCalloc = Pointer Function(int num, int size); -final PosixCalloc posixCalloc = - stdlib.lookupFunction('calloc'); - -typedef PosixFreeNative = Void Function(Pointer); -typedef PosixFree = void Function(Pointer); -final PosixFree posixFree = - stdlib.lookupFunction('free'); - -typedef WinGetProcessHeapFn = Pointer Function(); -final WinGetProcessHeapFn winGetProcessHeap = stdlib - .lookupFunction('GetProcessHeap'); -final Pointer processHeap = winGetProcessHeap(); - -typedef WinHeapAllocNative = Pointer Function(Pointer, Uint32, IntPtr); -typedef WinHeapAlloc = Pointer Function(Pointer, int, int); -final WinHeapAlloc winHeapAlloc = - stdlib.lookupFunction('HeapAlloc'); - -typedef WinHeapFreeNative = Int32 Function( - Pointer heap, Uint32 flags, Pointer memory); -typedef WinHeapFree = int Function(Pointer heap, int flags, Pointer memory); -final WinHeapFree winHeapFree = - stdlib.lookupFunction('HeapFree'); - -const int HEAP_ZERO_MEMORY = 8; - -/// Manages memory on the native heap. -/// -/// Initializes newly allocated memory to zero. -/// -/// For POSIX-based systems, this uses `calloc` and `free`. On Windows, it uses -/// `HeapAlloc` with [HEAP_ZERO_MEMORY] and `HeapFree` against the default -/// public heap. -class _CallocAllocator implements Allocator { - const _CallocAllocator(); - - /// Allocates [byteCount] bytes of zero-initialized of memory on the native - /// heap. - /// - /// 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 - /// satisfied. - // TODO: Stop ignoring alignment if it's large, for example for SSE data. - @override - Pointer allocate(int byteCount, {int alignment}) { - Pointer result; - if (Platform.isWindows) { - result = winHeapAlloc(processHeap, /*flags=*/ HEAP_ZERO_MEMORY, byteCount) - .cast(); - } else { - result = posixCalloc(byteCount, 1).cast(); - } - if (result.address == 0) { - throw ArgumentError('Could not allocate $byteCount bytes.'); - } - return result; - } - - /// Releases memory allocated on the native heap. - /// - /// For POSIX-based systems, this uses `free`. On Windows, it uses `HeapFree` - /// against the default public heap. It may only be used against pointers - /// allocated in a manner equivalent to [allocate]. - /// - /// Throws an [ArgumentError] if the memory pointed to by [pointer] cannot be - /// freed. - /// - // TODO(dartbug.com/36855): Once we have a ffi.Bool type we can use it instead - // of testing the return integer to be non-zero. - @override - void free(Pointer pointer) { - if (Platform.isWindows) { - if (winHeapFree(processHeap, /*flags=*/ 0, pointer) == 0) { - throw ArgumentError('Could not free $pointer.'); - } - } else { - posixFree(pointer); - } - } -} - -/// Manages memory on the native heap. -/// -/// Initializes newly allocated memory to zero. Use [malloc] for unintialized -/// memory allocation. -/// -/// For POSIX-based systems, this uses `calloc` and `free`. On Windows, it uses -/// `HeapAlloc` with [HEAP_ZERO_MEMORY] and `HeapFree` against the default -/// public heap. -const Allocator calloc = _CallocAllocator(); diff --git a/tests/ffi_2/calloc_test.dart b/tests/ffi_2/calloc_test.dart index b8b9bbff4493..56f1b973a7c5 100644 --- a/tests/ffi_2/calloc_test.dart +++ b/tests/ffi_2/calloc_test.dart @@ -5,8 +5,8 @@ import 'dart:ffi'; import 'package:expect/expect.dart'; +import 'package:ffi/ffi.dart'; -import 'calloc.dart'; import 'coordinate.dart'; void main() { diff --git a/tests/ffi_2/data_not_asan_test.dart b/tests/ffi_2/data_not_asan_test.dart index 69257d6cb282..b791d7167625 100644 --- a/tests/ffi_2/data_not_asan_test.dart +++ b/tests/ffi_2/data_not_asan_test.dart @@ -12,8 +12,6 @@ import 'dart:ffi'; import "package:ffi/ffi.dart"; import "package:expect/expect.dart"; -import 'calloc.dart'; - void main() { testPointerAllocateTooLarge(); testPointerAllocateNegative(); diff --git a/tests/ffi_2/data_test.dart b/tests/ffi_2/data_test.dart index 8fca1a1b28bf..6c3c488476cb 100644 --- a/tests/ffi_2/data_test.dart +++ b/tests/ffi_2/data_test.dart @@ -11,7 +11,6 @@ import 'dart:ffi'; import "package:expect/expect.dart"; import "package:ffi/ffi.dart"; -import 'calloc.dart'; import 'ffi_test_helpers.dart'; void main() { diff --git a/tests/ffi_2/extension_methods_test.dart b/tests/ffi_2/extension_methods_test.dart index 3524a7f646b9..64a6237a4205 100644 --- a/tests/ffi_2/extension_methods_test.dart +++ b/tests/ffi_2/extension_methods_test.dart @@ -7,8 +7,6 @@ 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(); diff --git a/tests/ffi_2/external_typed_data_test.dart b/tests/ffi_2/external_typed_data_test.dart index 18e8e3c61f5c..3c4c71a0aaff 100644 --- a/tests/ffi_2/external_typed_data_test.dart +++ b/tests/ffi_2/external_typed_data_test.dart @@ -9,8 +9,6 @@ import 'dart:typed_data'; import 'package:expect/expect.dart'; import "package:ffi/ffi.dart"; -import 'calloc.dart'; - main() { testInt8Load(); testInt8Store(); 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 e11d96290077..5e6d12f8d39f 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,7 +16,6 @@ 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/function_callbacks_structs_by_value_test.dart b/tests/ffi_2/function_callbacks_structs_by_value_test.dart index 5e9399a547df..3273bbd8f692 100644 --- a/tests/ffi_2/function_callbacks_structs_by_value_test.dart +++ b/tests/ffi_2/function_callbacks_structs_by_value_test.dart @@ -11,7 +11,6 @@ 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'; 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 6867406a74de..e95fc7a2a9a9 100644 --- a/tests/ffi_2/function_structs_by_value_generated_test.dart +++ b/tests/ffi_2/function_structs_by_value_generated_test.dart @@ -15,7 +15,6 @@ 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"); diff --git a/tests/ffi_2/function_structs_test.dart b/tests/ffi_2/function_structs_test.dart index 6bb3e56b5f64..c003fd448bf1 100644 --- a/tests/ffi_2/function_structs_test.dart +++ b/tests/ffi_2/function_structs_test.dart @@ -12,7 +12,6 @@ import 'dart:ffi'; 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'; diff --git a/tests/ffi_2/function_test.dart b/tests/ffi_2/function_test.dart index b547ffe6916d..d5fd3c0f1c5d 100644 --- a/tests/ffi_2/function_test.dart +++ b/tests/ffi_2/function_test.dart @@ -19,7 +19,6 @@ 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) { 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 7bd7c83c3638..81118025e428 100644 --- a/tests/ffi_2/generator/structs_by_value_tests_generator.dart +++ b/tests/ffi_2/generator/structs_by_value_tests_generator.dart @@ -749,7 +749,6 @@ 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"); @@ -802,7 +801,6 @@ 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 fb51f947f072..ec7b83712ef7 100644 --- a/tests/ffi_2/null_test.dart +++ b/tests/ffi_2/null_test.dart @@ -20,7 +20,6 @@ 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'; diff --git a/tests/ffi_2/regress_37254_test.dart b/tests/ffi_2/regress_37254_test.dart index e73562d8b02c..cf2378b72bec 100644 --- a/tests/ffi_2/regress_37254_test.dart +++ b/tests/ffi_2/regress_37254_test.dart @@ -65,8 +65,6 @@ 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() { diff --git a/tests/ffi_2/regress_39885_test.dart b/tests/ffi_2/regress_39885_test.dart index ef73ca75cfcc..77de64f3ec93 100644 --- a/tests/ffi_2/regress_39885_test.dart +++ b/tests/ffi_2/regress_39885_test.dart @@ -6,8 +6,6 @@ import 'dart:ffi'; import "package:ffi/ffi.dart"; -import 'calloc.dart'; - main() { final data = calloc(3); for (int i = 0; i < 3; ++i) { diff --git a/tests/ffi_2/regress_43693_test.dart b/tests/ffi_2/regress_43693_test.dart index b589b0c5aed4..01b7cfd4b541 100644 --- a/tests/ffi_2/regress_43693_test.dart +++ b/tests/ffi_2/regress_43693_test.dart @@ -9,7 +9,6 @@ import 'dart:ffi'; import 'package:ffi/ffi.dart'; import 'package:expect/expect.dart'; -import 'calloc.dart'; import 'dylib_utils.dart'; class Struct43693 extends Struct { diff --git a/tests/ffi_2/structs_nested_test.dart b/tests/ffi_2/structs_nested_test.dart index 3a69edbf2c58..522458fd52ac 100644 --- a/tests/ffi_2/structs_nested_test.dart +++ b/tests/ffi_2/structs_nested_test.dart @@ -11,7 +11,6 @@ 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"); diff --git a/tests/ffi_2/structs_test.dart b/tests/ffi_2/structs_test.dart index 275905648ec5..80b9f67e1edb 100644 --- a/tests/ffi_2/structs_test.dart +++ b/tests/ffi_2/structs_test.dart @@ -11,7 +11,6 @@ import 'dart:ffi'; import "package:expect/expect.dart"; import "package:ffi/ffi.dart"; -import 'calloc.dart'; import 'coordinate_bare.dart' as bare; import 'coordinate.dart'; import 'ffi_test_helpers.dart'; diff --git a/tests/ffi_2/variance_function_test.dart b/tests/ffi_2/variance_function_test.dart index f53cdfcbf365..210543a0a8c9 100644 --- a/tests/ffi_2/variance_function_test.dart +++ b/tests/ffi_2/variance_function_test.dart @@ -15,7 +15,6 @@ import 'dart:ffi'; import "package:expect/expect.dart"; import "package:ffi/ffi.dart"; -import 'calloc.dart'; import 'dylib_utils.dart'; typedef Int64PointerParamOpDart = void Function(Pointer); diff --git a/tests/ffi_2/vmspecific_enable_ffi_test.dart b/tests/ffi_2/vmspecific_enable_ffi_test.dart index ce906071f164..69ae0aaa3645 100644 --- a/tests/ffi_2/vmspecific_enable_ffi_test.dart +++ b/tests/ffi_2/vmspecific_enable_ffi_test.dart @@ -10,8 +10,6 @@ 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 calloc(); //# 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 8883658dde16..2fabfda8b9b5 100644 --- a/tests/ffi_2/vmspecific_static_checks_test.dart +++ b/tests/ffi_2/vmspecific_static_checks_test.dart @@ -10,7 +10,6 @@ import 'dart:ffi'; import "package:ffi/ffi.dart"; -import 'calloc.dart'; import 'dylib_utils.dart'; void main() {