Skip to content

Commit 76c8ff5

Browse files
committed
rust: replace kernel::str::CStr w/ core::ffi::CStr
This picks up from Michal Rostecki's work[0]. Per Michal's guidance I have omitted Co-authored tags, as the end result is quite different. Link: https://lore.kernel.org/rust-for-linux/[email protected]/t/#u [0] Closes: Rust-for-Linux#1075 To: Michal Rostecki <[email protected]> To: Miguel Ojeda <[email protected]> To: Alex Gaynor <[email protected]> To: Boqun Feng <[email protected]> To: Gary Guo <[email protected]> To: Björn Roy Baron <[email protected]> To: Benno Lossin <[email protected]> To: Andreas Hindborg <[email protected]> To: Alice Ryhl <[email protected]> To: Trevor Gross <[email protected]> To: Brendan Higgins <[email protected]> To: David Gow <[email protected]> To: Rae Moar <[email protected]> To: Danilo Krummrich <[email protected]> To: Maarten Lankhorst <[email protected]> To: Maxime Ripard <[email protected]> To: Thomas Zimmermann <[email protected]> To: David Airlie <[email protected]> To: Simona Vetter <[email protected]> To: Greg Kroah-Hartman <[email protected]> To: "Rafael J. Wysocki" <[email protected]> To: Luis Chamberlain <[email protected]> To: Russ Weight <[email protected]> To: FUJITA Tomonori <[email protected]> To: Rob Herring <[email protected]> To: Saravana Kannan <[email protected]> To: Peter Zijlstra <[email protected]> To: Ingo Molnar <[email protected]> To: Will Deacon <[email protected]> To: Waiman Long <[email protected]> To: Nathan Chancellor <[email protected]> To: Nick Desaulniers <[email protected]> To: Bill Wendling <[email protected]> To: Justin Stitt <[email protected]> To: Andrew Lunn <[email protected]> To: Heiner Kallweit <[email protected]> To: Russell King <[email protected]> To: "David S. Miller" <[email protected]> To: Eric Dumazet <[email protected]> To: Jakub Kicinski <[email protected]> To: Paolo Abeni <[email protected]> To: Bjorn Helgaas <[email protected]> To: Arnd Bergmann <[email protected]> To: Jens Axboe <[email protected]> To: Benno Lossin <[email protected]> To: Krzysztof Wilczyński <[email protected]> Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Signed-off-by: Tamir Duberstein <[email protected]> --- Changes in v11: - Use `quote_spanned!` to avoid `use<'a, T>` and generally reduce manual token construction. - Add a commit to simplify `quote_spanned!`. - Drop first commit in favor of https://lore.kernel.org/rust-for-linux/[email protected]/. (Miguel Ojeda) - Correctly handle expressions such as `pr_info!("{a}", a = a = a)`. (Benno Lossin) - Avoid dealing with `}}` escapes, which is not needed. (Benno Lossin) - Revert some unnecessary changes. (Benno Lossin) - Link to v10: https://lore.kernel.org/r/[email protected] Changes in v10: - Rebase on cbeaa41. - Implement Alice's suggestion to use a proc macro to work around orphan rules otherwise preventing `core::ffi::CStr` to be directly printed with `{}`. - Link to v9: https://lore.kernel.org/r/[email protected] Changes in v9: - Rebase on rust-next. - Restore `impl Display for BStr` which exists upstream[1]. - Link: https://doc.rust-lang.org/nightly/std/bstr/struct.ByteStr.html#impl-Display-for-ByteStr [1] - Link to v8: https://lore.kernel.org/r/[email protected] Changes in v8: - Move `{from,as}_char_ptr` back to `CStrExt`. This reduces the diff some. - Restore `from_bytes_with_nul_unchecked_mut`, `to_cstring`. - Link to v7: https://lore.kernel.org/r/[email protected] Changes in v7: - Rebased on mainline. - Restore functionality added in commit a321f3a ("rust: str: add {make,to}_{upper,lower}case() to CString"). - Used `diff.algorithm patience` to improve diff readability. - Link to v6: https://lore.kernel.org/r/[email protected] Changes in v6: - Split the work into several commits for ease of review. - Restore `{from,as}_char_ptr` to allow building on ARM (see commit message). - Add `CStrExt` to `kernel::prelude`. (Alice Ryhl) - Remove `CStrExt::from_bytes_with_nul_unchecked_mut` and restore `DerefMut for CString`. (Alice Ryhl) - Rename and hide `kernel::c_str!` to encourage use of C-String literals. - Drop implementation and invocation changes in kunit.rs. (Trevor Gross) - Drop docs on `Display` impl. (Trevor Gross) - Rewrite docs in the style of the standard library. - Restore the `test_cstr_debug` unit tests to demonstrate that the implementation has changed. Changes in v5: - Keep the `test_cstr_display*` unit tests. Changes in v4: - Provide the `CStrExt` trait with `display()` method, which returns a `CStrDisplay` wrapper with `Display` implementation. This addresses the lack of `Display` implementation for `core::ffi::CStr`. - Provide `from_bytes_with_nul_unchecked_mut()` method in `CStrExt`, which might be useful and is going to prevent manual, unsafe casts. - Fix a typo (s/preffered/prefered/). Changes in v3: - Fix the commit message. - Remove redundant braces in `use`, when only one item is imported. Changes in v2: - Do not remove `c_str` macro. While it's preferred to use C-string literals, there are two cases where `c_str` is helpful: - When working with macros, which already return a Rust string literal (e.g. `stringify!`). - When building macros, where we want to take a Rust string literal as an argument (for caller's convenience), but still use it as a C-string internally. - Use Rust literals as arguments in macros (`new_mutex`, `new_condvar`, `new_mutex`). Use the `c_str` macro to convert these literals to C-string literals. - Use `c_str` in kunit.rs for converting the output of `stringify!` to a `CStr`. - Remove `DerefMut` implementation for `CString`. --- b4-submit-tracking --- # This section is used internally by b4 prep for tracking purposes. { "series": { "revision": 11, "change-id": "20250201-cstr-core-d4b9b69120cf", "prefixes": [], "from-thread": "[email protected]", "history": { "v6": [ "[email protected]" ], "v7": [ "[email protected]" ], "v8": [ "[email protected]" ], "v9": [ "[email protected]" ], "v10": [ "[email protected]" ] } } }
1 parent bfc3cd8 commit 76c8ff5

File tree

0 file changed

+0
-0
lines changed

    0 file changed

    +0
    -0
    lines changed

    0 commit comments

    Comments
     (0)