Re: [PATCH v1] checkpatch: Add context-analysis attributes
From: Vincent Donnefort
Date: Sun Nov 15 2026 - 11:39:20 EST
On Sat, Nov 14, 2026 at 06:57:39AM -0800, Joe Perches wrote:
> On Sat, 2026-11-14 at 06:26 -0800, Joe Perches wrote:
> > > How about matching one internal () pair?
> > >
> > > __guarded_by\s*\(
> > > (?:
> > > [^()]++ |
> > > \([^()]*+\)
> > > )*+
> > > \)
> >
> > Sure.
> > Please add and use another variable so it's not repeated everywhere.
>
> Reading a bit about balanced parentheses in perl '(?R)'
> non capturing recursion works since 5.10.0
>
> Maybe instead use
>
> /\((?:[^()]++|(?R))*\)/
Somehow it doesn't work. I have tried the following:
my $p = qr/\((?:[^()]++|(?R))*\)/;
my $a = qr/__guarded_by\s*$p/;
for my $s ("__guarded_by(&mutex)", "__guarded_by(foobar())") {
print "$s:", ($s =~ /^$a$/ ? "ok" : "nope"), "\n";
}'
__guarded_by(&mutex): ok
__guarded_by(foobar()): nope
Did I miss something?
--
Vincent
>
> and I should probably rework all of checkpatch's uses of
> $balanced_parens to avoid all those weird capture group uses
> as it was originally written for perl 5.8 (thanks akpm)