-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
marshalling va_list crossplatform p/invoke binding #9316
Comments
Additional info to clear things up: va_args are interpreted as an IntPtr and given to the formatting function. This works well on Windows, but did not have any luck on linux. |
Yes, varargs structure size and internal details are platform specific. IIRC, it is 3 pointer size on Linux x64. You can try to work around this by having Linux x64 specific version of the callback that takes 3 pointer sized structure as argument. |
@jkotas : Thanks for your answer! I will try that. Do you have a documentation, a source code or something for that "magic" 3-pointers size? |
Yes, size of
I think something like this should work: Does your binding have unmanaged part in C/C++? It would be better to deal with the varargs in C/C++. |
The question about the calling convention was just for my own understanding and curiosity 🙂 We currently do not have any unmanaged part in our binding, and I'd like to avoid that as much as possible, because that would mean compiling another lib for each platform (say win32/64, linux 32/64, linux rasp, android?, tizen?...) before building our .net interop library. Those native libraries would then be included in a cross platform "libvlcsharp" nuget package, but only one would be really used. This doesn't feel clean, and I'd prefer having everything in .net I'll come back here once I've done some testing. |
Sharing my findings here : This archived pdf https://www.uclibc.org/docs/psABI-x86_64.pdf at page 52 suggests that va_list is a structure with 4 fields (2 unsigned ints and 2 pointers) This pdf http://infocenter.arm.com/help/topic/com.arm.doc.ihi0042f/IHI0042F_aapcs.pdf at page 27 has the declaration of va_list for the ARM architecture |
Hi, That being said, and now that I am a little more confident about how these stuff works, would you like me to make some contributions on the clrvarargs.cpp file to support that? |
The MarshalToManagedVaList / MarshalToUnmanagedVaList methods are left overs from .NET Framework managed C++ support (#659). I do not think they are really used in .NET Core. Thank you for your offer to contribute to CoreCLR. Could you please clarify what you would like to add support for exactly? A good way to clarify it would be to show a C# code snippet that will demonstrate what one will be able to do in .NET Core with your change, that is not possible today. |
Ok, thanks for the clarification.
for windows. |
I think that we would just want to add back the .NET Framework ArgIterator for this, and make it usable for more than just the very narrow case of getting valist from one PInvoke and passing it to another PInvoke - it is non-trivial feature though. We have decided to drop the ArgIterator from .NET Core because of it is rarely used, it does not have first class support in C#, but it is expensive to implement for every new platform. |
I'm not quite familiar with the ArgIterator class, but from what I understood, it's for methods with Let's sum up
Still thinking, but what do you think of this kind of things?
where args is a va_list
This still needs reflexion. In any case, thanks for your consideration, Merry Christmas and Happy New Year :) |
It does not work in .NET Core. ArgIterator does not exist in .NET Core today. |
@jkotas __arglist doesn't work for a callback that needs to be supplied from the managed world to the unmanaged world. ArgIterator doesn't work as far as I can tell. I already tried to make it work but couldn't. Every method throws an exception. |
Yes, that's correct, for both .NET Core and .NET Framework in C#. I think it worked in .NET Framework in managed C++. The story for vargs interop was always far from perfect. |
Wondering if anyone could provide guidance on this: |
Have there been any updates on this issue? I seem to have ran into this issue as well while looking into writing a binding for raylib. |
Hello. We're not satisfied with the solution, but it seems to work. Still feels hackish. We have also explored the possibility to change the API, but we faced strong opposition from the libvlc developpers. Do you also need that for logs? |
Closing here and tracking in #48796. |
Hello from VideoLAN!
We're currently implementing a new crossplatform .NET binding over
libvlc
and have ran into a bit of an issue. Our libvlc log callback prototype looks like this:typedef void(* libvlc_log_cb) (void *data, int level, const libvlc_log_t *ctx, const char *fmt, va_list args)
We need to marshal this from native to managed in a crossplatform way.
What is the recommended way to perform
va_list
marshalling with P/Invoke in a crossplatform way (i.e. Xamarin platforms + friends)?From what we see in clrvarargs.cpp, we assume this is currently unsupported on Linux. What is needed to be done to be able to support this?
Related issues:
https://github.com/dotnet/coreclr/issues/9204
dotnet/standard#20
Thanks for any pointers you may provide.
/cc @jeremyVignelles
The text was updated successfully, but these errors were encountered: