Is Devel::Peek not showing everything? COW oddness and concerns about no-oping /p regex modifiers

[email protected] (demerphq)
Newsgroups perl.perl5.porters
Message-ID <CANgJU+XC-_ORkb5SofS79jvoo_yn3yGZeabxH7k010NOHCHirQ@mail.gmail.com>
I was checking whether /p can actually be made a no-op as this has come up
a few times over the years, and each time we have found cases where COW
doesnt kick in and while(//g) matches become quadratic and the /p is
actually useful.

In older perls one of the ways to construct a scalar that can't be
COW'ed was to obtain it from readline (in the right circumstances). Another
way is via strings constructed in XS with no extra space for the COW
refcount.

While trying to trigger the readline version I noticed that the following
code does not behave the same, and I can't see why, with my intuition is
that perhaps there is a  new flag that is not being rendered by Devel::Peek
properly. Would that ring a bell?

Can anybody think of why the first example does not COW and the second does?

 $ echo 0123456789 > n.txt
 $ ./perl -Ilib -MDevel::Peek -e'while (<>) { my $x = $_; my $y = $_;
Dump($_);} ' n.txt
SV = PV(0x562de8fd1f78) at 0x562de9028160
  REFCNT = 1
  FLAGS = (POK,pPOK)
  PV = 0x562de8ff95f8 "0123456789\n"\0
  CUR = 11
  LEN = 88

$ ./perl -Ilib -MDevel::Peek -e'$_= "01234567889\n"; my $x = $_; my $y =
$_; Dump($_); '
SV = PV(0x560408566f28) at 0x5604085bd3c8
  REFCNT = 1
  FLAGS = (POK,IsCOW,pPOK)
  PV = 0x5604085a7538 "01234567889\n"\0
  CUR = 12
  LEN = 16
  COW_REFCNT = 3

It would be nice for testing if we had a utility function which constructed
unCOWable strings. It used to be that when the strings CUR and LEN are the
same and the string cant be COW'ed. (Maybe this was changed?)

Anyway, maybe to make the removal of /p acceptable we should just check if
the target of a match is not COW'able, and warn if there are capture
buffers in the pattern. Then at least when it goes quadratic people will
see the warning and can do something about it, for instance fixing the XS
code involved (assuming it is no longer possible to construct an
uncowable string in pure perl) or by copying the string (if it still is
possible in pure perl.)

Yves

-- 
perl -Mre=debug -e "/just|another|perl|hacker/"
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.