qemu-rust
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 03/11] rust: Add some block layer bindings


From: Paolo Bonzini
Subject: Re: [PATCH 03/11] rust: Add some block layer bindings
Date: Wed, 12 Feb 2025 14:47:46 +0100

On Wed, Feb 12, 2025 at 2:13 PM Kevin Wolf <kwolf@redhat.com> wrote:
> Yes, we definitely need some proper bindings there. I'm already tired of
> writing things like this:
>
>     return -(bindings::EINVAL as std::os::raw::c_int)
>
> Or even:
>
>     return e
>         .raw_os_error()
>         .unwrap_or(-(bindings::EIO as std::os::raw::c_int))

This by the way seemed incorrect to me as it should be

     return -(e
         .raw_os_error()
         .unwrap_or(bindings::EIO as std::os::raw::c_int))

(leaving aside that raw_os_error does not work on Windows)... But then
I noticed that read_raw() also does not negate, which causes the error
to print incorrectly...

> Which actually already shows that your errno binding patch does the
> opposite direction of what I needed in this series.

... so my patch already helps a bit: you can still change

    if ret < 0 {
         Err(Error::from_raw_os_error(ret))
    } else {
         Ok(())
    }

to

   errno::into_io_result(ret)?;
   Ok(())

and avoid the positive/negative confusion.

Anyhow, I guess the first one wouldn't be much better:

   return errno::into_negative_errno(ErrorKind::InvalidInput);

whereas the second could be

   return errno::into_negative_errno(e);

But then the first is already a special case; it only happens where
your bindings are not trivial thanks to the introduction of the
Mapping type.

Paolo

> My problem is when I
> need to return an int to C, and I either have an io::Result or I just
> want to directly return an errno value. So we'll have to add that part
> to your errno module, too.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]