develooper Front page | perl.perl5.porters | Postings from January 2012

Re: pack and ASCII

Thread Previous | Thread Next
From:
demerphq
Date:
January 12, 2012 04:29
Subject:
Re: pack and ASCII
Message ID:
CANgJU+XW3qjgDt+qQKXRrG6dfbVyjSn9juTSHPb=RGMEojGxdg@mail.gmail.com
On 12 January 2012 00:00, Eric Brine <ikegami@adaelis.com> wrote:
> On Wed, Jan 11, 2012 at 3:44 PM, Jesse Luehrs <doy@tozt.net> wrote:
>>
>> On Wed, Jan 11, 2012 at 02:38:48PM -0500, Eric Brine wrote:
>> > Of course, the bug would only manifest itself if you feed C<pack> bad
>> > data
>> > in the first place. Perhaps you should fix *that* bug instead of trying
>> > to
>> > change the function of C<< pack "A" >>. C<< pack "A" >> is documented to
>> > work on text, and that's what it does. Obviously, it's never been
>> > limited
>> > to 7-bit ASCII text inputs, but it's not limited to 8-bit text inputs
>> > either.
>>
>> Actually, pack 'A' is documented to work on ASCII - I thought that's how
>> this entire thread came up.
>
>
> "Actually" makes it sound like you're contradicting me, but you just
> repeated what I said. I'll rephrase in case I wasn't clear.
>
> It has always* been documented to work on ASCII text.
> It has never* been limited to ASCII characters.
> It has never* been documented to work on bytes.
>
> * -- To my knowledge.

Well pack predates Perl supporting Unicode at all, so in a sense you
are wrong here.

>
>> Also, nobody is arguing that the issue is anything other than bad data
>> being fed to pack.
>
>
> Then what do you think I've been saying?
>
> C<< pack "A20A20", chr(0x2660), chr(0x2660); >> is perfectly acceptable, so
> you can't warn or change it's behaviour without breaking it!

It depends on what you mean here. I agree the code you have quoted
here is valid. I disagree that what later perls do with it is valid.

On 5.8.5:

$ perl -MDevel::Peek -le'Dump  pack "A20A20", chr(0x2660), chr(0x2660);'
SV = PV(0x17137550) at 0x17137380
  REFCNT = 1
  FLAGS = (PADTMP,POK,pPOK)
  PV = 0x1714abc0 "\342\231\240                 \342\231\240                 "\0
  CUR = 40
  LEN = 41

On 5.10.1

$ perl -MDevel::Peek -le'Dump  pack "A20A20", chr(0x2660), chr(0x2660);'
SV = PV(0x981a6d8) at 0x981c8b8
  REFCNT = 1
  FLAGS = (PADTMP,POK,pPOK,UTF8)
  PV = 0x983e8f0 "\342\231\240                   \342\231\240
         "\0 [UTF8 "\x{2660}                   \x{2660}
   "]
  CUR = 44
  LEN = 60


I consider the utf8 flag being ON here to be both a regression, and a
bug. IMO the output of pack "A" should NEVER have the utf8 flag set.

Cheers,
Yves


-- 
perl -Mre=debug -e "/just|another|perl|hacker/"

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About