Uh oh!
There was an error while loading. Please reload this page.
Replace C types with Rust types in std, closes #7313 - #10943
Conversation
brson
commented
Dec 13, 2013
Thanks for working on this cleanup. There's no specific reason for all the runtime functions returning weird combinations of pointer types, it's just the legacy of refactoring in various ways. Ideally, they all agree on the types and there are no casts. CString should probably keep using c_char. I think it's debatable whether the various logging and other runtime functions that deal in c strings should use *c_char or *u8 or some other typedef. This is all internal details so it doesn't matter too much. Ultimately we're probably going to want to be able to compile out |
fhahn
commented
Dec 13, 2013
So should various functions pass C strings around as u8? *c_str functions are used in a lot of places. When working on this issue, another idea came to my mind. There probably are a couple of unnecessary type casts in the rust source code and while working on this issue, I accidentally introduced another. Would a lint for unnecessary type casts be useful in generel? |
brson
commented
Dec 18, 2013
@fhahn Public API's that deal with C strings should definitely use |
brson
commented
Dec 19, 2013
A lint for unnecessary type casts sounds useful, but I guess we won't know until we try. |
fhahn
commented
Dec 19, 2013
Bors failed to test this PR, because it could not be merged. I've rebased pull request to the current master. |
emberian
commented
Dec 25, 2013
@fhahn an "unneeded cast" lint sounds great. |
fhahn
commented
Dec 25, 2013
fhahn
commented
Dec 25, 2013
There was a missing type cast on Windows, which failed the build bot. It should be fixed now, but unfortunately I won't have a Windows (or OS X) installation handy over the next couple of days, to test the patch on other platforms than Linux. |
fhahn
commented
Jan 14, 2014
@brson no worries, I didn't have much time to work on this patch the last couple of days. Before this patch gets merged, I'd like to clear up a few points:
|
There was a problem hiding this comment.
That should probably be uint, since 32-bit wants u32.
There was a problem hiding this comment.
I've changed the type to uint and added a cast to size_t at the cast.
fhahn
commented
Jan 16, 2014
I've updated the commit. It compiles on 64- and 32-bit linux. |
fhahn
commented
Jan 19, 2014
I've updated the commit again, it should compile on win32 now. |
sfackler
commented
Jan 21, 2014
@fhahn needs a rebase. |
fhahn
commented
Jan 21, 2014
@sfackler I'll look into it tomorrow. I managed to compile this patch on windows (win7 32 bit) without errors today, but 2 run-pass tests fail at the moment. Following code compiles on Windows, but fails when building libstd in stage 1: I've reverted this change and I'm using the old code (with two c_int variables): https://github.com/mozilla/rust/blob/master/src/libstd/os.rs#L740 |
adrientetar
commented
Jan 22, 2014
Needs a snapshot? |
There was a problem hiding this comment.
I think this file came back from the dead!
alexcrichton
commented
Jan 22, 2014
With the extra file removed, we can give this another go-through with bors. |
fhahn
commented
Jan 22, 2014
I've removed the file again and squashed everything in one commit. I think another try with bors would be good. |
…richton I've started working on a patch for #7313 . So far I tried to replace C types in `src/libstd/unstable/*` and related files. So far, I have two questions. Is there a convention for passing pointers around in `std` as Rust types? Sometimes pointers are passed around as `*c_char` (which seems to be an `*i8`), `*c_void` or `*u8`, which leads to a lot of casts. E.g: [`exchange_malloc`](https://github.com/fhahn/rust/compare/issue-7313-replace-c-types?expand=1#diff-39f44b8c3f4496abab854b3425ac1617R60) used to return a `*c_char` but the function in turn only calls `malloc_raw` which returns a `*c_void`. Is there a specific reason for this? The second question is about `CString` and related functions like `with_c_str`. At the moment these functions use `*c_char*`. Should I replace it with `*u8` or keep it, because it's an wrapper around classical C strings?
[`map_identity`]: recognize tuple identity function Fixesrust-lang#7189 This lint now recognizes `.map(|(a, b)| (a, b))` as a useless `map` call. changelog: [`map_identity`]: recognize tuple identity function
10943: feat: Enable completions for attributes r=Veykril a=Veykril Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
I've started working on a patch for #7313 . So far I tried to replace C types in
src/libstd/unstable/*and related files.So far, I have two questions. Is there a convention for passing pointers around in
stdas Rust types? Sometimes pointers are passed around as*c_char(which seems to be an*i8),*c_voidor*u8, which leads to a lot of casts. E.g:exchange_mallocused to return a*c_charbut the function in turn only callsmalloc_rawwhich returns a*c_void.Is there a specific reason for this?
The second question is about
CStringand related functions likewith_c_str. At the moment these functions use*c_char*. Should I replace it with*u8or keep it, because it's an wrapper around classical C strings?