-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dart:ffi asFunction / lookupFunction static function vs instance method #35903
Comments
Let it crash? Or throw in If this was done using static extension types instead then dynamic invocation would not work. Much of the ffi functionality is compiler magic that works similar to this, so I'd not be worried if it just doesn't work when used through dynamic. It's already so very magical. The trampoline you create, is it for a particular function, or can it be reused for multiple functions with the same type, just with different native addresses? If it was the latter, you could create it when you see |
We will keep using instance methods for now and use extension methods once available, to ease migration. (Throwing an exception on a dynamic call). |
This should be addressed now that we have extension methods. |
This prevents them from being called dynamically. Moreover, it prevents asFunction from being called on a non-NativeFunction type argument, simplifying the amount of manual checks. Note that this CL had to change the CFE and analzyer, and their tests (including mock_sdk) as well. This can potentially be a breaking change, as the extension methods are only visible when `dart:ffi` is imported, while methods on objects are always visible. Issue: #35903 Change-Id: I1e291f154228d5d9a34b21a022088bf493f6557d Cq-Include-Trybots: luci.dart.try:vm-ffi-android-debug-arm-try,vm-ffi-android-debug-arm64-try,app-kernel-linux-debug-x64-try,vm-kernel-linux-debug-ia32-try,vm-kernel-win-debug-x64-try,vm-kernel-win-debug-ia32-try,vm-kernel-precomp-linux-debug-x64-try,vm-dartkb-linux-release-x64-abi-try,vm-kernel-precomp-android-release-arm64-try,vm-kernel-asan-linux-release-x64-try,vm-kernel-linux-release-simarm-try,vm-kernel-linux-release-simarm64-try,vm-kernel-precomp-android-release-arm_x64-try,vm-kernel-precomp-obfuscate-linux-release-x64-try,dart-sdk-linux-try,analyzer-analysis-server-linux-try,analyzer-linux-release-try,front-end-linux-release-x64-try,vm-kernel-precomp-win-release-x64-try,vm-kernel-mac-debug-x64-try,analyzer-nnbd-linux-release-try,dart2js-nnbd-linux-x64-chrome-try,ddc-nnbd-linux-release-chrome-try,front-end-nnbd-linux-release-x64-try,vm-kernel-nnbd-linux-debug-x64-try,vm-kernel-nnbd-linux-release-x64-try Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/135463 Commit-Queue: Daco Harkes <[email protected]> Reviewed-by: Martin Kustermann <[email protected]>
Currently
Pointer.asFunction
andDynamicLibrary.lookup
are instance methods.However, this enables users to call these dynamically.
Unfortunately we cannot at compile-time discover this, which means that we cannot generate trampolines in AOT mode.
We have two possible solutions:
f = asFunction(q)
The second option is a bit less ergonomic, but safer.
The text was updated successfully, but these errors were encountered: