[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PoCv2 02/15] scripts/qapi: teach c_param_type() to return const argumen
From: |
marcandre . lureau |
Subject: |
[PoCv2 02/15] scripts/qapi: teach c_param_type() to return const argument type |
Date: |
Mon, 12 Oct 2020 00:35:00 +0400 |
From: Marc-André Lureau <marcandre.lureau@redhat.com>
As it should be, since the argument isn't owned by the callee,
but a lot of code in QEMU rely on non-const arguments to tweak it.
Since Rust types / bindings are derived from the C version, we have to
be more accurate there to do correct ownership conversions.
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
scripts/qapi/schema.py | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py
index d1307ec661..ca85c7273a 100644
--- a/scripts/qapi/schema.py
+++ b/scripts/qapi/schema.py
@@ -167,8 +167,14 @@ class QAPISchemaType(QAPISchemaEntity):
pass
# Return the C type to be used in a parameter list.
- def c_param_type(self):
- return self.c_type()
+ #
+ # The argument should be considered const, since no ownership is given to
the callee,
+ # but qemu C code frequently tweaks it. Set const=True for a stricter
declaration.
+ def c_param_type(self, const=False):
+ c_type = self.c_type()
+ if const and c_type.endswith(pointer_suffix):
+ c_type = 'const ' + c_type
+ return c_type
# Return the C type to be used where we suppress boxing.
def c_unboxed_type(self):
@@ -221,10 +227,10 @@ class QAPISchemaBuiltinType(QAPISchemaType):
def c_type(self):
return self._c_type_name
- def c_param_type(self):
+ def c_param_type(self, const=False):
if self.name == 'str':
return 'const ' + self._c_type_name
- return self._c_type_name
+ return super().c_param_type(const)
def json_type(self):
return self._json_type_name
--
2.28.0
- [PoCv2 00/15] Rust binding for QAPI (qemu-ga only, for now), marcandre . lureau, 2020/10/11
- [PoCv2 01/15] mingw: fix error __USE_MINGW_ANSI_STDIO redefined, marcandre . lureau, 2020/10/11
- [PoCv2 02/15] scripts/qapi: teach c_param_type() to return const argument type,
marcandre . lureau <=
- [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, 2020/10/11
- [PoCv2 12/15] qga: implement get-host-name in Rust, marcandre . lureau, 2020/10/11