Perl / perl5

🐪 The Perl programming language
https://dev.perl.org/perl5/
Other
1.94k stars 554 forks source link

qr/$/m ignores m when result is used #5722

Closed p5pRT closed 19 years ago

p5pRT commented 22 years ago

Migrated from rt.perl.org#10054 (status was 'resolved')

Searchable as RT10054$

p5pRT commented 22 years ago

From nagler@jump.bivio.com

Created by nagler@bivio.biz

qr/bla$/m doesn't work when assigned to a var and reused. Case bad3 shouldn't fail.

#!perl -w use strict; my($x) = "abc\ndef\n"; die("bad1") unless $x =~ /^abc$/m; my($re) = qr/^abc$/m; my($s) = "$re"; die("bad2") unless $x =~ /$s/; die("bad3") unless $x =~ /$re/; __END__

bad2 is the workaround which I'm using right now.

Perl Info ``` Flags: category=core severity=medium Site configuration information for perl v5.6.1: Configured by bhcompile at Wed Feb 20 15:00:12 EST 2002. Summary of my perl5 (revision 5.0 version 6 subversion 1) configuration: Platform: osname=linux, osvers=2.4.17-0.13smp, archname=i386-linux uname='linux daffy.perf.redhat.com 2.4.17-0.13smp #1 smp fri feb 1 10:30:48 est 2002 i686 unknown ' config_args='-des -Doptimize=-O2 -march=i386 -mcpu=i686 -Dcc=gcc -Dcf_by=Red Hat, Inc. -Dcccdlflags=-fPIC -Dinstallprefix=/usr -Dprefix=/usr -Darchname=i386-linux -Uusethreads -Uuseithreads -Uuselargefiles -Dd_dosuid -Dd_semctl_semun -Di_db -Di_ndbm -Di_gdbm -Di_shadow -Di_syslog -Dman3ext=3pm -Dlocincpth=' hint=recommended, useposix=true, d_sigaction=define usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef useperlio=undef d_sfio=undef uselargefiles=undef usesocks=undef use64bitint=undef use64bitall=undef uselongdouble=undef Compiler: cc='gcc', ccflags ='-fno-strict-aliasing -I/usr/local/include', optimize='-O2 -march=i386 -mcpu=i686', cppflags='-fno-strict-aliasing -I/usr/local/include' ccversion='', gccversion='2.96 20000731 (Red Hat Linux 7.1 2.96-98)', gccosandvers='' intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234 d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12 ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=4 alignbytes=4, usemymalloc=n, prototype=define Linker and Libraries: ld='gcc', ldflags =' -L/usr/local/lib' libpth=/usr/local/lib /lib /usr/lib libs=-lnsl -ldl -lm -lc -lcrypt -lutil perllibs=-lnsl -ldl -lm -lc -lcrypt -lutil libc=/lib/libc-2.2.4.so, so=so, useshrplib=false, libperl=libperl.a Dynamic Linking: dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic' cccdlflags='-fPIC', lddlflags='-shared -L/usr/local/lib' Locally applied patches: @INC for perl v5.6.1: /home/nagler/src_dev/perl /usr/lib/perl5/5.6.1/i386-linux /usr/lib/perl5/5.6.1 /usr/lib/perl5/site_perl/5.6.1/i386-linux /usr/lib/perl5/site_perl/5.6.1 /usr/lib/perl5/site_perl/5.6.0/i386-linux /usr/lib/perl5/site_perl/5.6.0 /usr/lib/perl5/site_perl . Environment for perl v5.6.1: HOME=/home/nagler LANG=en_US LANGUAGE (unset) LD_LIBRARY_PATH=/usr/local/oracle/product/8.1.6/lib:/usr/local/oracle/product/8.1.6/lib:/usr/local/oracle/product/8.1.6/lib:/usr/local/oracle/product/8.1.6/lib:/usr/local/oracle/product/8.1.6/lib LOGDIR (unset) PATH=/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin:/usr/local/oracle/product/8.1.6/bin:/home/nagler/bin:/usr/local/oracle/product/8.1.6/bin:/usr/local/oracle/product/8.1.6/bin:/usr/local/oracle/product/8.1.6/bin:/usr/local/oracle/product/8.1.6/bin PERLLIB=/home/nagler/src_dev/perl PERL_BADLANG (unset) PERL_MM_OPT=PREFIX=/home/nagler INSTALLMAN1DIR=/home/nagler/man/man1 INSTALLMAN3DIR=/home/nagler/man/man3 SHELL=/bin/bash ```
p5pRT commented 22 years ago

From @vanstyn

nagler@​jump.bivio.com wrote​: :qr/bla$/m doesn't work when assigned to a var and reused.

Attached patch is enough to fix your actual example of qr/^abc$/m\, but only works when the '^' is there​: qr/abc$/m still fails\, and though I haven't determined precisely why\, I think it unlikely to succumb to a patch small and safe enough to have any chance of getting into 5.8 at this late stage. See the %todo tests below for the specific examples.

For 5.9 I have plans to rework substantial parts of this area of the code\, and would hope to achieve results that are much more consistently correct.

Given that this fixes only a part of the problem and is decidedly not the right long-term fix\, I don't think this patch should go into 5.8.0\, but I thought it worth getting it on the record.

Hugo

Inline Patch ```diff --- regexec.c.old Wed Jul 10 22:17:07 2002 +++ regexec.c Sun Jul 14 19:19:09 2002 @@ -547,11 +547,13 @@ else if (prog->reganch & ROPT_CANY_SEEN) s = fbm_instr((U8*)(s + start_shift), (U8*)(strend - end_shift), - check, PL_multiline ? FBMrf_MULTILINE : 0); + check, (PL_multiline || (prog->reganch & ROPT_ANCH_MBOL)) + ? FBMrf_MULTILINE : 0); else s = fbm_instr(HOP3(s, start_shift, strend), HOP3(strend, -end_shift, strbeg), - check, PL_multiline ? FBMrf_MULTILINE : 0); + check, (PL_multiline || (prog->reganch & ROPT_ANCH_MBOL)) + ? FBMrf_MULTILINE : 0); /* Update the count-of-usability, remove useless subpatterns, unshift s. */ --- t/op/pat.t.old Mon Jul 1 15:46:10 2002 +++ t/op/pat.t Sun Jul 14 19:47:30 2002 @@ -6,7 +6,7 @@ $| = 1; -print "1..922\n"; +print "1..931\n"; BEGIN { chdir 't' if -d 't'; @@ -2901,4 +2901,22 @@ } } -$test = 923; +{ + print "# [ID 20020713.007] qr/\$/m ignores m when used\n"; + $test = 923; + my $re_both = qr{^abc$}m; + my $re_head = qr{^abc}m; + my $re_tail = qr{abc$}m; + # current fix still leaves MEOL without MBOL incorrectly treated as SEOL + my %todo = map +($_ => 1), qw/ 925 928 /; + for ("abc\ndef\n", "xyz\nabc\ndef\n", "xyz\nabc\n") { + for my $re ($re_both, $re_head, $re_tail) { + print /$re/ ? "ok $test\n" : $todo{$test} + ? "not ok $test\t# TODO: MEOL treated as SEOL in fbm_instr()\n" + : "not ok $test\n"; + ++$test; + } + } +} + +$test = 932; ```
p5pRT commented 19 years ago

@smpeters - Status changed from 'open' to 'resolved'