From 6f9328ca348b95ff60b2672e0c425242e6e87419 Mon Sep 17 00:00:00 2001 From: Yves Orton Date: Sun, 8 Jan 2023 14:16:36 +0100 Subject: regcomp.pl - fixup intflags debug data to handle gaps properly We were not handling gaps in the sequence properly, and effectively showing the wrong flag names or missing the last flag. Now we die if there are any collisions or if any of the PREGf defines set more than one bit. This also adds some crude tests to validate that intflags serialization is working properly. Note, extflags handles more complex scenarios and seems to handle this gracefully already, hence the reason I haven't touched it as well. This also tweaks a comment in lexical_debug.t which part of this was cribbed from. --- ext/re/re.pm | 2 +- ext/re/t/intflags.pl | 16 ++++++++++++++++ ext/re/t/intflags.t | 25 +++++++++++++++++++++++++ ext/re/t/lexical_debug.t | 2 +- 4 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 ext/re/t/intflags.pl create mode 100644 ext/re/t/intflags.t (limited to 'ext') diff --git a/ext/re/re.pm b/ext/re/re.pm index cf1f7421a2..6da4e02f32 100644 --- a/ext/re/re.pm +++ b/ext/re/re.pm @@ -4,7 +4,7 @@ package re; use strict; use warnings; -our $VERSION = "0.43"; +our $VERSION = "0.44"; our @ISA = qw(Exporter); our @EXPORT_OK = qw{ is_regexp regexp_pattern diff --git a/ext/re/t/intflags.pl b/ext/re/t/intflags.pl new file mode 100644 index 0000000000..a79180681e --- /dev/null +++ b/ext/re/t/intflags.pl @@ -0,0 +1,16 @@ +use re 'Debug' => qw(DUMP FLAGS); +our $count; +my $code= '(?{$count++})'; +my @p= ( + qr/(foo)(?1)?/, + qr/\Gfoo/, + qr/.*foo/, + qr/^foo/, + qr/(foo(*THEN)bar|food)/, + qr/a.*b.*/, + qr/a{1,4}\Gfoo/, + qr/a+/, + do { use re 'eval'; qr/a$code/}, +); + +print STDERR "-OK-\n"; diff --git a/ext/re/t/intflags.t b/ext/re/t/intflags.t new file mode 100644 index 0000000000..256bf1f007 --- /dev/null +++ b/ext/re/t/intflags.t @@ -0,0 +1,25 @@ +#!./perl + +BEGIN { + require Config; + if (($Config::Config{'extensions'} !~ /\bre\b/) ){ + print "1..0 # Skip -- Perl configured without re module\n"; + exit 0; + } +} + +use strict; + +# must use a BEGIN or the prototypes wont be respected meaning +# tests could pass that shouldn't. +BEGIN { require "../../t/test.pl"; } +my $out = runperl(progfile => "t/intflags.pl", stderr => 1 ); +like($out,qr/-OK-\n/, "intflags.pl ran to completion"); + +my %seen; +foreach my $line (split /\n/, $out) { + $line=~s/^r->intflags:\s+// or next; + length($_) and $seen{$_}++ for split /\s+/, $line; +} +is(0+keys %seen,14); +done_testing; diff --git a/ext/re/t/lexical_debug.t b/ext/re/t/lexical_debug.t index b2570f0e2d..4c8b47d54f 100644 --- a/ext/re/t/lexical_debug.t +++ b/ext/re/t/lexical_debug.t @@ -11,7 +11,7 @@ BEGIN { use strict; # must use a BEGIN or the prototypes wont be respected meaning - # tests could pass that shouldn't +# tests could pass that shouldn't BEGIN { require "../../t/test.pl"; } my $out = runperl(progfile => "t/lexical_debug.pl", stderr => 1 ); -- cgit v1.2.1