Matching function pointer typedef
Hello,
I am trying to modify an function pointer typedef something like:
@@
@@
- typedef void (*toto_t)(int a, int b);
+ typedef void (*toto_t)(int a, int b, int c);
But it seems spatch or the semantic does not handle function pointer. Or simply that typedef is not well handled in the first place. Thing like:
@@
@@
- typedef int nombre;
+ typedef unsigned nombre;
also fails to work. But if typedef is use with struct then it works. For instance:
@@
@@
- typedef struct {int a;} nombre;
+ typedef struct {unsigned a;} nombre;
Do work. Looking at declaration grammar i do not see why the former does not work. I am using fedora 27 coccinelle 1.0.6 if that matters.
Is this a known limitation or am i writting it wrong ?
Thank you for any input on this,
J?r?me
It's been a while since I used coccinelle, but I think to remember that you must (and in any case should) keep the non-changing parts outside of the +/- lines, e.g.
@@
@@
typedef void (*toto_t)(int a, int b
+ , int c
);
etc
BR H?kon L?vdal
Quoted 37 lines · Jerome Glisse
Hello,
I am trying to modify an function pointer typedef something like:
@@
@@
- typedef void (*toto_t)(int a, int b);
+ typedef void (*toto_t)(int a, int b, int c);But it seems spatch or the semantic does not handle function pointer. Or simply that typedef is not well handled in the first place. Thing like:
@@
@@
- typedef int nombre;
+ typedef unsigned nombre;also fails to work. But if typedef is use with struct then it works. For instance:
@@
@@
- typedef struct {int a;} nombre;
+ typedef struct {unsigned a;} nombre;Do work. Looking at declaration grammar i do not see why the former does not work. I am using fedora 27 coccinelle 1.0.6 if that matters.
Is this a known limitation or am i writting it wrong ?
Thank you for any input on this,
J?r?me
_______________________________________________
Cocci mailing list
Cocci at systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci
Quoted 9 lines · H?kon L?vdal
It's been a while since I used coccinelle, but I think to remember that you must (and in any case should) keep the non-changing parts outside of the +/- lines, e.g.
@@
@@
typedef void (*toto_t)(int a, int b
+ , int c);
I think that typedefs of function pointers just don't work. It is looking for typedef type name;. I can try to fix this.
julia
Quoted 48 lines
etc
BR H?kon L?vdal
Quoted 29 lines · Jerome Glisse
Hello,
I am trying to modify an function pointer typedef something like:
@@
@@
- typedef void (*toto_t)(int a, int b);
+ typedef void (*toto_t)(int a, int b, int c);But it seems spatch or the semantic does not handle function pointer. Or simply that typedef is not well handled in the first place. Thing like:
@@
@@
- typedef int nombre;
+ typedef unsigned nombre;also fails to work. But if typedef is use with struct then it works. For instance:
@@
@@
- typedef struct {int a;} nombre;
+ typedef struct {unsigned a;} nombre;Do work. Looking at declaration grammar i do not see why the former does not work. I am using fedora 27 coccinelle 1.0.6 if that matters.
Quoted 8 lines
Is this a known limitation or am i writting it wrong ?
Thank you for any input on this,
J?r?me
_______________________________________________
Cocci mailing list
Cocci at systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci_______________________________________________
Cocci mailing list
Cocci at systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci
Quoted 8 lines · Julia Lawall
Quoted 4 lines · H?kon L?vdal
It's been a while since I used coccinelle, but I think to remember that you must (and in any case should) keep the non-changing parts outside of the +/- lines, e.g.
Quoted 9 lines
Quoted 5 lines
@@
@@
typedef void (*toto_t)(int a, int b
+ , int c);I think that typedefs of function pointers just don't work. It is looking for typedef type name;. I can try to fix this.
Above does not work either. The error is same roughly spatch complains that it matches whole content ... I have a workaround, namely abusing gcc which accept:
typedef void toto_t(int a, int b);
For function pointer typedef and then coccinelle on function declaration do work. Still it would be nice if coccinelle can understand function pointer typedef.
J?r?me
Quoted 23 lines · Jerome Glisse
Quoted 8 lines · Julia Lawall
Quoted 4 lines · H?kon L?vdal
It's been a while since I used coccinelle, but I think to remember that you must (and in any case should) keep the non-changing parts outside of the +/- lines, e.g.
Quoted 9 lines
Quoted 5 lines
@@
@@
typedef void (*toto_t)(int a, int b
+ , int c);I think that typedefs of function pointers just don't work. It is looking for typedef type name;. I can try to fix this.
Above does not work either. The error is same roughly spatch complains that it matches whole content ... I have a workaround, namely abusing gcc which accept:
Quoted 5 lines
typedef void
toto_t(int a, int b);For function pointer typedef and then coccinelle on function declaration do work. Still it would be nice if coccinelle can understand function pointer typedef.
Ok my work around does work that well, it seems gcc allow this abuse only for function parameter type, it can not be use as a type inside a structure and so it doesn't cover all cases i am dealing with.
Is there a way to modify code using python inside coccinelle ? I have seen example that print thing inside coccinelle but i haven't not seen an example that use coccinelle to match something and then do changes to the code using python.
I am guessing i can open the file and use the position information to do that but was wondering if there is already helper provided for that.
Cheers,
J?r?me
Quoted 34 lines · Jerome Glisse
Quoted 23 lines · Jerome Glisse
Quoted 8 lines · Julia Lawall
Quoted 4 lines · H?kon L?vdal
It's been a while since I used coccinelle, but I think to remember that you must (and in any case should) keep the non-changing parts outside of the +/- lines, e.g.
Quoted 9 lines
Quoted 5 lines
@@
@@
typedef void (*toto_t)(int a, int b
+ , int c);I think that typedefs of function pointers just don't work. It is looking for typedef type name;. I can try to fix this.
Above does not work either. The error is same roughly spatch complains that it matches whole content ... I have a workaround, namely abusing gcc which accept:
Quoted 5 lines
typedef void
toto_t(int a, int b);For function pointer typedef and then coccinelle on function declaration do work. Still it would be nice if coccinelle can understand function pointer typedef.
Ok my work around does work that well, it seems gcc allow this abuse only for function parameter type, it can not be use as a type inside a structure and so it doesn't cover all cases i am dealing with.
Quoted 7 lines
Is there a way to modify code using python inside coccinelle ? I have seen example that print thing inside coccinelle but i haven't not seen an example that use coccinelle to match something and then do changes to the code using python.
I am guessing i can open the file and use the position information to do that but was wondering if there is already helper provided for that.
No, python code doesn't have access to the ast, which is an ocaml structure.
julia
Quoted 4 lines
Cheers,
J?r?me
Quoted 8 lines · Jerome Glisse
Hello,
I am trying to modify an function pointer typedef something like:
@@
@@
- typedef void (*toto_t)(int a, int b);
+ typedef void (*toto_t)(int a, int b, int c);
This now works. Currently, you need to remove the whole typedef and add it back, not just add the third argument as H?kon suggested.
Quoted 9 lines
But it seems spatch or the semantic does not handle function pointer. Or simply that typedef is not well handled in the first place. Thing like:
@@
@@
- typedef int nombre;
+ typedef unsigned nombre;
Was this just an experiment, or is it something you need? I would imagine that the problem is that "unsigned" as a type by itself is not well supported.
julia
Quoted 20 lines
also fails to work. But if typedef is use with struct then it works. For instance:
@@
@@
- typedef struct {int a;} nombre;
+ typedef struct {unsigned a;} nombre;Do work. Looking at declaration grammar i do not see why the former does not work. I am using fedora 27 coccinelle 1.0.6 if that matters.
Is this a known limitation or am i writting it wrong ?
Thank you for any input on this,
J?r?me
_______________________________________________
Cocci mailing list
Cocci at systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci
Quoted 8 lines · Julia Lawall
Quoted 4 lines · Jerome Glisse
Hello,
I am trying to modify an function pointer typedef something like:
Quoted 7 lines
Quoted 4 lines
@@
@@
- typedef void (*toto_t)(int a, int b);
+ typedef void (*toto_t)(int a, int b, int c);This now works. Currently, you need to remove the whole typedef and add it back, not just add the third argument as H?kon suggested.
Awesome ! :) Thank you for working on that.
Quoted 6 lines
Quoted 6 lines
But it seems spatch or the semantic does not handle function pointer. Or simply that typedef is not well handled in the first place. Thing like:
Quoted 8 lines
Quoted 4 lines
@@
@@
- typedef int nombre;
+ typedef unsigned nombre;Was this just an experiment, or is it something you need? I would imagine that the problem is that "unsigned" as a type by itself is not well supported.
This was just an experiment i did while trying to understand why my function pointer typedef changes did not work. If i use long or any basic ctype then it works.
Cheers,
J?r?me
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 9 lines · SF Markus Elfring
Quoted 8 lines
Quoted 6 lines
I am trying to modify an function pointer typedef something like:
@@
@@
- typedef void (*toto_t)(int a, int b);
+ typedef void (*toto_t)(int a, int b, int c);This now works.
Quoted 8 lines
Thanks for another software improvement.
https://github.com/coccinelle/coccinelle/commit/80dcf751e411f1421fdcdb7119a95e50b841609cQuoted 1 line
Currently, you need to remove the whole typedef and add it back,
I find this information inappropriate because such a source code replacement was attempted.
It was attempted before the change was made.
julia
Quoted 12 lines
Quoted 3 lines
not just add the third argument as H?kon suggested.
It can be clearer to limit changes precisely while it can be also occasionally nice to extend the adjustment a bit so that the affected source code will be hopefully reformatted by the Coccinelle software in a desired way.
https://github.com/coccinelle/coccinelle/issues/37Regards,
Markus
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 10 lines · SF Markus Elfring
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
Currently, you need to remove the whole typedef and add it back,
I find this information inappropriate because such a source code replacement was attempted.
It was attempted before the change was made.
I get the impression from such feedback that another clarification would be useful about the granularity if each function parameter can be adjusted in data type definitions finally.
Concretely, the typedef name has to appear on the same line as all the parameters.
julia