Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re^8: SvUV vs SvIV for pointers in SVs, typemap

by patcat88 (Deacon)
on Feb 21, 2011 at 17:01 UTC ( #889421=note: print w/replies, xml ) Need Help??

in reply to Re^7: SvUV vs SvIV for pointers in SVs, typemap
in thread SvUV vs SvIV for pointers in SVs, typemap

#!/usr/bin/perl -w use Devel::Peek; $ptrUV = unpack('J',pack('P[12]',"Hello World")); $ptrIV = unpack('j',pack('P[12]',"Hello World")); print Dump($ptrUV); print Dump($ptrIV); $ptrUV += 2**31; print Dump($ptrUV);

SV = IV(0x182a260) at 0x182a264 REFCNT = 1 FLAGS = (IOK,pIOK) IV = 28545556 SV = IV(0x182a3e0) at 0x182a3e4 REFCNT = 1 FLAGS = (IOK,pIOK) IV = 26107564 SV = IV(0x182a260) at 0x182a264 REFCNT = 1 FLAGS = (IOK,pIOK,IsUV) UV = 2176029204
Perl keeps all unsigneds as IVs until they are greater than IV_MAX (~ +2 billion), then it uses the UV flag/UV mode. [sv.c#l1620 in perl.git] But, if the pointer is larger than 2 billion, and the user manipulates the pointer, for struct offsets for example, before passing it to unpack, or passes the scalar with the pointer inside it to an XSUB that takes a pointer (bad XSUB design right?)

Replies are listed 'Best First'.
Re^9: SvUV vs SvIV for pointers in SVs, typemap
by BrowserUk (Pope) on Feb 21, 2011 at 18:05 UTC

    There is also the possibility of performing pointer arithmetic with two pointers, one just before the 2GB boundary and one just after it. Thus mixing IV and UV math.

    Whether deriving offsets in structs, or extracting or manipulating sub-strings, I'm not at all convinced that there are not places within the Perl sources themselves where such manipulations are done, that work only because most 32-bit Perls run limited to 2GB.

    Certainly, when I was playing with 32-bit perl made /largeaddressaware and with /3GB set, I saw enough weirdness and crashes to give up on the idea of using that instead of a 64-bit Perl in order to get access to my full complement of ram.

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
Re^9: SvUV vs SvIV for pointers in SVs, typemap
by ikegami (Pope) on Feb 21, 2011 at 19:36 UTC

    If someone changes your internals to the point of failure, it doesn't make your design bad.

    Besides, if you were to fake the internals using pack and ended up with a UV, it would still work with the existing typemap.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://889421]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2018-06-23 04:46 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (125 votes). Check out past polls.