mirror of
https://github.com/dart-lang/sdk
synced 2024-10-14 09:31:58 +00:00
5a1ef6089c
This reverts commitf706ff4ee2
. Reason for revert: b/321667799 - package:win32 uses this method -a78ff108fb/lib/src/com/iapplicationactivationmanager.dart (L46)
Original change's description: > [ffi]: Remove pointer elementAt method. > > Closes #54250 > > TEST=test/ffi > > R=dacoharkes@google.com > Change-Id: I0e88adfcfe3caef0ad3bb6814ad8f27dce5dc7f4 > CoreLibraryReviewExempt: FFI only > Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/346380 > Reviewed-by: Daco Harkes <dacoharkes@google.com> > Commit-Queue: Martin Kustermann <kustermann@google.com> > Reviewed-by: Martin Kustermann <kustermann@google.com> > Auto-Submit: Shikhar <shikharish05@gmail.com> Change-Id: I1b7a48d14e9b85676a27f76a926e21cac9c76c85 No-Presubmit: true No-Tree-Checks: true No-Try: true Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/347600 Reviewed-by: Martin Kustermann <kustermann@google.com> Reviewed-by: Daco Harkes <dacoharkes@google.com> Commit-Queue: Daco Harkes <dacoharkes@google.com>
146 lines
2.9 KiB
Dart
146 lines
2.9 KiB
Dart
// 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.
|
|
|
|
// SharedObjects=ffi_test_functions
|
|
|
|
import 'dart:ffi';
|
|
|
|
import 'package:expect/expect.dart';
|
|
import 'package:ffi/ffi.dart';
|
|
|
|
// We want at least 1 mapping to satisfy the static checks.
|
|
const notTestingOn = Abi.fuchsiaArm64;
|
|
|
|
@AbiSpecificIntegerMapping({
|
|
notTestingOn: Int8(),
|
|
})
|
|
final class Incomplete extends AbiSpecificInteger {
|
|
const Incomplete();
|
|
}
|
|
|
|
void main() {
|
|
if (Abi.current() == notTestingOn) {
|
|
return;
|
|
}
|
|
testSizeOf();
|
|
testStoreLoad();
|
|
testStoreLoadIndexed();
|
|
testStruct();
|
|
testInlineArray();
|
|
testInlineArray2();
|
|
testAsFunction();
|
|
}
|
|
|
|
void testSizeOf() {
|
|
Expect.throws(() {
|
|
sizeOf<Incomplete>();
|
|
});
|
|
}
|
|
|
|
void testStoreLoad() {
|
|
final p = calloc<Int64>().cast<Incomplete>();
|
|
Expect.throws(() {
|
|
p.value = 10;
|
|
});
|
|
Expect.throws(() {
|
|
p.value;
|
|
});
|
|
calloc.free(p);
|
|
}
|
|
|
|
void testStoreLoadIndexed() {
|
|
final p = calloc<Int64>().cast<Incomplete>();
|
|
Expect.throws(() {
|
|
p[0] = 10;
|
|
});
|
|
Expect.throws(() {
|
|
p[1];
|
|
});
|
|
calloc.free(p);
|
|
}
|
|
|
|
final class IncompleteStruct extends Struct {
|
|
@Incomplete()
|
|
external int a0;
|
|
|
|
@Incomplete()
|
|
external int a1;
|
|
}
|
|
|
|
void testStruct() {
|
|
final p = calloc<Int64>(2).cast<IncompleteStruct>();
|
|
Expect.throws(() {
|
|
p.ref.a0 = 1;
|
|
});
|
|
Expect.throws(() {
|
|
p.ref.a0;
|
|
});
|
|
calloc.free(p);
|
|
}
|
|
|
|
final class IncompleteArrayStruct extends Struct {
|
|
@Array(100)
|
|
external Array<Incomplete> a0;
|
|
}
|
|
|
|
void testInlineArray() {
|
|
final p = calloc<Int64>(100).cast<IncompleteArrayStruct>();
|
|
final array = p.ref.a0;
|
|
Expect.throws(() {
|
|
array[3] = 4;
|
|
});
|
|
Expect.throws(() {
|
|
array[3];
|
|
});
|
|
calloc.free(p);
|
|
}
|
|
|
|
const _dim1 = 8;
|
|
const _dim2 = 4;
|
|
|
|
final class IncompleteArrayArrayStruct extends Struct {
|
|
@Array(_dim1, _dim2)
|
|
external Array<Array<Incomplete>> a0;
|
|
}
|
|
|
|
void testInlineArray2() {
|
|
final p = calloc<Int64>(100).cast<IncompleteArrayArrayStruct>();
|
|
Expect.throws(() {
|
|
p.elementAt(3);
|
|
});
|
|
Expect.throws(() {
|
|
(p + 3);
|
|
});
|
|
calloc.free(p);
|
|
}
|
|
|
|
void testAsFunction() {
|
|
Expect.throws(() {
|
|
nullptr
|
|
.cast<NativeFunction<Int32 Function(Incomplete)>>()
|
|
.asFunction<int Function(int)>()
|
|
.call(42);
|
|
});
|
|
Expect.throws(() {
|
|
nullptr
|
|
.cast<NativeFunction<Incomplete Function(Int32)>>()
|
|
.asFunction<int Function(int)>()
|
|
.call(42);
|
|
});
|
|
final p = calloc<Int64>(100).cast<IncompleteArrayStruct>();
|
|
Expect.throws(() {
|
|
nullptr
|
|
.cast<NativeFunction<Int32 Function(IncompleteArrayStruct)>>()
|
|
.asFunction<int Function(IncompleteArrayStruct)>()
|
|
.call(p.ref);
|
|
});
|
|
calloc.free(p);
|
|
Expect.throws(() {
|
|
nullptr
|
|
.cast<NativeFunction<IncompleteArrayStruct Function()>>()
|
|
.asFunction<IncompleteArrayStruct Function()>()
|
|
.call();
|
|
});
|
|
}
|