Re: [cocci] Searching for duplicate exception handling code with SmPL?
Julia Lawall <[email protected]> Sun, 21 Jun 2026 09:10:57 +0200 (CEST)
| Newsgroups | fr.inria.cocci |
|---|---|
| Message-ID | <[email protected]> |
This message is in MIME format. The first part should be readable text,
while the remaining parts are likely unreadable without MIME-aware tools.
--8323329-2095889798-1782025857=:3925
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8BIT
On Sun, 21 Jun 2026, Markus Elfring wrote:
> > Can such measurements influence any development approaches?
>
> I suggest to take also information from another SmPL script variant
> better into account.
>
>
> @initialize:python@
> @@
> import sys, time
> records = []
>
> def convert_to_seconds(x):
> return x / (10 ** 9)
>
> def store_data(source):
> """Add data to the list."""
> x = time.monotonic_ns()
> sys.stderr.write(f"store_data() was called after {x - init_time} ns from initialisation.\n")
>
> for place in source:
> records.append(1)
>
> sys.stderr.write(f"store_data() was finished after {time.monotonic_ns() - x} ns.\n")
>
> init_time = time.monotonic_ns()
> sys.stderr.write(f"{convert_to_seconds(init_time)}: Initialisation was finished.\n")
>
> @searching exists@
> expression e, x;
> identifier item, rc;
> position p;
> @@
> if (...)
> {
> ... when != rc = e
> when != item = x
> kfree@p(item);
> return rc;
> }
>
> @script:python collection@
> p << searching.p;
> @@
> store_data(p)
>
> @finalize:python@
> @@
> if records:
> sys.stdout.write(f"{len(records)} selected statement combinations were found after {time.monotonic_ns() - init_time} ns from initialisation.\n")
> else:
> sys.stderr.write("No result for this analysis!\n")
>
>
>
> Test result:
> Markus_Elfring@Sonne:…/Projekte/Coccinelle/Probe> time echo $(grep -E 'kfree\(name2\);' map_fnode_dirent-excerpt-20260618.c | wc -l)
> 9
>
> real 0m0,007s
> user 0m0,002s
> sys 0m0,005s
> Markus_Elfring@Sonne:…/Projekte/Coccinelle/Probe> time /usr/bin/spatch --no-loops ../janitor/count_selected_if_branches.cocci map_fnode_dirent-excerpt-20260618.c
> …
> 5647.095966535: Initialisation was finished.
> HANDLING: map_fnode_dirent-excerpt-20260618.c
> store_data() was called after 365741113 ns from initialisation.
> store_data() was finished after 46703 ns.
> …
> store_data() was called after 366355893 ns from initialisation.
> store_data() was finished after 13051 ns.
> 9 selected statement combinations were found after 366512248 ns from initialisation.
>
> real 0m0,602s
> user 0m0,517s
> sys 0m0,081s
>
>
> The last kfree() call is counted here despite of the implementation detail
> that it is actually not explicitly specified within a known if branch.
>
> How would you determine the incidence distribution for discussed if branches
> from all Linux source files then?
As now mentioned numerous times, you have to prevent the ... from matching
a goto.
julia
>
> Regards,
> Markus
>
--8323329-2095889798-1782025857=:3925--