Skip to content

[ffi] Support passing and returning composites (structs) by value. #36730

@mraleph

Description

@mraleph

I wanted to writing bindings for libclang (so that I can generate bindings from C/C++ header files automatically), but I discovered that libclang API uses structs passed and returned by value.

typedef struct {
  unsigned int_data[4];
  void *ptr_data;
} CXToken;

typedef struct {
  const void *data;
  unsigned private_flags;
} CXString;

CINDEX_LINKAGE CXString clang_getTokenSpelling(CXTranslationUnit, CXToken);

So I can't really bind to this API. There are some interesting design problems to resolve: e.g. when a structure is returned by value who manages the memory of that struct and how do we prevent people from making a mistake of passing address of that struct to some other method.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-vmUse area-vm for VM related issues, including code coverage, and the AOT and JIT backends.library-ffi

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions