Skip to contentSkip to conversation

qobject coccinelle followups

PATCH Applied Eric Blake 6 participants 13 messages Jun 9, 2017 – Jul 12, 2017 Coccinelle/Semantic Patches (SmPL)

v1 of 2 Applied Latest is v2 →

lore
Share & tools
lore

Eric Blake

author
#0 lore raw

cover qobject coccinelle followups

Inspired by https://lists.gnu.org/archive/html/qemu-devel/2017-06/msg02505.html

Surprisingly, the updated script didn't find any existing longhand use as candidates for QDECREF() (our last such use was cleaned up as a side effect, in commit b72fe9e), but it DID find another straggler missed in commit 579cf1d1.

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

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

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

A recent patch submission was about to use qobject_decref(QOBJECT(E)), even though we already have QDECREF(E) for that purpose. While our tree is currently free from the longhand form, we might as well update our coccinelle script to catch any future relapses.

---
 scripts/coccinelle/qobject.cocci | 6 ++++++
 1 file changed, 6 insertions(+)
scripts/coccinelle/qobject.cocci +6 -0
index 97703a4..656dc3e 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
author
#7 lore raw

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

In reply to Eric Blake

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
---
 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
#2 lore raw

Re: [Qemu-devel] [PATCH 1/2] qobject: Update coccinelle script to catch Q{INC, DEC}REF

In reply to Eric Blake

Hi

Quoted 4 lines · Eric Blake

A recent patch submission was about to use qobject_decref(QOBJECT(E)), even though we already have QDECREF(E) for that purpose. While our tree is currently free from the longhand form, we might as well update

Oh?

 $ git grep 'object_unref(OBJECT('  | wc -l
152

our coccinelle script to catch any future relapses.

Quoted 1 line

sadly, coccinelle is unabarebly slow on my machine, not easy to grasp, and thereby fails to catch a lot of cases.. I am looking at alternative from clang tools/lib, by curiosity.

Quoted 28 lines
---
 scripts/coccinelle/qobject.cocci | 6 ++++++
 1 file changed, 6 insertions(+)
scripts/coccinelle/qobject.cocci +6 -1
index 97703a4..656dc3e 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);
 |
--

2.9.4

Quoted 1 line

--

Marc-André Lureau

#3 lore raw

Re: [Qemu-devel] [PATCH 1/2] qobject: Update coccinelle script to catch Q{INC, DEC}REF

Quoted 9 lines · Marc-André Lureau

Hi

Quoted 4 lines · Eric Blake

A recent patch submission was about to use qobject_decref(QOBJECT(E)), even though we already have QDECREF(E) for that purpose. While our tree is currently free from the longhand form, we might as well update

Quoted 6 lines

Oh?

 $ git grep 'object_unref(OBJECT('  | wc -l
152

ah not the same object kind :)

our coccinelle script to catch any future relapses.

Quoted 38 lines
Quoted 1 line

sadly, coccinelle is unabarebly slow on my machine, not easy to grasp, and thereby fails to catch a lot of cases.. I am looking at alternative from clang tools/lib, by curiosity.

Quoted 28 lines
---
 scripts/coccinelle/qobject.cocci | 6 ++++++
 1 file changed, 6 insertions(+)
scripts/coccinelle/qobject.cocci +6 -1
index 97703a4..656dc3e 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);
 |
--

2.9.4

Quoted 1 line

--

Marc-André Lureau

Signature · 1 line
Marc-André Lureau
author
#4 lore raw

Re: [Qemu-devel] [PATCH 1/2] qobject: Update coccinelle script to catch Q{INC, DEC}REF

In reply to Marc-André Lureau
Quoted 9 lines · Marc-André Lureau

Hi

Quoted 4 lines · Eric Blake

A recent patch submission was about to use qobject_decref(QOBJECT(E)), even though we already have QDECREF(E) for that purpose. While our tree is currently free from the longhand form, we might as well update

Quoted 4 lines

Oh?

 $ git grep 'object_unref(OBJECT('  | wc -l
152

Quit mixing QOM and QObject ;)

$ git grep qobject_'..cref(QOBJECT'
include/qapi/qmp/qobject.h:    qobject_incref(QOBJECT(obj))
scripts/coccinelle/qobject.cocci:- qobject_incref(QOBJECT(E));
scripts/coccinelle/qobject.cocci:- qobject_decref(QOBJECT(E));

Yes, we may want to add a script to clean QOM abuses, but that's a different project for a different day.

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org
#5 lore raw

Re: [Qemu-devel] [PATCH 1/2] qobject: Update coccinelle script to catch Q{INC, DEC}REF

Quoted 15 lines · Eric Blake
Quoted 9 lines · Marc-André Lureau

Hi

Quoted 4 lines · Eric Blake

A recent patch submission was about to use qobject_decref(QOBJECT(E)), even though we already have QDECREF(E) for that purpose. While our tree is currently free from the longhand form, we might as well update

Quoted 4 lines

Oh?

 $ git grep 'object_unref(OBJECT('  | wc -l
152
Quoted 9 lines

Quit mixing QOM and QObject ;)

$ git grep qobject_'..cref(QOBJECT'
include/qapi/qmp/qobject.h:    qobject_incref(QOBJECT(obj))
scripts/coccinelle/qobject.cocci:- qobject_incref(QOBJECT(E));
scripts/coccinelle/qobject.cocci:- qobject_decref(QOBJECT(E));

Yeah, I got mixed by your comments, my patch doesn't do qobject_decref(QOBJECT(E)) but object_unref(OBJECT(E)), which doesn't have macro helper afaik.

Quoted 9 lines

Yes, we may want to add a script to clean QOM abuses, but that's a different project for a different day.

--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3266 <+1%20919-301-3266>
Virtualization: qemu.org | libvirt.org

--

Marc-André Lureau

author
#6 lore raw

Re: [Qemu-devel] [PATCH 1/2] qobject: Update coccinelle script to catch Q{INC, DEC}REF

In reply to Marc-André Lureau
Quoted 1 line · Marc-André Lureau

sadly, coccinelle is unabarebly slow on my machine,

Odd. It's pretty fast for this series:

$ time spatch --sp-file scripts/coccinelle/qobject.cocci \
  --macro-file scripts/cocci-macro-file.h --dir . --in-place 2>/dev/null

real 0m2.136s
user 0m2.003s
sys 0m0.125s

This is on Fedora 25. Although I _will_ grant that the time taken is also dependent on the complexity of the script it is running on (some scripts are inherently slower than others, and coccinelle takes shortcuts like grepping for which files to even fully analyze, but not all scripts are conducive to those shortcuts).

Quoted 2 lines

not easy to grasp, and
thereby fails to catch a lot of cases..

I agree with the 'not easy to grasp'. As for not catching cases, you HAVE to use the --macro-file scripts/cocci-macro-file.h to avoid a lot of skipped files. But even so, you're probably right that it still misses some things (although it often catches far more than "grep in anger" is able to do).

Quoted 2 lines

I am looking at alternative from
clang tools/lib, by curiosity.

I'll be interested to see if it produces any (easy-to-reproduce) cleanup results.

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org
Reviewed-by on v1 2/2
#8 lore raw

Re: [Qemu-devel] [PATCH 2/2] qobject: Catch another straggler for use of qdict_put_str()

In reply to Eric Blake
Quoted 11 lines · Eric Blake

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
---
 qemu-img.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Reviewed-by on v1 2/2
#9 lore raw

Re: [Qemu-devel] [Qemu-block] [PATCH 2/2] qobject: Catch another straggler for use of qdict_put_str()

In reply to Eric Blake
Quoted 8 lines · Eric Blake

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

Berto

#10 lore raw
In reply to Eric Blake
Quoted 10 lines · Eric Blake

Inspired by https://lists.gnu.org/archive/html/qemu-devel/2017-06/msg02505.html

Surprisingly, the updated script didn't find any existing longhand use as candidates for QDECREF() (our last such use was cleaned up as a side effect, in commit b72fe9e), but it DID find another straggler missed in commit 579cf1d1.

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

Applied to -trivial, thanks!

/mjt

author
#11 lore raw
Quoted 8 lines · Michael Tokarev
Quoted 7 lines · Eric Blake

Inspired by https://lists.gnu.org/archive/html/qemu-devel/2017-06/msg02505.html

Surprisingly, the updated script didn't find any existing longhand use as candidates for QDECREF() (our last such use was cleaned up as a side effect, in commit b72fe9e), but it DID find another straggler missed in commit 579cf1d1.

Quoted 5 lines
Quoted 3 lines

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

Applied to -trivial, thanks!

Markus has taken v2 of these patches through his qapi-next tree:
https://lists.gnu.org/archive/html/qemu-devel/2017-06/msg05589.html

so you can drop this v1 from -trivial

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org
#12 lore raw
Quoted 13 lines · Eric Blake
Quoted 12 lines · Michael Tokarev
Quoted 10 lines · Eric Blake

Inspired by https://lists.gnu.org/archive/html/qemu-devel/2017-06/msg02505.html

Surprisingly, the updated script didn't find any existing longhand use as candidates for QDECREF() (our last such use was cleaned up as a side effect, in commit b72fe9e), but it DID find another straggler missed in commit 579cf1d1.

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

Quoted 6 lines
Quoted 1 line

Applied to -trivial, thanks!

Markus has taken v2 of these patches through his qapi-next tree:
https://lists.gnu.org/archive/html/qemu-devel/2017-06/msg05589.html

so you can drop this v1 from -trivial

I've dragged my feet on the pull request in the hope of still adding a few patches of my own. Figure I better put them into the next one.