[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH v5 3/5] qobject: replace qobject_incref/QINCREF
From: |
Eric Blake |
Subject: |
Re: [Qemu-devel] [PATCH v5 3/5] qobject: replace qobject_incref/QINCREF qobject_decref/QDECREF |
Date: |
Tue, 17 Apr 2018 13:46:20 -0500 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 |
On 04/17/2018 08:36 AM, Marc-André Lureau wrote:
> Now that we can safely call QOBJECT() on QObject * as well as its
> subtypes, we can have macros qobject_ref() / qobject_unref() that work
> everywhere instead of having to use QINCREF() / QDECREF() for QObject
> and qobject_incref() / qobject_decref() for its subtypes.
>
> Note that the new macros evaluate their argument exactly once, thus no
> need to shout them.
>
> Signed-off-by: Marc-André Lureau <address@hidden>
> ---
> +++ b/monitor.c
> @@ -346,7 +346,7 @@ static void monitor_qmp_cleanup_req_queue_locked(Monitor
> *mon)
> static void monitor_qmp_cleanup_resp_queue_locked(Monitor *mon)
> {
> while (!g_queue_is_empty(mon->qmp.qmp_responses)) {
> - qobject_decref(g_queue_pop_head(mon->qmp.qmp_responses));
> + qobject_unref((QObject *)g_queue_pop_head(mon->qmp.qmp_responses));
Interesting that you have to add a cast here. That is, the new macro is
more type-safe than the old version (since g_queue_pop_head() returns
void*); a quick audit of monitor.c shows we only ever pushed QObject*
onto the queue in the first place...
> @@ -494,9 +494,9 @@ static void monitor_json_emitter(Monitor *mon, QObject
> *data)
> * caller won't free the data (which will be finally freed in
> * responder thread).
> */
> - qobject_incref(data);
> + qobject_ref(data);
> qemu_mutex_lock(&mon->qmp.qmp_queue_lock);
> - g_queue_push_tail(mon->qmp.qmp_responses, (void *)data);
> + g_queue_push_tail(mon->qmp.qmp_responses, data);
...but you did manage to get rid of the pointless cast to void* in the
process.
Reviewed-by: Eric Blake <address@hidden>
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3266
Virtualization: qemu.org | libvirt.org
signature.asc
Description: OpenPGP digital signature
- Re: [Qemu-devel] [PATCH v5 2/5] qobject: use a QObjectBase_ struct, (continued)