mirror of
https://github.com/dart-lang/sdk
synced 2024-10-14 16:13:19 +00:00
a45276ab91
This can only be landed when `Allocator`, `Opaque`, and `AllocatorAlloc` have rolled into Flutter/engine, that into Flutter/flutter, and into g3. Deletes all the copies of `_CallocAllocator` and uses the one from `package:ffi` instead. Bug: https://github.com/dart-lang/sdk/issues/44622 Bug: https://github.com/dart-lang/sdk/issues/43974 Bug: https://github.com/dart-lang/sdk/issues/44621 Bug: https://github.com/dart-lang/sdk/issues/38721 Change-Id: I486034b379b5a63cad4aefd503ccd0f2ce5dd45e Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/180188 Commit-Queue: Daco Harkes <dacoharkes@google.com> Reviewed-by: Aske Simon Christensen <askesc@google.com>
36 lines
1.2 KiB
Dart
36 lines
1.2 KiB
Dart
// Copyright (c) 2019, 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.
|
|
//
|
|
// Dart test program for testing dart:ffi primitive data pointers.
|
|
//
|
|
// These callocs trigger an asan alarm, so these tests are in a separate file
|
|
// which is excluded in asan mode.
|
|
|
|
import 'dart:ffi';
|
|
|
|
import "package:ffi/ffi.dart";
|
|
import "package:expect/expect.dart";
|
|
|
|
void main() {
|
|
testPointerAllocateTooLarge();
|
|
testPointerAllocateNegative();
|
|
}
|
|
|
|
void testPointerAllocateTooLarge() {
|
|
// Try to allocate something that doesn't fit in 64 bit address space.
|
|
int maxInt = 9223372036854775807; // 2^63 - 1
|
|
Expect.throws(() => calloc<Int64>(maxInt));
|
|
|
|
// Try to allocate almost the full 64 bit address space.
|
|
int maxInt1_8 = 1152921504606846975; // 2^60 -1
|
|
Expect.throws(() => calloc<Int64>(maxInt1_8));
|
|
}
|
|
|
|
void testPointerAllocateNegative() {
|
|
// Passing in -1 will be converted into an unsigned integer. So, it will try
|
|
// to allocate SIZE_MAX - 1 + 1 bytes. This will fail as it is the max amount
|
|
// of addressable memory on the system.
|
|
Expect.throws(() => calloc<Int8>(-1));
|
|
}
|