Skip to content
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

Support for passing strings that contain nul accross the FFI boundary #94

Open
FeldrinH opened this issue Jun 29, 2023 · 2 comments
Open
Labels
c-core Interoptopus Core Crate enhancement Make existing things better. needs-discussion Something rather fuzzy, input wanted.

Comments

@FeldrinH
Copy link

FeldrinH commented Jun 29, 2023

In C all strings are terminated by a null byte (0x0), which means that strings using the idiomatic C representation cannot contain null.
However, many languages, including Python and C# support strings that store length as a separate value and can contain null. It would be nice if Interoptopus provided a canonical way to pass such strings accross the FFI boundary.

The only way to do this currently that I can figure out is to use a slice of bytes and convert manually whenever you cross the FFI boundary, which is incovenient and in for example Python requires copying the entire string for every conversion.

@ralfbiedert ralfbiedert added c-core Interoptopus Core Crate needs-discussion Something rather fuzzy, input wanted. enhancement Make existing things better. labels Jun 29, 2023
@ralfbiedert
Copy link
Owner

To comment I'd need more specific info, like how would that work in Python or C#, i.e., what specifically would be a new Rust type, and what would be the foreign counterparts?

@FeldrinH
Copy link
Author

FeldrinH commented Jun 29, 2023

what specifically would be a new Rust type, and what would be the foreign counterparts?

I was hoping that the foreign counterpart could be the the target language's built-in string type (e.g. str in Python or string in C#), but that might have technical complications. As for the Rust type I don't really know and as long as I can convert a normal std::string::String into it I don't think it makes much of a difference.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c-core Interoptopus Core Crate enhancement Make existing things better. needs-discussion Something rather fuzzy, input wanted.
Projects
None yet
Development

No branches or pull requests

2 participants