Re: [Qemu-devel] [PATCH v2] scripts/checkpatch.pl: Bug fix

2018-04-03 Thread Su Hang
Please ignore this email, this patch was accidentally sent.

"Su Hang" wrote:
> checkpatch.pl stops complaining about following pattern:
> """
> do {
> //do somethins;
> } while (conditions);
> """
> 
> One things need to be mentioned:
> Becasue `if`, `while` and `for` check have been done in this
> `if` block(Line: 2356), and this block contains following statement:
> """ Line: 2379
> $suppress_ifbraces{$ln + $offset} = 1;
> """
> So the behind block may never run:
> """ Line: 2415
> if (!defined $suppress_ifbraces{$linenr - 1} &&
> $line =~ /\b(if|while|for|else)\b/ &&
> $line !~ /\#\s*if/ &&
> $line !~ /\#\s*else/) {
> """
> I'm not sure, please give me some advice.
> 
> (Sorry, I don't know this patch should base on which commit,
>  so I generate this patch based on
>  commit:fb8446d94ec7a3dc0c3a7e7da672406476f075ac,
>  I choose this by `git log -2 scripts/checkpath.pl`.
>  Sincerely say sorry, if I have misunderstand any meaning.)
> 
> Signed-off-by: Su Hang 
> ---
>  scripts/checkpatch.pl | 21 +
>  1 file changed, 17 insertions(+), 4 deletions(-)
> 
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index a88af61ed4ee..d6f0747ba20a 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -2352,8 +2352,22 @@ sub process {
>   }
>   }
> 
> -# check for missing bracing round if etc
> - if ($line =~ /(^.*)\bif\b/ && $line !~ /\#\s*if/) {
> +# check for missing bracing around if etc
> + if ($line =~ /(^.*)\b(?:if|while|for)\b/ &&
> + $line !~ /\#\s*if/) {
> + my $allowed = 0;
> +
> + # Check the pre-context.
> + if ($line =~ /(\}.*?)$/) {
> + my $pre = $1;
> +
> + if ($line !~ /else/) {
> + print "APW: ALLOWED: pre<$pre> 
> line<$line>\n"
> + if $dbg_adv_apw;
> + $allowed = 1;
> + }
> + }
> +
>   my ($level, $endln, @chunks) =
>   ctx_statement_full($linenr, $realcnt, 1);
>  if ($dbg_adv_apw) {
> @@ -2362,7 +2376,6 @@ sub process {
>  if $#chunks >= 1;
>  }
>   if ($#chunks >= 0 && $level == 0) {
> - my $allowed = 0;
>   my $seen = 0;
>   my $herectx = $here . "\n";
>   my $ln = $linenr - 1;
> @@ -2406,7 +2419,7 @@ sub process {
>  $allowed = 1;
>   }
>   }
> - if ($seen != ($#chunks + 1)) {
> + if ($seen != ($#chunks + 1) && !$allowed) {
>   ERROR("braces {} are necessary for all 
> arms of this statement\n" . $herectx);
>   }
>   }
> --
> 2.7.4
> 


[Qemu-devel] [PATCH v2] scripts/checkpatch.pl: Bug fix

2018-04-03 Thread Su Hang
checkpatch.pl stops complaining about following pattern:
"""
do {
//do somethins;
} while (conditions);
"""

One things need to be mentioned:
Becasue `if`, `while` and `for` check have been done in this
`if` block(Line: 2356), and this block contains following statement:
""" Line: 2379
$suppress_ifbraces{$ln + $offset} = 1;
"""
So the behind block may never run:
""" Line: 2415
if (!defined $suppress_ifbraces{$linenr - 1} &&
$line =~ /\b(if|while|for|else)\b/ &&
$line !~ /\#\s*if/ &&
$line !~ /\#\s*else/) {
"""
I'm not sure, please give me some advice.

(Sorry, I don't know this patch should base on which commit,
 so I generate this patch based on
 commit:fb8446d94ec7a3dc0c3a7e7da672406476f075ac,
 I choose this by `git log -2 scripts/checkpath.pl`.
 Sincerely say sorry, if I have misunderstand any meaning.)

Signed-off-by: Su Hang 
---
 scripts/checkpatch.pl | 21 +
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index a88af61ed4ee..d6f0747ba20a 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -2352,8 +2352,22 @@ sub process {
}
}

-# check for missing bracing round if etc
-   if ($line =~ /(^.*)\bif\b/ && $line !~ /\#\s*if/) {
+# check for missing bracing around if etc
+   if ($line =~ /(^.*)\b(?:if|while|for)\b/ &&
+   $line !~ /\#\s*if/) {
+   my $allowed = 0;
+
+   # Check the pre-context.
+   if ($line =~ /(\}.*?)$/) {
+   my $pre = $1;
+
+   if ($line !~ /else/) {
+   print "APW: ALLOWED: pre<$pre> 
line<$line>\n"
+   if $dbg_adv_apw;
+   $allowed = 1;
+   }
+   }
+
my ($level, $endln, @chunks) =
ctx_statement_full($linenr, $realcnt, 1);
 if ($dbg_adv_apw) {
@@ -2362,7 +2376,6 @@ sub process {
 if $#chunks >= 1;
 }
if ($#chunks >= 0 && $level == 0) {
-   my $allowed = 0;
my $seen = 0;
my $herectx = $here . "\n";
my $ln = $linenr - 1;
@@ -2406,7 +2419,7 @@ sub process {
 $allowed = 1;
}
}
-   if ($seen != ($#chunks + 1)) {
+   if ($seen != ($#chunks + 1) && !$allowed) {
ERROR("braces {} are necessary for all 
arms of this statement\n" . $herectx);
}
}
--
2.7.4




Re: [Qemu-devel] [PATCH v2] scripts/checkpatch.pl: Bug fix

2018-03-16 Thread Su Hang
Thanks for your reply!
I'm glad to understand where problem lies.

Su Hang

> -Original Messages-
> From: "Fam Zheng" 
> Sent Time: 2018-03-16 15:08:19 (Friday)
> To: "Su Hang" 
> Cc: peter.mayd...@linaro.org, vsement...@virtuozzo.com, qemu-devel@nongnu.org
> Subject: Re: [Qemu-devel] [PATCH v2] scripts/checkpatch.pl: Bug fix
> 
> On Fri, 03/16 14:31, Su Hang wrote:
> > Because I generate my first patch on master, it should work.
> 
> Nope. "git am" doesn't know to resolve the conflict automatically despite it
> being straightforward, unfortunately:
> 
> http://patchew.org/QEMU/1521169105-32041-1-git-send-email-suhan...@mails.ucas.ac.cn/
> 
> Fam


Re: [Qemu-devel] [PATCH v2] scripts/checkpatch.pl: Bug fix

2018-03-16 Thread Fam Zheng
On Fri, 03/16 14:31, Su Hang wrote:
> Because I generate my first patch on master, it should work.

Nope. "git am" doesn't know to resolve the conflict automatically despite it
being straightforward, unfortunately:

http://patchew.org/QEMU/1521169105-32041-1-git-send-email-suhan...@mails.ucas.ac.cn/

Fam



Re: [Qemu-devel] [PATCH v2] scripts/checkpatch.pl: Bug fix

2018-03-15 Thread Su Hang
Because I generate my first patch on master, it should work.

I have a little trouble understanding what Mr.Peter wants me to do,
would you please spare a little of your time and have a look at it?
It will help me. Please...

Su Hang


> -Original Messages-
> From: "Fam Zheng" 
> Sent Time: 2018-03-16 14:15:20 (Friday)
> To: "Su Hang" 
> Cc: peter.mayd...@linaro.org, ebl...@redhat.com, vsement...@virtuozzo.com, 
> qemu-devel@nongnu.org
> Subject: Re: [Qemu-devel]  [PATCH v2] scripts/checkpatch.pl: Bug fix
> 
> On Fri, 03/16 10:58, Su Hang wrote:
> > (Sorry, I don't know this patch should base on which commit,
> >  so I generate this patch based on
> >  commit:fb8446d94ec7a3dc0c3a7e7da672406476f075ac,
> >  I choose this by `git log -2 scripts/checkpath.pl`.
> >  Sincerely say sorry, if I have misunderstand any meaning.)
> 
> This should base on master. Basing on an older commit will only make it hard 
> for
> maintainers to apply it.
> 
> (Don't be sorry at all, thank you for spending your time improving QEMU!)
> 
> Fam


Re: [Qemu-devel] [PATCH v2] scripts/checkpatch.pl: Bug fix

2018-03-15 Thread Fam Zheng
On Fri, 03/16 10:58, Su Hang wrote:
> (Sorry, I don't know this patch should base on which commit,
>  so I generate this patch based on
>  commit:fb8446d94ec7a3dc0c3a7e7da672406476f075ac,
>  I choose this by `git log -2 scripts/checkpath.pl`.
>  Sincerely say sorry, if I have misunderstand any meaning.)

This should base on master. Basing on an older commit will only make it hard for
maintainers to apply it.

(Don't be sorry at all, thank you for spending your time improving QEMU!)

Fam



[Qemu-devel] [PATCH v2] scripts/checkpatch.pl: Bug fix

2018-03-15 Thread Su Hang
checkpatch.pl stops complaining about following pattern:
"""
do {
//do somethins;
} while (conditions);
"""

One things need to be mentioned:
Becasue `if`, `while` and `for` check have been done in this
`if` block(Line: 2356), and this block contains following statement:
""" Line: 2379
$suppress_ifbraces{$ln + $offset} = 1;
"""
So the behind block may never run:
""" Line: 2415
if (!defined $suppress_ifbraces{$linenr - 1} &&
$line =~ /\b(if|while|for|else)\b/ &&
$line !~ /\#\s*if/ &&
$line !~ /\#\s*else/) {
"""
I'm not sure, please give me some advice.

(Sorry, I don't know this patch should base on which commit,
 so I generate this patch based on
 commit:fb8446d94ec7a3dc0c3a7e7da672406476f075ac,
 I choose this by `git log -2 scripts/checkpath.pl`.
 Sincerely say sorry, if I have misunderstand any meaning.)

Signed-off-by: Su Hang 
---
 scripts/checkpatch.pl | 21 +
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index a88af61ed4ee..d6f0747ba20a 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -2352,8 +2352,22 @@ sub process {
}
}

-# check for missing bracing round if etc
-   if ($line =~ /(^.*)\bif\b/ && $line !~ /\#\s*if/) {
+# check for missing bracing around if etc
+   if ($line =~ /(^.*)\b(?:if|while|for)\b/ &&
+   $line !~ /\#\s*if/) {
+   my $allowed = 0;
+
+   # Check the pre-context.
+   if ($line =~ /(\}.*?)$/) {
+   my $pre = $1;
+
+   if ($line !~ /else/) {
+   print "APW: ALLOWED: pre<$pre> 
line<$line>\n"
+   if $dbg_adv_apw;
+   $allowed = 1;
+   }
+   }
+
my ($level, $endln, @chunks) =
ctx_statement_full($linenr, $realcnt, 1);
 if ($dbg_adv_apw) {
@@ -2362,7 +2376,6 @@ sub process {
 if $#chunks >= 1;
 }
if ($#chunks >= 0 && $level == 0) {
-   my $allowed = 0;
my $seen = 0;
my $herectx = $here . "\n";
my $ln = $linenr - 1;
@@ -2406,7 +2419,7 @@ sub process {
 $allowed = 1;
}
}
-   if ($seen != ($#chunks + 1)) {
+   if ($seen != ($#chunks + 1) && !$allowed) {
ERROR("braces {} are necessary for all 
arms of this statement\n" . $herectx);
}
}
--
2.7.4