[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 15/33] monitor: Use GString instead of QString for output buffer
From: |
Markus Armbruster |
Subject: |
[PULL 15/33] monitor: Use GString instead of QString for output buffer |
Date: |
Sat, 19 Dec 2020 11:55:14 +0100 |
GString has a richer set of string operations than QString. It should
be preferred to QString except where we need a QObject or reference
counting. We don't here. Switch to GString, and put its richer
interface to use.
Cc: Dr. David Alan Gilbert <dgilbert@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20201211171152.146877-3-armbru@redhat.com>
Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
---
monitor/monitor-internal.h | 2 +-
monitor/misc.c | 2 +-
monitor/monitor.c | 20 ++++++++------------
3 files changed, 10 insertions(+), 14 deletions(-)
diff --git a/monitor/monitor-internal.h b/monitor/monitor-internal.h
index a6131554da..40903d6386 100644
--- a/monitor/monitor-internal.h
+++ b/monitor/monitor-internal.h
@@ -105,7 +105,7 @@ struct Monitor {
* Members that are protected by the per-monitor lock
*/
QLIST_HEAD(, mon_fd_t) fds;
- QString *outbuf;
+ GString *outbuf;
guint out_watch;
/* Read under either BQL or mon_lock, written with BQL+mon_lock. */
int mux_out;
diff --git a/monitor/misc.c b/monitor/misc.c
index 33d0dae2e8..10444b4e7a 100644
--- a/monitor/misc.c
+++ b/monitor/misc.c
@@ -136,7 +136,7 @@ char *qmp_human_monitor_command(const char *command_line,
bool has_cpu_index,
handle_hmp_command(&hmp, command_line);
WITH_QEMU_LOCK_GUARD(&hmp.common.mon_lock) {
- output = g_strdup(qstring_get_str(hmp.common.outbuf));
+ output = g_strdup(hmp.common.outbuf->str);
}
out:
diff --git a/monitor/monitor.c b/monitor/monitor.c
index 84222cd130..1e4a6b3f20 100644
--- a/monitor/monitor.c
+++ b/monitor/monitor.c
@@ -29,7 +29,6 @@
#include "qapi/qapi-emit-events.h"
#include "qapi/qapi-visit-control.h"
#include "qapi/qmp/qdict.h"
-#include "qapi/qmp/qstring.h"
#include "qemu/error-report.h"
#include "qemu/option.h"
#include "sysemu/qtest.h"
@@ -181,22 +180,19 @@ static void monitor_flush_locked(Monitor *mon)
return;
}
- buf = qstring_get_str(mon->outbuf);
- len = qstring_get_length(mon->outbuf);
+ buf = mon->outbuf->str;
+ len = mon->outbuf->len;
if (len && !mon->mux_out) {
rc = qemu_chr_fe_write(&mon->chr, (const uint8_t *) buf, len);
if ((rc < 0 && errno != EAGAIN) || (rc == len)) {
/* all flushed or error */
- qobject_unref(mon->outbuf);
- mon->outbuf = qstring_new();
+ g_string_truncate(mon->outbuf, 0);
return;
}
if (rc > 0) {
/* partial write */
- QString *tmp = qstring_from_str(buf + rc);
- qobject_unref(mon->outbuf);
- mon->outbuf = tmp;
+ g_string_erase(mon->outbuf, 0, rc);
}
if (mon->out_watch == 0) {
mon->out_watch =
@@ -223,9 +219,9 @@ int monitor_puts(Monitor *mon, const char *str)
for (i = 0; str[i]; i++) {
c = str[i];
if (c == '\n') {
- qstring_append_chr(mon->outbuf, '\r');
+ g_string_append_c(mon->outbuf, '\r');
}
- qstring_append_chr(mon->outbuf, c);
+ g_string_append_c(mon->outbuf, c);
if (c == '\n') {
monitor_flush_locked(mon);
}
@@ -602,7 +598,7 @@ void monitor_data_init(Monitor *mon, bool is_qmp, bool
skip_flush,
}
qemu_mutex_init(&mon->mon_lock);
mon->is_qmp = is_qmp;
- mon->outbuf = qstring_new();
+ mon->outbuf = g_string_new(NULL);
mon->skip_flush = skip_flush;
mon->use_io_thread = use_io_thread;
}
@@ -616,7 +612,7 @@ void monitor_data_destroy(Monitor *mon)
} else {
readline_free(container_of(mon, MonitorHMP, common)->rs);
}
- qobject_unref(mon->outbuf);
+ g_string_free(mon->outbuf, true);
qemu_mutex_destroy(&mon->mon_lock);
}
--
2.26.2
- [PULL 06/33] tests/check-qjson: Cover number 2^63, (continued)
- [PULL 06/33] tests/check-qjson: Cover number 2^63, Markus Armbruster, 2020/12/19
- [PULL 10/33] test-string-output-visitor: Cover "unround" number, Markus Armbruster, 2020/12/19
- [PULL 08/33] tests/check-qnum: Cover qnum_to_string() for "unround" argument, Markus Armbruster, 2020/12/19
- [PULL 12/33] test-visitor-serialization: Drop insufficient precision workaround, Markus Armbruster, 2020/12/19
- [PULL 07/33] tests/check-qjson: Replace redundant large_number(), Markus Armbruster, 2020/12/19
- [PULL 02/33] migration: Refactor migrate_cap_add, Markus Armbruster, 2020/12/19
- [PULL 26/33] qobject: Drop qstring_get_try_str(), Markus Armbruster, 2020/12/19
- [PULL 13/33] test-visitor-serialization: Clean up test_primitives(), Markus Armbruster, 2020/12/19
- [PULL 19/33] Revert "qstring: add qstring_free()", Markus Armbruster, 2020/12/19
- [PULL 16/33] qobject: Make qobject_to_json_pretty() take a pretty argument, Markus Armbruster, 2020/12/19
- [PULL 15/33] monitor: Use GString instead of QString for output buffer,
Markus Armbruster <=
- [PULL 22/33] qmp: Fix tracing of non-string command IDs, Markus Armbruster, 2020/12/19
- [PULL 20/33] hw/rdma: Replace QList by GQueue, Markus Armbruster, 2020/12/19
- [PULL 23/33] block: Avoid qobject_get_try_str(), Markus Armbruster, 2020/12/19
- [PULL 28/33] qobject: Factor JSON writer out of qobject_to_json(), Markus Armbruster, 2020/12/19
- [PULL 25/33] qobject: Drop qobject_get_try_str(), Markus Armbruster, 2020/12/19
- [PULL 30/33] json: Use GString instead of QString to accumulate strings, Markus Armbruster, 2020/12/19
- [PULL 31/33] keyval: Use GString to accumulate value strings, Markus Armbruster, 2020/12/19
- [PULL 18/33] qobject: Change qobject_to_json()'s value to GString, Markus Armbruster, 2020/12/19
- [PULL 33/33] qobject: Make QString immutable, Markus Armbruster, 2020/12/19
- [PULL 27/33] qobject: Factor quoted_str() out of to_json(), Markus Armbruster, 2020/12/19