[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PoCv2 11/15] qga: add qmp! macro helper
From: |
marcandre . lureau |
Subject: |
[PoCv2 11/15] qga: add qmp! macro helper |
Date: |
Mon, 12 Oct 2020 00:35:09 +0400 |
From: Marc-André Lureau <marcandre.lureau@redhat.com>
Add a macro to help wrapping higher-level qmp handlers, by taking care
of errors and return value pointer translation.
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
qga/lib.rs | 1 +
qga/qmp/mod.rs | 36 ++++++++++++++++++++++++++++++++++++
2 files changed, 37 insertions(+)
create mode 100644 qga/qmp/mod.rs
diff --git a/qga/lib.rs b/qga/lib.rs
index bff4107569..5fe08c25a3 100644
--- a/qga/lib.rs
+++ b/qga/lib.rs
@@ -1,2 +1,3 @@
mod qapi;
mod qapi_sys;
+mod qmp;
diff --git a/qga/qmp/mod.rs b/qga/qmp/mod.rs
new file mode 100644
index 0000000000..38060100af
--- /dev/null
+++ b/qga/qmp/mod.rs
@@ -0,0 +1,36 @@
+use common::*;
+
+use crate::*;
+
+macro_rules! qmp {
+ // the basic return value variant
+ ($e:expr, $errp:ident, $errval:expr) => {{
+ assert!(!$errp.is_null());
+ unsafe {
+ *$errp = std::ptr::null_mut();
+ }
+
+ match $e {
+ Ok(val) => val,
+ Err(err) => unsafe {
+ *$errp = err.to_qemu_full();
+ $errval
+ },
+ }
+ }};
+ // the ptr return value variant
+ ($e:expr, $errp:ident) => {{
+ assert!(!$errp.is_null());
+ unsafe {
+ *$errp = std::ptr::null_mut();
+ }
+
+ match $e {
+ Ok(val) => val.to_qemu_full().into(),
+ Err(err) => unsafe {
+ *$errp = err.to_qemu_full();
+ std::ptr::null_mut()
+ },
+ }
+ }};
+}
--
2.28.0
- Re: [PoCv2 01/15] mingw: fix error __USE_MINGW_ANSI_STDIO redefined, (continued)
- [PoCv2 02/15] scripts/qapi: teach c_param_type() to return const argument type, marcandre . lureau, 2020/10/11
- [PoCv2 03/15] build-sys: add --with-rust{-target} & basic build infrastructure, marcandre . lureau, 2020/10/11
- [PoCv2 04/15] build-sys: add a cargo-wrapper script, marcandre . lureau, 2020/10/11
- [PoCv2 05/15] qga/rust: build and link an empty static library, marcandre . lureau, 2020/10/11
- [PoCv2 06/15] rust: provide a common crate for QEMU, marcandre . lureau, 2020/10/11
- [PoCv2 07/15] scripts/qapi: add Rust sys bindings generation, marcandre . lureau, 2020/10/11
- [PoCv2 08/15] qga/rust: generate QGA QAPI sys bindings, marcandre . lureau, 2020/10/11
- [PoCv2 09/15] scripts/qapi: add generation of Rust bindings for types, marcandre . lureau, 2020/10/11
- [PoCv2 10/15] qga/rust: build Rust types, marcandre . lureau, 2020/10/11
- [PoCv2 11/15] qga: add qmp! macro helper,
marcandre . lureau <=
- [PoCv2 12/15] qga: implement get-host-name in Rust, marcandre . lureau, 2020/10/11
- [PoCv2 13/15] qga: implement {get,set}-vcpus in Rust, marcandre . lureau, 2020/10/11
- [PoCv2 14/15] travis: add Rust, marcandre . lureau, 2020/10/11
- [PoCv2 15/15] rust: use vendored-sources, marcandre . lureau, 2020/10/11
- Re: [PoCv2 00/15] Rust binding for QAPI (qemu-ga only, for now), no-reply, 2020/10/11