Re: [PATCH v5 6/7] rust: Add read_poll_timeout functions
From: Alice Ryhl
Date: Thu Nov 07 2024 - 08:07:03 EST
On Thu, Nov 7, 2024 at 1:50 PM Rasmus Villemoes <ravi@xxxxxxxxx> wrote:
>
> On Fri, Nov 01 2024, FUJITA Tomonori <fujita.tomonori@xxxxxxxxx> wrote:
>
> > For the proper debug info, readx_poll_timeout() and __might_sleep()
> > are implemented as a macro. We could implement them as a normal
> > function if there is a clean way to get a null-terminated string
> > without allocation from core::panic::Location::file().
>
> Would it be too much to hope for either a compiler flag or simply
> default behaviour for having the backing, static store of the file!()
> &str being guaranteed to be followed by a nul character? (Of course that
> nul should not be counted in the slice's length). That would in general
> increase interop with C code.
>
> This is hardly the last place where Rust code would pass
> Location::file() into C, and having to pass that as a (ptr,len) pair
> always and updating the receiving C code to use %.*s seems like an
> uphill battle, especially when the C code passes the const char* pointer
> through a few layers before it is finally passed to a printf-like
> function.
This is actively being discussed at:
https://github.com/rust-lang/libs-team/issues/466
> And creating the nul-terminated strings with c_str! needlessly doubles
> the storage needed for the file names (unless the rust compiler is smart
> enough to then re-use the c_str result for the backing store of the
> file!() &str).
For the case of c_str!(file!()), the compiler should do the right
thing. Not via deduplication, but via removal of unused globals.
Alice