On Thu, Jun 05, 2025 at 12:15:35PM +0200, Paolo Bonzini wrote:
> Date: Thu, 5 Jun 2025 12:15:35 +0200
> From: Paolo Bonzini <pbonz...@redhat.com>
> Subject: [PATCH 06/14] rust: qemu-api: add bindings to Error
> X-Mailer: git-send-email 2.49.0
> 
> Provide an implementation of std::error::Error that bridges the Rust
> anyhow::Error and std::panic::Location types with QEMU's Error*.
> 
> It also has several utility methods, analogous to error_propagate(),
> that convert a Result into a return value + Error** pair.  One important
> difference is that these propagation methods *panic* if *errp is NULL,

nit: *panic* if *errp is not NULL

> unlike error_propagate() which eats subsequent errors[1].  The reason
> for this is that in C you have an error_set*() call at the site where
> the error is created, and calls to error_propagate() are relatively rare.
> 
> In Rust instead, even though these functions do "propagate" a
> qemu_api::Error into a C Error**, there is no error_setg() anywhere that
> could check for non-NULL errp and call abort().  error_propagate()'s
> behavior of ignoring subsequent errors is generally considered weird,
> and there would be a bigger risk of triggering it from Rust code.
> 
> [1] This is actually a violation of the preconditions of error_propagate(),
>     so it should not happen.  But you never know...
> 
> Signed-off-by: Paolo Bonzini <pbonz...@redhat.com>
> ---
>  docs/devel/rust.rst        |   5 +
>  rust/Cargo.lock            |  17 ++
>  rust/Cargo.toml            |   1 +
>  rust/qemu-api/Cargo.toml   |   2 +
>  rust/qemu-api/meson.build  |   1 +
>  rust/qemu-api/src/error.rs | 312 +++++++++++++++++++++++++++++++++++++
>  rust/qemu-api/src/lib.rs   |   3 +
>  7 files changed, 341 insertions(+)
>  create mode 100644 rust/qemu-api/src/error.rs

Reviewed-by: Zhao Liu <zhao1....@intel.com>


Reply via email to