Re: [PATCH 09/27] qapi char: Elide redundant has_FOO in generated C

2022-09-16 Thread Daniel P . Berrangé
On Thu, Sep 15, 2022 at 10:42:59PM +0200, Markus Armbruster wrote:
> The has_FOO for pointer-valued FOO are redundant, except for arrays.
> They are also a nuisance to work with.  Recent commit "qapi: Start to
> elide redundant has_FOO in generated C" provided the means to elide
> them step by step.  This is the step for qapi/char.json.
> 
> Said commit explains the transformation in more detail.  The invariant
> violations mentioned there do not occur here.
> 
> Cc: Marc-André Lureau 
> Cc: Paolo Bonzini 
> Signed-off-by: Markus Armbruster 
> ---
>  chardev/char-file.c|  2 +-
>  chardev/char-socket.c  | 10 --
>  chardev/char-udp.c |  1 -
>  chardev/char.c |  6 +-
>  tests/unit/test-char.c |  1 -
>  scripts/qapi/schema.py |  1 -
>  6 files changed, 6 insertions(+), 15 deletions(-)

Reviewed-by: Daniel P. Berrangé 


With regards,
Daniel
-- 
|: https://berrange.com  -o-https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o-https://fstop138.berrange.com :|
|: https://entangle-photo.org-o-https://www.instagram.com/dberrange :|




[PATCH 09/27] qapi char: Elide redundant has_FOO in generated C

2022-09-15 Thread Markus Armbruster
The has_FOO for pointer-valued FOO are redundant, except for arrays.
They are also a nuisance to work with.  Recent commit "qapi: Start to
elide redundant has_FOO in generated C" provided the means to elide
them step by step.  This is the step for qapi/char.json.

Said commit explains the transformation in more detail.  The invariant
violations mentioned there do not occur here.

Cc: Marc-André Lureau 
Cc: Paolo Bonzini 
Signed-off-by: Markus Armbruster 
---
 chardev/char-file.c|  2 +-
 chardev/char-socket.c  | 10 --
 chardev/char-udp.c |  1 -
 chardev/char.c |  6 +-
 tests/unit/test-char.c |  1 -
 scripts/qapi/schema.py |  1 -
 6 files changed, 6 insertions(+), 15 deletions(-)

diff --git a/chardev/char-file.c b/chardev/char-file.c
index 2fd80707e5..91a86b0a06 100644
--- a/chardev/char-file.c
+++ b/chardev/char-file.c
@@ -83,7 +83,7 @@ static void qmp_chardev_open_file(Chardev *chr,
 return;
 }
 
-if (file->has_in) {
+if (file->in) {
 flags = O_RDONLY;
 in = qmp_chardev_open_file_source(file->in, flags, errp);
 if (in < 0) {
diff --git a/chardev/char-socket.c b/chardev/char-socket.c
index 879564aa8a..29ffe5075e 100644
--- a/chardev/char-socket.c
+++ b/chardev/char-socket.c
@@ -1251,7 +1251,7 @@ static bool qmp_chardev_validate_socket(ChardevSocket 
*sock,
"'fd' address type");
 return false;
 }
-if (sock->has_tls_creds &&
+if (sock->tls_creds &&
 !(sock->has_server && sock->server)) {
 error_setg(errp,
"'tls_creds' option is incompatible with "
@@ -1261,7 +1261,7 @@ static bool qmp_chardev_validate_socket(ChardevSocket 
*sock,
 break;
 
 case SOCKET_ADDRESS_TYPE_UNIX:
-if (sock->has_tls_creds) {
+if (sock->tls_creds) {
 error_setg(errp,
"'tls_creds' option is incompatible with "
"'unix' address type");
@@ -1273,7 +1273,7 @@ static bool qmp_chardev_validate_socket(ChardevSocket 
*sock,
 break;
 
 case SOCKET_ADDRESS_TYPE_VSOCK:
-if (sock->has_tls_creds) {
+if (sock->tls_creds) {
 error_setg(errp,
"'tls_creds' option is incompatible with "
"'vsock' address type");
@@ -1284,7 +1284,7 @@ static bool qmp_chardev_validate_socket(ChardevSocket 
*sock,
 break;
 }
 
-if (sock->has_tls_authz && !sock->has_tls_creds) {
+if (sock->tls_authz && !sock->tls_creds) {
 error_setg(errp, "'tls_authz' option requires 'tls_creds' option");
 return false;
 }
@@ -1465,9 +1465,7 @@ static void qemu_chr_parse_socket(QemuOpts *opts, 
ChardevBackend *backend,
 sock->wait = qemu_opt_get_bool(opts, "wait", true);
 sock->has_reconnect = qemu_opt_find(opts, "reconnect");
 sock->reconnect = qemu_opt_get_number(opts, "reconnect", 0);
-sock->has_tls_creds = qemu_opt_get(opts, "tls-creds");
 sock->tls_creds = g_strdup(qemu_opt_get(opts, "tls-creds"));
-sock->has_tls_authz = qemu_opt_get(opts, "tls-authz");
 sock->tls_authz = g_strdup(qemu_opt_get(opts, "tls-authz"));
 
 addr = g_new0(SocketAddressLegacy, 1);
diff --git a/chardev/char-udp.c b/chardev/char-udp.c
index 6756e69924..3d9a2d5e77 100644
--- a/chardev/char-udp.c
+++ b/chardev/char-udp.c
@@ -178,7 +178,6 @@ static void qemu_chr_parse_udp(QemuOpts *opts, 
ChardevBackend *backend,
 udp->remote = addr;
 
 if (has_local) {
-udp->has_local = true;
 addr = g_new0(SocketAddressLegacy, 1);
 addr->type = SOCKET_ADDRESS_TYPE_INET;
 addr->u.inet.data = g_new(InetSocketAddress, 1);
diff --git a/chardev/char.c b/chardev/char.c
index 0169d8dde4..74f6bd6da5 100644
--- a/chardev/char.c
+++ b/chardev/char.c
@@ -240,7 +240,7 @@ static void qemu_char_open(Chardev *chr, ChardevBackend 
*backend,
 /* Any ChardevCommon member would work */
 ChardevCommon *common = backend ? backend->u.null.data : NULL;
 
-if (common && common->has_logfile) {
+if (common && common->logfile) {
 int flags = O_WRONLY;
 if (common->has_logappend &&
 common->logappend) {
@@ -496,9 +496,7 @@ void qemu_chr_parse_common(QemuOpts *opts, ChardevCommon 
*backend)
 {
 const char *logfile = qemu_opt_get(opts, "logfile");
 
-backend->has_logfile = logfile != NULL;
 backend->logfile = g_strdup(logfile);
-
 backend->has_logappend = true;
 backend->logappend = qemu_opt_get_bool(opts, "logappend", false);
 }
@@ -1057,7 +1055,6 @@ ChardevReturn *qmp_chardev_add(const char *id, 
ChardevBackend *backend,
 ret = g_new0(ChardevReturn, 1);
 if (CHARDEV_IS_PTY(chr)) {
 ret->pty = g_strdup(chr->filename + 4);
-ret->has_pty = true;
 }
 
 return ret;
@@ -1160,7 +1157,6 @@ ChardevReturn *qmp_chardev_change(const char *id, 
ChardevBackend *backend,
 ret = g_new0(ChardevReturn, 1);
 if