bottlenoselabs / c2cs

Generate C# bindings from a C header.
MIT License
250 stars 18 forks source link

`va_list` #15

Closed lithiumtoast closed 1 year ago

lithiumtoast commented 3 years ago

Found when generating bindings for flecs: https://github.com/SanderMertens/flecs

/* Append format string with argument list to a buffer.
 * Returns false when max is reached, true when there is still space */
FLECS_API
bool ecs_strbuf_vappend(
    ecs_strbuf_t *buffer,
    const char *fmt,
    va_list args);

It's not clear how va_list should be handled.

There is some discussion here on a similar issue: https://github.com/dotnet/runtime/issues/9316

lithiumtoast commented 3 years ago

It's my understanding that for flecs, functions which use va_list which are exported are optional. Short term solution is to ignore any exported function which has va_list in the parameters.

lithiumtoast commented 3 years ago

There is no immediate clear way to proceed with this. Best to tread water on this and look into it again at a future date.

For now, va_list is remapped into IntPtr where necessary to avoid compilation errors.

mfkl commented 2 years ago

heya, this might interest you https://github.com/jeremyVignelles/va-list-interop-demo

lithiumtoast commented 2 years ago

@mfkl Thanks.

va_list reading seems hard to do in a cross-platform way. Each platforms has its own implementation and I'm not sure it would work.

Rough. I'm working on adding support for multi-pass so that Clang can parse the translation unit using cross-compilation. Once that is finished I can expand the integration tests to do a dry-run of calling C# bindgen code for each platform and see what passes / fails. From there I can tackle this and add support for va_list but it will be limited by what hardware I have available either on cloud or in house.

lithiumtoast commented 2 years ago

Now that multi-pass is in, I'm taking a look at this again. While it would be interesting to do, I don't think I'm very interested in adding support right now myself. If someone wants to take a crack at it, I'm always open to contributions.

lithiumtoast commented 1 year ago

With usage of DisableRuntimeMarshallingAttribute .NET variadic argument method signatures are not supported; closing this out because DisableRuntimeMarshallingAttribute is what should be used for .NET 7+ with C2CS generated bindings.