Skip to content

[vm/ffi] Support .address.cast() in leaf calls #55971

Closed
@dcharkes

Description

@dcharkes

Many functions with buffers take a void*, for example https://en.cppreference.com/w/c/io/fread.

However, using a Uint8List and .address yields a Pointer<Uint8>.

It would be useful to be able to pass uint8list.address.cast(). That would prevent having to modify the FFIgen generated function signature.

Thanks for the suggestion @brianquinlan!

For anyone willing to contribute, the implementation is in:

/// Converts a single parameter with argument for [_replaceNativeCall].
(
/// '' for non-Pointer.
/// 'P' for Pointer.
/// 'T' for TypedData.
/// 'C' for _Compound (TypedData/Pointer and offset in bytes).
/// 'E' for errors.
String methodPostFix,
DartType parameterType,
Expression argument,
) _replaceNativeCallParameterAndArgument(
VariableDeclaration parameter,
DartType parameterType,
Expression argument,
int fileOffset,
) {

The implementation should find the cast() invocation and use its receiver instead (effectively ignoring the cast expression as a no-op).

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-native-interopUsed for native interop related issues, including FFI.contributions-welcomeContributions welcome to help resolve this (the resolution is expected to be clear from the issue)library-ffi

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions