Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

what does private/public data mean in Devel::Peek

by xiaoyafeng (Chaplain)
on Aug 09, 2019 at 02:35 UTC ( #11104211=perlquestion: print w/replies, xml ) Need Help??

xiaoyafeng has asked for the wisdom of the Perl Monks concerning the following question:

Below is a snippet in Devel::Peek documents:

use Devel::Peek; $a = 42; $a = "hello"; Dump $a; The output: SV = PVIV(0xbc288) at 0xbe9a8 REFCNT = 1 FLAGS = (POK,pPOK) IV = 42 PV = 0xb2048 "hello"\0 CUR = 5 LEN = 8
I found XOK(X would be P, I, N etc.) always follow a pXOK. I looked up perldoc, say XOK means public data, pXOK means private data. But what does it really mean? Please enlighten me, Thanks


I am trying to improve my English skills, if you see a mistake please feel free to reply or /msg me a correction

Replies are listed 'Best First'.
Re: what does private/public data mean in Devel::Peek
by syphilis (Bishop) on Aug 09, 2019 at 05:19 UTC
    But what does it really mean?

    The POK flag indicates that the stored PV is valid and can be used.
    The pPOK flag is used internally by the magic system to establish that the PV is valid.
    (And similarly for "I" and "N".)

    I don't know if it's still the case that one can be set without the other.
    I found an example in section 4.3 of "Extending and Embedding Perl" by Jenness and Cousins that sets pPOK without setting POK - but only on perl-5.16 and perhaps (unchecked) earlier perl versions.
    On perl-5.18 and later the same code sets both POK and pPOK.

    Obviously there's no need for both unless they sometimes need to be set by themselves.

    Here's that demo from "Extending and Embedding Perl":
    C:\_32\pscrpt>type package TieFoo; sub TIESCALAR { my $obj = "foo1"; return bless(\$obj, "TieFoo"); } sub FETCH { ${ $_[0] }++; } 1; C:\_32\pscrpt>type use Devel::Peek; use lib '.'; use TieFoo; tie $a, 'TieFoo'; print "Initial State: \n"; Dump $a; print "\nFirst Value: $a\n\n"; print "State after a FETCH: \n"; Dump $a;
    On perl-5.16, the final Dump() begins:
    State after a FETCH: SV = PVMG(0x1cd4f9c) at 0x1cdf054 REFCNT = 1 FLAGS = (GMG,SMG,RMG,pPOK) ...
    On later versions of perl that changes to:
    State after a FETCH: SV = PVMG(0x7deea8) at 0x7cbc58 REFCNT = 1 FLAGS = (GMG,SMG,RMG,POK,IsCOW,pPOK) ....
    According to Jenness and Cousins, that pPOK indicates that a cached value is available (though that cached value gets overwritten with every FETCH).
    Sorry - probably not much help.
    Hopefully there's someone kicking around that can do better.

      Thanks Rob, I've searched perl5.30 source, there still has some parts to test pPOK flag. I guess maybe pXOK flag indicate this SV is used for perl internal. (can't see and use from outside) but since 5.18 onward, pXOK maybe desprecated, and replaced by XOK.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://11104211]
Approved by Marshall
Front-paged by haukex
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2019-08-23 13:03 GMT
Find Nodes?
    Voting Booth?

    No recent polls found