cbindgen icon indicating copy to clipboard operation
cbindgen copied to clipboard

Why does std::ffi, specifically CStr and CString not (at least fully in the case of std::ffi) work?

Open RandomGamingDev opened this issue 3 years ago • 3 comments

I do not know whether or not this is purposeful due to some limitations or something of the sort, but a lot of the types from std::ffi don't seem to be supported. For example, trying to use CStr and CString in external functions, or the other types that aren't supported gives this message: WARN: Can't find <type>. This usually means that this type was incompatible or not found. Why doesn't this work, and if it does work, how do I get it working?

RandomGamingDev avatar Sep 01 '22 23:09 RandomGamingDev

So... CString is not supposed to work, because it's not ABI-compatible, but we should add it to the opaque type list here: https://github.com/eqrion/cbindgen/blob/ccd1f0e9ec2369735b9481c85057b9c65b6b0908/src/bindgen/parser.rs#L430-L460 so that you can pass them by reference or so probably. Same for CStr, which is not ffi-safe either, actually (so you shouldn't use them in function signatures, see the docs).

emilio avatar Sep 02 '22 09:09 emilio

Thanks for telling me, I'll pass an array of chars instead.

RandomGamingDev avatar Sep 06 '22 20:09 RandomGamingDev

Is this issue supposed to be closed?

youknowone avatar Nov 22 '23 05:11 youknowone