qobject coccinelle followups
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
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
@@ -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
PATCH 2/2 qobject: Catch another straggler for use of qdict_put_str()
In reply to Eric BlakeDan'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
@@ -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
Re: [Qemu-devel] [PATCH 1/2] qobject: Update coccinelle script to catch Q{INC, DEC}REF
In reply to Eric BlakeHi
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
152our 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
Signed-off-by Eric Blake <[email protected]>--- scripts/coccinelle/qobject.cocci | 6 ++++++ 1 file changed, 6 insertions(+)scripts/coccinelle/qobject.cocci +6
-1@@ -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
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
Signed-off-by Eric Blake <[email protected]>--- scripts/coccinelle/qobject.cocci | 6 ++++++ 1 file changed, 6 insertions(+)scripts/coccinelle/qobject.cocci +6
-1@@ -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
Re: [Qemu-devel] [PATCH 1/2] qobject: Update coccinelle script to catch Q{INC, DEC}REF
In reply to Marc-André LureauQuoted 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
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
Re: [Qemu-devel] [PATCH 1/2] qobject: Update coccinelle script to catch Q{INC, DEC}REF
In reply to Marc-André LureauQuoted 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
clangtools/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
Re: [Qemu-devel] [PATCH 2/2] qobject: Catch another straggler for use of qdict_put_str()
In reply to Eric BlakeQuoted 11 lines · Eric Blake
Dan's addition of key-secret improvements in commit
29cf9336was developed prior to the addition of QDict scalar insertion macros, but merged after the general cleanup in commit46f5ac20. Patch created mechanically by rerunning:spatch --sp-file scripts/coccinelle/qobject.cocci \ --macro-file scripts/cocci-macro-file.h --dir . --in-placeSigned-off-by Eric Blake <[email protected]>--- qemu-img.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Re: [Qemu-devel] [Qemu-block] [PATCH 2/2] qobject: Catch another straggler for use of qdict_put_str()
In reply to Eric BlakeQuoted 8 lines · Eric Blake
Dan's addition of key-secret improvements in commit
29cf9336was developed prior to the addition of QDict scalar insertion macros, but merged after the general cleanup in commit46f5ac20. Patch created mechanically by rerunning:spatch --sp-file scripts/coccinelle/qobject.cocci \ --macro-file scripts/cocci-macro-file.h --dir . --in-placeSigned-off-by Eric Blake <[email protected]>
Berto
Michael Tokarev
AppliedQuoted 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 commit579cf1d1.Eric Blake (2):
qobject: Update coccinelle script to catch Q{INC,DEC}REF
qobject: Catch another straggler for use ofqdict_put_str()
Applied to -trivial, thanks!
/mjt
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 commit579cf1d1.
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 ofqdict_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
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 commit579cf1d1.Eric Blake (2):
qobject: Update coccinelle script to catch Q{INC,DEC}REF
qobject: Catch another straggler for use ofqdict_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.htmlso 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.