[master] a3e3c4231 cocci: Work around usleep.cocci shortcoming

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Thu Feb 6 10:00:10 UTC 2025


commit a3e3c423164858f4b6e7b60d08939ae6505287fb
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date:   Thu Feb 6 10:56:20 2025 +0100

    cocci: Work around usleep.cocci shortcoming
    
    Refs coccinelle/coccinelle#390

diff --git a/tools/coccinelle/usleep.cocci b/tools/coccinelle/usleep.cocci
index d8d245bd5..1dcda70c0 100644
--- a/tools/coccinelle/usleep.cocci
+++ b/tools/coccinelle/usleep.cocci
@@ -1,45 +1,33 @@
 /* This patch turns hard-coded usleep() usage into a VTIM_sleep() equivalent.
- *
- * Unfortunately, if a file contains the same usleep() call twice, each call
- * site will be substituted twice.
- *
- * This code:
- *
- *     usleep(10000);
- *     usleep(10000);
- *
- * Will turn into this:
- *
- *     VTIM_sleep(0.01)VTIM_sleep(0.01);
- *     VTIM_sleep(0.01)VTIM_sleep(0.01);
- *
- * Fortunately, it does not compile and cannot go unnoticed.
  */
 
 @found@
 constant int usec;
+position pos;
 @@
 
-usleep(usec)
+usleep at pos(usec)
 
 @script:python conv@
 usec << found.usec;
+pos << found.pos;
 sec;
 @@
 
 coccinelle.sec = cocci.make_expr("{:g}".format(int(usec) / 1000000.0))
 
- at uncast@
+ at replace@
 constant int found.usec;
+position found.pos;
+expression conv.sec;
 @@
 
-- (void)usleep(usec)
-+ usleep(usec)
+- usleep at pos(usec)
++ VTIM_sleep(sec)
 
- at replace@
-constant int found.usec;
-expression conv.sec;
+ at uncast@
+expression e;
 @@
 
--  usleep(usec)
-++ VTIM_sleep(sec)
+- (void)
+  VTIM_sleep(e)


More information about the varnish-commit mailing list