string parameter concatenation
Hi!
I've found a small nit in the handling of strings that spans over multiple lines:
nit.c:
int main(void)
{
f("This is a string that continues to the next line"
" just string continuation");
}
nit.cocci:
@@
expression list L;
@@
- f(L);
+ g(L);
spatch nit.cocci nit.cinit_defs_builtins: /usr/local/share/coccinelle/standard.h
HANDLING: nit.c
tmp/cocci-output-8374-71ffd9-nit.c renamed from nit.c +1 -2
@@ -1,5 +1,4 @@int main (void ) { -f ("This is a string that continues to the next line" -" just string continuation" ); +g ("This is a string that continues to the next line"" just string continuation" ); }
While this produces perfectly correct C code it would be nicer if the strings were merged into one single C string. Othewise this still breaks what LKML coding style says about being able to grep user-visible strings in the source code.
Signature · 2 lines
Cyril Hrubis chrubis at suse.cz
Quoted 33 lines · Cyril Hrubis
Hi!
I've found a small nit in the handling of strings that spans over multiple lines:
nit.c:
int main(void)
{
f("This is a string that continues to the next line"
" just string continuation");
}
nit.cocci:
@@
expression list L;
@@
- f(L);
+ g(L);spatch
nit.coccinit.cinit_defs_builtins:/usr/local/share/coccinelle/standard.h
HANDLING:nit.c
diff =tmp/cocci-output-8374-71ffd9-nit.c renamed from nit.c +1
-2@@ -1,5 +1,4 @@int main (void ) { -f ("This is a string that continues to the next line" -" just string continuation" ); +g ("This is a string that continues to the next line"" just string continuation" ); }
Quoted 4 lines
While this produces perfectly correct C code it would be nicer if the strings were merged into one single C string. Othewise this still breaks what LKML coding style says about being able to grep user-visible strings in the source code.
I can try to see what to do about it. String made up of multiple concatenated strings are perhaps not so well supported. I don't think that automatic concatenation would be a good idea, because some users might not want it.
Thanks!
julia
Quoted 3 lines
String made up of multiple concatenated strings are perhaps not so well supported. I don't think that automatic concatenation would be a good idea, because some users might not want it.
Does the semantic patch language support to find source code places where values are constructed out of several substrings?
How much do other string layouts matter in coding styles?
Regards,
Markus
Quoted 6 lines · SF Markus Elfring
Quoted 3 lines
String made up of multiple concatenated strings are perhaps not so well supported. I don't think that automatic concatenation would be a good idea, because some users might not want it.
Does the semantic patch language support to find source code places where values are constructed out of several substrings?
No.
julia
Quoted 5 lines
How much do other string layouts matter in coding styles?
Regards,
Markus
Quoted 35 lines · Julia Lawall
Quoted 33 lines · Cyril Hrubis
Hi!
I've found a small nit in the handling of strings that spans over multiple lines:
nit.c:
int main(void)
{
f("This is a string that continues to the next line"
" just string continuation");
}
nit.cocci:
@@
expression list L;
@@
- f(L);
+ g(L);spatch
nit.coccinit.cinit_defs_builtins:/usr/local/share/coccinelle/standard.h
HANDLING:nit.c
diff =tmp/cocci-output-8374-71ffd9-nit.c renamed from nit.c +1
-2@@ -1,5 +1,4 @@int main (void ) { -f ("This is a string that continues to the next line" -" just string continuation" ); +g ("This is a string that continues to the next line"" just string continuation" ); }
Quoted 9 lines
Quoted 4 lines
While this produces perfectly correct C code it would be nicer if the strings were merged into one single C string. Othewise this still breaks what LKML coding style says about being able to grep user-visible strings in the source code.
I can try to see what to do about it. String made up of multiple concatenated strings are perhaps not so well supported. I don't think that automatic concatenation would be a good idea, because some users might not want it.
If at any point in time you find some odd things C may do which might be real hard to gramatically handle within Coccinelle it may be worthwhile for us to consider on the kernel as something to consider to avoid as coding practice. This obviously cannot apply to all odd-ball C hacks possible I certainly would not rule it out given the gains.
Luis
Hi!
And here is another small nit:
nit.c:
int main(void)
{
f(param1, "Long string that fits to 80 chars .........................",
param2, param3);
}nit.cocci:
@@
expression list L;
@@
- f(L);
+ g(L);
output:init_defs_builtins: /usr/local/share/coccinelle/standard.h
HANDLING: nit.c
tmp/cocci-output-30698-a2be52-nit.c renamed from nit.c +1 -2
@@ -1,5 +1,4 @@int main (void ) { -f (param1,"Long string that fits to 80 chars ........................." , - param2, param3); +g (param1,"Long string that fits to 80 chars ........................." , param2, param3); }
Here the whole list of parameters is put on single line after the substitution which sometimes creates 150 chars long lines for printf-like functions.
Unfortunatelly I cannot think of a good solution here. Conservative one would be keeping the parameters as they are, but that would break anyway if function name lenght, number or lenght of parameters changes.
Signature · 2 lines
Cyril Hrubis chrubis at suse.cz
Quoted 31 lines · Cyril Hrubis
Hi!
And here is another small nit:
nit.c:
int main(void){ f(param1, "Long string that fits to 80 chars .........................", param2, param3); }
nit.cocci:
@@
expression list L;
@@
- f(L);
+ g(L);output:
init_defs_builtins:/usr/local/share/coccinelle/standard.h
HANDLING:nit.c
diff =tmp/cocci-output-30698-a2be52-nit.c renamed from nit.c +1
-2@@ -1,5 +1,4 @@int main (void ) { -f (param1,"Long string that fits to 80 chars ........................." , - param2, param3); +g (param1,"Long string that fits to 80 chars ........................." , param2, param3); }
Quoted 6 lines
Here the whole list of parameters is put on single line after the substitution which sometimes creates 150 chars long lines for printf-like functions.
Unfortunatelly I cannot think of a good solution here. Conservative one would be keeping the parameters as they are, but that would break anyway if function name lenght, number or lenght of parameters changes.
It should do the right thing here. I will look into it. Maybe the problem is the expression list...
julia
Quoted 6 lines
nit.cocci:
@@
expression list L;
@@
- f(L);
+ g(L);
Would it make sense and work to write a semantic patch rule like the following?
@replacement@
@@
-f
+g
(L);
Can the passed parameters be omitted from the desired adjustment by "the plus line"?
Regards,
Markus
Quoted 16 lines · SF Markus Elfring
Quoted 6 lines
nit.cocci:
@@
expression list L;
@@
- f(L);
+ g(L);Would it make sense and work to write a semantic patch rule like the following?
@replacement@
@@(quoted diff) +1
-1-f +g(L);
Quoted 1 line
Can the passed parameters be omitted from the desired adjustment by "the plus line"?
For the particular example, this would be better, but presumably the real case is more complex.
julia
Hi!
Quoted 10 lines
Would it make sense and work to write a semantic patch rule like the following?
@replacement@
@@(quoted diff) +1
-1-f +g(L);
Can the passed parameters be omitted from the desired adjustment by "the plus line"?
The whole rule that I'm working with is:
@@
expression list L;
expression C != {TINFO, TPASS};
@@
- tst_resm(C, L);
- tst_exit();
+ tst_brkm(C, NULL, L);
Which is used to replace two functions with one and shuffles the arguments a bit.
Signature · 2 lines
Cyril Hrubis chrubis at suse.cz
Quoted 22 lines · Cyril Hrubis
Hi!
Quoted 10 lines
Would it make sense and work to write a semantic patch rule like the following?
@replacement@
@@(quoted diff) +1
-1-f +g(L);
Can the passed parameters be omitted from the desired adjustment by "the plus line"?
The whole rule that I'm working with is:
@@
expression list L;
expression C != {TINFO, TPASS};
@@
-tst_resm(C, L);
-tst_exit();
+tst_brkm(C, NULL, L);
Quoted 2 lines
Which is used to replace two functions with one and shuffles the arguments a bit.
It is not actually necessary to remove and add back L. You could write:
- tst_resm
+ txt_brkm
(C,
+ NULL,
L);
- tst_exit();
However, it is useful to have the bug reports.
julia
Hi!
Quoted 8 lines
It is not actually necessary to remove and add back L. You could write:
-
tst_resm
+txt_brkm
(C,
+ NULL,L);-
tst_exit();
Ah, you are right. I should really stop thinking in terms of lines of code and focus more on the tokens lines are composed of.
Quoted 1 line
However, it is useful to have the bug reports.
I'm a proffesional QA and therefore I'm very skilled in breaking things :).
Signature · 2 lines
Cyril Hrubis chrubis at suse.cz
Quoted 10 lines · Cyril Hrubis
Hi!
I've found a small nit in the handling of strings that spans over multiple lines:
nit.c:
int main(void)
{
f("This is a string that continues to the next line"
" just string continuation");
}
The patch below solves this problem as well as the one with the long string in the argument list.
julia
parsing_c/pretty_print_c.ml +2 -1
@@ -101,7 +101,8 @@ let mk_pretty_printers (match exp, ii with | Ident (ident), [] -> pp_name ident (* only a MultiString can have multiple ii *) - | Constant (MultiString _), is -> is +> List.iter pr_elem + | Constant (MultiString _), is -> + is +> Common.print_between pr_space pr_elem | Constant (c), [i] -> pr_elem i | StringConstant(s,os,w), [i1;i2] -> pr_elem i1;
parsing_c/unparse_c.ml +68 -34
269 lines not on this page · raw message
Hi!
Quoted 10 lines
Quoted 9 lines
I've found a small nit in the handling of strings that spans over multiple lines:
nit.c:
int main(void)
{
f("This is a string that continues to the next line"
" just string continuation");
}
Quoted 2 lines
The patch below solves this problem as well as the one with the long string in the argument list.
It's better but it produces changes like this:
@@ -250,9 +250,14 @@ void l_seek(int fdesc, off_t offset, int whence, off_t checkoff)
off_t offloc;
if ((offloc = lseek(fdesc, offset, whence)) != checkoff) {- tst_resm(TFAIL, "(%ld = lseek(%d, %ld, %d)) != %ld) errno = %d",
- offloc, fdesc, offset, whence, checkoff, errno);
- tst_exit();
+ tst_brkm(TFAIL, NULL,
+ "(%ld = lseek(%d, %ld, %d)) != %ld) errno = %d",
+ offloc,
+ fdesc,
+ offset,
+ whence,
+ checkoff,
+ errno);
}}
Which seems to be waste of vertical space to me.
Signature · 2 lines
Cyril Hrubis chrubis at suse.cz
Quoted 34 lines · Cyril Hrubis
Hi!
Quoted 10 lines
Quoted 9 lines
I've found a small nit in the handling of strings that spans over multiple lines:
nit.c:
int main(void)
{
f("This is a string that continues to the next line"
" just string continuation");
}Quoted 2 lines
The patch below solves this problem as well as the one with the long string in the argument list.
It's better but it produces changes like this:
(quoted diff) +8
-3@@ -250,9 +250,14 @@ void l_seek(int fdesc, off_t offset, int whence, off_t checkoff) off_t offloc; if ((offloc = lseek(fdesc, offset, whence)) != checkoff) { - tst_resm(TFAIL, "(%ld = lseek(%d, %ld, %d)) != %ld) errno = %d", - offloc, fdesc, offset, whence, checkoff, errno); - tst_exit(); + tst_brkm(TFAIL, NULL, + "(%ld = lseek(%d, %ld, %d)) != %ld) errno = %d", + offloc, + fdesc, + offset, + whence, + checkoff, + errno); } }
Quoted 1 line
Which seems to be waste of vertical space to me.
Ah. Indeed. Thanks for the report. I will look into it. Some counter must not be getting reset.
julia
[Cocci] Configuration for alignment of function parameters?
Quoted 3 lines
Quoted 1 line
Which seems to be waste of vertical space to me.
I will look into it. Some counter must not be getting reset.
How do you think about to make the parameter alignment configurable? Do other coding styles prefer the shown source code layout?
Regards,
Markus
Quoted 20 lines
It's better but it produces changes like this:
(quoted diff) +8
-3@@ -250,9 +250,14 @@ void l_seek(int fdesc, off_t offset, int whence, off_t checkoff) off_t offloc; if ((offloc = lseek(fdesc, offset, whence)) != checkoff) { - tst_resm(TFAIL, "(%ld = lseek(%d, %ld, %d)) != %ld) errno = %d", - offloc, fdesc, offset, whence, checkoff, errno); - tst_exit(); + tst_brkm(TFAIL, NULL, + "(%ld = lseek(%d, %ld, %d)) != %ld) errno = %d", + offloc, + fdesc, + offset, + whence, + checkoff, + errno); } }
Quoted 1 line
Which seems to be waste of vertical space to me.
This may be solved by the following patch:
parsing_c/unparse_c.ml +6 -8
@@ -1288,14 +1288,12 @@ let add_newlines toks tabbing_unit = | _ -> (count,List.tl stack,space_cell,seen_cocci) in let update_by_stack s count stack sp space_cell seen_cocci = let count = simple_string_length s (count + 1 (*space*)) in - let newinfo = - match stack with - | [(x,tustack)] -> - (match check_for_newline count x tustack space_cell with - | Some count -> (stack,Some (x,sp), seen_cocci) - | None -> (stack,Some (count,sp),seen_cocci)) - | _ -> (stack,space_cell,seen_cocci) in - (newinfo,count) in + match stack with + | [(x,tustack)] -> + (match check_for_newline count x tustack space_cell with + | Some count -> ((stack,Some (x,sp), seen_cocci),count) + | None -> ((stack,Some (count,sp),seen_cocci),count)) + | _ -> ((stack,space_cell,seen_cocci),count) in let rec loop ((stack,space_cell,seen_cocci) as info) count seeneq = function | [] -> []
Hi!
Quoted 15 lines
parsing_c/unparse_c.ml +0
-7@@ -1288,14 +1288,12 @@ let add_newlines toks tabbing_unit = | _ -> (count,List.tl stack,space_cell,seen_cocci) in let update_by_stack s count stack sp space_cell seen_cocci = let count = simple_string_length s (count + 1 (*space*)) in - let newinfo = - match stack with - | [(x,tustack)] -> - (match check_for_newline count x tustack space_cell with - | Some count -> (stack,Some (x,sp), seen_cocci) - | None -> (stack,Some (count,sp),seen_cocci)) - | _ -> (stack,space_cell,seen_cocci) in
parsing_c/unparse_c.ml let add_newlines toks tabbing_unit = · line 1299
Quoted 10 lines
parsing_c/unparse_c.ml +6
-1- (newinfo,count) in + match stack with + | [(x,tustack)] -> + (match check_for_newline count x tustack space_cell with + | Some count -> ((stack,Some (x,sp), seen_cocci),count) + | None -> ((stack,Some (count,sp),seen_cocci),count)) + | _ -> ((stack,space_cell,seen_cocci),count) in let rec loop ((stack,space_cell,seen_cocci) as info) count seeneq = function | [] -> []
Sorry, I've lost context on this one. Over what patches should I apply this patch? I've tried both 1.0.0-rc22 and 1.0.0-rc22 + patches you send previously and neither of them worked :(.
It would have been easier if coccinelle had official git repository you could have pushed the patch there and easily point me to it...
Signature · 2 lines
Cyril Hrubis chrubis at suse.cz