qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
To: Zhao Liu <zhao1.liu@intel.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
	qemu-devel@nongnu.org, qemu-rust@nongnu.org, shentey@gmail.com
Subject: Re: [PATCH] rust: log: implement io::Write
Date: Tue, 24 Jun 2025 11:22:10 +0300	[thread overview]
Message-ID: <CAAjaMXZvi7FxdOgC8xpw5O1sQD3ncZSpRQpNEetNDMR3MdfhvA@mail.gmail.com> (raw)
In-Reply-To: <aFpR7+RMBlgt5DTD@intel.com>

On Tue, Jun 24, 2025 at 10:00 AM Zhao Liu <zhao1.liu@intel.com> wrote:
>
> >  /// A macro to log messages conditionally based on a provided mask.
> > @@ -24,6 +96,8 @@ pub enum Log {
> >  /// log level and, if so, formats and logs the message. It is the Rust
> >  /// counterpart of the `qemu_log_mask()` macro in the C implementation.
> >  ///
> > +/// Errors from writing to the log are ignored.
> > +///
> >  /// # Parameters
> >  ///
> >  /// - `$mask`: A log level mask. This should be a variant of the `Log` enum.
> > @@ -62,12 +136,9 @@ macro_rules! log_mask_ln {
> >          if unsafe {
> >              (::qemu_api::bindings::qemu_loglevel & ($mask as std::os::raw::c_int)) != 0
> >          } {
> > -            let formatted_string = format!("{}\n", format_args!($fmt $($args)*));
> > -            let c_string = std::ffi::CString::new(formatted_string).unwrap();
> > -
> > -            unsafe {
> > -                ::qemu_api::bindings::qemu_log(c_string.as_ptr());
> > -            }
> > +            #[allow(unused_must_use)]
>
> I found this doesn't work :-( :
>
> error: unused `Result` that must be used
>    --> ../rust/hw/char/pl011/src/device.rs:281:21
>     |
> 281 |                     log_mask_ln!(Log::Unimp, "pl011: DMA not implemented");
>     |                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>     |
>     = note: this `Result` may be an `Err` variant, which should be handled
>     = note: `-D unused-must-use` implied by `-D warnings`
>     = help: to override `-D warnings` add `#[allow(unused_must_use)]`
>     = note: this error originates in the macro `log_mask_ln` (in Nightly builds, run with -Z macro-backtrace for more info)
>
> I understand meson sets `-D warings` so that `allow` can't work...
>
> What about just ignoring the return value? Afterall pl011 doesn't care
> the returned value.
>
> @@ -136,8 +137,7 @@ macro_rules! log_mask_ln {
>          if unsafe {
>              (::qemu_api::bindings::qemu_loglevel & ($mask as std::os::raw::c_int)) != 0
>          } {
> -            #[allow(unused_must_use)]
> -            ::qemu_api::log::LogGuard::log_fmt(
> +            let _ = ::qemu_api::log::LogGuard::log_fmt(
>                  format_args!("{}\n", format_args!($fmt $($args)*)));
>          }
>      }};


Just `_ = ::qemu_api::log::LogGuard::log_fmt(...);` is sufficient, no
`let` needed.

Paolo: I haven't tested it to see the warning Zhao did (busy
lately...), but LGTM, as well. With that fixed,

Reviewed-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>


  reply	other threads:[~2025-06-24  8:23 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-17  8:12 [PATCH] rust: log: implement io::Write Paolo Bonzini
2025-06-24  6:25 ` Zhao Liu
2025-06-24  7:21 ` Zhao Liu
2025-06-24  8:22   ` Manos Pitsidianakis [this message]
2025-06-24  9:05     ` Zhao Liu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAAjaMXZvi7FxdOgC8xpw5O1sQD3ncZSpRQpNEetNDMR3MdfhvA@mail.gmail.com \
    --to=manos.pitsidianakis@linaro.org \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-rust@nongnu.org \
    --cc=shentey@gmail.com \
    --cc=zhao1.liu@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).