From: Joe Perches <joe@perches.com>
To: Ivo Sieben <meltedpianoman@gmail.com>
Cc: LKML <linux-kernel@vger.kernel.org>, Andy Whitcroft <apw@canonical.com>
Subject: Re: [PATCH] [checkpatch.pl] ctx_statement_block #if/#else/#endif fix
Date: Tue, 10 Jun 2014 09:24:01 -0700 [thread overview]
Message-ID: <1402417441.30479.0.camel@joe-AO725> (raw)
In-Reply-To: <CAMSQXEE9ZgE8wuXz_qu5ndbfFne7zjhN24R44trPE11e02hmWQ@mail.gmail.com>
On Tue, 2014-06-10 at 08:19 +0200, Ivo Sieben wrote:
> Andy, Joe,
>
> What do you think about my patchset below?
Andy wrote that originally and I think he should respond.
> Regards,
> Ivo Sieben
>
> 2014-05-15 16:43 GMT+02:00 Ivo Sieben <meltedpianoman@gmail.com>:
> > When picking up a complete statement block #if/#else/#endif prepocesor
> > boundaries are taken into account by pushing current level & type on a stack.
> > But on an #else the level was read from stack again (without actually popping it
> > from stack) causing the statement block to end too early on the next ';'.
> > Fixed this.
> >
> > For example the following code:
> >
> > if (!test()) {
> > #ifdef NEVER
> > foo();
> > bar();
> > #else
> > bar();
> > foo();
> > #endif
> > }
> >
> > Results in statement block:
> >
> > STATEMENT<+ if (!test()) {
> > +#ifdef NEVER
> > + foo();
> > + bar();
> > +#else
> > + bar();>
> > CONDITION<+ if (!test())>
> >
> > While you would expect:
> >
> > STATEMENT<+ if (!test()) {
> > +#ifdef NEVER
> > + foo();
> > + bar();
> > +#else
> > + bar();
> > + foo();
> > +#endif
> > + }>
> > CONDITION<+ if (!test())>
> >
> > Signed-off-by: Ivo Sieben <meltedpianoman@gmail.com>
> > ---
> >
> > Request for comments:
> > I think I fixed a problem here that I encountered while I was working on another
> > changeset in which I check the statement block after a condition.
> > Somehow the statement block did not contain everything I expected.
> >
> > scripts/checkpatch.pl | 4 ++--
> > 1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> > index 34eb216..e7bca89 100755
> > --- a/scripts/checkpatch.pl
> > +++ b/scripts/checkpatch.pl
> > @@ -878,7 +878,7 @@ sub ctx_statement_block {
> > if ($remainder =~ /^#\s*(?:ifndef|ifdef|if)\s/) {
> > push(@stack, [ $type, $level ]);
> > } elsif ($remainder =~ /^#\s*(?:else|elif)\b/) {
> > - ($type, $level) = @{$stack[$#stack - 1]};
> > + # no changes to stack: type & level remain the same
> > } elsif ($remainder =~ /^#\s*endif\b/) {
> > ($type, $level) = @{pop(@stack)};
> > }
> > @@ -1050,7 +1050,7 @@ sub ctx_block_get {
> > if ($lines[$line] =~ /^.\s*#\s*(?:ifndef|ifdef|if)\s/) {
> > push(@stack, $level);
> > } elsif ($lines[$line] =~ /^.\s*#\s*(?:else|elif)\b/) {
> > - $level = $stack[$#stack - 1];
> > + # no changes to stack: type & level remain the same
> > } elsif ($lines[$line] =~ /^.\s*#\s*endif\b/) {
> > $level = pop(@stack);
> > }
> > --
> > 1.7.9.5
> >
next prev parent reply other threads:[~2014-06-10 16:24 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-15 14:43 Ivo Sieben
2014-06-10 6:19 ` Ivo Sieben
2014-06-10 16:24 ` Joe Perches [this message]
2014-06-11 9:16 ` Andy Whitcroft
2014-06-11 9:57 ` Andy Whitcroft
2014-06-11 9:59 ` Andy Whitcroft
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1402417441.30479.0.camel@joe-AO725 \
--to=joe@perches.com \
--cc=apw@canonical.com \
--cc=linux-kernel@vger.kernel.org \
--cc=meltedpianoman@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®