You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using FFI to load a function that has a handle in the signature, you can either put Handle in the signature, or Pointer<Void>. If you use Handle, the FFI trampoline will automatically convert the C Dart_Handle to a Dart Object. If you use Pointer<Void>, you'll just get an opaque value that is C compatible.
I have a use case where I want to put a Dart_PersistentHandle to a Dart Function in a C struct. I used FFI to load Dart_NewPersistentHandle and Dart_DeletePersistentHandle. I loaded Dart_NewPersistentHandle as void*(Handle) so I could pass in an Object and get back something I could stick in the struct, and loaded Dart_DeletePersistentHandle as void(void*) so I could delete the handle later.
But I also wanted to get the Function out of the C struct so I could call it, and I couldn't find a way of converting the Pointer<Void> that was the Dart_PersistentHandle to a Dart Object. My hacky work around was to load another copy of Dart_NewPersistentHandle and Dart_DeletePersistentHandle, this time as Handle(void*) and void(Handle), so I could use the generated trampolines to do the conversion.
When using FFI to load a function that has a handle in the signature, you can either put
Handle
in the signature, orPointer<Void>
. If you useHandle
, the FFI trampoline will automatically convert the CDart_Handle
to a DartObject
. If you usePointer<Void>
, you'll just get an opaque value that is C compatible.I have a use case where I want to put a
Dart_PersistentHandle
to a DartFunction
in a C struct. I used FFI to loadDart_NewPersistentHandle
andDart_DeletePersistentHandle
. I loadedDart_NewPersistentHandle
asvoid*(Handle)
so I could pass in anObject
and get back something I could stick in the struct, and loadedDart_DeletePersistentHandle
asvoid(void*)
so I could delete the handle later.But I also wanted to get the
Function
out of the C struct so I could call it, and I couldn't find a way of converting thePointer<Void>
that was theDart_PersistentHandle
to a DartObject
. My hacky work around was to load another copy ofDart_NewPersistentHandle
andDart_DeletePersistentHandle
, this time asHandle(void*)
andvoid(Handle)
, so I could use the generated trampolines to do the conversion.Context: dart-lang/native#233
@dcharkes How hard would it be to add a util to
package:ffi
that can convertDart_Handle
etc to a DartObject
?The text was updated successfully, but these errors were encountered: