mirror of
https://github.com/dart-lang/sdk
synced 2024-09-05 16:41:07 +00:00
![Daco Harkes](/assets/img/avatar_default.png)
Adds a way to express native effects in Dart expressions in kernel. This CL adds a `void _nativeEffect(Object)` to `dart:internal`. The semantics of `_nativeEffect` are to not execute its arguments and return `null`. This CL uses this `_nativeEffect` to make sure that we never execute the struct constructor invocations used to simulate the native behavior of FFI trampolines. Closes: https://github.com/dart-lang/sdk/issues/45607 TEST=tests/ffi(_2)/native_effect_test.dart Change-Id: Ie06de145e49f8b1cae9e148c2d5d97d5cd8e6878 Cq-Include-Trybots: luci.dart.try:vm-precomp-ffi-qemu-linux-release-arm-try,vm-ffi-android-debug-arm64-try,vm-kernel-precomp-asan-linux-release-x64-try,vm-kernel-precomp-dwarf-linux-product-x64-try,vm-kernel-precomp-linux-debug-x64-try,vm-kernel-precomp-obfuscate-linux-release-x64-try,analyzer-analysis-server-linux-try,analyzer-linux-release-try,dart-sdk-linux-try,vm-kernel-reload-rollback-linux-debug-x64-try,vm-kernel-reload-linux-debug-x64-try Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/194421 Reviewed-by: Alexander Markov <alexmarkov@google.com> Commit-Queue: Daco Harkes <dacoharkes@google.com>
34 lines
870 B
Dart
34 lines
870 B
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
|
|
|
|
// Tests that the dart:internal _nativeEffect flow graph builder works.
|
|
|
|
import 'dart:ffi';
|
|
|
|
import "package:expect/expect.dart";
|
|
|
|
import 'dylib_utils.dart';
|
|
|
|
void main() {
|
|
testReturnStruct1ByteInt();
|
|
}
|
|
|
|
final ffiTestFunctions = dlopenPlatformSpecific("ffi_test_functions");
|
|
|
|
final returnStruct1ByteInt = ffiTestFunctions.lookupFunction<
|
|
Struct1ByteInt Function(Int8),
|
|
Struct1ByteInt Function(int)>("ReturnStruct1ByteInt");
|
|
|
|
void testReturnStruct1ByteInt() {
|
|
final result = returnStruct1ByteInt(1);
|
|
Expect.equals(1, result.a0);
|
|
}
|
|
|
|
class Struct1ByteInt extends Struct {
|
|
@Int8()
|
|
external int a0;
|
|
}
|