-
-
Notifications
You must be signed in to change notification settings - Fork 48
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
Interface with C unions #77
Comments
There was some initial discussion about this at the sync call. The primary concern is around making sure that use of such a "C union" type in a package would qualify as FFI use, for the purposes of Pony's security feature of allowing the user calling the compiler to limit FFI calls (which are inherently memory-unsafe operations) to specific whitelisted packages. Any use of a C union field would be inherently memory-unsafe in the same way, so we'd want to limit it as well, but there are some technical questions about how exactly that would be done. |
Not sure if this is the right issue, but it seems that some C libraries requires support for C unions. SDL2 for example won't work in pony, as it uses a union for its events (SDL_events.h). It would be nice to use unsafe C unions for FFI, but somehow disallow it for regular pony code. E.g. by prefixing it with @ to indicate that it is an unsafe FFI feature. |
Has there been any progress regarding this issue? I wanted to use SFML for some simulations and UI, but it turned that Pony's FFI can't handle C unions and returning a struct from a C function, thus forcing me to write a lot (really, a lot) of C code to hide all of that from Pony. And this meant that using Pony wasn't an option anymore. |
No one has written an RFC for this at this time @KoczurekK. |
Currently there is no possibility in pony to map directly to C
unions. Since unions are much similar to struct type, we could
just have annotation, for example:
LLVM does not have union types. So allocation could be done
using size of biggest union field. Accessing fields could be
done just by casting to apropriate type.
Here is example for LLVM IR generated for union types:
Results in generated IR
The text was updated successfully, but these errors were encountered: