diff options
| author | Jacob Pratt <jacob@jhpratt.dev> | 2025-01-15 04:08:11 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-01-15 04:08:11 -0500 |
| commit | 229c91bc31835d7793efac6cb18a25f467889fb9 (patch) | |
| tree | bfd32540aaf85f7a33cb436d212ac200c8eb0362 /compiler/rustc_codegen_gcc | |
| parent | f9d8b6590dad2414e5ce9270df393b1fda3df266 (diff) | |
| parent | 86b86fa8fb89aca91aa176a0727b9f233cd14353 (diff) | |
| download | rust-229c91bc31835d7793efac6cb18a25f467889fb9.tar.gz rust-229c91bc31835d7793efac6cb18a25f467889fb9.zip | |
Rollup merge of #134143 - nyurik:err-nul, r=dtolnay
Convert `struct FromBytesWithNulError` into enum This PR renames the former `kind` enum from `FromBytesWithNulErrorKind` to `FromBytesWithNulError`, and removes the original struct. See https://github.com/rust-lang/libs-team/issues/493 ## Possible Changes - TBD * [x] should the new `enum FromBytesWithNulError` derive `Copy`? * [ ] should there be any new/changed attributes? * [x] add some more tests ## Problem One of `CStr` constructors, `CStr::from_bytes_with_nul(bytes: &[u8])` handles 3 cases: 1. `bytes` has one NULL as the last value - creates CStr 2. `bytes` has no NULL - error 3. `bytes` has a NULL in some other position - error The 3rd case is error that may require lossy conversion, but the 2nd case can easily be handled by the user code. Unfortunately, this function returns an opaque `FromBytesWithNulError` error in both 2nd and 3rd case, so the user cannot detect just the 2nd case - having to re-implement the entire function and bring in the `memchr` dependency. ## Motivating examples or use cases In [this code](https://github.com/gquintard/varnish-rs/blob/f86d7a87683b08d2e634d63e77d9dc1d24ed4a13/varnish-sys/src/vcl/ws.rs#L158), my FFI code needs to copy user's `&[u8]` into a C-allocated memory blob in a NUL-terminated `CStr` format. My code must first validate if `&[u8]` has a trailing NUL (case 1), no NUL (adds one on the fly - case 2), or NUL in the middle (3rd case - error). I had to re-implement `from_bytes_with_nul` and add `memchr`dependency just to handle the 2nd case. r? `@Amanieu`
Diffstat (limited to 'compiler/rustc_codegen_gcc')
0 files changed, 0 insertions, 0 deletions
