* [Cocci] Patching nested if's?
@ 2015-03-31 12:56 François Armand
2015-03-31 13:15 ` SF Markus Elfring
2015-03-31 13:47 ` Julia Lawall
0 siblings, 2 replies; 8+ messages in thread
From: François Armand @ 2015-03-31 12:56 UTC (permalink / raw)
To: cocci
Hi,
I'd like to patch the third if of a code block that looks like:
if (MY_SUCCESS != ret) {
if (MY_EPERM != ret && MY_ENOENT != ret) {
if (t < MAXR) {
foo();
goto retry;
} else {
bar();
}
}
}
I'd like to get:
if (MY_SUCCESS != ret) {
if (MY_EPERM != ret && MY_ENOENT != ret) {
if (myfunc() == 0) {
goto retry;
} else {
bar();
}
}
}
I've been able so far to replace the if (t <MAXR) but this
also replaces lines with it (expresion < constant) elsewhere.
Which is why I'd like to constrain the pacth to this 3 nested
ifs pattern.
Removing calls to foo() is easy, since I want to remove them all.
I came up with the following invalid attempt
@@
expression t;
constant M;
@@
if (...)
if (...)
{
if (
- t < M
+ myfunc()
)
{
...
} else {
...
}
}
}
Thanks for any hint.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://systeme.lip6.fr/pipermail/cocci/attachments/20150331/092cd2c1/attachment.html>
^ permalink raw reply [flat|nested] 8+ messages in thread* [Cocci] Patching nested if's? 2015-03-31 12:56 [Cocci] Patching nested if's? François Armand @ 2015-03-31 13:15 ` SF Markus Elfring 2015-03-31 13:47 ` Julia Lawall 1 sibling, 0 replies; 8+ messages in thread From: SF Markus Elfring @ 2015-03-31 13:15 UTC (permalink / raw) To: cocci > I've been able so far to replace the if (t <MAXR) but this > also replaces lines with it (expresion < constant) elsewhere. Would you like to consider any additional SmPL constraints? > Which is why I'd like to constrain the pacth to this 3 nested > ifs pattern. Do you really want to deal only with a specific nesting level? > if ( > - t < M > + myfunc() How do you think about to add also " == 0" here? > ) > { > ... > } else { > ... > } Would you like to replace these ellipsis by metavariables of the type "statement"? Regards, Markus ^ permalink raw reply [flat|nested] 8+ messages in thread
* [Cocci] Patching nested if's? 2015-03-31 12:56 [Cocci] Patching nested if's? François Armand 2015-03-31 13:15 ` SF Markus Elfring @ 2015-03-31 13:47 ` Julia Lawall 2015-03-31 15:18 ` François Armand 1 sibling, 1 reply; 8+ messages in thread From: Julia Lawall @ 2015-03-31 13:47 UTC (permalink / raw) To: cocci > I came up with the following invalid attempt > @@ > expression t; > constant M; > @@ > ?if (...) I think that the only problem is that you are missing an open brace here, after the first if line. > ??? if (...) > ??? { > ?????? if ( > -??? ?? t < M > +????????? myfunc() > ????????? ) > ????????? { > ??? ? ... > ??? ? } else { > ??? ? ... > ??? ? } Markus suggested to put else S here. Doing that would allow the else to disappear, if sometimes in your code there is no else in this case. If any of your ifs may or may not have an else, you can put eg else S1, else S2, else S3. An isomorphism will allow them all to disppear. julia > ??? } > ? } > > Thanks for any hint. > > ^ permalink raw reply [flat|nested] 8+ messages in thread
* [Cocci] Patching nested if's? 2015-03-31 13:47 ` Julia Lawall @ 2015-03-31 15:18 ` François Armand 2015-03-31 15:49 ` Julia Lawall 0 siblings, 1 reply; 8+ messages in thread From: François Armand @ 2015-03-31 15:18 UTC (permalink / raw) To: cocci Better send my real stuff, than making misleading typos :-) My code: #define MAX_RETRIES 3 tmy_status my_getattr_timeout(tmy_ctx *ctx, u64 ino) { tmy_status ret; int tries = 0; int delay = 1; retry: ret = my_getattr(ctx, ino); if (MY_SUCCESS != ret) { if (MY_ENOENT != ret && MY_EPERM != ret) { if (tries < MAX_RETRIES) { HANDLE_TIMEOUT(tries, delay, "ino %llu", ino); goto retry; } else { MY_TRACE(MY_ERROR, 0u, "getattr: ino %llu"": I/O error", ino); return MY_FAILURE; } } } return ret; } A working patch @@ expression t; constant M; @@ if ( - t < M + foo(&ctx->retry_ctx) ) { ... } else { ... } A patch I can't make to work. That last one exists w/o producing anything @@ expression t; constant M; @@ if (...) { if (...) { if ( - t < M + foo(&ctx->retry_ctx) ) { ... } else { ... } } } 2015-03-31 15:47 GMT+02:00 Julia Lawall <julia.lawall@lip6.fr>: > > I came up with the following invalid attempt > > @@ > > expression t; > > constant M; > > @@ > > if (...) > > I think that the only problem is that you are missing an open brace here, > after the first if line. > > > if (...) > > { > > if ( > > - t < M > > + myfunc() > > ) > > { > > ... > > } else { > > ... > > } > > Markus suggested to put else S here. Doing that would allow the else to > disappear, if sometimes in your code there is no else in this case. If > any of your ifs may or may not have an else, you can put eg else S1, else > S2, else S3. An isomorphism will allow them all to disppear. > > julia > > > } > > } > > > > Thanks for any hint. > > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: <https://systeme.lip6.fr/pipermail/cocci/attachments/20150331/628f0ced/attachment.html> ^ permalink raw reply [flat|nested] 8+ messages in thread
* [Cocci] Patching nested if's? 2015-03-31 15:18 ` François Armand @ 2015-03-31 15:49 ` Julia Lawall 2015-03-31 16:06 ` François Armand 0 siblings, 1 reply; 8+ messages in thread From: Julia Lawall @ 2015-03-31 15:49 UTC (permalink / raw) To: cocci On Tue, 31 Mar 2015, Fran?ois Armand wrote: > Better send my real stuff, than making misleading typos :-) > > My code: > #define MAX_RETRIES 3 > > tmy_status > my_getattr_timeout(tmy_ctx *ctx, > ??? ??? ?? u64 ino) > { > ? tmy_status ret; > ? int tries = 0; > ? int delay = 1; > > ?retry: > ? ret = my_getattr(ctx, ino); > ? if (MY_SUCCESS != ret) > ??? { > ????? if (MY_ENOENT != ret && > ????????? MY_EPERM != ret) > ??????? { > ????????? if (tries < MAX_RETRIES) > ??????????? { > ????????????? HANDLE_TIMEOUT(tries, delay, "ino %llu", ino); > ????????????? goto retry; > ??????????? } > ????????? else > ??????????? { > ????????????? MY_TRACE(MY_ERROR, 0u, "getattr: ino %llu"": I/O error", ino); > ????????????? return MY_FAILURE; > ??????????? } > ??????? } > ??? } > ? return ret; > } > > A working patch > @@ > expression t; > constant M; > @@ > ?????? if ( > -??? ?? t < M > +????????? foo(&ctx->retry_ctx) > ????????? ) > ????????? { > ??? ? ... > ??? ? } else { > ??? ? ... > ??? ? } > > A patch I can't make to work. That last one exists w/o producing anything > > @@ > expression t; > constant M; > @@ > ?if (...) > ?{? > ??? if (...) > ??? { > ?????? if ( > -??? ?? t < M > +????????? foo(&ctx->retry_ctx) > ????????? ) > ????????? { > ??? ? ... > ??? ? } else { > ??? ? ... > ??? ? } > ??? } > ? } It seems to work fine for me: @@ -15,7 +15,7 @@ my_getattr_timeout(tmy_ctx *ctx, if (MY_ENOENT != ret && MY_EPERM != ret) { - if (tries < MAX_RETRIES) + if (foo(&ctx->retry_ctx)) { HANDLE_TIMEOUT(tries, delay, "ino %llu", ino); goto retry; What version of Coccinelle do you have? julia ^ permalink raw reply [flat|nested] 8+ messages in thread
* [Cocci] Patching nested if's? 2015-03-31 15:49 ` Julia Lawall @ 2015-03-31 16:06 ` François Armand 2015-03-31 16:11 ` Julia Lawall 0 siblings, 1 reply; 8+ messages in thread From: François Armand @ 2015-03-31 16:06 UTC (permalink / raw) To: cocci I'm on Ubuntu 14.04 spatch version 1.0.0-rc19 with Python support and with PCRE support 2015-03-31 17:49 GMT+02:00 Julia Lawall <julia.lawall@lip6.fr>: > > > On Tue, 31 Mar 2015, Fran?ois Armand wrote: > > > Better send my real stuff, than making misleading typos :-) > > > > My code: > > #define MAX_RETRIES 3 > > > > tmy_status > > my_getattr_timeout(tmy_ctx *ctx, > > u64 ino) > > { > > tmy_status ret; > > int tries = 0; > > int delay = 1; > > > > retry: > > ret = my_getattr(ctx, ino); > > if (MY_SUCCESS != ret) > > { > > if (MY_ENOENT != ret && > > MY_EPERM != ret) > > { > > if (tries < MAX_RETRIES) > > { > > HANDLE_TIMEOUT(tries, delay, "ino %llu", ino); > > goto retry; > > } > > else > > { > > MY_TRACE(MY_ERROR, 0u, "getattr: ino %llu"": I/O error", > ino); > > return MY_FAILURE; > > } > > } > > } > > return ret; > > } > > > > A working patch > > @@ > > expression t; > > constant M; > > @@ > > if ( > > - t < M > > + foo(&ctx->retry_ctx) > > ) > > { > > ... > > } else { > > ... > > } > > > > A patch I can't make to work. That last one exists w/o producing anything > > > > @@ > > expression t; > > constant M; > > @@ > > if (...) > > { > > if (...) > > { > > if ( > > - t < M > > + foo(&ctx->retry_ctx) > > ) > > { > > ... > > } else { > > ... > > } > > } > > } > > It seems to work fine for me: > > @@ -15,7 +15,7 @@ my_getattr_timeout(tmy_ctx *ctx, > if (MY_ENOENT != ret && > MY_EPERM != ret) > { > - if (tries < MAX_RETRIES) > + if (foo(&ctx->retry_ctx)) > { > HANDLE_TIMEOUT(tries, delay, "ino %llu", ino); > goto retry; > > What version of Coccinelle do you have? > > julia -------------- next part -------------- An HTML attachment was scrubbed... URL: <https://systeme.lip6.fr/pipermail/cocci/attachments/20150331/f929bd49/attachment-0001.html> ^ permalink raw reply [flat|nested] 8+ messages in thread
* [Cocci] Patching nested if's? 2015-03-31 16:06 ` François Armand @ 2015-03-31 16:11 ` Julia Lawall 2015-03-31 16:12 ` François Armand 0 siblings, 1 reply; 8+ messages in thread From: Julia Lawall @ 2015-03-31 16:11 UTC (permalink / raw) To: cocci On Tue, 31 Mar 2015, Fran?ois Armand wrote: > I'm on Ubuntu 14.04 > spatch version 1.0.0-rc19 with Python support and with PCRE support The current release is 1.0.0-rc24. For Ubuntu, rc22 is available as a PPA: https://launchpad.net/~npalix/+archive/ubuntu/coccinelle. Or you can just get the github version: https://github.com/coccinelle/coccinelle julia > > > > 2015-03-31 17:49 GMT+02:00 Julia Lawall <julia.lawall@lip6.fr>: > > > On Tue, 31 Mar 2015, Fran?ois Armand wrote: > > > Better send my real stuff, than making misleading typos :-) > > > > My code: > > #define MAX_RETRIES 3 > > > > tmy_status > > my_getattr_timeout(tmy_ctx *ctx, > > ??? ??? ?? u64 ino) > > { > > ? tmy_status ret; > > ? int tries = 0; > > ? int delay = 1; > > > > ?retry: > > ? ret = my_getattr(ctx, ino); > > ? if (MY_SUCCESS != ret) > > ??? { > > ????? if (MY_ENOENT != ret && > > ????????? MY_EPERM != ret) > > ??????? { > > ????????? if (tries < MAX_RETRIES) > > ??????????? { > > ????????????? HANDLE_TIMEOUT(tries, delay, "ino %llu", ino); > > ????????????? goto retry; > > ??????????? } > > ????????? else > > ??????????? { > > ????????????? MY_TRACE(MY_ERROR, 0u, "getattr: ino %llu"": I/O > error", ino); > > ????????????? return MY_FAILURE; > > ??????????? } > > ??????? } > > ??? } > > ? return ret; > > } > > > > A working patch > > @@ > > expression t; > > constant M; > > @@ > > ?????? if ( > > -??? ?? t < M > > +????????? foo(&ctx->retry_ctx) > > ????????? ) > > ????????? { > > ??? ? ... > > ??? ? } else { > > ??? ? ... > > ??? ? } > > > > A patch I can't make to work. That last one exists w/o > producing anything > > > > @@ > > expression t; > > constant M; > > @@ > > ?if (...) > > ?{? > > ??? if (...) > > ??? { > > ?????? if ( > > -??? ?? t < M > > +????????? foo(&ctx->retry_ctx) > > ????????? ) > > ????????? { > > ??? ? ... > > ??? ? } else { > > ??? ? ... > > ??? ? } > > ??? } > > ? } > > It seems to work fine for me: > > @@ -15,7 +15,7 @@ my_getattr_timeout(tmy_ctx *ctx, > ? ? ? ? ? ? ?if (MY_ENOENT != ret && > ? ? ? ? ? ? ? ? ? ? ? ? ? MY_EPERM != ret) > ? ? ? ? ? ? ? ? { > -? ? ? ? ? ? ? ? ?if (tries < MAX_RETRIES) > +? ? ? ? ? ? ? ? ?if (foo(&ctx->retry_ctx)) > ? ? ? ? ? ? ? ? ? ? ? { > ? ? ? ? ? ? ? ? ? ? ? ? HANDLE_TIMEOUT(tries, delay, "ino %llu", ino); > ? ? ? ? ? ? ? ? ? ? ? goto retry; > > What version of Coccinelle do you have? > > julia > > > > ^ permalink raw reply [flat|nested] 8+ messages in thread
* [Cocci] Patching nested if's? 2015-03-31 16:11 ` Julia Lawall @ 2015-03-31 16:12 ` François Armand 0 siblings, 0 replies; 8+ messages in thread From: François Armand @ 2015-03-31 16:12 UTC (permalink / raw) To: cocci Thanks. I'll update my version. 2015-03-31 18:11 GMT+02:00 Julia Lawall <julia.lawall@lip6.fr>: > > > On Tue, 31 Mar 2015, Fran?ois Armand wrote: > > > I'm on Ubuntu 14.04 > > spatch version 1.0.0-rc19 with Python support and with PCRE support > > The current release is 1.0.0-rc24. For Ubuntu, rc22 is available as a > PPA: https://launchpad.net/~npalix/+archive/ubuntu/coccinelle. Or you can > just get the github version: https://github.com/coccinelle/coccinelle > > julia > > > > > > > > > 2015-03-31 17:49 GMT+02:00 Julia Lawall <julia.lawall@lip6.fr>: > > > > > > On Tue, 31 Mar 2015, Fran?ois Armand wrote: > > > > > Better send my real stuff, than making misleading typos :-) > > > > > > My code: > > > #define MAX_RETRIES 3 > > > > > > tmy_status > > > my_getattr_timeout(tmy_ctx *ctx, > > > u64 ino) > > > { > > > tmy_status ret; > > > int tries = 0; > > > int delay = 1; > > > > > > retry: > > > ret = my_getattr(ctx, ino); > > > if (MY_SUCCESS != ret) > > > { > > > if (MY_ENOENT != ret && > > > MY_EPERM != ret) > > > { > > > if (tries < MAX_RETRIES) > > > { > > > HANDLE_TIMEOUT(tries, delay, "ino %llu", ino); > > > goto retry; > > > } > > > else > > > { > > > MY_TRACE(MY_ERROR, 0u, "getattr: ino %llu"": I/O > > error", ino); > > > return MY_FAILURE; > > > } > > > } > > > } > > > return ret; > > > } > > > > > > A working patch > > > @@ > > > expression t; > > > constant M; > > > @@ > > > if ( > > > - t < M > > > + foo(&ctx->retry_ctx) > > > ) > > > { > > > ... > > > } else { > > > ... > > > } > > > > > > A patch I can't make to work. That last one exists w/o > > producing anything > > > > > > @@ > > > expression t; > > > constant M; > > > @@ > > > if (...) > > > { > > > if (...) > > > { > > > if ( > > > - t < M > > > + foo(&ctx->retry_ctx) > > > ) > > > { > > > ... > > > } else { > > > ... > > > } > > > } > > > } > > > > It seems to work fine for me: > > > > @@ -15,7 +15,7 @@ my_getattr_timeout(tmy_ctx *ctx, > > if (MY_ENOENT != ret && > > MY_EPERM != ret) > > { > > - if (tries < MAX_RETRIES) > > + if (foo(&ctx->retry_ctx)) > > { > > HANDLE_TIMEOUT(tries, delay, "ino %llu", ino); > > goto retry; > > > > What version of Coccinelle do you have? > > > > julia > > > > > > > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: <https://systeme.lip6.fr/pipermail/cocci/attachments/20150331/3e51602c/attachment.html> ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2015-03-31 16:12 UTC | newest] Thread overview: 8+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2015-03-31 12:56 [Cocci] Patching nested if's? François Armand 2015-03-31 13:15 ` SF Markus Elfring 2015-03-31 13:47 ` Julia Lawall 2015-03-31 15:18 ` François Armand 2015-03-31 15:49 ` Julia Lawall 2015-03-31 16:06 ` François Armand 2015-03-31 16:11 ` Julia Lawall 2015-03-31 16:12 ` François Armand
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.