Re: [PATCH v5 6/7] rust: Add read_poll_timeout functions

From: Rasmus Villemoes
Date: Thu Nov 07 2024 - 07:50:35 EST


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.

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).

Rasmus