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

Re: [perl #108952] [PATCH] 97df921 fix PerlIO-scalar test when unpackJ fails

Thread Previous | Thread Next
From:
Eric Brine
Date:
January 24, 2012 10:34
Subject:
Re: [perl #108952] [PATCH] 97df921 fix PerlIO-scalar test when unpackJ fails
Message ID:
CALJW-qE41fr_EtvEe1SdAH08BRh=42QUWb4BgV5uiAibxUW9Rg@mail.gmail.com
On Tue, Jan 24, 2012 at 12:26 PM, Father Chrysostomos via RT <
perlbug-followup@perl.org> wrote:

> On Tue Jan 24 09:14:08 2012, rurban wrote:
> > The reason of the failure is Config::Config{ptrsize} ==
> > $Config::Config{intsize}.
> > On the failing platform it is 4 vs 8.
> >
> > So use unpack "I" instead.
>
> Eric Brine’s patch has already been applied as 6fa2c250307, but yours
> looks more robust to me, er, I *think*.
>
> Is it guaranteed that unpack "J" will return undef in those cases where
> it fails?
>

Assuming we take it for granted that these unpack return undef when the
string is too short (even though that's not documented).

If sizeof(void*) == sizeof(UV): No problem
If sizeof(void*) < sizeof(UV) && sizeof(void*) == sizeof(int): Ok
If sizeof(void*) < sizeof(UV) && sizeof(void*) > sizeof(int): Won't work,
but not currently possible.
If sizeof(void*) < sizeof(UV) && sizeof(void*) < sizeof(int): Won't work,
but not currently possible.
If sizeof(void*) > sizeof(UV): Impossible

UV are guaranteed to be large enough to hold a pointer,

If you want more robust, I'd recommend:

my $ptrlen = length(pack("P", "abc"));
my $ptrfmt = $ptrlen == length(pack("J", 0)) ? "J"
           : $ptrlen == length(pack("I", 0)) ? "I"
           : die;

- Eric

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