[PATCH 04/12] util/error: expose Error definition to Rust code

Paolo Bonzini posted 12 patches 5 months, 3 weeks ago
Maintainers: "Michael S. Tsirkin" <mst@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>, Markus Armbruster <armbru@redhat.com>, Michael Roth <michael.roth@amd.com>, Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
There is a newer version of this series
[PATCH 04/12] util/error: expose Error definition to Rust code
Posted by Paolo Bonzini 5 months, 3 weeks ago
This is used to preserve the file and line in a roundtrip from
C Error to Rust and back to C.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 include/qapi/error-internal.h | 26 ++++++++++++++++++++++++++
 rust/wrapper.h                |  1 +
 util/error.c                  | 10 +---------
 3 files changed, 28 insertions(+), 9 deletions(-)
 create mode 100644 include/qapi/error-internal.h

diff --git a/include/qapi/error-internal.h b/include/qapi/error-internal.h
new file mode 100644
index 00000000000..d5c3904adec
--- /dev/null
+++ b/include/qapi/error-internal.h
@@ -0,0 +1,26 @@
+/*
+ * QEMU Error Objects - struct definition
+ *
+ * Copyright IBM, Corp. 2011
+ * Copyright (C) 2011-2015 Red Hat, Inc.
+ *
+ * Authors:
+ *  Anthony Liguori   <aliguori@us.ibm.com>
+ *  Markus Armbruster <armbru@redhat.com>,
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2.  See
+ * the COPYING.LIB file in the top-level directory.
+ */
+
+#ifndef QAPI_ERROR_INTERNAL_H
+
+struct Error
+{
+    char *msg;
+    ErrorClass err_class;
+    const char *src, *func;
+    int line;
+    GString *hint;
+};
+
+#endif
diff --git a/rust/wrapper.h b/rust/wrapper.h
index beddd9aab2f..6060d3ba1ab 100644
--- a/rust/wrapper.h
+++ b/rust/wrapper.h
@@ -60,6 +60,7 @@ typedef enum memory_order {
 #include "hw/qdev-properties-system.h"
 #include "hw/irq.h"
 #include "qapi/error.h"
+#include "qapi/error-internal.h"
 #include "migration/vmstate.h"
 #include "chardev/char-serial.h"
 #include "exec/memattrs.h"
diff --git a/util/error.c b/util/error.c
index 673011b89e9..e5bcb7c0225 100644
--- a/util/error.c
+++ b/util/error.c
@@ -15,15 +15,7 @@
 #include "qemu/osdep.h"
 #include "qapi/error.h"
 #include "qemu/error-report.h"
-
-struct Error
-{
-    char *msg;
-    ErrorClass err_class;
-    const char *src, *func;
-    int line;
-    GString *hint;
-};
+#include "qapi/error-internal.h"
 
 Error *error_abort;
 Error *error_fatal;
-- 
2.49.0
Re: [PATCH 04/12] util/error: expose Error definition to Rust code
Posted by Markus Armbruster 5 months, 3 weeks ago
Paolo Bonzini <pbonzini@redhat.com> writes:

> This is used to preserve the file and line in a roundtrip from
> C Error to Rust and back to C.
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  include/qapi/error-internal.h | 26 ++++++++++++++++++++++++++
>  rust/wrapper.h                |  1 +
>  util/error.c                  | 10 +---------
>  3 files changed, 28 insertions(+), 9 deletions(-)
>  create mode 100644 include/qapi/error-internal.h
>
> diff --git a/include/qapi/error-internal.h b/include/qapi/error-internal.h
> new file mode 100644
> index 00000000000..d5c3904adec
> --- /dev/null
> +++ b/include/qapi/error-internal.h
> @@ -0,0 +1,26 @@
> +/*
> + * QEMU Error Objects - struct definition
> + *
> + * Copyright IBM, Corp. 2011
> + * Copyright (C) 2011-2015 Red Hat, Inc.
> + *
> + * Authors:
> + *  Anthony Liguori   <aliguori@us.ibm.com>
> + *  Markus Armbruster <armbru@redhat.com>,
> + *
> + * This work is licensed under the terms of the GNU LGPL, version 2.  See
> + * the COPYING.LIB file in the top-level directory.
> + */
> +
> +#ifndef QAPI_ERROR_INTERNAL_H
> +
> +struct Error
> +{
> +    char *msg;
> +    ErrorClass err_class;
> +    const char *src, *func;
> +    int line;
> +    GString *hint;
> +};
> +
> +#endif
> diff --git a/rust/wrapper.h b/rust/wrapper.h
> index beddd9aab2f..6060d3ba1ab 100644
> --- a/rust/wrapper.h
> +++ b/rust/wrapper.h
> @@ -60,6 +60,7 @@ typedef enum memory_order {
>  #include "hw/qdev-properties-system.h"
>  #include "hw/irq.h"
>  #include "qapi/error.h"
> +#include "qapi/error-internal.h"
>  #include "migration/vmstate.h"
>  #include "chardev/char-serial.h"
>  #include "exec/memattrs.h"
> diff --git a/util/error.c b/util/error.c
> index 673011b89e9..e5bcb7c0225 100644
> --- a/util/error.c
> +++ b/util/error.c
> @@ -15,15 +15,7 @@
>  #include "qemu/osdep.h"
>  #include "qapi/error.h"
>  #include "qemu/error-report.h"
> -
> -struct Error
> -{
> -    char *msg;
> -    ErrorClass err_class;
> -    const char *src, *func;
> -    int line;
> -    GString *hint;
> -};
> +#include "qapi/error-internal.h"

Please move this up to keep the #include sorted (except for
qemu/osdep.h, which is special).

>  
>  Error *error_abort;
>  Error *error_fatal;

Since error.h is always included when error-internal.h is, we could make
error-internal.h include error.h.  Matter of taste, up to you.