-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Cannot find documentation: How to use dart_api_dl.h correctly (espeically in Flutter Android and Flutter iOS)? #47356
Comments
//cc @kwalrath |
Hi @kwalrath May I know the suggestions? Thanks |
I don't know the answer, but I'd be happy to help with communicating the answer... once we have it. |
Thank you! Imho this api is quite important, so it show be documented how people should use it. |
I guess you have already found the include directory inside the dart sdk. There you can find Then you have to call Note, that this will only load a subset of the api functions. This includes only these, that a postfixed with I found this information in the first comment of But you can find an example implementation: sdk/samples/ffi/async/sample_async_callback.dart Lines 31 to 33 in ec829af
sdk/runtime/bin/ffi_test/ffi_test_functions_vmspecific.cc Lines 411 to 413 in ec829af
|
And while we are at it, why does it only load such a small subset of functions? I would like to be able, to directly build dart objects from C, which should be possible, with the whole set of functions! I think I will open a new Issue for this. EditIssue can be found here: #48497 |
@dcharkes, Can you help with this? Do I understand correctly that we can use functions from dart_api_dl.h on the c/c++/rust side to manipulate Dart_Hadle? Is it intended for this and is not deprecated? |
Yes, but only a subset of them, rather than using the Dart API, you can do callbacks back into Dart. Right now, there's a limitation that you have to be on the Dart thread to do those callbacks. Callbacks from other threads are being worked on #37022. So you cannot manipulate a handle such as asking the field of an object with the Dart API. The subset it runtime/include/dart_api_dl.h
Our end goal is to use callbacks instead of the Dart API. The Dart API is reflective and much slower than FFI. So, we want to get rid of this API if possible. However, some parts will stay.
Wait, that is all the parts of Please let me know if you have more questions. |
Thanks for your reply. Do I understand correctly that we should not rely on
but only on WeakPersistent and GC. |
You can also rely on PersistentHandle. (The normal For the use case with strong references from C/C++/Rust/Go you need persistent handles. (Sorry for missing those in my previous post.) |
@dcharkes, сan you help using dart_api_dl.c? |
How will you integrate, by source or compiling these to dynamic libraries? It doesn't matter if Of course it's fine too to make sure all your code uses a single copy. |
Hi thanks for the language! I wonder how to use dart_api_dl.h correctly (espeically in Flutter Android and Flutter iOS)? I have a Flutter app with some native C/C++/Rust(but you can just consider C) code. I want to call Dart_PostCObject from the native code, such that my dart (Flutter) program can receive some data.
I have tried to search on Google and dart doc, but do not find out anything useful.
My naive guess: In
my_code.c
, just#include "dart_api_dl.h"
. Then simply callDart_PostCObject_DL(my_port, my_data);
.However, is this the correct way? Thanks!
P.S. Of course, the Flutter app will be run on Android and iOS. Thus here are some very simple background if you are not familiar with how Dart is used in Flutter Android and iOS: For android, the native code is transformed into
my_native_lib.so
. In iOS, it seems to be static linked (not sure). So imho we need to consider the dynamic link and static linked cases. (I am not an expert in this, so there can be problems in what I said above.)The text was updated successfully, but these errors were encountered: