<feed xmlns='http://www.w3.org/2005/Atom'>
<title>rust/library/std/src/ffi/c_str.rs, branch perf-tmp</title>
<subtitle>https://github.com/rust-lang/rust
</subtitle>
<id>http://git.dreamy.place/mirrors/rust/atom?h=perf-tmp</id>
<link rel='self' href='http://git.dreamy.place/mirrors/rust/atom?h=perf-tmp'/>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/'/>
<updated>2024-07-28T22:26:52+00:00</updated>
<entry>
<title>Reformat `use` declarations.</title>
<updated>2024-07-28T22:26:52+00:00</updated>
<author>
<name>Nicholas Nethercote</name>
<email>n.nethercote@gmail.com</email>
</author>
<published>2024-07-28T22:13:50+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=84ac80f1921afc243d71fd0caaa4f2838c294102'/>
<id>urn:sha1:84ac80f1921afc243d71fd0caaa4f2838c294102</id>
<content type='text'>
The previous commit updated `rustfmt.toml` appropriately. This commit is
the outcome of running `x fmt --all` with the new formatting options.
</content>
</entry>
<entry>
<title>Add std::ffi::c_str modules</title>
<updated>2024-02-22T07:09:26+00:00</updated>
<author>
<name>ltdk</name>
<email>usr@ltdk.xyz</email>
</author>
<published>2023-08-19T22:46:11+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=1ea6cd715e01f14395ee3f7d944ecc68adf0dde4'/>
<id>urn:sha1:1ea6cd715e01f14395ee3f7d944ecc68adf0dde4</id>
<content type='text'>
</content>
</entry>
<entry>
<title>library: Move `CStr` to libcore, and `CString` to liballoc</title>
<updated>2022-04-14T18:53:11+00:00</updated>
<author>
<name>Vadim Petrochenkov</name>
<email>vadim.petrochenkov@gmail.com</email>
</author>
<published>2022-02-16T11:23:37+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=5bee741a08a267f68ac6c3d24dadfe927bd45008'/>
<id>urn:sha1:5bee741a08a267f68ac6c3d24dadfe927bd45008</id>
<content type='text'>
</content>
</entry>
<entry>
<title>add CStr::from_bytes_until_nul</title>
<updated>2022-03-18T22:46:49+00:00</updated>
<author>
<name>Eric Seppanen</name>
<email>eds@reric.net</email>
</author>
<published>2022-03-15T23:47:26+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=d5fe4cad5a68a305b9fa7d421b0ffa358b14b0a9'/>
<id>urn:sha1:d5fe4cad5a68a305b9fa7d421b0ffa358b14b0a9</id>
<content type='text'>
This adds a member fn that converts a slice into a CStr; it is intended
to be safer than from_ptr (which is unsafe and may read out of bounds),
and more useful than from_bytes_with_nul (which requires that the caller
already know where the nul byte is).

feature gate: cstr_from_bytes_until_nul

Also add an error type FromBytesUntilNulError for this fn.
</content>
</entry>
<entry>
<title>Use implicit capture syntax in format_args</title>
<updated>2022-03-10T15:23:40+00:00</updated>
<author>
<name>T-O-R-U-S</name>
<email>bageliq@protonmail.com</email>
</author>
<published>2022-02-12T19:16:17+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=72a25d05bf1a4b155d74139ef700ff93af6d8e22'/>
<id>urn:sha1:72a25d05bf1a4b155d74139ef700ff93af6d8e22</id>
<content type='text'>
This updates the standard library's documentation to use the new syntax. The
documentation is worthwhile to update as it should be more idiomatic
(particularly for features like this, which are nice for users to get acquainted
with). The general codebase is likely more hassle than benefit to update: it'll
hurt git blame, and generally updates can be done by folks updating the code if
(and when) that makes things more readable with the new format.

A few places in the compiler and library code are updated (mostly just due to
already having been done when this commit was first authored).
</content>
</entry>
<entry>
<title>Rollup merge of #93979 - SUPERCILEX:debug_check, r=dtolnay</title>
<updated>2022-02-19T05:45:30+00:00</updated>
<author>
<name>Matthias Krüger</name>
<email>matthias.krueger@famsik.de</email>
</author>
<published>2022-02-19T05:45:30+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=26dd6ac8302ab7230cd2d78797910931e4b83015'/>
<id>urn:sha1:26dd6ac8302ab7230cd2d78797910931e4b83015</id>
<content type='text'>
Add debug assertions to validate NUL terminator in c strings

The `unchecked` variants from the stdlib usually perform the check anyway if debug assertions are on (for example, `unwrap_unchecked`). This PR does the same thing for `CStr` and `CString`, validating the correctness for the NUL byte in debug mode.
</content>
</entry>
<entry>
<title>Rollup merge of #89869 - kpreid:from-doc, r=yaahc</title>
<updated>2022-02-17T05:29:57+00:00</updated>
<author>
<name>Matthias Krüger</name>
<email>matthias.krueger@famsik.de</email>
</author>
<published>2022-02-17T05:29:57+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=1cc0ae4cbbcb9909035b5b99fc20bf6b79f4010c'/>
<id>urn:sha1:1cc0ae4cbbcb9909035b5b99fc20bf6b79f4010c</id>
<content type='text'>
Add documentation to more `From::from` implementations.

For users looking at documentation through IDE popups, this gives them relevant information rather than the generic trait documentation wording “Performs the conversion”. For users reading the documentation for a specific type for any reason, this informs them when the conversion may allocate or copy significant memory versus when it is always a move or cheap copy.

Notes on specific cases:
* The new documentation for `From&lt;T&gt; for T` explains that it is not a conversion at all.
* Also documented `impl&lt;T, U&gt; Into&lt;U&gt; for T where U: From&lt;T&gt;`, the other central blanket implementation of conversion.
* The new documentation for construction of maps and sets from arrays of keys mentions the handling of duplicates. Future work could be to do this for *all* code paths that convert an iterable to a map or set.
* I did not add documentation to conversions of a specific error type to a more general error type.
* I did not add documentation to unstable code.

This change was prepared by searching for the text "From&lt;... for" and so may have missed some cases that for whatever reason did not match. I also looked for `Into` impls but did not find any worth documenting by the above criteria.
</content>
</entry>
<entry>
<title>Add debug asserts to validate NUL terminator in c strings</title>
<updated>2022-02-17T02:34:17+00:00</updated>
<author>
<name>Alex Saveau</name>
<email>saveau.alexandre@gmail.com</email>
</author>
<published>2022-02-13T23:04:11+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=897c8d0ab9d3cb2cf1c112f31c6ac3e93d9884bc'/>
<id>urn:sha1:897c8d0ab9d3cb2cf1c112f31c6ac3e93d9884bc</id>
<content type='text'>
Signed-off-by: Alex Saveau &lt;saveau.alexandre@gmail.com&gt;
</content>
</entry>
<entry>
<title>Auto merge of #87869 - thomcc:skinny-io-error, r=yaahc</title>
<updated>2022-02-07T20:32:56+00:00</updated>
<author>
<name>bors</name>
<email>bors@rust-lang.org</email>
</author>
<published>2022-02-07T20:32:56+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=734368a200904ef9c21db86c595dc04263c87be0'/>
<id>urn:sha1:734368a200904ef9c21db86c595dc04263c87be0</id>
<content type='text'>
Make io::Error use 64 bits on targets with 64 bit pointers.

I've wanted this for a long time, but didn't see a good way to do it without having extra allocation. When looking at it yesterday, it was more clear what to do for some reason.

This approach avoids any additional allocations, and reduces the size by half (8 bytes, down from 16). AFAICT it doesn't come additional runtime cost, and the compiler seems to do a better job with code using it.

Additionally, this `io::Error` has a niche (still), so `io::Result&lt;()&gt;` is *also* 64 bits (8 bytes, down from 16), and `io::Result&lt;usize&gt;` (used for lots of io trait functions) is 2x64 bits (16 bytes, down from 24 — this means on x86_64 it can use the nice rax/rdx 2-reg struct return). More generally, it shaves a whole 64 bit integer register off of the size of basically any `io::Result&lt;()&gt;`.

(For clarity: Improving `io::Result` (rather than io::Error) was most of the motivation for this)

On 32 bit (or other non-64bit) targets we still use something equivalent the old repr — I don't think think there's improving it, since one of the fields it stores is a `i32`, so we can't get below that, and it's already about as close as we can get to it.

---

### Isn't Pointer Tagging Dodgy?

The details of the layout, and why its implemented the way it is, are explained in the header comment of library/std/src/io/error/repr_bitpacked.rs. There's probably more details than there need to be, but I didn't trim it down that much, since there's a lot of stuff I did deliberately, that might have not seemed that way.

There's actually only one variant holding a pointer which gets tagged. This one is the (holder for the) user-provided error.

I believe the scheme used to tag it is not UB, and that it preserves pointer provenance (even though often pointer tagging does not) because the tagging operation is just `core::ptr::add`, and untagging is `core::ptr::sub`. The result of both operations lands inside the original allocation, so it would follow the safety contract of `core::ptr::{add,sub}`.

The other pointer this had to encode is not tagged — or rather, the tagged repr is equivalent to untagged (it's tagged with 0b00, and has &gt;=4b alignment, so we can reuse the bottom bits). And the other variants we encode are just integers, which (which can be untagged using bitwise operations without worry — they're integers).

CC `@RalfJung` for the stuff in repr_bitpacked.rs, as my comments are informed by a lot of the UCG work, but it's possible I missed something or got it wrong (even if the implementation is okay, there are parts of the header comment that says things like "We can't do $x" which could be false).

---

### Why So Many Changes?

The repr change was mostly internal, but changed one widely used API: I had to switch how `io::Error::new_const` works.

This required switching `io::Error::new_const` to take the full message data (including the kind) as a `&amp;'static`, rather than just the string. This would have been really tedious, but I made a macro that made it much simpler, but it was a wide change since `io::Error::new_const` is used everywhere.

This included changing files for a lot of targets I don't have easy access to (SGX? Haiku? Windows? Who has heard of these things), so I expect there to be spottiness in CI initially, unless luck is on my side.

Anyway this large only tangentially-related change is all in the first commit (although that commit also pulls the previous repr out into its own file), whereas the packing stuff is all in commit 2.

---

P.S. I haven't looked at all of this since writing it, and will do a pass over it again later, sorry for any obvious typos or w/e. I also definitely repeat myself in comments and such.

(It probably could use more tests too. I did some basic testing, and made it so we `debug_assert!` in cases the decode isn't what we encoded, but I don't know the degree which I can assume libstd's testing of IO would exercise this. That is: it wouldn't be surprising to me if libstds IO testing were minimal, especially around error cases, although I have no idea).
</content>
</entry>
<entry>
<title>rewrite from_bytes_with_nul to match code style in from_vec_with_nul</title>
<updated>2022-02-06T19:07:03+00:00</updated>
<author>
<name>Inteon</name>
<email>42113979+inteon@users.noreply.github.com</email>
</author>
<published>2022-02-06T19:07:03+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=afb7a502f6e4e564d034ebf9601f4a4a13551f15'/>
<id>urn:sha1:afb7a502f6e4e564d034ebf9601f4a4a13551f15</id>
<content type='text'>
Signed-off-by: Inteon &lt;42113979+inteon@users.noreply.github.com&gt;
</content>
</entry>
</feed>
