mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* Improving output for single characters (with SmPL)?
@ 2026-07-22 17:03 Markus Elfring
  2026-07-23 19:26 ` Markus Elfring
  2026-07-24  9:02 ` Markus Elfring
  0 siblings, 2 replies; 8+ messages in thread
From: Markus Elfring @ 2026-07-22 17:03 UTC (permalink / raw)
  To: cocci, kernel-janitors; +Cc: LKML

Hello,

I would like to achieve further source code adjustments by the means of
the following script variant for the semantic patch language.


Example:
@initialize:python@
@@
input = ''

def convert(item):
   mark = ["'", item, "'"]
   coccinelle.text = cocci.make_expr(''.join(mark))

def common_checks(unescaped):
   if input[1] == '"':
      if input[2:] == '':
         convert(input[0] if unescaped else '\\' + input[0])
      else:
         cocci.include_match(False)
   else:
      cocci.include_match(False)

@find_update_candidate@
constant char[] input_string;
expression input_context;
position pos;
@@
 fprintf@pos(input_context, input_string);

@script:python selection@
param << find_update_candidate.input_string;
text;
@@
if param[0] == '"':
   input = param[1:]
   if input[0] == '\\':
      input = input[1:]
      if input[0] == '"':
         if input[1] == '"':
            if input[2:] == '':
               convert('"')
            else:
               cocci.include_match(False)
         else:
            cocci.include_match(False)
      else:
         common_checks(False)
   else:
      common_checks(True)
else:
   cocci.include_match(False)

@replacement@
constant char[] find_update_candidate.input_string, selection.text;
expression find_update_candidate.input_context;
position find_update_candidate.pos;
@@
(
-fprintf@pos
+putchar
 (
-stdout,
-input_string
+text
 )
|
-fprintf@pos
+fputc
 (input_context,
-input_string
+text
 )
)


Questionable test result (according to the software combination “Coccinelle 1.3.1”):
Markus_Elfring@Sonne:…/Projekte/Linux/next-analyses/tools> time /usr/bin/spatch --timeout 23 -j4 --chunksize 1 --include-headers --no-loops -dir . …/Projekte/Coccinelle/janitor/use_fputc-20260722.cocci > …/Projekte/Bau/Linux/scripts/Coccinelle/tuning1/next/20260721/use_fputc.diff
…
HANDLING: ./tracing/rtla/src/osnoise.c
An error occurred when attempting to transform some files.

real    0m34,627s
user    1m52,330s
sys     0m4,022s

Markus_Elfring@Sonne:…/Projekte/Linux/next-analyses> lsdiff …/Projekte/Bau/Linux/scripts/Coccinelle/tuning1/next/20260721/use_fputc.diff | wc -l
49

Markus_Elfring@Sonne:…/Projekte/Linux/next2-patched/tools> LANG=C git apply …/Projekte/Bau/Linux/scripts/Coccinelle/tuning1/next/20260721/use_fputc.diff
error: patch failed: tools/bpf/bpftool/netlink_dumper.h:25
error: tools/bpf/bpftool/netlink_dumper.h: patch does not apply


Which implementation details should be reconsidered here for an affected macro?
https://elixir.bootlin.com/linux/v7.2-rc4/source/tools/bpf/bpftool/netlink_dumper.h#L25

How will chances evolve to adjust more places according to remaining update candidates?

Regards,
Markus

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Improving output for single characters (with SmPL)?
  2026-07-22 17:03 Improving output for single characters (with SmPL)? Markus Elfring
@ 2026-07-23 19:26 ` Markus Elfring
  2026-07-24  9:02 ` Markus Elfring
  1 sibling, 0 replies; 8+ messages in thread
From: Markus Elfring @ 2026-07-23 19:26 UTC (permalink / raw)
  To: cocci, kernel-janitors; +Cc: LKML

> I would like to achieve further source code adjustments by the means of
> the following script variant for the semantic patch language.

Unfortunately, the SmPL code needs to be corrected a bit in the final
replacement rule.
The parameter order should be reversed from selected fprintf() to fputc() calls.

@initialize:python@
@@
input = ''

def convert(item):
   mark = ["'", item, "'"]
   coccinelle.text = cocci.make_expr(''.join(mark))

def common_checks(unescaped):
   if input[1] == '"':
      if input[2:] == '':
         convert(input[0] if unescaped else '\\' + input[0])
      else:
         cocci.include_match(False)
   else:
      cocci.include_match(False)

@find_update_candidate@
constant char[] input_string;
expression input_context;
position pos;
@@
 fprintf@pos(input_context, input_string);

@script:python selection@
param << find_update_candidate.input_string;
text;
@@
if param[0] == '"':
   input = param[1:]
   if input[0] == '\\':
      input = input[1:]
      if input[0] == '"':
         if input[1] == '"':
            if input[2:] == '':
               convert('"')
            else:
               cocci.include_match(False)
         else:
            cocci.include_match(False)
      else:
         common_checks(False)
   else:
      common_checks(True)
else:
   cocci.include_match(False)

@replacement@
constant char[] find_update_candidate.input_string, selection.text;
expression find_update_candidate.input_context;
position find_update_candidate.pos;
@@
(
-fprintf@pos
+putchar
 (
-stdout,
-input_string
+text
 )
|
-fprintf@pos
+fputc
 (
-input_context
+text
 ,
-input_string
+input_context
 )
)


Another test result (according to the software combination “Coccinelle 1.3.1”):
Markus_Elfring@Sonne:…/Projekte/Linux/next-analyses> time /usr/bin/spatch --timeout 23  -j4 --chunksize 1 --no-loops --include-headers -dir tools …/Projekte/Coccinelle/janitor/use_fputc-20260723.cocci > …/Projekte/Bau/Linux/scripts/Coccinelle/tuning1/next/20260721/use_fputc.diff
…
548 files match
…
real    0m35,324s
user    1m54,532s
sys     0m3,473s
Markus_Elfring@Sonne:/home/altes_Heim2/elfring/Projekte/Linux/next-analyses> lsdiff /home/altes_Heim2/elfring/Projekte/Bau/Linux/scripts/Coccinelle/tuning1/next/20260721/use_fputc.diff | wc -l
50



I hope that demonstrated data processing possibilities can influence further
development ideas in constructive ways besides hints that some compilers
can also perform such a source code transformation already.

Regards,
Markus

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Improving output for single characters (with SmPL)?
  2026-07-22 17:03 Improving output for single characters (with SmPL)? Markus Elfring
  2026-07-23 19:26 ` Markus Elfring
@ 2026-07-24  9:02 ` Markus Elfring
  2026-08-01  8:10   ` Markus Elfring
  1 sibling, 1 reply; 8+ messages in thread
From: Markus Elfring @ 2026-07-24  9:02 UTC (permalink / raw)
  To: cocci; +Cc: LKML, kernel-janitors

> Which implementation details should be reconsidered here for an affected macro?
> https://elixir.bootlin.com/linux/v7.2-rc4/source/tools/bpf/bpftool/netlink_dumper.h#L25

The shown source code transformation approach can be repeated on demand
for selected areas.

Another test result (according to the software combination “Coccinelle 1.3.1”):
Markus_Elfring@Sonne:…/Projekte/Linux/next-analyses> time /usr/bin/spatch --timeout 23 -j4 --chunksize 1 --no-loops --include-headers -dir tools/bpf/bpftool /home/altes_Heim2/elfring/Projekte/Coccinelle/janitor/use_fputc-20260723.cocci > /home/altes_Heim2/elfring/Projekte/Bau/Linux/scripts/Coccinelle/tuning1/next/20260721/use_fputc-bpftool-2.diff
…
17 files match
…
real    0m1,998s
user    0m4,143s
sys     0m0,372s



Now I wonder about the following information.

Markus_Elfring@Sonne:/home/altes_Heim2/elfring/Projekte/Linux/next-analyses> grep 'diff -u -p a/netlink_dumper.h b/netlink_dumper.h' /home/altes_Heim2/elfring/Projekte/Bau/Linux/scripts/Coccinelle/tuning1/next/20260721/use_fputc-bpftool-2.diff | wc -l
2


Should it be sufficient to adjust an affected header file only once
(according to the means of the mentioned development tool)?
https://gitlab.inria.fr/coccinelle/coccinelle/-/blob/bd41911b6d35eda4d9a03247043bd3879733fb3f/docs/manual/spatch_options.tex#L43-46

Regards,
Markus

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Improving output for single characters (with SmPL)?
  2026-07-24  9:02 ` Markus Elfring
@ 2026-08-01  8:10   ` Markus Elfring
  2026-08-01  8:18     ` Julia Lawall
  0 siblings, 1 reply; 8+ messages in thread
From: Markus Elfring @ 2026-08-01  8:10 UTC (permalink / raw)
  To: cocci; +Cc: LKML, kernel-janitors

>> Which implementation details should be reconsidered here for an affected macro?
>> https://elixir.bootlin.com/linux/v7.2-rc4/source/tools/bpf/bpftool/netlink_dumper.h#L25
> 
> The shown source code transformation approach can be repeated on demand
> for selected areas.

I would like to add that only a single diff hunk is generated for the following script variant
of the semantic patch language (as it would usually be expected for the mentioned software component).

@replacement@
@@
-fprintf
+putchar
 (
-stdout, "\n"
+'\n'
 )


> Now I wonder about the following information.
> 
> Markus_Elfring@Sonne:/home/altes_Heim2/elfring/Projekte/Linux/next-analyses> grep 'diff -u -p a/netlink_dumper.h b/netlink_dumper.h' /home/altes_Heim2/elfring/Projekte/Bau/Linux/scripts/Coccinelle/tuning1/next/20260721/use_fputc-bpftool-2.diff | wc -l
> 2

How can the generation of duplicate difference output be avoided here
for other SmPL script variations?

Regards,
Markus

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Improving output for single characters (with SmPL)?
  2026-08-01  8:10   ` Markus Elfring
@ 2026-08-01  8:18     ` Julia Lawall
  2026-08-01 12:00       ` [cocci] " Markus Elfring
  2026-08-02 10:06       ` Markus Elfring
  0 siblings, 2 replies; 8+ messages in thread
From: Julia Lawall @ 2026-08-01  8:18 UTC (permalink / raw)
  To: Markus Elfring; +Cc: cocci, LKML, kernel-janitors



On Sat, 1 Aug 2026, Markus Elfring wrote:

> >> Which implementation details should be reconsidered here for an affected macro?
> >> https://elixir.bootlin.com/linux/v7.2-rc4/source/tools/bpf/bpftool/netlink_dumper.h#L25
> >
> > The shown source code transformation approach can be repeated on demand
> > for selected areas.
>
> I would like to add that only a single diff hunk is generated for the following script variant
> of the semantic patch language (as it would usually be expected for the mentioned software component).
>
> @replacement@
> @@
> -fprintf
> +putchar
>  (
> -stdout, "\n"
> +'\n'
>  )
>
>
> > Now I wonder about the following information.
> >
> > Markus_Elfring@Sonne:/home/altes_Heim2/elfring/Projekte/Linux/next-analyses> grep 'diff -u -p a/netlink_dumper.h b/netlink_dumper.h' /home/altes_Heim2/elfring/Projekte/Bau/Linux/scripts/Coccinelle/tuning1/next/20260721/use_fputc-bpftool-2.diff | wc -l
> > 2
>
> How can the generation of duplicate difference output be avoided here
> for other SmPL script variations?

I don't know the details o what you are doing, but if you have duplicated
output about herder files, it would be because the header file is included
in other files.  If there is no need to process the header file
specifically based on a given .c file (which would be the case for the rul
shown above), then you can use the option --no-includes.  If you want some
type information from header files but you don't want to transform them in
a way that is specific to the .c file in which they are included then you
can also use --include-headers-for-types.

julia


>
> Regards,
> Markus
>
>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [cocci] Improving output for single characters (with SmPL)?
  2026-08-01  8:18     ` Julia Lawall
@ 2026-08-01 12:00       ` Markus Elfring
  2026-08-02 10:06       ` Markus Elfring
  1 sibling, 0 replies; 8+ messages in thread
From: Markus Elfring @ 2026-08-01 12:00 UTC (permalink / raw)
  To: Julia Lawall, cocci; +Cc: LKML, kernel-janitors

>>> Markus_Elfring@Sonne:/home/altes_Heim2/elfring/Projekte/Linux/next-analyses> grep 'diff -u -p a/netlink_dumper.h b/netlink_dumper.h' /home/altes_Heim2/elfring/Projekte/Bau/Linux/scripts/Coccinelle/tuning1/next/20260721/use_fputc-bpftool-2.diff | wc -l
>>> 2
>>
>> How can the generation of duplicate difference output be avoided here
>> for other SmPL script variations?
> 
> I don't know the details o what you are doing,

How does such a feedback fit to provided information?


>                                                but if you have duplicated
> output about herder files, it would be because the header file is included
> in other files.

Duplicate difference hunks are not produced in all test cases.

Can you reproduce unexpected software behaviour also in your test environment?

Regards,
Markus

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [cocci] Improving output for single characters (with SmPL)?
  2026-08-01  8:18     ` Julia Lawall
  2026-08-01 12:00       ` [cocci] " Markus Elfring
@ 2026-08-02 10:06       ` Markus Elfring
  2026-08-03  5:40         ` [cocci] Improving parallel data processing for hierarchical structures? Markus Elfring
  1 sibling, 1 reply; 8+ messages in thread
From: Markus Elfring @ 2026-08-02 10:06 UTC (permalink / raw)
  To: Julia Lawall, cocci; +Cc: LKML, kernel-janitors

>> How can the generation of duplicate difference output be avoided here
>> for other SmPL script variations?
> 
>                                             …, but if you have duplicated
> output about herder files, it would be because the header file is included
> in other files.  …
I would appreciate further clarifications for corresponding case distinctions.
Is it usual that header files would be included multiple times by other files?

Do additional developers care any more for working file inclusion
also according to mentioned source code transformation approaches?

How will development interests and resources grow?

Regards,
Markus

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [cocci] Improving parallel data processing for hierarchical structures?
  2026-08-02 10:06       ` Markus Elfring
@ 2026-08-03  5:40         ` Markus Elfring
  0 siblings, 0 replies; 8+ messages in thread
From: Markus Elfring @ 2026-08-03  5:40 UTC (permalink / raw)
  To: Julia Lawall, cocci, kernel-janitors; +Cc: LKML

> Do additional developers care any more for working file inclusion
> also according to mentioned source code transformation approaches?
> 
> How will development interests and resources grow?

There are some challenges involved especially according to parallel data processing
for hierarchical structures.
Will any more design and implementation approaches be picked up accordingly?

Regards,
Markus

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2026-08-03  5:41 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-07-22 17:03 Improving output for single characters (with SmPL)? Markus Elfring
2026-07-23 19:26 ` Markus Elfring
2026-07-24  9:02 ` Markus Elfring
2026-08-01  8:10   ` Markus Elfring
2026-08-01  8:18     ` Julia Lawall
2026-08-01 12:00       ` [cocci] " Markus Elfring
2026-08-02 10:06       ` Markus Elfring
2026-08-03  5:40         ` [cocci] Improving parallel data processing for hierarchical structures? Markus Elfring

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®