[vm/ffi] Unwrapping Strings in FFI calls #47992
Labels
area-vm
Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends.
library-ffi
We could consider supporting unwrapping
String
s toPointer
s in FFI calls, this would make the following code much more ergonomic.New code, with the dart signature of
messageBox
havingString
rather thanPointer<Utf16>
as argument types:We would have to specify the encoding expected, which we could do with the type argument of
Pointer
. The encoding would work exactly aspackage:ffi
'stoNativeUtf8()
andtoNativeUtf16()
extension methods.The life-time would be duration of the FFI call. (And for callbacks until the GC collects the String copied to Dart memory.)
For leaf-calls, if the string happens to be in the right encoding, we could pass the interior pointer. #39787 (comment)
One of the questions to answer is how to select the transform. Do we want support for more encodings than Utf8/Utf16? Do we always zero-terminate? And because the
Utf16
andUtf8
are inpackage:ffi
, do we move them?Related:
The text was updated successfully, but these errors were encountered: