mbox icon indicating copy to clipboard operation
mbox copied to clipboard

How to take ownership of an array of strings allocated in C?

Open jplatte opened this issue 8 years ago • 0 comments

The crate documentation says this about MArray<T>:

MArray<T> — A null-terminated array, which can be used to represent e.g. array of C strings terminated by a null pointer.

However, there are no examples anywhere and I can't figure out how to do this. I've been using my own non-generic version of MArray, as well as my own own version of MString (or rather, MBox<CStr>) so far, where I have just casted from *mut *mut c_char to *mut MallocCString, based on the assumption that MallocCString, which is just a tuple struct containing a *mut c_char, has the same representation as the plain *mut c_char. But I'd like to cut down on the amount of stuff I'm reimplementing in my crate, as well as my rather uneducated use of unsafe.

My current code can be found here, for reference.

jplatte avatar Jun 17 '17 12:06 jplatte