I was responding to a tweet contending that we should get rid of CString. I didn't say the libc thing couldn't be safer. I totally agree your thing works on that angle. Again, I used that same trick a million times in Stylo
-
This Tweet is unavailable.
-
-
Replying to @ManishEarth @withoutboats and
Having a &c_char value and then sending that to C code which expects to read the starting char as well as following chars until the null will give UB because it'll end up using pointers off the end of the object.
2 replies 0 retweets 1 like -
Replying to @Lokathor @ManishEarth and
I don't think `&` implies anything different than `*const` does WRT object size
1 reply 0 retweets 0 likes -
I've actually been wondering that too. It at least to LLVM is a hint that at least sizeof(T) many bytes are safely derefenceable, but idk if anything beyond that is strictly UB
1 reply 0 retweets 0 likes -
It doesn't have a different memory repr, but it does have narrowed provenance for the pointer you get. That's why the as_ptr method for slices first makes *const [T] and then makes *const T, in that very specific ordering. Sounds stupid, but RalfJ assures me it's true.
1 reply 0 retweets 2 likes -
Wow that basically eliminates the ability to have a safer version of `as_ptr` for many types then. That's really unfortunate.
1 reply 0 retweets 0 likes -
Does it? Why can't it be a transparent type that is basically just the pointer, but has a PhantomData reference to the original CStr?
1 reply 0 retweets 0 likes -
Because a transparent type that is basically just the pointer can't be passed to a function that takes a pointer
1 reply 0 retweets 0 likes -
Well yeah, my argument is still to have that type in the function signature as well, so you never touch a raw pointer at all
1 reply 0 retweets 0 likes
Sure, but now you have to change both `CString` *and* whatever it's being passed to, which you may or may not have control of. So I can't just release a "better CString" crate, I also have to release a "better libc" or whatever else to go along with it.
-
-
There's a ton of code out there that works with raw pointers, expecting all of those signatures to change is a pipe dream IMO
1 reply 0 retweets 2 likes -
Libc, maybe not, smaller APIs might work. like you can make a better curses api fairly easily or whatever.
1 reply 0 retweets 0 likes - 4 more replies
New conversation -
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.