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

PTR2NV (was Re: [perl.git] branch blead, updated.v5.17.3-154-g9e7f031)

From:
Nicholas Clark
Date:
August 31, 2012 04:26
Subject:
PTR2NV (was Re: [perl.git] branch blead, updated.v5.17.3-154-g9e7f031)
Message ID:
20120831112633.GB22938@plum.flirble.org
On Tue, Aug 28, 2012 at 10:38:18AM +0200, Father Chrysostomos wrote:

> commit 60f40a389519ab4482a60df44e5e9a03c8710752
> Author: Father Chrysostomos <sprout@cpan.org>
> Date:   Tue Aug 28 01:11:30 2012 -0700
> 
>     Use PL_parser->lex_shared instead of Sv[IN]VX(PL_linestr)
>     
>     Unfortunately, PL_parser->linestr and PL_parser->bufptr are both
>     part of the API, so we can't just move them to PL_parser->lex_shared.
>     Instead, we have to copy them in sublex_push, to make them visible to
>     inner lexing scopes.
>     
>     This allows the SvIVX(PL_linestr) and SvNVX(PL_linestr) hack to
>     be removed.

>       */
> -    SvUPGRADE(PL_linestr, SVt_PVIV);
> -    /* A null super_bufptr means the outer lexing scope is not peekable,
> -       because it is a single line from an input stream. */
> -    SAVEIV(SvIVX(PL_linestr));
> -    SvIVX(PL_linestr) = PTR2IV(PL_sublex_info.super_bufptr);
> -    PL_sublex_info.super_bufptr =
> -	(SvTYPE(PL_linestr) < SVt_PVNV || !SvNVX(PL_linestr))
> -	 && (PL_rsfp || PL_parser->filtered)
> -	 ? NULL
> -	 : PL_bufptr;
> -    SvUPGRADE(PL_lex_stuff, SVt_PVNV);
> -    SvNVX(PL_lex_stuff) = PTR2NV(PL_linestr);
> +    PL_parser->lex_shared->ls_linestr = PL_linestr;
> +    PL_parser->lex_shared->ls_bufptr  = PL_bufptr;


That's excellent that it's gone. As I'd worked out that the change to use
PTR2NV() was the cause of a failing test on (at least) 64 bit HP-UX and
ia64 Linux, but hadn't worked out what to do next. Both have address spaces
where pointers have high bits set:

$ ./perl -le 'print "$^O ", []'
linux ARRAY(0x600000000000dfc8)

$ ./perl -le 'print "$^O ", []'
hpux ARRAY(0x8000000100011258)


(There's a bunch of code in the numeric comparison ops to cope with the
fact that it can be that no integer or numeric type is large enough to
hold a pointer losslessly)

Probably we should annotate perl.h to note that PTR2NV() is potentially
lossy, and not portably safe.

The only use of it in the core seems to be in Perl_sv_2nv_flags(), when
asked for the "numeric" version of a reference.

Nicholas Clark



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