Skip to contentSkip to conversation

qobject coccinelle followups

PATCH Applied Eric Blake 3 participants 5 messages Jun 24, 2017 – Jun 26, 2017 Coccinelle/Semantic Patches (SmPL)

lore
Share & tools
lore

Eric Blake

author
#0 lore raw

v2 cover qobject coccinelle followups

v1 was here:
https://lists.gnu.org/archive/html/qemu-devel/2017-06/msg02589.html

Since then:
- reorder the series
- add R-b on patch 1
- patch 2 updated to catch recent introduction of longhand usage

Eric Blake (2):
qobject: Catch another straggler for use of qdict_put_str()
qobject: Update coccinelle script to catch Q{INC,DEC}REF

 monitor.c                        | 2 +-
 qemu-img.c                       | 2 +-
 scripts/coccinelle/qobject.cocci | 6 ++++++
 3 files changed, 8 insertions(+), 2 deletions(-)
Signature · 1 line
2.9.4
author
#1 lore raw

PATCH v2 1/2 qobject: Catch another straggler for use of qdict_put_str()

Dan's addition of key-secret improvements in commit 29cf9336 was developed prior to the addition of QDict scalar insertion macros, but merged after the general cleanup in commit 46f5ac20. Patch created mechanically by rerunning:

  spatch --sp-file scripts/coccinelle/qobject.cocci \
         --macro-file scripts/cocci-macro-file.h --dir . --in-place

---
v2: reorder series

---
 qemu-img.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
qemu-img.c +1 -1
index 0ad698d..6c972f7 100644
@@ -355,7 +355,7 @@ static int img_add_key_secrets(void *opaque,
     QDict *options = opaque;
 
     if (g_str_has_suffix(name, "key-secret")) {
-        qdict_put(options, name, qstring_from_str(value));
+        qdict_put_str(options, name, value);
     }
 
     return 0;
Signature · 1 line
2.9.4
author
#2 lore raw

PATCH v2 2/2 qobject: Update coccinelle script to catch Q{INC, DEC}REF

In reply to Eric Blake

The recent commit b097efc0 used qobject_decref(QOBJECT(E)), even though we already have QDECREF(E) for that purpose. We can update our coccinelle script to catch any future relapses; with that in place, the rest of the patch is generated with:

 spatch --sp-file scripts/coccinelle/qobject.cocci \
        --macro-file scripts/cocci-macro-file.h --dir . --in-place

---
v2: fix a misuse that crept in since v1

---
 monitor.c                        | 2 +-
 scripts/coccinelle/qobject.cocci | 6 ++++++
 2 files changed, 7 insertions(+), 1 deletion(-)
monitor.c +1 -1
index 3c369f4..b0fde7f 100644
@@ -3829,7 +3829,7 @@ static void handle_qmp_command(JSONMessageParser *parser, GQueue *tokens)
 
     req_json = qobject_to_json(req);
     trace_handle_qmp_command(mon, qstring_get_str(req_json));
-    qobject_decref(QOBJECT(req_json));
+    QDECREF(req_json);
 
     rsp = qmp_dispatch(cur_mon->qmp.commands, req);
 
scripts/coccinelle/qobject.cocci +6 -0
index c3253de..c518caf 100644
@@ -3,6 +3,12 @@
 expression Obj, Key, E;
 @@
 (
+- qobject_incref(QOBJECT(E));
++ QINCREF(E);
+|
+- qobject_decref(QOBJECT(E));
++ QDECREF(E);
+|
 - qdict_put_obj(Obj, Key, QOBJECT(E));
 + qdict_put(Obj, Key, E);
 |
Signature · 1 line
2.9.4
Reviewed-by on the v2 series
#4 lore raw
In reply to Eric Blake
Quoted 8 lines · Eric Blake

v1 was here:
https://lists.gnu.org/archive/html/qemu-devel/2017-06/msg02589.html

Since then:
- reorder the series
- add R-b on patch 1
- patch 2 updated to catch recent introduction of longhand usage

Quoted 12 lines

Eric Blake (2):
qobject: Catch another straggler for use of qdict_put_str()
qobject: Update coccinelle script to catch Q{INC,DEC}REF

 monitor.c                        | 2 +-
 qemu-img.c                       | 2 +-
 scripts/coccinelle/qobject.cocci | 6 ++++++
 3 files changed, 8 insertions(+), 2 deletions(-)
Signature · 1 line
2.9.4