Skip to contentSkip to conversation

Replacing one (specific!) type with another

Cocci Nikolaus Rath 4 participants 46 messages Oct 5, 2016 – Oct 12, 2016 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

Hello,

In a set of C files, I would like to replace each instance of one type (struct fasel_foo) with another type (struct fasel_bar). For instance,

char* fasel_foo_print(struct fasel_foo *ptr) {
    // ...

return "this struct fasel_foo string should not change";
}

should become

char* fasel_foo_print(struct fasel_bar *ptr) {
    // ...

return "this struct fasel_foo string should not change";
}

Based on the LWN articles that I've read, this seems like the perfect use-case for coccinelle. However, somehow I'm struggling to write a patch for this. All the documentation that I could get my hands on seems to describe more abstract changes that require the use of variables - but as far as I can tell, I need something much simpler:

@@
"struct fasel_foo must be a type name!"
@@
- struct fasel_foo
+ struct fasel_bar

...if only I knew what to put between the @@.

Can someone point me in the right direction?

Best,
-Nikolaus

Signature · 4 lines
GPG encrypted emails preferred. Key id: 0xD113FCAC3C4E599F
Fingerprint: ED31 791B 2C5C 1613 AF38 8B8A D113 FCAC 3C4E 599F

             ?Time flies like an arrow, fruit flies like a Banana.?
#1 lore raw
Quoted 24 lines · Nikolaus Rath

Hello,

In a set of C files, I would like to replace each instance of one type (struct fasel_foo) with another type (struct fasel_bar). For instance,

char* fasel_foo_print(struct fasel_foo *ptr) {
    // ...

return "this struct fasel_foo string should not change";
}

should become

char* fasel_foo_print(struct fasel_bar *ptr) {
    // ...

return "this struct fasel_foo string should not change";
}

Based on the LWN articles that I've read, this seems like the perfect use-case for coccinelle. However, somehow I'm struggling to write a patch for this. All the documentation that I could get my hands on seems to describe more abstract changes that require the use of variables - but as far as I can tell, I need something much simpler:

Quoted 8 lines

@@
"struct fasel_foo must be a type name!"
@@
- struct fasel_foo
+ struct fasel_bar

...if only I knew what to put between the @@.

Put nothing :) From the word struct it should figure out that it is working on a type.

julia

Quoted 17 lines

Can someone point me in the right direction?

Best,
-Nikolaus

--
GPG encrypted emails preferred. Key id: 0xD113FCAC3C4E599F
Fingerprint: ED31 791B 2C5C 1613 AF38 8B8A D113 FCAC 3C4E 599F

?Time flies like an arrow, fruit flies like a Banana.?
_______________________________________________
Cocci mailing list
Cocci at systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

#2 lore raw
Quoted 33 lines · Julia Lawall
Quoted 31 lines · Nikolaus Rath

Hello,

In a set of C files, I would like to replace each instance of one type (struct fasel_foo) with another type (struct fasel_bar). For instance,

char* fasel_foo_print(struct fasel_foo *ptr) {
    // ...

return "this struct fasel_foo string should not change";
}

should become

char* fasel_foo_print(struct fasel_bar *ptr) {
    // ...

return "this struct fasel_foo string should not change";
}

Based on the LWN articles that I've read, this seems like the perfect use-case for coccinelle. However, somehow I'm struggling to write a patch for this. All the documentation that I could get my hands on seems to describe more abstract changes that require the use of variables - but as far as I can tell, I need something much simpler:

@@
"struct fasel_foo must be a type name!"
@@
- struct fasel_foo
+ struct fasel_bar

Quoted 4 lines
Quoted 1 line

...if only I knew what to put between the @@.

Put nothing :) From the word struct it should figure out that it is working on a type.

Oh, great! Thanks!

This solves my problem, but it makes me wonder how this generalizes to other problems. For example,

1. What would I need to do if I don't want to replace a struct but something typedef'd? (my_type *ptr --> new_type *ptr).

2. ..and how would I go about if instead of the type, I want to replace a variable name? (my_type *ptr --> my_type *pointer).

Best,
-Nikolaus

Signature · 4 lines
GPG encrypted emails preferred. Key id: 0xD113FCAC3C4E599F
Fingerprint: ED31 791B 2C5C 1613 AF38 8B8A D113 FCAC 3C4E 599F

             ?Time flies like an arrow, fruit flies like a Banana.?
#3 lore raw
Quoted 39 lines · Nikolaus Rath
Quoted 33 lines · Julia Lawall
Quoted 31 lines · Nikolaus Rath

Hello,

In a set of C files, I would like to replace each instance of one type (struct fasel_foo) with another type (struct fasel_bar). For instance,

char* fasel_foo_print(struct fasel_foo *ptr) {
    // ...

return "this struct fasel_foo string should not change";
}

should become

char* fasel_foo_print(struct fasel_bar *ptr) {
    // ...

return "this struct fasel_foo string should not change";
}

Based on the LWN articles that I've read, this seems like the perfect use-case for coccinelle. However, somehow I'm struggling to write a patch for this. All the documentation that I could get my hands on seems to describe more abstract changes that require the use of variables - but as far as I can tell, I need something much simpler:

@@
"struct fasel_foo must be a type name!"
@@
- struct fasel_foo
+ struct fasel_bar

Quoted 4 lines
Quoted 1 line

...if only I knew what to put between the @@.

Put nothing :) From the word struct it should figure out that it is working on a type.

Quoted 8 lines

Oh, great! Thanks!

This solves my problem, but it makes me wonder how this generalizes to other problems. For example,

1. What would I need to do if I don't want to replace a struct but something typedef'd? (my_type *ptr --> new_type *ptr).

Easy

@@
typedef my_type, new_type;
@@
- my_type
+ new_type

Quoted 2 lines

2. ..and how would I go about if instead of the type, I want to replace a variable name? (my_type *ptr --> my_type *pointer).

Depends on the exact circumstance. But that's easy to figure out. I recommend the workshop papers and tutorials from
http://coccinelle.lip6.fr/papers.php; I wish I would have had those when I started with coccinelle.

bye
michael

#4 lore raw

[Cocci] Replacing one variable name with another

In reply to Nikolaus Rath
Quoted 2 lines

2. ..and how would I go about if instead of the type, I want to replace a variable name? (my_type *ptr --> my_type *pointer).

Would you like to try another small SmPL script out like the following?

@name_replacement@
@@
my_type *
-ptr
+pointer
;

How will your software development experiments evolve for the desired application of the semantic patch language?

Regards,
Markus

#5 lore raw

[Cocci] Replacing one variable name with another

Review

Quoted 12 lines · SF Markus Elfring
Quoted 2 lines

2. ..and how would I go about if instead of the type, I want to replace a variable name? (my_type *ptr --> my_type *pointer).

Would you like to try another small SmPL script out like the following?

@name_replacement@
@@
my_type *

(quoted diff) +1 -1
-ptr
+pointer
 ;

I could try it, but I'm actually more interested in understanding how this works (I already solved my primariy problem). Could you explain this script a bit more? What exactly does "@name_replacement@" mean? Does it the interpretation of "my_type *" further down?

Quoted 2 lines

How will your software development experiments evolve for the desired application of the semantic patch language?

Aeh, sorry, I don't understand the question.

Best,
-Nikolaus

Signature · 4 lines
GPG encrypted emails preferred. Key id: 0xD113FCAC3C4E599F
Fingerprint: ED31 791B 2C5C 1613 AF38 8B8A D113 FCAC 3C4E 599F

             ?Time flies like an arrow, fruit flies like a Banana.?
#6 lore raw

[Cocci] Replacing one variable name with another

Quoted 9 lines

Review

Quoted 6 lines

@name_replacement@
@@
my_type *

(quoted diff) +1 -1
-ptr
+pointer
 ;

I could try it, but I'm actually more interested in understanding how this works (I already solved my primariy problem).

Thanks for your interest.

Quoted 1 line

Could you explain this script a bit more?

Yes, of course.

It shows the general structure of a simple script for the semantic patch language.

Outline:
* Block for definition of SmPL metavariables
* Specification of C source code fragments (together with desired changes)

Quoted 1 line

What exactly does "@name_replacement@" mean?

Such a SmPL rule can specify a name for it. Which identifier would you choose there according to your naming preferences?
http://coccinelle.lip6.fr/docs/main_grammar002.html

Quoted 1 line

Does it the interpretation of "my_type *" further down?

No. - I tend to use a title there which is descriptive somewhat.

Quoted 4 lines
Quoted 2 lines

How will your software development experiments evolve for the desired application of the semantic patch language?

Aeh, sorry, I don't understand the question.

Do you plan to try any more SmPL scripts out? How do you think about to share further experiences?

Regards,
Markus

#7 lore raw

[Cocci] Replacing one variable name with another

In reply to Nikolaus Rath
Quoted 7 lines · Nikolaus Rath
Quoted 6 lines · SF Markus Elfring
Quoted 2 lines

2. ..and how would I go about if instead of the type, I want to replace a variable name? (my_type *ptr --> my_type *pointer).

Would you like to try another small SmPL script out like the following?

Quoted 10 lines

Review

Quoted 6 lines

@name_replacement@
@@
my_type *

(quoted diff) +1 -1
-ptr
+pointer
 ;

I could try it, but I'm actually more interested in understanding how this works (I already solved my primariy problem). Could you explain this script a bit more? What exactly does "@name_replacement@" mean?

Between the initial @@ you can put the name of the rule, as well as some other information. If no other rule needs to refer to this one, then there is no need for a name.

julia

Quoted 22 lines

Does it the interpretation of "my_type *" further down?

Quoted 2 lines

How will your software development experiments evolve for the desired application of the semantic patch language?

Aeh, sorry, I don't understand the question.

Best,
-Nikolaus

--
GPG encrypted emails preferred. Key id: 0xD113FCAC3C4E599F
Fingerprint: ED31 791B 2C5C 1613 AF38 8B8A D113 FCAC 3C4E 599F

?Time flies like an arrow, fruit flies like a Banana.?
_______________________________________________
Cocci mailing list
Cocci at systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

#8 lore raw
In reply to Nikolaus Rath
Quoted 39 lines · Nikolaus Rath
Quoted 33 lines · Julia Lawall
Quoted 31 lines · Nikolaus Rath

Hello,

In a set of C files, I would like to replace each instance of one type (struct fasel_foo) with another type (struct fasel_bar). For instance,

char* fasel_foo_print(struct fasel_foo *ptr) {
    // ...

return "this struct fasel_foo string should not change";
}

should become

char* fasel_foo_print(struct fasel_bar *ptr) {
    // ...

return "this struct fasel_foo string should not change";
}

Based on the LWN articles that I've read, this seems like the perfect use-case for coccinelle. However, somehow I'm struggling to write a patch for this. All the documentation that I could get my hands on seems to describe more abstract changes that require the use of variables - but as far as I can tell, I need something much simpler:

@@
"struct fasel_foo must be a type name!"
@@
- struct fasel_foo
+ struct fasel_bar

Quoted 4 lines
Quoted 1 line

...if only I knew what to put between the @@.

Put nothing :) From the word struct it should figure out that it is working on a type.

Quoted 7 lines

Oh, great! Thanks!

Quoted 1 line

This solves my problem, but it makes me wonder how this generalizes to other problems. For example,

1. What would I need to do if I don't want to replace a struct but something typedef'd? (my_type *ptr --> new_type *ptr).

Coccinelle needs to know that the thing is a typedef. So this time, you can start your rule with

@@
typedef my_type;
typedef new_type;
@@

Quoted 3 lines

2. ..and how would I go about if instead of the type, I want to replace a variable name? (my_type *ptr --> my_type *pointer).

I'm not completely sure what the issue is here. Do you specifically want to convert ptr to pointer? Is the type important? To make exactly what you have written, you could put:

@@
typedef my_type;
idexpression mytype * p1;
@@

- ptr at p1
+ pointer

This checks for the word ptr, and also checks that it is an identifier of the right type. I haven't tested it, so let me know if there is any problem.

julia

#9 lore raw
Quoted 10 lines · Julia Lawall
Quoted 2 lines

1. What would I need to do if I don't want to replace a struct but something typedef'd? (my_type *ptr --> new_type *ptr).

Coccinelle needs to know that the thing is a typedef. So this time, you can start your rule with

@@
typedef my_type;
typedef new_type;
@@

Makes sense, thanks!

Quoted 12 lines
Quoted 2 lines

2. ..and how would I go about if instead of the type, I want to replace a variable name? (my_type *ptr --> my_type *pointer).

I'm not completely sure what the issue is here. Do you specifically want to convert ptr to pointer? Is the type important? To make exactly what you have written, you could put:

@@
typedef my_type;
idexpression mytype * p1;
@@

Quoted 6 lines

- ptr at p1
+ pointer

This checks for the word ptr, and also checks that it is an identifier of the right type. I haven't tested it, so let me know if there is any problem.

Well, I don't have an actual use-case anymore. My problem is solved, I'm just curious what else I could do with Coccinelle to do :-).

Somehow I'm having a really hard time grasping the fundamentals. The first two examples make sense - I could adapt them for similar situations. But then, I still have absolutely no idea how I would come up with the third example, or how to adapt it. What does "idexpression" mean? What does "ptr at p1" mean? Is this documented anywhere?

I'd hate to waste your time asking tons of such trivial questions on the mailing list, but I just can't find any helpful documentation at all...

Best,
-Nikolaus

Signature · 4 lines
GPG encrypted emails preferred. Key id: 0xD113FCAC3C4E599F
Fingerprint: ED31 791B 2C5C 1613 AF38 8B8A D113 FCAC 3C4E 599F

             ?Time flies like an arrow, fruit flies like a Banana.?
#10 lore raw
Quoted 33 lines · Nikolaus Rath
Quoted 10 lines · Julia Lawall
Quoted 2 lines

1. What would I need to do if I don't want to replace a struct but something typedef'd? (my_type *ptr --> new_type *ptr).

Coccinelle needs to know that the thing is a typedef. So this time, you can start your rule with

@@
typedef my_type;
typedef new_type;
@@

Makes sense, thanks!

Quoted 12 lines
Quoted 2 lines

2. ..and how would I go about if instead of the type, I want to replace a variable name? (my_type *ptr --> my_type *pointer).

I'm not completely sure what the issue is here. Do you specifically want to convert ptr to pointer? Is the type important? To make exactly what you have written, you could put:

@@
typedef my_type;
idexpression mytype * p1;
@@

Quoted 6 lines

- ptr at p1
+ pointer

This checks for the word ptr, and also checks that it is an identifier of the right type. I haven't tested it, so let me know if there is any problem.

Quoted 8 lines

Well, I don't have an actual use-case anymore. My problem is solved, I'm just curious what else I could do with Coccinelle to do :-).

Somehow I'm having a really hard time grasping the fundamentals. The first two examples make sense - I could adapt them for similar situations. But then, I still have absolutely no idea how I would come up with the third example, or how to adapt it. What does "idexpression" mean? What does "ptr at p1" mean? Is this documented anywhere?

idexpression is an expression that is resricted to be an identifier. It allows you to put a type on an expression that has the form of an identifier. You can also say identifier x; But that is just a name. It has no type. It could be an expression, a field name, a parameter name, etc.

@ connects patterns that match the same term. So match a term against the explicit name ptr and also match it against an identifier expression that has a particular type. This is not exactly a beginner example.

Quoted 2 lines

I'd hate to waste your time asking tons of such trivial questions on the mailing list, but I just can't find any helpful documentation at all...

If you look on the web page in the papers and slides section, at the top there are several tutorials and overview talks, some with video.

There is a grammar of the language at
http://coccinelle.lip6.fr/documentation.php
I doubt that it would be very helpful for a beginner. But there are many examples at another link on the same page.

julia

Quoted 9 lines

Best,
-Nikolaus
--
GPG encrypted emails preferred. Key id: 0xD113FCAC3C4E599F
Fingerprint: ED31 791B 2C5C 1613 AF38 8B8A D113 FCAC 3C4E 599F

?Time flies like an arrow, fruit flies like a Banana.?

#11 lore raw
Quoted 11 lines · Julia Lawall
Quoted 5 lines

Somehow I'm having a really hard time grasping the fundamentals. The first two examples make sense - I could adapt them for similar situations. But then, I still have absolutely no idea how I would come up with the third example, or how to adapt it. What does "idexpression" mean? What does "ptr at p1" mean? Is this documented anywhere?

idexpression is an expression that is resricted to be an identifier. It allows you to put a type on an expression that has the form of an identifier. You can also say identifier x; But that is just a name. It has no type. It could be an expression, a field name, a parameter name, etc.

Hm. Based on your last two sentences I'd conclude that 'idexpression' matches variable names for variables of a specific type. But that doesn't seem to be what you describe in your first two sentences. Could you explain what you meant iwth "expression that has the form of an identifier"?

To me, an identifier is something that's written literally into the source code and cannot be meaningfully taken apart, e.g. a function name, variable name, or the member of a struct. An expression, on the other hand, is something that can be meaningfully split into sub-components. Is that also how you use these terms?

Quoted 3 lines

@ connects patterns that match the same term. So match a term against the explicit name ptr and also match it against an identifier expression that has a particular type. This is not exactly a beginner example.

Okay, I'll just ignore that for now.

Quoted 5 lines
Quoted 2 lines

I'd hate to waste your time asking tons of such trivial questions on the mailing list, but I just can't find any helpful documentation at all...

If you look on the web page in the papers and slides section, at the top there are several tutorials and overview talks, some with video.

I think I looked at everything that is not a video. But none of it mentioned that you can put an arbitrary name between the @@ or explained what the different metavariable types (idexpression, expression, etc) are.

Anyway, enough whining. Coccinelle seems like a really useful tool, even if I'm having an impedance mismatch with its documentation.

Best,
-Niko

Signature · 4 lines
GPG encrypted emails preferred. Key id: 0xD113FCAC3C4E599F
Fingerprint: ED31 791B 2C5C 1613 AF38 8B8A D113 FCAC 3C4E 599F

             ?Time flies like an arrow, fruit flies like a Banana.?
#12 lore raw
Quoted 19 lines · Nikolaus Rath
Quoted 11 lines · Julia Lawall
Quoted 5 lines

Somehow I'm having a really hard time grasping the fundamentals. The first two examples make sense - I could adapt them for similar situations. But then, I still have absolutely no idea how I would come up with the third example, or how to adapt it. What does "idexpression" mean? What does "ptr at p1" mean? Is this documented anywhere?

idexpression is an expression that is resricted to be an identifier. It allows you to put a type on an expression that has the form of an identifier. You can also say identifier x; But that is just a name. It has no type. It could be an expression, a field name, a parameter name, etc.

Hm. Based on your last two sentences I'd conclude that 'idexpression' matches variable names for variables of a specific type. But that doesn't seem to be what you describe in your first two sentences. Could you explain what you meant iwth "expression that has the form of an identifier"?

Quoted 5 lines

To me, an identifier is something that's written literally into the source code and cannot be meaningfully taken apart, e.g. a function name, variable name, or the member of a struct. An expression, on the other hand, is something that can be meaningfully split into sub-components. Is that also how you use these terms?

An expression is something that has a value. So an idexpression would be something that cannot be taken apart, but it is also used in a context where it has a value. Unlike in the case of a parameter name or field name, where it is a name for something that will get a value in the future.

Quoted 10 lines
Quoted 4 lines

@ connects patterns that match the same term. So match a term against the explicit name ptr and also match it against an identifier expression that has a particular type. This is not exactly a beginner example.

Okay, I'll just ignore that for now.

Quoted 3 lines
Quoted 2 lines

I'd hate to waste your time asking tons of such trivial questions on the mailing list, but I just can't find any helpful documentation at all...

Quoted 7 lines
Quoted 2 lines

If you look on the web page in the papers and slides section, at the top there are several tutorials and overview talks, some with video.

I think I looked at everything that is not a video. But none of it mentioned that you can put an arbitrary name between the @@ or explained what the different metavariable types (idexpression, expression, etc) are.

The name is illustrated in Advanced SmPL:
http://coccinelle.lip6.fr/papers/cocciwk4_talk2.pdf

A variety of metavariable types are listed in slide 11 of the Linux oriented tutorial: http://coccinelle.lip6.fr/papers/tutorial.pdf

julia

Quoted 17 lines

Anyway, enough whining. Coccinelle seems like a really useful tool, even if I'm having an impedance mismatch with its documentation.

Best,
-Niko

--
GPG encrypted emails preferred. Key id: 0xD113FCAC3C4E599F
Fingerprint: ED31 791B 2C5C 1613 AF38 8B8A D113 FCAC 3C4E 599F

?Time flies like an arrow, fruit flies like a Banana.?
_______________________________________________
Cocci mailing list
Cocci at systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

#13 lore raw
Quoted 27 lines · Julia Lawall
Quoted 19 lines · Nikolaus Rath
Quoted 11 lines · Julia Lawall
Quoted 5 lines

Somehow I'm having a really hard time grasping the fundamentals. The first two examples make sense - I could adapt them for similar situations. But then, I still have absolutely no idea how I would come up with the third example, or how to adapt it. What does "idexpression" mean? What does "ptr at p1" mean? Is this documented anywhere?

idexpression is an expression that is resricted to be an identifier. It allows you to put a type on an expression that has the form of an identifier. You can also say identifier x; But that is just a name. It has no type. It could be an expression, a field name, a parameter name, etc.

Hm. Based on your last two sentences I'd conclude that 'idexpression' matches variable names for variables of a specific type. But that doesn't seem to be what you describe in your first two sentences. Could you explain what you meant iwth "expression that has the form of an identifier"?

Quoted 5 lines

To me, an identifier is something that's written literally into the source code and cannot be meaningfully taken apart, e.g. a function name, variable name, or the member of a struct. An expression, on the other hand, is something that can be meaningfully split into sub-components. Is that also how you use these terms?

Quoted 5 lines

An expression is something that has a value. So an idexpression would be something that cannot be taken apart, but it is also used in a context where it has a value. Unlike in the case of a parameter name or field name, where it is a name for something that will get a value in the future.

Got it, thanks!

Quoted 12 lines
Quoted 12 lines
Quoted 3 lines

@ connects patterns that match the same term. So match a term against the explicit name ptr and also match it against an identifier expression that has a particular type. This is not exactly a beginner example.

Okay, I'll just ignore that for now.

Quoted 5 lines
Quoted 2 lines

I'd hate to waste your time asking tons of such trivial questions on the mailing list, but I just can't find any helpful documentation at all...

If you look on the web page in the papers and slides section, at the top there are several tutorials and overview talks, some with video.

Quoted 7 lines
Quoted 4 lines

I think I looked at everything that is not a video. But none of it mentioned that you can put an arbitrary name between the @@ or explained what the different metavariable types (idexpression, expression, etc) are.

The name is illustrated in Advanced SmPL:
http://coccinelle.lip6.fr/papers/cocciwk4_talk2.pdf

Call me stupid, but I just went through it again and I still don't see it. There are lots of examples with "@ ..stuff..@" (the first on slide 4), but as far as I can tell it never explains what this means.

Actually, the frequent occurence of @script:python@ makes me think that this actually has semantic signficance and is much more than a label that I can choose for my own convenience...?

Quoted 2 lines

A variety of metavariable types are listed in slide 11 of the Linux oriented tutorial: http://coccinelle.lip6.fr/papers/tutorial.pdf

Yes, I saw that. But I deliberately wrote "explained" rather than just "listed" :-).

Best,
-Nikolaus

Signature · 4 lines
GPG encrypted emails preferred. Key id: 0xD113FCAC3C4E599F
Fingerprint: ED31 791B 2C5C 1613 AF38 8B8A D113 FCAC 3C4E 599F

             ?Time flies like an arrow, fruit flies like a Banana.?
#14 lore raw
Quoted 6 lines
Quoted 2 lines

The name is illustrated in Advanced SmPL:
http://coccinelle.lip6.fr/papers/cocciwk4_talk2.pdf

Call me stupid, but I just went through it again and I still don't see it. There are lots of examples with "@ ..stuff..@" (the first on slide 4), but as far as I can tell it never explains what this means.

OK, perhaps it is mentioned in the video:
http://faultlinux.lip6.fr/videos/workshop_videos_2011/Julia_Lawall_introduction_part2.f4v

Quoted 4 lines

Actually, the frequent occurence of @script:python@ makes me think that this actually has semantic signficance and is much more than a label that I can choose for my own convenience...?

script:python indicates that the rule has python code rather than pattern matching. The name of a rule that you can choose freely should not contain :

Quoted 7 lines
Quoted 4 lines

A variety of metavariable types are listed in slide 11 of the Linux oriented tutorial: http://coccinelle.lip6.fr/papers/tutorial.pdf

Yes, I saw that. But I deliberately wrote "explained" rather than just "listed" :-).

In the video, perhaps...

The following paper is quite old, but may also be helpful:

Tutorial paper: Semantic Patches, Documenting and Automating Collateral Evolutions in Linux Device Drivers
Yoann Padioleau, Julia L. Lawall, and Gilles Muller
Ottawa Linux Symposium (OLS 2007), June 2007.

julia

#15 lore raw
In reply to Nikolaus Rath
Quoted 6 lines
Quoted 2 lines

The name is illustrated in Advanced SmPL:
http://coccinelle.lip6.fr/papers/cocciwk4_talk2.pdf

Call me stupid, but I just went through it again and I still don't see it. There are lots of examples with "@ ..stuff..@" (the first on slide 4), but as far as I can tell it never explains what this means.

How do you find information from a corresponding syntax description for the semantic patch language?

Metavariables for transformations
http://coccinelle.lip6.fr/docs/main_grammar002.html

Quoted 3 lines

Actually, the frequent occurence of @script:python@ makes me think that this actually has semantic signficance and is much more than a label that I can choose for my own convenience...?

Did you read another published document already?

Metavariables for scripts
http://coccinelle.lip6.fr/docs/main_grammar003.html

Regards,
Markus

#16 lore raw

[Cocci] Usage of "expressions" and "identifiers" with SmPL

In reply to Nikolaus Rath
Quoted 5 lines

To me, an identifier is something that's written literally into the source code and cannot be meaningfully taken apart, e.g. a function name, variable name, or the member of a struct. An expression, on the other hand, is something that can be meaningfully split into sub-components. Is that also how you use these terms?

Yes, in principle.

The Coccinelle software was designed for the generation of semantic patches.

1. Its tool "spatch" expects some input and will usually produce corresponding output.

2. One kind of such input are source files for which data processing is also directly supported if they were mostly written in a programming language like "C".

3. Another kind of required input is the specification of source code search or transformation patterns in the semantic patch language.

4. Special data processing is also possible just because the programming languages "OCaml" and "Python" can be used in SmPL script rules already.

5. There are several languages involved. SmPL script developers need to be careful about the relevant syntax context.

* So while you are looking from a view of "C source", you might tend to think about "C identifiers". The semantic patch language provides metavariables which can get the data type "identifier".

* But what was an "item" in the source language can become an other in the Coccinelle technology.
One example is the use of a metavariable with the type "idexpression" in your case. At which places would you start to think about a code situation by the means of "expressions"?

* Syntax constructs from the supported source languages are matched with "key words" that are often similar (or even identical) to the host language (within SmPL scripts).

Quoted 6 lines
Quoted 3 lines

@ connects patterns that match the same term. So match a term against the explicit name ptr and also match it against an identifier expression that has a particular type. This is not exactly a beginner example.

Okay, I'll just ignore that for now.

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

I'd hate to waste your time asking tons of such trivial questions on the mailing list, but I just can't find any helpful documentation at all...

If you look on the web page in the papers and slides section, at the top there are several tutorials and overview talks, some with video.

I think I looked at everything that is not a video.

Thanks for your feedback.

Quoted 1 line

But none of it mentioned that you can put an arbitrary name between the @@

I got an other impression from the available documentation.

Quoted 2 lines

or explained what the different metavariable types (idexpression, expression, etc) are.

I see some improvement possibilities there, too.

Quoted 1 line

Anyway, enough whining. Coccinelle seems like a really useful tool,

Yes, of course.

Quoted 1 line

even if I'm having an impedance mismatch with its documentation.

Do you see further chances to reduce this mismatch for following software developers?

Regards,
Markus

#17 lore raw

[Cocci] Usage of "expressions" and "identifiers" with SmPL

Nicolaus, please ignore this message.

julia

Quoted 86 lines · SF Markus Elfring
Quoted 5 lines

To me, an identifier is something that's written literally into the source code and cannot be meaningfully taken apart, e.g. a function name, variable name, or the member of a struct. An expression, on the other hand, is something that can be meaningfully split into sub-components. Is that also how you use these terms?

Yes, in principle.

The Coccinelle software was designed for the generation of semantic patches.

1. Its tool "spatch" expects some input and will usually produce corresponding output.

2. One kind of such input are source files for which data processing is also directly supported if they were mostly written in a programming language like "C".

3. Another kind of required input is the specification of source code search or transformation patterns in the semantic patch language.

4. Special data processing is also possible just because the programming languages "OCaml" and "Python" can be used in SmPL script rules already.

5. There are several languages involved. SmPL script developers need to be careful about the relevant syntax context.

* So while you are looking from a view of "C source", you might tend to think about "C identifiers". The semantic patch language provides metavariables which can get the data type "identifier".

* But what was an "item" in the source language can become an other in the Coccinelle technology.
One example is the use of a metavariable with the type "idexpression" in your case. At which places would you start to think about a code situation by the means of "expressions"?

* Syntax constructs from the supported source languages are matched with "key words" that are often similar (or even identical) to the host language (within SmPL scripts).

Quoted 6 lines
Quoted 3 lines

@ connects patterns that match the same term. So match a term against the explicit name ptr and also match it against an identifier expression that has a particular type. This is not exactly a beginner example.

Okay, I'll just ignore that for now.

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

I'd hate to waste your time asking tons of such trivial questions on the mailing list, but I just can't find any helpful documentation at all...

If you look on the web page in the papers and slides section, at the top there are several tutorials and overview talks, some with video.

I think I looked at everything that is not a video.

Thanks for your feedback.

Quoted 1 line

But none of it mentioned that you can put an arbitrary name between the @@

I got an other impression from the available documentation.

Quoted 2 lines

or explained what the different metavariable types (idexpression, expression, etc) are.

I see some improvement possibilities there, too.

Quoted 1 line

Anyway, enough whining. Coccinelle seems like a really useful tool,

Yes, of course.

Quoted 1 line

even if I'm having an impedance mismatch with its documentation.

Do you see further chances to reduce this mismatch for following software developers?

Regards,
Markus
_______________________________________________
Cocci mailing list
Cocci at systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

A message that is not in the archive (sent off-list or not yet received): alpine.DEB.2.10.1610080850470.7750@hadrien

#19 lore raw

[Cocci] Usage of "expressions" and "identifiers" with SmPL

Quoted 5 lines
Quoted 3 lines

* Syntax constructs from the supported source languages are matched with "key words" that are often similar (or even identical) to the host language (within SmPL scripts).

This is an enormous amount of verbiage,

Interesting view ?

Quoted 1 line

and I don't see the relevance to the question.

I am trying to explain the matching from syntax elements of the C programming language to the means of the semantic patch language from my view.

Quoted 2 lines

Furthermore, I would very much appreciate it if you would stop responding to any questions from new users.

I find this kind of response surprising.

Would you eventually like to benefit from additional views which evolved during collaboration of some years?

Quoted 1 line

You are not the developer or maintainer of Coccinelle.

This information is appropriate to some degree.

How do you think about the evolution around roles like "intensive SmPL user", "system tester", "bug reporter" and "supporter"?

* I am trying to contribute a bit also to your software.

* I am active as another ordinary free software for years.

Quoted 1 line

You don't represent the tool in any way.

I do not represent it "officially". - But I can imagine that my software development activities have got some useful "side effects" from which a kind of "image" or "representation" could have evolved already.

Quoted 1 line

A very large portion of the information that you provide is incorrect

Would you like to clarify this a bit more?

Quoted 1 line

or unnecessary.

I got an other impression about the necessity.

Quoted 1 line

I am very concerned that you will frighten people away,

I can understand your concern a bit.

Quoted 3 lines

especially if you ask them to do things that go beyond their intended involvement, such as your "Do you see further chances to reduce..." comment below.

The involvement can eventually increase, can't it?

Quoted 4 lines

The next time you answer a question from a newcomer where your answer either includes a question or goes beyond say 3 lines of text, I will adjust your subscription to the mailing list such that you no longer receive mail.

Did you really get so angry that you reconsider our collaboration in such a drastic way?

Quoted 1 line

I'm sure you consider that you are helping out,

I hope so.

Did my small script examples help a bit in the requested clarification?

Quoted 1 line

but you are not,

I find this feedback interesting and surprising.

Quoted 1 line

and it needs to stop immediately.

How can software development discussions be continued after such a response?

Regards,
Markus

#20 lore raw

[Cocci] Usage of "expressions" and "identifiers" with SmPL

Quoted 7 lines
Quoted 4 lines

The next time you answer a question from a newcomer where your answer either includes a question or goes beyond say 3 lines of text, I will adjust your subscription to the mailing list such that you no longer receive mail.

Did you really get so angry that you reconsider our collaboration in such a drastic way?

I'm not angry at all, only tired of so much incorrect or unnecessary information being provided to new users. It's not practical to write to each new user and say "Please ignore this message". I would prefer that they just stop in the first place.

julia

#21 lore raw

[Cocci] Usage of "expressions" and "identifiers" with SmPL

Quoted 1 line

I'm not angry at all,

Thanks for your feedback that there are other emotions involved.

Quoted 1 line

only tired of so much incorrect

Which details from my description approach are inappropriate in your view?

Quoted 1 line

or unnecessary information being provided to new users.

I got the impression somehow that the clarification request by Nikolaus Rath evolved into a direction where further technical background information would be useful.
He can also decide on his own if and how he would eventually like to continue this software development and user support discussion.

Regards,
Markus

#22 lore raw

[Cocci] Usage of "expressions" and "identifiers" with SmPL

Quoted 8 lines · SF Markus Elfring
Quoted 1 line

I'm not angry at all,

Thanks for your feedback that there are other emotions involved.

Quoted 1 line

only tired of so much incorrect

Which details from my description approach are inappropriate in your view?

The whole numbered list was pointless. He was trying to understand what is meant by "idexpression". This is a concept particular to Coccinelle, that was introduced because we discovered that sometimes one wants to focus only on identifiers, but to also specify their types. I couldn't tell from your answer what question it was intended to be relevant to, but I don't think it is the same as the one he was asking. It seems to be a generic overview of what Coccinelle does. Someone who has to read so much text and in the end has no information about the question he was asking will not likely get a good impression about the software he is trying to use.

julia

#23 lore raw

[Cocci] Usage of "expressions" and "identifiers" with SmPL

Quoted 3 lines
Quoted 1 line

Which details from my description approach are inappropriate in your view?

The whole numbered list was pointless.

I hope that we can eventually benefit from such a disagreement in constructive ways.

Quoted 1 line

He was trying to understand what is meant by "idexpression".

Yes. - The functionality and relationship of this key word was unclear to some degree together with the usage of "identifiers", wasn't it?

Quoted 1 line

This is a concept particular to Coccinelle,

I can follow this view.

Quoted 2 lines

that was introduced because we discovered that sometimes one wants to focus only on identifiers, but to also specify their types.

Thanks for this kind of background information.

Quoted 1 line

I couldn't tell from your answer what question it was intended to be relevant to,

I am curious if a bit more clarification of the relevance and my corresponding intention would be needed.

Quoted 2 lines

but I don't think it is the same as the one he was asking. It seems to be a generic overview of what Coccinelle does.

I am also unsure if and how quick Nikolaus Rath will find the provided technical details a bit useful.

Quoted 3 lines

Someone who has to read so much text and in the end has no information about the question he was asking will not likely get a good impression about the software he is trying to use.

A beginner should usually read some text for the desired learning experience. Can it be that you worry a bit too much about the potential for bad impressions around your software?

Would you like to start another marketing project?

I find that this mailing list gets only low message traffic so far. So I would imagine that most well-intended discussion contributions could be useful. Is the mixture of presented topics reasonable?

We came along different views around the usage of "expressions" in previous discussions, didn't we?
You repeated the explanation "An expression is something that has a value." which is reasonable to some degree. I would like to know then:
Which "value" is provided by the software construct "idexpression" in the semantic patch language?

Regards,
Markus

#24 lore raw

[Cocci] Usage of "expressions" and "identifiers" with SmPL

Quoted 7 lines · SF Markus Elfring
Quoted 3 lines

Someone who has to read so much text and in the end has no information about the question he was asking will not likely get a good impression about the software he is trying to use.

A beginner should usually read some text for the desired learning experience. Can it be that you worry a bit too much about the potential for bad impressions around your software?

Sorry to be the bringer of bad news, but Julia is spot on. The only effect your emails had on me was a big "WTF!?". Had Julia not responded to my messages at almost the same time, I would have left this list and Coccinelle for good.

Quoted 1 line

Would you like to start another marketing project?

What's the point of all these random questions that you bring up in response to every sentence? Do you think they are helpful?

Quoted 1 line

I find that this mailing list gets only low message traffic so far.

Do you think others share this impression? Do you think this is a good thing or a bad thing? How do you think will this situation evolve?

Quoted 2 lines

So I would imagine that most well-intended discussion contributions could be useful. Is the mixture of presented topics reasonable?

What do you mean with discussion contributions? Do you think that asking if the topic is reasonable is equivalent to asking if the specific contributions are reasonable?

Quoted 2 lines

We came along different views around the usage of "expressions" in previous discussions, didn't we?

Whom do you mean with "we"? Is it important in this context?

Quoted 4 lines

You repeated the explanation "An expression is something that has a value." which is reasonable to some degree. I would like to know then:
Which "value" is provided by the software construct "idexpression" in the semantic patch language?

Do you think you will be able to find out the answer to this question? How could we best assist you in that?

Best,
-Nikolaus

Signature · 4 lines
GPG encrypted emails preferred. Key id: 0xD113FCAC3C4E599F
Fingerprint: ED31 791B 2C5C 1613 AF38 8B8A D113 FCAC 3C4E 599F

             ?Time flies like an arrow, fruit flies like a Banana.?
#25 lore raw

[Cocci] Usage of "expressions" and "identifiers" with SmPL

Quoted 9 lines
Quoted 7 lines
Quoted 3 lines

Someone who has to read so much text and in the end has no information about the question he was asking will not likely get a good impression about the software he is trying to use.

A beginner should usually read some text for the desired learning experience. Can it be that you worry a bit too much about the potential for bad impressions around your software?

Sorry to be the bringer of bad news, but Julia is spot on.

Thanks for your interesting feedback.

It seems to indicate also special details about your learning approach.

Quoted 1 line

The only effect your emails had on me was a big "WTF!?".

All of them (including the provided small SmPL script examples on 2016-10-05)?

Do you care for the consequences around the usage of embedded (programming) languages within the semantic patch language as "a host"?
Can such a distinction be useful also for you?

Quoted 1 line

Had Julia not responded to my messages at almost the same time,

Here software support is very nice, isn't it?

Quoted 1 line

I would have left this list and Coccinelle for good.

I wonder that you would really run away so quickly just because a few alternative description approaches became a bit longer.

Quoted 4 lines
Quoted 1 line

Would you like to start another marketing project?

What's the point of all these random questions that you bring up in response to every sentence?

Did you inspect any items from the GitHub issue tracker?

Quoted 1 line

Do you think they are helpful?

I hope so.

Quoted 3 lines
Quoted 1 line

I find that this mailing list gets only low message traffic so far.

Do you think others share this impression?

Yes. - I guess so. (I do not know concrete numbers for my view.)

Quoted 1 line

Do you think this is a good thing or a bad thing?

It might be easier to get started than in other areas you could get involved in depending on your desire.

I hope that the varying topic mixture is interesting enough as another valuable information source.

Quoted 1 line

How do you think will this situation evolve?

I imagine that the Coccinelle software will be improved in various directions. I hope that the attractiveness of the provided tools will increase accordingly. Will such an evolution mean more users with a higher message exchange rate at various places?

Quoted 4 lines
Quoted 2 lines

So I would imagine that most well-intended discussion contributions could be useful. Is the mixture of presented topics reasonable?

What do you mean with discussion contributions?

Did I (and the other contributors) publish any messages on this mailing list before that could fit to your way of looking for helpful information already?

Quoted 2 lines

Do you think that asking if the topic is reasonable is equivalent to asking if the specific contributions are reasonable?

No. - Would you like to discuss this aspect any further?

Quoted 4 lines
Quoted 2 lines

We came along different views around the usage of "expressions" in previous discussions, didn't we?

Whom do you mean with "we"?

I guess that it could be primarily interpreted as Julia and me.

Quoted 1 line

Is it important in this context?

I find the software development history somewhat relevant also in this use case.

Quoted 6 lines
Quoted 4 lines

You repeated the explanation "An expression is something that has a value." which is reasonable to some degree. I would like to know then:
Which "value" is provided by the software construct "idexpression" in the semantic patch language?

Do you think you will be able to find out the answer to this question?

I could get some information from reading OCaml source code in principle. But I would prefer an other clarification approach.

Quoted 1 line

How could we best assist you in that?

Which possibilities have you got in mind at the moment?
Are you really interested in improving your "assistance" in significant ways?

Regards,
Markus

#26 lore raw

[Cocci] Usage of "expressions" and "identifiers" with SmPL

Quoted 4 lines · SF Markus Elfring
Quoted 1 line

The only effect your emails had on me was a big "WTF!?".

All of them (including the provided small SmPL script examples on 2016-10-05)?

You wrote three emails on that day. I assume you mean this one?

,----

| > 2. ..and how would I go about if instead of the type, I want to replace
| >    a variable name? (my_type *ptr --> my_type *pointer).
| 
| Would you like to try another small SmPL script out like the following?
| 
| 
| @name_replacement@
| @@
|  my_type *
| -ptr
| +pointer
|  ;
| 
| 
| How will your software development experiments evolve for the desired
| application of the semantic patch language?

`----

I'm afraid the answer is yes. Even though the snippet was relevant, its presentation triggered the same WTF effect.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

Would you like to start another marketing project?

What's the point of all these random questions that you bring up in response to every sentence?

Did you inspect any items from the GitHub issue tracker?

[...]

Well, I tried to make a point here., but it quite obviously failed utterly.

Best,
-Nikolaus

Signature · 4 lines
GPG encrypted emails preferred. Key id: 0xD113FCAC3C4E599F
Fingerprint: ED31 791B 2C5C 1613 AF38 8B8A D113 FCAC 3C4E 599F

             ?Time flies like an arrow, fruit flies like a Banana.?
#27 lore raw

[Cocci] Usage of "expressions" and "identifiers" with SmPL

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

The only effect your emails had on me was a big "WTF!?".

All of them (including the provided small SmPL script examples on 2016-10-05)?

You wrote three emails on that day. I assume you mean this one?

There are further possibilities to improve your learning experience around the replacement of data types and variable names, aren't there?

Quoted 17 lines

,----

| > 2. ..and how would I go about if instead of the type, I want to replace
| >    a variable name? (my_type *ptr --> my_type *pointer).
| 
| Would you like to try another small SmPL script out like the following?
| 
| 
| @name_replacement@
| @@
|  my_type *
| -ptr
| +pointer
|  ;
| 
| 
| How will your software development experiments evolve for the desired
| application of the semantic patch language?
Quoted 3 lines

`----

I'm afraid the answer is yes.

Interesting ?

Quoted 1 line

Even though the snippet was relevant,

Nice. - Thanks for this kind of feedback.

Quoted 1 line

its presentation triggered the same WTF effect.

Are you really at the beginning of a learning process where almost every new information can make you upset anyhow?

* How would this fit to your academic education?

* Did you start reading the Coccinelle manual?

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

What's the point of all these random questions that you bring up in response to every sentence?

Did you inspect any items from the GitHub issue tracker?

[...]

Well, I tried to make a point here., but it quite obviously failed utterly.

I find that a constructive discussion consists of several questions and some corresponding answers, doesn't it?

I am wondering about the learning style that you seem to present here in comparison to some information which was published in your blog. Are there any further challenges to clarify around a term like "mental capacity"?

Can any additional techniques or tools help to avoid unwanted communication difficulties so that another software development "fusion" would be achievable?

Regards,
Markus

#28 lore raw

[Cocci] Usage of "expressions" and "identifiers" with SmPL

OK, Markus, out you go...

julia

Quoted 76 lines · SF Markus Elfring
Quoted 6 lines
Quoted 4 lines
Quoted 1 line

The only effect your emails had on me was a big "WTF!?".

All of them (including the provided small SmPL script examples on 2016-10-05)?

You wrote three emails on that day. I assume you mean this one?

There are further possibilities to improve your learning experience around the replacement of data types and variable names, aren't there?

Quoted 17 lines

,----

| > 2. ..and how would I go about if instead of the type, I want to replace
| >    a variable name? (my_type *ptr --> my_type *pointer).
|
| Would you like to try another small SmPL script out like the following?
|
|
| @name_replacement@
| @@
|  my_type *
| -ptr
| +pointer
|  ;
|
|
| How will your software development experiments evolve for the desired
| application of the semantic patch language?
Quoted 3 lines

`----

I'm afraid the answer is yes.

Interesting ?

Quoted 1 line

Even though the snippet was relevant,

Nice. - Thanks for this kind of feedback.

Quoted 1 line

its presentation triggered the same WTF effect.

Are you really at the beginning of a learning process where almost every new information can make you upset anyhow?

* How would this fit to your academic education?

* Did you start reading the Coccinelle manual?

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

What's the point of all these random questions that you bring up in response to every sentence?

Did you inspect any items from the GitHub issue tracker?

[...]

Well, I tried to make a point here., but it quite obviously failed utterly.

I find that a constructive discussion consists of several questions and some corresponding answers, doesn't it?

I am wondering about the learning style that you seem to present here in comparison to some information which was published in your blog. Are there any further challenges to clarify around a term like "mental capacity"?

Can any additional techniques or tools help to avoid unwanted communication difficulties so that another software development "fusion" would be achievable?

Regards,
Markus
_______________________________________________
Cocci mailing list
Cocci at systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

#29 lore raw
In reply to Nikolaus Rath
Quoted 5 lines
Quoted 5 lines

@@
typedef my_type;
idexpression mytype * p1;
@@

Quoted 7 lines
Quoted 5 lines

- ptr at p1
+ pointer

This checks for the word ptr, and also checks that it is an identifier of the right type. I haven't tested it, so let me know if there is any problem.

Well, I don't have an actual use-case anymore.

I am curious when the next one will evolve for you.

Quoted 1 line

My problem is solved,

Nice to hear.

Quoted 1 line

I'm just curious what else I could do with Coccinelle to do :-).

This software supports a lot of development possibilities.

Quoted 1 line

Somehow I'm having a really hard time grasping the fundamentals.

The learning process can take a while as usual.

Quoted 1 line

The first two examples make sense - I could adapt them for similar situations.

Thanks for your understanding.

Quoted 2 lines

But then, I still have absolutely no idea how I would come up with the third example, or how to adapt it.

The usage of SmPL metavariables was demonstrated a bit.

Quoted 1 line

What does "idexpression" mean?

This is a specific metavariable type which handles C variables.

Quoted 1 line

What does "ptr at p1" mean?

This expression shows the restriction of a C code identifier by the means of a SmPL variable.

Quoted 1 line

Is this documented anywhere?

Yes, of course.
http://coccinelle.lip6.fr/docs/main_grammar002.html#elem

Would you like to help in improving corresponding descriptions?

Quoted 2 lines

I'd hate to waste your time asking tons of such trivial questions on the mailing list,

The answers will be published from which others can hopefully learn a bit. It will take some time to become more familiar with an evolving software technology.

Are you looking for a FAQ document?

Quoted 1 line

but I just can't find any helpful documentation at all...

I find this feedback strange. - Where did you look so far?

The help could become better there as usual.
Which information sources did you check before?

Regards,
Markus

#30 lore raw
In reply to Julia Lawall
Quoted 13 lines · Julia Lawall
Quoted 3 lines

2. ..and how would I go about if instead of the type, I want to replace a variable name? (my_type *ptr --> my_type *pointer).

I'm not completely sure what the issue is here. Do you specifically want to convert ptr to pointer? Is the type important? To make exactly what you have written, you could put:

@@
typedef my_type;
idexpression mytype * p1;
@@

Quoted 6 lines

- ptr at p1
+ pointer

This checks for the word ptr, and also checks that it is an identifier of the right type. I haven't tested it, so let me know if there is any problem.

It workes somewhat... but not completely.

Here's what I wanted to do: I merged two structures (struct fuse_session and struct fuse_ll) into one (struct fuse_session). I've first replaced all the type names, and then manually fixed the cases where this resulted in bogus/redundant code (typically in functions that used to work with both structs).

Now my project compiles and runs fine, but I the variable naming is
inconsistent: in some cases the struct fuse_session pointer is called *se (these were the variables that were always of type struct fuse_session), and in other cases the pointer is called *f (these were the variables that were previously of type struct fuse_ll).

I'd like to fix this too, and always refer call fuse_session pointers "se" (except where this name is already used for something else, but I'll just fix this up by hand afterwards). I tried the following patch:

$ cat se-name.cocci 
@@
idexpression struct fuse_session *p1;
@@
- f at p1
+ se

but it resulted in these changes:

struct fuse_session *f = req->se;
- struct cuse_data *cd = f->cuse_data;
- size_t bufsize = f->bufsize;
+ struct cuse_data *cd = se->cuse_data;
+ size_t bufsize = se->bufsize;

So it seems to replace the variable where its used, but not where it's defined.

Is there a way to catch the definitions too?

Best,
-Nikolaus

Signature · 4 lines
GPG encrypted emails preferred. Key id: 0xD113FCAC3C4E599F
Fingerprint: ED31 791B 2C5C 1613 AF38 8B8A D113 FCAC 3C4E 599F

             ?Time flies like an arrow, fruit flies like a Banana.?
#31 lore raw
Quoted 54 lines · Nikolaus Rath
Quoted 13 lines · Julia Lawall
Quoted 3 lines

2. ..and how would I go about if instead of the type, I want to replace a variable name? (my_type *ptr --> my_type *pointer).

I'm not completely sure what the issue is here. Do you specifically want to convert ptr to pointer? Is the type important? To make exactly what you have written, you could put:

@@
typedef my_type;
idexpression mytype * p1;
@@

Quoted 6 lines

- ptr at p1
+ pointer

This checks for the word ptr, and also checks that it is an identifier of the right type. I haven't tested it, so let me know if there is any problem.

It workes somewhat... but not completely.

Here's what I wanted to do: I merged two structures (struct fuse_session and struct fuse_ll) into one (struct fuse_session). I've first replaced all the type names, and then manually fixed the cases where this resulted in bogus/redundant code (typically in functions that used to work with both structs).

Now my project compiles and runs fine, but I the variable naming is
inconsistent: in some cases the struct fuse_session pointer is called *se (these were the variables that were always of type struct fuse_session), and in other cases the pointer is called *f (these were the variables that were previously of type struct fuse_ll).

I'd like to fix this too, and always refer call fuse_session pointers "se" (except where this name is already used for something else, but I'll just fix this up by hand afterwards). I tried the following patch:

$ cat se-name.cocci
@@
idexpression struct fuse_session *p1;
@@
- f at p1
+ se

but it resulted in these changes:

(quoted diff) +2 -2
 	struct fuse_session *f = req->se;
-	struct cuse_data *cd = f->cuse_data;
-	size_t bufsize = f->bufsize;
+	struct cuse_data *cd = se->cuse_data;
+	size_t bufsize = se->bufsize;
Quoted 4 lines

So it seems to replace the variable where its used, but not where it's defined.

Is there a way to catch the definitions too?

Write separate rules for that. You would need one case for a local variable and one case fora parameter. You can actually probably just drop the rule you have currently. I would imagine something like the following:

@@
symbol f, se; // avoid unneeded warnings from Coccinelle @@

struct fuse_session *
-f
+se
;
<...
-f
+se
...>

@@
identifier fn;
@@

fn(...,struct fuse_session *f,...) { <...
-f
+se
...> }

I think that the symbol declaration has effect in the rest of the semantic patch, and does not have to be repeated. If you get warnings for the second rule, just copy it down.

julia

#32 lore raw
Quoted 77 lines · Julia Lawall
Quoted 54 lines · Nikolaus Rath
Quoted 13 lines · Julia Lawall
Quoted 3 lines

2. ..and how would I go about if instead of the type, I want to replace a variable name? (my_type *ptr --> my_type *pointer).

I'm not completely sure what the issue is here. Do you specifically want to convert ptr to pointer? Is the type important? To make exactly what you have written, you could put:

@@
typedef my_type;
idexpression mytype * p1;
@@

Quoted 6 lines

- ptr at p1
+ pointer

This checks for the word ptr, and also checks that it is an identifier of the right type. I haven't tested it, so let me know if there is any problem.

It workes somewhat... but not completely.

Here's what I wanted to do: I merged two structures (struct fuse_session and struct fuse_ll) into one (struct fuse_session). I've first replaced all the type names, and then manually fixed the cases where this resulted in bogus/redundant code (typically in functions that used to work with both structs).

Now my project compiles and runs fine, but I the variable naming is
inconsistent: in some cases the struct fuse_session pointer is called *se (these were the variables that were always of type struct fuse_session), and in other cases the pointer is called *f (these were the variables that were previously of type struct fuse_ll).

I'd like to fix this too, and always refer call fuse_session pointers "se" (except where this name is already used for something else, but I'll just fix this up by hand afterwards). I tried the following patch:

$ cat se-name.cocci
@@
idexpression struct fuse_session *p1;
@@
- f at p1
+ se

but it resulted in these changes:

(quoted diff) +2 -2
 	struct fuse_session *f = req->se;
-	struct cuse_data *cd = f->cuse_data;
-	size_t bufsize = f->bufsize;
+	struct cuse_data *cd = se->cuse_data;
+	size_t bufsize = se->bufsize;
Quoted 4 lines

So it seems to replace the variable where its used, but not where it's defined.

Is there a way to catch the definitions too?

Write separate rules for that. You would need one case for a local variable and one case fora parameter. You can actually probably just drop the rule you have currently. I would imagine something like the following:

@@
symbol f, se; // avoid unneeded warnings from Coccinelle @@

struct fuse_session *

(quoted diff) +1 -1
-f
+se
 ;

<...

(quoted diff) +1 -1
-f
+se
Quoted 1 line

...>

Could you explain how this works (in particular the effect of the angle brackets)? I also can't resist to point out that "symbol" is not included in the list of metavariable types from the tutorial slides :-).

Quoted 9 lines

@@
identifier fn;
@@

fn(...,struct fuse_session *f,...) { <...

(quoted diff) +1 -1
-f
+se

...> }

Quoted 3 lines

I think that the symbol declaration has effect in the rest of the semantic patch, and does not have to be repeated. If you get warnings for the second rule, just copy it down.

Not sure what you mean with "copy it down". I don't get Coccinelle warnings, but if I just use the two rules as you gave them, then it looks as if the second one isn't working:

@@ -584,9 +584,9 @@ static struct fuse_ll_pipe *fuse_ll_get_

static void fuse_ll_clear_pipe(struct fuse_session *f) {
- struct fuse_ll_pipe *llp = pthread_getspecific(f->pipe_key);
+ struct fuse_ll_pipe *llp = pthread_getspecific(se->pipe_key);
if (llp) {
- pthread_setspecific(f->pipe_key, NULL);
+ pthread_setspecific(se->pipe_key, NULL);
fuse_ll_pipe_free(llp);
}
}

Is the problem that "...," does not match nothing, i.e. *f must not be the first argument of the function?

Best,
-Nikolaus

Signature · 4 lines
GPG encrypted emails preferred. Key id: 0xD113FCAC3C4E599F
Fingerprint: ED31 791B 2C5C 1613 AF38 8B8A D113 FCAC 3C4E 599F

             ?Time flies like an arrow, fruit flies like a Banana.?
#33 lore raw
Quoted 71 lines · Nikolaus Rath
Quoted 70 lines · Julia Lawall
Quoted 54 lines · Nikolaus Rath
Quoted 13 lines · Julia Lawall
Quoted 3 lines

2. ..and how would I go about if instead of the type, I want to replace a variable name? (my_type *ptr --> my_type *pointer).

I'm not completely sure what the issue is here. Do you specifically want to convert ptr to pointer? Is the type important? To make exactly what you have written, you could put:

@@
typedef my_type;
idexpression mytype * p1;
@@

Quoted 6 lines

- ptr at p1
+ pointer

This checks for the word ptr, and also checks that it is an identifier of the right type. I haven't tested it, so let me know if there is any problem.

It workes somewhat... but not completely.

Here's what I wanted to do: I merged two structures (struct fuse_session and struct fuse_ll) into one (struct fuse_session). I've first replaced all the type names, and then manually fixed the cases where this resulted in bogus/redundant code (typically in functions that used to work with both structs).

Now my project compiles and runs fine, but I the variable naming is
inconsistent: in some cases the struct fuse_session pointer is called *se (these were the variables that were always of type struct fuse_session), and in other cases the pointer is called *f (these were the variables that were previously of type struct fuse_ll).

I'd like to fix this too, and always refer call fuse_session pointers "se" (except where this name is already used for something else, but I'll just fix this up by hand afterwards). I tried the following patch:

$ cat se-name.cocci
@@
idexpression struct fuse_session *p1;
@@
- f at p1
+ se

but it resulted in these changes:

(quoted diff) +2 -2
 	struct fuse_session *f = req->se;
-	struct cuse_data *cd = f->cuse_data;
-	size_t bufsize = f->bufsize;
+	struct cuse_data *cd = se->cuse_data;
+	size_t bufsize = se->bufsize;
Quoted 4 lines

So it seems to replace the variable where its used, but not where it's defined.

Is there a way to catch the definitions too?

Write separate rules for that. You would need one case for a local variable and one case fora parameter. You can actually probably just drop the rule you have currently. I would imagine something like the following:

@@
symbol f, se; // avoid unneeded warnings from Coccinelle @@

Quoted 12 lines
Quoted 8 lines

struct fuse_session *

(quoted diff) +1 -1
-f
+se
 ;

<...

(quoted diff) +1 -1
-f
+se

...>

Could you explain how this works (in particular the effect of the angle brackets)? I also can't resist to point out that "symbol" is not included in the list of metavariable types from the tutorial slides :-).

<... P ...> is called a nest. It means that the pattern can appear 0 or more times. You can put a transformation on the pattern. It will happen as many times as the thing appears.

The list on the slides is not exhaustive. The list in the language grammar should be exhaustive:
http://coccinelle.lip6.fr/docs/index.html

Symbol also just exists to quiet a warning message; it's not essential.

Quoted 10 lines
Quoted 10 lines

@@
identifier fn;
@@

fn(...,struct fuse_session *f,...) { <...

(quoted diff) +1 -1
-f
+se

...> }

Quoted 5 lines
Quoted 3 lines

I think that the symbol declaration has effect in the rest of the semantic patch, and does not have to be repeated. If you get warnings for the second rule, just copy it down.

Not sure what you mean with "copy it down".

Put the symbol declaration in both rules.

Quoted 18 lines

I don't get Coccinelle
warnings, but if I just use the two rules as you gave them, then it looks as if the second one isn't working:

(quoted diff) +2 -2
@@ -584,9 +584,9 @@ static struct fuse_ll_pipe *fuse_ll_get_
 
 static void fuse_ll_clear_pipe(struct fuse_session *f)
 {
-	struct fuse_ll_pipe *llp = pthread_getspecific(f->pipe_key);
+	struct fuse_ll_pipe *llp = pthread_getspecific(se->pipe_key);
 	if (llp) {
-		pthread_setspecific(f->pipe_key, NULL);
+		pthread_setspecific(se->pipe_key, NULL);
 		fuse_ll_pipe_free(llp);
 	}
 }
Quoted 2 lines

Is the problem that "...," does not match nothing, i.e. *f must not be the first argument of the function?

It should match nothing. What version of Coccinelle do you have?

julia

Quoted 14 lines

Best,
-Nikolaus

--
GPG encrypted emails preferred. Key id: 0xD113FCAC3C4E599F
Fingerprint: ED31 791B 2C5C 1613 AF38 8B8A D113 FCAC 3C4E 599F

?Time flies like an arrow, fruit flies like a Banana.?
_______________________________________________
Cocci mailing list
Cocci at systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

#34 lore raw
Quoted 47 lines · Julia Lawall
Quoted 47 lines
Quoted 26 lines

Write separate rules for that. You would need one case for a local variable and one case fora parameter. You can actually probably just drop the rule you have currently. I would imagine something like the following:

@@
symbol f, se; // avoid unneeded warnings from Coccinelle @@

struct fuse_session *

(quoted diff) +1 -1
-f
+se
 ;

<...

(quoted diff) +1 -1
-f
+se

...>
@@
identifier fn;
@@

fn(...,struct fuse_session *f,...) { <...

(quoted diff) +1 -1
-f
+se

...> }

Quoted 3 lines

I think that the symbol declaration has effect in the rest of the semantic patch, and does not have to be repeated. If you get warnings for the second rule, just copy it down.

I don't get Coccinelle warnings, but if I just use the two rules as you gave them, then it looks as if the second one isn't working:

(quoted diff) +2 -2
@@ -584,9 +584,9 @@ static struct fuse_ll_pipe *fuse_ll_get_
 
 static void fuse_ll_clear_pipe(struct fuse_session *f)
 {
-	struct fuse_ll_pipe *llp = pthread_getspecific(f->pipe_key);
+	struct fuse_ll_pipe *llp = pthread_getspecific(se->pipe_key);
 	if (llp) {
-		pthread_setspecific(f->pipe_key, NULL);
+		pthread_setspecific(se->pipe_key, NULL);
 		fuse_ll_pipe_free(llp);
 	}
 }
Quoted 4 lines
Quoted 2 lines

Is the problem that "...," does not match nothing, i.e. *f must not be the first argument of the function?

It should match nothing. What version of Coccinelle do you have?

I used 1.0.0-rc22 (from Debian stable). However, I just downloaded the pre-compiled version from http://coccinelle.lip6.fr/download.php and it gives the same result.

In case you want to try yourself: the sources that I'm running this on are available at https://github.com/libfuse/libfuse.

Best,
-Nikolaus

Signature · 4 lines
GPG encrypted emails preferred. Key id: 0xD113FCAC3C4E599F
Fingerprint: ED31 791B 2C5C 1613 AF38 8B8A D113 FCAC 3C4E 599F

             ?Time flies like an arrow, fruit flies like a Banana.?
#35 lore raw
Quoted 48 lines · Nikolaus Rath
Quoted 47 lines · Julia Lawall
Quoted 47 lines
Quoted 26 lines

Write separate rules for that. You would need one case for a local variable and one case fora parameter. You can actually probably just drop the rule you have currently. I would imagine something like the following:

@@
symbol f, se; // avoid unneeded warnings from Coccinelle @@

struct fuse_session *

(quoted diff) +1 -1
-f
+se
 ;

<...

(quoted diff) +1 -1
-f
+se

...>
@@
identifier fn;
@@

fn(...,struct fuse_session *f,...) { <...

(quoted diff) +1 -1
-f
+se

...> }

Quoted 3 lines

I think that the symbol declaration has effect in the rest of the semantic patch, and does not have to be repeated. If you get warnings for the second rule, just copy it down.

I don't get Coccinelle warnings, but if I just use the two rules as you gave them, then it looks as if the second one isn't working:

(quoted diff) +2 -2
@@ -584,9 +584,9 @@ static struct fuse_ll_pipe *fuse_ll_get_
 
 static void fuse_ll_clear_pipe(struct fuse_session *f)
 {
-	struct fuse_ll_pipe *llp = pthread_getspecific(f->pipe_key);
+	struct fuse_ll_pipe *llp = pthread_getspecific(se->pipe_key);
 	if (llp) {
-		pthread_setspecific(f->pipe_key, NULL);
+		pthread_setspecific(se->pipe_key, NULL);
 		fuse_ll_pipe_free(llp);
 	}
 }
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

Is the problem that "...," does not match nothing, i.e. *f must not be the first argument of the function?

It should match nothing. What version of Coccinelle do you have?

I used 1.0.0-rc22 (from Debian stable). However, I just downloaded the pre-compiled version from http://coccinelle.lip6.fr/download.php and it gives the same result.

OK, any rc is quite old.

Quoted 2 lines

In case you want to try yourself: the sources that I'm running this on are available at https://github.com/libfuse/libfuse.

Thanks, I'll check on it.

julia

#36 lore raw
In reply to Nikolaus Rath
Quoted 22 lines · Nikolaus Rath
Quoted 21 lines · Julia Lawall
Quoted 21 lines
Quoted 21 lines

Write separate rules for that. You would need one case for a local variable and one case fora parameter. You can actually probably just drop the rule you have currently. I would imagine something like the following:

@@
symbol f, se; // avoid unneeded warnings from Coccinelle @@

struct fuse_session *

(quoted diff) +1 -1
-f
+se
 ;

<...

(quoted diff) +1 -1
-f
+se

...>
@@
identifier fn;
@@

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

fn(...,struct fuse_session *f,...) { <...

Oops, the first line should be:

fn(...,struct fuse_session *
-f
+se
,...) { <...

The rule works fine even when f is the first argument.

julia

Quoted 51 lines
Quoted 25 lines
Quoted 25 lines
Quoted 7 lines
(quoted diff) +1 -1
-f
+se

...> }

I think that the symbol declaration has effect in the rest of the semantic patch, and does not have to be repeated. If you get warnings for the second rule, just copy it down.

I don't get Coccinelle warnings, but if I just use the two rules as you gave them, then it looks as if the second one isn't working:

(quoted diff) +2 -2
@@ -584,9 +584,9 @@ static struct fuse_ll_pipe *fuse_ll_get_
 
 static void fuse_ll_clear_pipe(struct fuse_session *f)
 {
-	struct fuse_ll_pipe *llp = pthread_getspecific(f->pipe_key);
+	struct fuse_ll_pipe *llp = pthread_getspecific(se->pipe_key);
 	if (llp) {
-		pthread_setspecific(f->pipe_key, NULL);
+		pthread_setspecific(se->pipe_key, NULL);
 		fuse_ll_pipe_free(llp);
 	}
 }
Quoted 4 lines
Quoted 2 lines

Is the problem that "...," does not match nothing, i.e. *f must not be the first argument of the function?

It should match nothing. What version of Coccinelle do you have?

I used 1.0.0-rc22 (from Debian stable). However, I just downloaded the pre-compiled version from http://coccinelle.lip6.fr/download.php and it gives the same result.

In case you want to try yourself: the sources that I'm running this on are available at https://github.com/libfuse/libfuse.

Best,
-Nikolaus

--
GPG encrypted emails preferred. Key id: 0xD113FCAC3C4E599F
Fingerprint: ED31 791B 2C5C 1613 AF38 8B8A D113 FCAC 3C4E 599F

?Time flies like an arrow, fruit flies like a Banana.?
_______________________________________________
Cocci mailing list
Cocci at systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

#37 lore raw
Quoted 33 lines · Julia Lawall
Quoted 22 lines · Nikolaus Rath
Quoted 21 lines · Julia Lawall
Quoted 21 lines
Quoted 21 lines

Write separate rules for that. You would need one case for a local variable and one case fora parameter. You can actually probably just drop the rule you have currently. I would imagine something like the following:

@@
symbol f, se; // avoid unneeded warnings from Coccinelle @@

struct fuse_session *

(quoted diff) +1 -1
-f
+se
 ;

<...

(quoted diff) +1 -1
-f
+se

...>
@@
identifier fn;
@@

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

fn(...,struct fuse_session *f,...) { <...

Oops, the first line should be:

fn(...,struct fuse_session *

(quoted diff) +1 -1
-f
+se
  ,...) { <...
Quoted 1 line

The rule works fine even when f is the first argument.

Ouch, I guess I could have caught that too. Works like a charm now!

Best,
-Nikolaus

Signature · 4 lines
GPG encrypted emails preferred. Key id: 0xD113FCAC3C4E599F
Fingerprint: ED31 791B 2C5C 1613 AF38 8B8A D113 FCAC 3C4E 599F

             ?Time flies like an arrow, fruit flies like a Banana.?
#38 lore raw
Quoted 29 lines · Nikolaus Rath
Quoted 28 lines · Julia Lawall
Quoted 22 lines · Nikolaus Rath
Quoted 21 lines · Julia Lawall
Quoted 21 lines
Quoted 21 lines

Write separate rules for that. You would need one case for a local variable and one case fora parameter. You can actually probably just drop the rule you have currently. I would imagine something like the following:

@@
symbol f, se; // avoid unneeded warnings from Coccinelle @@

struct fuse_session *

(quoted diff) +1 -1
-f
+se
 ;

<...

(quoted diff) +1 -1
-f
+se

...>
@@
identifier fn;
@@

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

fn(...,struct fuse_session *f,...) { <...

Oops, the first line should be:

Quoted 8 lines
Quoted 6 lines

fn(...,struct fuse_session *

(quoted diff) +1 -1
-f
+se
  ,...) { <...

The rule works fine even when f is the first argument.

Ouch, I guess I could have caught that too. Works like a charm now!

I claimed success too early. There are still the following cases left:

static void do_destroy(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)

{
	struct fuse_session *f = req->se;

[....]

I tried to adapt the rules myself as follows:

@@
symbol f, se;
@@
struct fuse_session *
-f
+se
;
<...
-f
+se
...>

@@
symbol f, se;
expression expr;
@@
struct fuse_session *
-f
+se
= expr;
<...
-f
+se
...>

@@
identifier fn;
@@
fn(...,struct fuse_session *
-f
+se
,...) { <...
-f
+se
...> }

But this gives an error:

Fatal error: exception Failure("meta: parse error:
= File "se-rename.cocci", line 14, column 7, charpos = 79

    around = 'f', whole content = symbol f, se;

")

What am I doing wrong?

Thanks!
-Nikolaus

Signature · 4 lines
GPG encrypted emails preferred. Key id: 0xD113FCAC3C4E599F
Fingerprint: ED31 791B 2C5C 1613 AF38 8B8A D113 FCAC 3C4E 599F

             ?Time flies like an arrow, fruit flies like a Banana.?
#39 lore raw
Quoted 90 lines · Nikolaus Rath
Quoted 29 lines · Nikolaus Rath
Quoted 28 lines · Julia Lawall
Quoted 22 lines · Nikolaus Rath
Quoted 21 lines · Julia Lawall
Quoted 21 lines
Quoted 21 lines

Write separate rules for that. You would need one case for a local variable and one case fora parameter. You can actually probably just drop the rule you have currently. I would imagine something like the following:

@@
symbol f, se; // avoid unneeded warnings from Coccinelle @@

struct fuse_session *

(quoted diff) +1 -1
-f
+se
 ;

<...

(quoted diff) +1 -1
-f
+se

...>
@@
identifier fn;
@@

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

fn(...,struct fuse_session *f,...) { <...

Oops, the first line should be:

Quoted 8 lines
Quoted 6 lines

fn(...,struct fuse_session *

(quoted diff) +1 -1
-f
+se
  ,...) { <...

The rule works fine even when f is the first argument.

Ouch, I guess I could have caught that too. Works like a charm now!

I claimed success too early. There are still the following cases left:

static void do_destroy(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)

{
	struct fuse_session *f = req->se;

[....]

I tried to adapt the rules myself as follows:

@@
symbol f, se;
@@
struct fuse_session *

(quoted diff) +1 -1
-f
+se

;
<...

(quoted diff) +1 -1
-f
+se

...>

@@
symbol f, se;
expression expr;
@@
struct fuse_session *

(quoted diff) +1 -1
-f
+se

= expr;
<...

(quoted diff) +1 -1
-f
+se

...>

@@
identifier fn;
@@
fn(...,struct fuse_session *

(quoted diff) +1 -1
-f
+se

,...) { <...

(quoted diff) +1 -1
-f
+se

...> }

But this gives an error:

Quoted 7 lines

Fatal error: exception Failure("meta: parse error:
= File "se-rename.cocci", line 14, column 7, charpos = 79

    around = 'f', whole content = symbol f, se;

")

What am I doing wrong?

What version of Coccinelle are you using? Before 1.0.6, it was not possible to declare something to be a symbol more than once. In any case, once it is declared as a symbol, it is always a symbol.

julia

#40 lore raw
Quoted 57 lines · Julia Lawall
Quoted 57 lines

I claimed success too early. There are still the following cases left:

static void do_destroy(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)

{
	struct fuse_session *f = req->se;

[....]

I tried to adapt the rules myself as follows:

@@
symbol f, se;
@@
struct fuse_session *

(quoted diff) +1 -1
-f
+se

;
<...

(quoted diff) +1 -1
-f
+se

...>

@@
symbol f, se;
expression expr;
@@
struct fuse_session *

(quoted diff) +1 -1
-f
+se

= expr;
<...

(quoted diff) +1 -1
-f
+se

...>

@@
identifier fn;
@@
fn(...,struct fuse_session *

(quoted diff) +1 -1
-f
+se

,...) { <...

(quoted diff) +1 -1
-f
+se

...> }

But this gives an error:

Fatal error: exception Failure("meta: parse error:
= File "se-rename.cocci", line 14, column 7, charpos = 79

    around = 'f', whole content = symbol f, se;

")

Quoted 5 lines
Quoted 1 line

What am I doing wrong?

What version of Coccinelle are you using? Before 1.0.6, it was not possible to declare something to be a symbol more than once. In any case, once it is declared as a symbol, it is always a symbol.

Ok, we're getting there. I've removed the second 'symbol' line, and (permanently) updated to 1.0.6. However, now it seems to simply run forever:

$ ../coccinelle-1.0.6/spatch.opt --sp-file ~/in-progress/libfuse/se-rename.cocci --in-place lib/ include/ test/ example/ util/
init_defs_builtins: /home/nikratio/tmp/coccinelle-1.0.6/standard.h
warning: patch output can only be created when only one
directory is specified or when the -patch flag is used
HANDLING: lib/fuse.c
(ONCE) Expected tokens fuse_session f
Skipping:lib/fuse_opt.c
HANDLING: lib/helper.c
Skipping:lib/mount_bsd.c
Skipping:lib/fuse_loop_mt.c
Skipping:lib/fuse_loop.c
HANDLING: lib/cuse_lowlevel.c
diff = 
[...]
HANDLING: lib/fuse_lowlevel.c

At this point it has been hanging for about 15 minutes now, steady eating CPU time.

Is it supposed to take that long? The fuse_lowlevel.c file is 74k with 2465 lines of code.

Best,
-Nikolaus

Signature · 4 lines
GPG encrypted emails preferred. Key id: 0xD113FCAC3C4E599F
Fingerprint: ED31 791B 2C5C 1613 AF38 8B8A D113 FCAC 3C4E 599F

             ?Time flies like an arrow, fruit flies like a Banana.?
#41 lore raw
Quoted 84 lines · Nikolaus Rath
Quoted 57 lines · Julia Lawall
Quoted 57 lines

I claimed success too early. There are still the following cases left:

static void do_destroy(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)

{
	struct fuse_session *f = req->se;

[....]

I tried to adapt the rules myself as follows:

@@
symbol f, se;
@@
struct fuse_session *

(quoted diff) +1 -1
-f
+se

;
<...

(quoted diff) +1 -1
-f
+se

...>

@@
symbol f, se;
expression expr;
@@
struct fuse_session *

(quoted diff) +1 -1
-f
+se

= expr;
<...

(quoted diff) +1 -1
-f
+se

...>

@@
identifier fn;
@@
fn(...,struct fuse_session *

(quoted diff) +1 -1
-f
+se

,...) { <...

(quoted diff) +1 -1
-f
+se

...> }

But this gives an error:

Fatal error: exception Failure("meta: parse error:
= File "se-rename.cocci", line 14, column 7, charpos = 79

    around = 'f', whole content = symbol f, se;

")

Quoted 5 lines
Quoted 1 line

What am I doing wrong?

What version of Coccinelle are you using? Before 1.0.6, it was not possible to declare something to be a symbol more than once. In any case, once it is declared as a symbol, it is always a symbol.

Ok, we're getting there. I've removed the second 'symbol' line, and (permanently) updated to 1.0.6. However, now it seems to simply run forever:

$ ../coccinelle-1.0.6/spatch.opt --sp-file ~/in-progress/libfuse/se-rename.cocci --in-place lib/ include/ test/ example/ util/
init_defs_builtins: /home/nikratio/tmp/coccinelle-1.0.6/standard.h
warning: patch output can only be created when only one
directory is specified or when the -patch flag is used
HANDLING: lib/fuse.c
(ONCE) Expected tokens fuse_session f
Skipping:lib/fuse_opt.c
HANDLING: lib/helper.c
Skipping:lib/mount_bsd.c
Skipping:lib/fuse_loop_mt.c
Skipping:lib/fuse_loop.c
HANDLING: lib/cuse_lowlevel.c
diff =
[...]
HANDLING: lib/fuse_lowlevel.c
Quoted 5 lines

At this point it has been hanging for about 15 minutes now, steady eating CPU time.

Is it supposed to take that long? The fuse_lowlevel.c file is 74k with 2465 lines of code.

You can use --show-trying to see what function it is getting stuck on. If the function has a lot of ifs and loops, it may indeed take a long time. ... follows possible paths in the execution graph and a sequence of ifs makes the number of paths grow exponentially.

A solution is to add a timeout, eg --timeout 120 (120 seconds). You will need to check a file on which there is a timeout manually.

Tracing paths around loops is not really relevant in your case, so you can also safely use the option --no-loops, which will avoid taking the back edges.

julia

Quoted 14 lines

Best,
-Nikolaus

--
GPG encrypted emails preferred. Key id: 0xD113FCAC3C4E599F
Fingerprint: ED31 791B 2C5C 1613 AF38 8B8A D113 FCAC 3C4E 599F

?Time flies like an arrow, fruit flies like a Banana.?
_______________________________________________
Cocci mailing list
Cocci at systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

#42 lore raw
Quoted 33 lines · Julia Lawall
Quoted 22 lines

Ok, we're getting there. I've removed the second 'symbol' line, and (permanently) updated to 1.0.6. However, now it seems to simply run forever:

$ ../coccinelle-1.0.6/spatch.opt --sp-file
~/in-progress/libfuse/se-rename.cocci --in-place lib/ include/ test/
example/ util/
init_defs_builtins: /home/nikratio/tmp/coccinelle-1.0.6/standard.h
warning: patch output can only be created when only one
directory is specified or when the -patch flag is used
HANDLING: lib/fuse.c
(ONCE) Expected tokens fuse_session f
Skipping:lib/fuse_opt.c
HANDLING: lib/helper.c
Skipping:lib/mount_bsd.c
Skipping:lib/fuse_loop_mt.c
Skipping:lib/fuse_loop.c
HANDLING: lib/cuse_lowlevel.c
diff =
[...]
HANDLING: lib/fuse_lowlevel.c
Quoted 5 lines

At this point it has been hanging for about 15 minutes now, steady eating CPU time.

Is it supposed to take that long? The fuse_lowlevel.c file is 74k with 2465 lines of code.

You can use --show-trying to see what function it is getting stuck on. If the function has a lot of ifs and loops, it may indeed take a long time. ... follows possible paths in the execution graph and a sequence of ifs makes the number of paths grow exponentially.

Quoted 6 lines

A solution is to add a timeout, eg --timeout 120 (120 seconds). You will need to check a file on which there is a timeout manually.

Tracing paths around loops is not really relevant in your case, so you can also safely use the option --no-loops, which will avoid taking the back edges.

I tried doing both, but it still gets stuck:

init_defs_builtins: /home/nikratio/tmp/coccinelle-1.0.6/standard.h
HANDLING: lib/fuse_lowlevel.c
-----------------------------------------------------------------------
rule starting on line 1 =
-----------------------------------------------------------------------
[...]
-----------------------------------------------------------------------
rule starting on line 13 =
-----------------------------------------------------------------------
[...]
trying function: do_init: fuse_lowlevel.c:1812

The do_init() function doesn't seem all that terrible to me though:
https://github.com/libfuse/libfuse/blob/58273972f0b20/lib/fuse_lowlevel.c#L1812

Best,
-Nikolaus

Signature · 4 lines
GPG encrypted emails preferred. Key id: 0xD113FCAC3C4E599F
Fingerprint: ED31 791B 2C5C 1613 AF38 8B8A D113 FCAC 3C4E 599F

             ?Time flies like an arrow, fruit flies like a Banana.?
#43 lore raw
Quoted 56 lines · Nikolaus Rath
Quoted 33 lines · Julia Lawall
Quoted 22 lines

Ok, we're getting there. I've removed the second 'symbol' line, and (permanently) updated to 1.0.6. However, now it seems to simply run forever:

$ ../coccinelle-1.0.6/spatch.opt --sp-file
~/in-progress/libfuse/se-rename.cocci --in-place lib/ include/ test/
example/ util/
init_defs_builtins: /home/nikratio/tmp/coccinelle-1.0.6/standard.h
warning: patch output can only be created when only one
directory is specified or when the -patch flag is used
HANDLING: lib/fuse.c
(ONCE) Expected tokens fuse_session f
Skipping:lib/fuse_opt.c
HANDLING: lib/helper.c
Skipping:lib/mount_bsd.c
Skipping:lib/fuse_loop_mt.c
Skipping:lib/fuse_loop.c
HANDLING: lib/cuse_lowlevel.c
diff =
[...]
HANDLING: lib/fuse_lowlevel.c
Quoted 5 lines

At this point it has been hanging for about 15 minutes now, steady eating CPU time.

Is it supposed to take that long? The fuse_lowlevel.c file is 74k with 2465 lines of code.

You can use --show-trying to see what function it is getting stuck on. If the function has a lot of ifs and loops, it may indeed take a long time. ... follows possible paths in the execution graph and a sequence of ifs makes the number of paths grow exponentially.

Quoted 6 lines

A solution is to add a timeout, eg --timeout 120 (120 seconds). You will need to check a file on which there is a timeout manually.

Tracing paths around loops is not really relevant in your case, so you can also safely use the option --no-loops, which will avoid taking the back edges.

I tried doing both, but it still gets stuck:

init_defs_builtins: /home/nikratio/tmp/coccinelle-1.0.6/standard.h
HANDLING: lib/fuse_lowlevel.c
-----------------------------------------------------------------------
rule starting on line 1 =
-----------------------------------------------------------------------
[...]
-----------------------------------------------------------------------
rule starting on line 13 =
-----------------------------------------------------------------------
[...]
trying function: do_init: fuse_lowlevel.c:1812

Quoted 2 lines

The do_init() function doesn't seem all that terrible to me though:
https://github.com/libfuse/libfuse/blob/58273972f0b20/lib/fuse_lowlevel.c#L1812

Yes it does. Look at lines 1852-1877. There are 2^13 execution paths there, and there is another such stack of ifs later in the function.

So you did add a timeout and it is still getting stuck? Try a very short timeout just to see what happens.

julia

#44 lore raw
Quoted 58 lines · Julia Lawall
Quoted 56 lines · Nikolaus Rath
Quoted 33 lines · Julia Lawall
Quoted 22 lines

Ok, we're getting there. I've removed the second 'symbol' line, and (permanently) updated to 1.0.6. However, now it seems to simply run forever:

$ ../coccinelle-1.0.6/spatch.opt --sp-file
~/in-progress/libfuse/se-rename.cocci --in-place lib/ include/ test/
example/ util/
init_defs_builtins: /home/nikratio/tmp/coccinelle-1.0.6/standard.h
warning: patch output can only be created when only one
directory is specified or when the -patch flag is used
HANDLING: lib/fuse.c
(ONCE) Expected tokens fuse_session f
Skipping:lib/fuse_opt.c
HANDLING: lib/helper.c
Skipping:lib/mount_bsd.c
Skipping:lib/fuse_loop_mt.c
Skipping:lib/fuse_loop.c
HANDLING: lib/cuse_lowlevel.c
diff =
[...]
HANDLING: lib/fuse_lowlevel.c
Quoted 5 lines

At this point it has been hanging for about 15 minutes now, steady eating CPU time.

Is it supposed to take that long? The fuse_lowlevel.c file is 74k with 2465 lines of code.

You can use --show-trying to see what function it is getting stuck on. If the function has a lot of ifs and loops, it may indeed take a long time. ... follows possible paths in the execution graph and a sequence of ifs makes the number of paths grow exponentially.

Quoted 6 lines

A solution is to add a timeout, eg --timeout 120 (120 seconds). You will need to check a file on which there is a timeout manually.

Tracing paths around loops is not really relevant in your case, so you can also safely use the option --no-loops, which will avoid taking the back edges.

I tried doing both, but it still gets stuck:

init_defs_builtins: /home/nikratio/tmp/coccinelle-1.0.6/standard.h
HANDLING: lib/fuse_lowlevel.c
-----------------------------------------------------------------------
rule starting on line 1 =
-----------------------------------------------------------------------
[...]
-----------------------------------------------------------------------
rule starting on line 13 =
-----------------------------------------------------------------------
[...]
trying function: do_init: fuse_lowlevel.c:1812

Quoted 8 lines
Quoted 2 lines

The do_init() function doesn't seem all that terrible to me though:
https://github.com/libfuse/libfuse/blob/58273972f0b20/lib/fuse_lowlevel.c#L1812

Yes it does. Look at lines 1852-1877. There are 2^13 execution paths there, and there is another such stack of ifs later in the function.

So you did add a timeout and it is still getting stuck? Try a very short timeout just to see what happens.

Sorry for the confusion. No, when I add the timeout then it aborts. But I thought that with --no-loops it would not trace out all the different paths and should complete more quickly.

Also, it seems that with --timeout it aborts completely (instead of just going to the next function):

trying function: do_fallocate: fuse_lowlevel.c:1798 trying function: do_init: fuse_lowlevel.c:1812
timeout (we abort)
Fatal error: exception Common.Timeout

$

Is that intended?

Best,
-Nikolaus

Signature · 4 lines
GPG encrypted emails preferred. Key id: 0xD113FCAC3C4E599F
Fingerprint: ED31 791B 2C5C 1613 AF38 8B8A D113 FCAC 3C4E 599F

             ?Time flies like an arrow, fruit flies like a Banana.?
#45 lore raw
Quoted 65 lines · Nikolaus Rath
Quoted 64 lines · Julia Lawall
Quoted 56 lines · Nikolaus Rath
Quoted 33 lines · Julia Lawall
Quoted 22 lines

Ok, we're getting there. I've removed the second 'symbol' line, and (permanently) updated to 1.0.6. However, now it seems to simply run forever:

$ ../coccinelle-1.0.6/spatch.opt --sp-file
~/in-progress/libfuse/se-rename.cocci --in-place lib/ include/ test/
example/ util/
init_defs_builtins: /home/nikratio/tmp/coccinelle-1.0.6/standard.h
warning: patch output can only be created when only one
directory is specified or when the -patch flag is used
HANDLING: lib/fuse.c
(ONCE) Expected tokens fuse_session f
Skipping:lib/fuse_opt.c
HANDLING: lib/helper.c
Skipping:lib/mount_bsd.c
Skipping:lib/fuse_loop_mt.c
Skipping:lib/fuse_loop.c
HANDLING: lib/cuse_lowlevel.c
diff =
[...]
HANDLING: lib/fuse_lowlevel.c
Quoted 5 lines

At this point it has been hanging for about 15 minutes now, steady eating CPU time.

Is it supposed to take that long? The fuse_lowlevel.c file is 74k with 2465 lines of code.

You can use --show-trying to see what function it is getting stuck on. If the function has a lot of ifs and loops, it may indeed take a long time. ... follows possible paths in the execution graph and a sequence of ifs makes the number of paths grow exponentially.

Quoted 6 lines

A solution is to add a timeout, eg --timeout 120 (120 seconds). You will need to check a file on which there is a timeout manually.

Tracing paths around loops is not really relevant in your case, so you can also safely use the option --no-loops, which will avoid taking the back edges.

I tried doing both, but it still gets stuck:

init_defs_builtins: /home/nikratio/tmp/coccinelle-1.0.6/standard.h
HANDLING: lib/fuse_lowlevel.c
-----------------------------------------------------------------------
rule starting on line 1 =
-----------------------------------------------------------------------
[...]
-----------------------------------------------------------------------
rule starting on line 13 =
-----------------------------------------------------------------------
[...]
trying function: do_init: fuse_lowlevel.c:1812

Quoted 2 lines

The do_init() function doesn't seem all that terrible to me though:
https://github.com/libfuse/libfuse/blob/58273972f0b20/lib/fuse_lowlevel.c#L1812

Yes it does. Look at lines 1852-1877. There are 2^13 execution paths there, and there is another such stack of ifs later in the function.

Quoted 6 lines
Quoted 2 lines

So you did add a timeout and it is still getting stuck? Try a very short timeout just to see what happens.

Sorry for the confusion. No, when I add the timeout then it aborts. But I thought that with --no-loops it would not trace out all the different paths and should complete more quickly.

--no-loops just eliminates the back edges of loops. That is not your problem, so it won't help.

Quoted 11 lines

Also, it seems that with --timeout it aborts completely (instead of just going to the next function):

trying function: do_fallocate: fuse_lowlevel.c:1798 trying function: do_init: fuse_lowlevel.c:1812
timeout (we abort)
Fatal error: exception Common.Timeout

$

Is that intended?

Yes. In general, there can be (both positive and negative) dependencies between rules, and incompletely processing one function could lead to an inconsistent state. Coccinelle could perhaps analyze the dependencies in the specific semantic patch at hand, and firgure out whether there could be a problem, but for now it doesn't do that.

julia

#46 lore raw
In reply to Nikolaus Rath
Quoted 2 lines

Based on the LWN articles that I've read, this seems like the perfect use-case for coccinelle.

I would expect this also if you are interested in the simple replacement for the data type of a function parameter.

Quoted 1 line

However, somehow I'm struggling to write a patch for this.

Are you exploring the software development possibilities together with the semantic patch language?

Quoted 2 lines

All the documentation that I could get my hands on seems to describe more abstract changes that require the use of variables

SmPL metavariables have got their purposes. How do you think about to discuss a bit more if you will eventually use them also?

Quoted 1 line

- but as far as I can tell, I need something much simpler:

There are some improvement opportunities in this approach.

Quoted 3 lines

@@
"struct fasel_foo must be a type name!"
@@

How did you get the idea to place this test string there?

Quoted 5 lines

- struct fasel_foo
+ struct fasel_bar

...if only I knew what to put between the @@.

Are the other parts of this source code search pattern also incomplete so far?

Quoted 1 line

Can someone point me in the right direction?

I hope so.

Would the following small SmPL script fit to your expectations?

@data_type_replacement@
@@
char* fasel_foo_print(
-struct fasel_foo
+struct fasel_bar

                       *ptr) {
    // ...

return "this struct fasel_foo string should not change";
}

Regards,
Markus