dart-sdk/tests/ffi/regress_43693_test.dart
Daco Harkes a45276ab91 Reland "[vm/ffi] Roll package:ffi to Allocator and Opaque"
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>
2021-02-10 10:19:28 +00:00

37 lines
1 KiB
Dart

// Copyright (c) 2020, 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.
//
// SharedObjects=ffi_test_functions
import 'dart:ffi';
import 'package:ffi/ffi.dart';
import 'package:expect/expect.dart';
import 'dylib_utils.dart';
class Struct43693 extends Struct {
external Pointer<Void> somePtr;
@Uint64()
external int someValue;
}
final int Function(Pointer<Struct43693>) readMyStructSomeValue =
ffiTestFunctions
.lookup<NativeFunction<Uint64 Function(Pointer<Struct43693>)>>(
"Regress43693")
.asFunction<int Function(Pointer<Struct43693>)>();
final ffiTestFunctions = dlopenPlatformSpecific("ffi_test_functions");
void main() {
final myStructs = calloc<Struct43693>();
myStructs[0].somePtr = nullptr;
myStructs[0].someValue = 0xAAAAAAAABBBBBBBB;
final result = readMyStructSomeValue(myStructs);
Expect.equals(0xAAAAAAAABBBBBBBB, result);
calloc.free(myStructs);
}