mirror of
https://github.com/dart-lang/sdk
synced 2024-09-05 16:41:07 +00:00
![Simon Binder](/assets/img/avatar_default.png)
This adds the providesSymbol method to DynamicLibrary. It returns whether the library contains a function with the given name. As per dlsym(3), it is valid for dlsym to return nullptr in a success case if the symbol actually has a NULL value. So I've changed the logic to check for dlerror() after we invoke dlsym(), both in the existing lookup and in the new method. Closes https://github.com/dart-lang/sdk/issues/46192 TEST=tests/ffi(_2)/has_symbol_test.dart Change-Id: Ibcb1c051cc0cdd95a104fe86ef2fc76da5bafb5d Cq-Include-Trybots: luci.dart.try:vm-precomp-ffi-qemu-linux-release-arm-try,vm-ffi-android-debug-arm64-try,vm-ffi-android-debug-arm-try,vm-kernel-linux-debug-x64-try,vm-kernel-win-debug-x64-try,vm-kernel-mac-debug-x64-try Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/201900 Reviewed-by: Daco Harkes <dacoharkes@google.com> Commit-Queue: Daco Harkes <dacoharkes@google.com>
35 lines
1 KiB
Dart
35 lines
1 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 'dart:io';
|
|
|
|
import 'package:expect/expect.dart';
|
|
|
|
import 'ffi_test_helpers.dart';
|
|
|
|
void main() {
|
|
testHasSymbol();
|
|
}
|
|
|
|
void testHasSymbol() {
|
|
Expect.isTrue(ffiTestFunctions.providesSymbol('ReturnMaxUint8'));
|
|
Expect.isFalse(ffiTestFunctions.providesSymbol('SymbolNotInLibrary'));
|
|
|
|
if (Platform.isMacOS ||
|
|
Platform.isIOS ||
|
|
Platform.isAndroid ||
|
|
Platform.isLinux) {
|
|
DynamicLibrary p = DynamicLibrary.process();
|
|
Expect.isTrue(p.providesSymbol('dlopen'));
|
|
Expect.isFalse(p.providesSymbol('symbol_that_does_not_exist_in_process'));
|
|
}
|
|
|
|
DynamicLibrary e = DynamicLibrary.executable();
|
|
Expect.isTrue(e.providesSymbol('Dart_Invoke'));
|
|
Expect.isFalse(e.providesSymbol('symbol_that_does_not_exist_in_executable'));
|
|
}
|