Skip to contentSkip to conversation

Changing function pointer typedef

Cocci Jerome Glisse 2 participants 6 messages Mar 8, 2019 – Mar 17, 2019

lore
Share & tools
lore
#0 lore raw

Coccinelle seems to have issue with function pointer. For instance if i want to add a new argument to a function pointer typdef i need to replace the whole typedef as one line. For instance:

test.c:
typedef int (*filler_t)(void *, struct page *);

test.spatch:
@@
type T1, T2;
@@
-typedef int (*filler_t)(T1, T2);
+typedef int (*filler_t)(T1, struct address_space *, T2);

Anything else will not work and also if the function pointer typedef spread accross multiple line then the above does not work, in fact i have not found a work around for that case.

I am missing some syntax that make this work with coccinelle ?

Cheers,
Jérôme
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

#1 lore raw
Quoted 14 lines · Jerome Glisse

Coccinelle seems to have issue with function pointer. For instance if i want to add a new argument to a function pointer typdef i need to replace the whole typedef as one line. For instance:

test.c:
typedef int (*filler_t)(void *, struct page *);

test.spatch:
@@
type T1, T2;
@@

(quoted diff) +1 -1
-typedef int (*filler_t)(T1, T2);
+typedef int (*filler_t)(T1, struct address_space *, T2);
Quoted 5 lines

Anything else will not work and also if the function pointer typedef spread accross multiple line then the above does not work, in fact i have not found a work around for that case.

I am missing some syntax that make this work with coccinelle ?

Thanks for the report. Is the error you got something like:

error in collection of - tokens: line 4 less than line 6

I will have to look into it.

julia
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

#2 lore raw
Quoted 22 lines · Julia Lawall
Quoted 18 lines · Jerome Glisse

Coccinelle seems to have issue with function pointer. For instance if i want to add a new argument to a function pointer typdef i need to replace the whole typedef as one line. For instance:

test.c:
typedef int (*filler_t)(void *, struct page *);

test.spatch:
@@
type T1, T2;
@@

(quoted diff) +1 -1
-typedef int (*filler_t)(T1, T2);
+typedef int (*filler_t)(T1, struct address_space *, T2);

Anything else will not work and also if the function pointer typedef spread accross multiple line then the above does not work, in fact i have not found a work around for that case.

Quoted 7 lines
Quoted 1 line

I am missing some syntax that make this work with coccinelle ?

Thanks for the report. Is the error you got something like:

error in collection of - tokens: line 4 less than line 6

I will have to look into it.

With:
@@
type T1, T2;
@@
typedef int (*filler_t)(T1,
+struct address_space *,
T2);

I get:
error in collection of - tokens: line 4 less than line 6

The error message depends on the semantic patch i tried several variation hopping to find some syntax that would work but failed so far.

In case of multiline typdef:
minus: parse error:
File "typedef-func.spatch", line 6, column 0, charpos = 101 around = '',
whole content =

test.c:
typedef int (*filler_t)(void *,

    struct page *);

test.spatch
@@
type T1, T2;
@@
-typedef int (*filler_t)(T1,
+typedef int (*filler_t)(T1, struct address_space *,
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

#3 lore raw

Review

Quoted 6 lines

test.spatch
@@
type T1, T2;
@@

(quoted diff) +1 -1
-typedef int (*filler_t)(T1,
+typedef int (*filler_t)(T1, struct address_space *,

If this is the whole rule, it is clear that it will not work. A semantic patch rule has to e a complete syntactic unit. So something with an open parenthesis and no corresponding close parenthesis will not be accepted.

julia
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

#4 lore raw
Quoted 10 lines · Julia Lawall

Review

Quoted 6 lines

test.spatch
@@
type T1, T2;
@@

(quoted diff) +1 -1
-typedef int (*filler_t)(T1,
+typedef int (*filler_t)(T1, struct address_space *,

If this is the whole rule, it is clear that it will not work. A semantic patch rule has to e a complete syntactic unit. So something with an open parenthesis and no corresponding close parenthesis will not be accepted.

Yeah and adding "T2);" to the rule does not help either it error to error in collection of - tokens: line 4 less than line 6

Any variation really do error in some way or another.

Cheers,
Jérôme
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

#5 lore raw
Quoted 12 lines · Jerome Glisse
Quoted 10 lines · Julia Lawall

Review

Quoted 6 lines

test.spatch
@@
type T1, T2;
@@

(quoted diff) +1 -1
-typedef int (*filler_t)(T1,
+typedef int (*filler_t)(T1, struct address_space *,

If this is the whole rule, it is clear that it will not work. A semantic patch rule has to e a complete syntactic unit. So something with an open parenthesis and no corresponding close parenthesis will not be accepted.

Quoted 4 lines

Yeah and adding "T2);" to the rule does not help either it error to error in collection of - tokens: line 4 less than line 6

Any variation really do error in some way or another.

This problem is fixed. Thanks for the report.

julia
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci