Skip to contentSkip to conversation

Updating all call sites of a function?

cocci Richard Weinberger 3 participants 3 messages Nov 27, 2023 1 message not in the archive

lore
Share & tools
lore
#1 lore raw
In reply to a message not in the archive

----- Ursprüngliche Mail -----

Quoted 22 lines

Von: "richard" <[email protected]>
An: "cocci" <[email protected]>
Gesendet: Dienstag, 21. November 2023 12:55:51
Betreff: Updating all call sites of a function?

Hi!

I would like to inquire about best practices for updating all call sites of a function.
During refactoring, I changed the name and arguments of a function. For example:

ubi_rmvol(libubi, dev, n);

becomes:

ubi_rmvol_wait(libubi, dev, n, 10);

What approach do you suggest to catch all call sites, especially where the call is
part of a non-trivial expression?

Quoted 6 lines

e.g.
ret = ubi_rmvol(libubi, dev, n);

if (ubi_rmvol(libubi, dev, n)) { ...

while(0 != ubi_rmvol(libubi, dev, n)) ...

Johannes pointed out on IRC that I think too complicated and gave me an example. This does the trick:
@@
expression uctx, dev, n;
@@
- ubi_rmvol(uctx, dev, n)
+ ubi_rmvol_wait(uctx, dev, n, 10)

My fist version always had a trailing ";", so they matched only trivial callers...

Thanks,
//richard

#2 lore raw
Quoted 38 lines · Richard Weinberger

----- Ursprüngliche Mail -----

Quoted 22 lines

Von: "richard" <[email protected]>
An: "cocci" <[email protected]>
Gesendet: Dienstag, 21. November 2023 12:55:51
Betreff: Updating all call sites of a function?

Hi!

I would like to inquire about best practices for updating all call sites of a function.
During refactoring, I changed the name and arguments of a function. For example:

ubi_rmvol(libubi, dev, n);

becomes:

ubi_rmvol_wait(libubi, dev, n, 10);

What approach do you suggest to catch all call sites, especially where the call is
part of a non-trivial expression?

Quoted 6 lines

e.g.
ret = ubi_rmvol(libubi, dev, n);

if (ubi_rmvol(libubi, dev, n)) { ...

while(0 != ubi_rmvol(libubi, dev, n)) ...

Johannes pointed out on IRC that I think too complicated and gave me an example. This does the trick:
@@
expression uctx, dev, n;
@@
- ubi_rmvol(uctx, dev, n)
+ ubi_rmvol_wait(uctx, dev, n, 10)

Quoted 1 line

My fist version always had a trailing ";", so they matched only trivial callers...

Exactly.

julia

#3 lore raw
In reply to Richard Weinberger
Quoted 7 lines

Johannes pointed out on IRC that I think too complicated and gave me an example. This does the trick:
@@
expression uctx, dev, n;
@@
- ubi_rmvol(uctx, dev, n)
+ ubi_rmvol_wait(uctx, dev, n, 10)

How do you think about the possibility to apply the following SmPL script variant?

@adjustment@
@@
-ubi_rmvol
+ubi_rmvol_wait
(
...
+ , 10
)

Regards,
Markus