-
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
Implement support for creating isolate independent native functions code in dart:ffi #47778
Comments
Assigning to myself for the initial design. |
Another use case for this is async callbacks: we could potentially compile a function using the Dart API turning a callback into |
@mraleph is this work complete sufficiently to close out the issue? |
This is in early design stages. |
half year passed and only 2 month left to Dart 2.18 release, any update on this? |
@dcharkes has done some initial prototyping and we have been discussing different approaches. It currently looks possible that we decide against implementing isolate independent code as a embedded DSL and choose to follow cgo route instead - simplify bundling C/C++ code with the Dart packages as this would address the same problem in a more robust way. But the final decision is not yet made. |
@calvin2021y We have a prototype on https://dart-review.googlesource.com/c/sdk/+/246241/ if you know how to build the Dart SDK and want to try it out. |
I like this much better, will try the Dart SDK branch. |
Any update about this @calvin2021y ? |
Cleared the milestone to reflect the change in our plans. |
Side note, if you just need a finalizer to reliably free a pointer, this works without any extra C code for a guaranteed freeing of your native resources: // filename: lib/src/utils/memory.dart
/// A generic [NativeFinalizer] to free any pointer by calling the C function
/// `free`. It's kind of like a workaround to combat the restriction of
/// [NativeFinalizer] (which only accepts a C function, not a Dart
/// function).
final freenalizer = NativeFinalizer(DynamicLibrary.executable().lookup('free')); Then, import 'dart:ffi';
import 'package:mypackage/src/utils/memory.dart';
class Foo extends Finalizable {
Pointer<X> _ptr = calloc();
Foo() {
freenalizer.attach(this, _ptr.cast());
}
} |
That is not entirely true. On Windows |
How would you embed C++ code when compiling Dart as an AOT executable and when running in JIT mode? |
Currently, you bundle dynamic libraries.
This is not ideal. Future:
|
The idea of isolate independent native code is described in finalization proposal
The text was updated successfully, but these errors were encountered: