Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upConsider using `&T` for returning pointers into the buffer of C wrapper types like CString #382
Comments
This comment has been minimized.
This comment has been minimized.
|
In general, the C wrapper types could use a rethink before stabilization (see this issue for example). @huonw are you interested in working together on a revised design? I had this on the stabilization schedule for November. |
This comment has been minimized.
This comment has been minimized.
|
See also rust-lang/rust#16035 and rust-lang/rust#9564 |
This comment has been minimized.
This comment has been minimized.
ben0x539
commented
Oct 13, 2014
|
Doesn't this suggest the wrong thing in terms of aliasing? |
This comment has been minimized.
This comment has been minimized.
|
These types and signatures have since been stabilized, so closing. |
alexcrichton
closed this
Feb 11, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
huonw commentedOct 9, 2014
Code like
is unsafe because the
CStringis deallocated at the end of the initializer forpleaving that pointer dangling and hence the dereference inside theprintln!is incorrect.as_ptris currently returning a*const i8, which, due to being a raw pointer, does not have any compiler-enforced connection to its parent object, meaning it can become dangling as demonstrated above.We could address the worse examples of this by making it instead return
&i8(connected toself), and since&i8implicitly coerces to*const i8I expect that most code will not have to change. However, I don't know of any other place that uses a&as a pointer-to-a-buffer (using it as a pointer to a single element is common, of course) so this would be a new 'feature'.Thoughts?