When dumping perl SV with Devel::Peek
I can see:
SV = IV(0x1c13168) at 0x1c13178
REFCNT = 1
FLAGS = (IOK,pIOK)
IV = 2
But can not find the description what pIOK
mean.
I tried to look it at Devel::Peek
, perlapi
, perlguts
, perlxs
...
In sources I found that:
{SVp_IOK, "pIOK,"}
But still can not find what SVp_IOK
is. What is it?
UPD
I found this document. It shed the light a bit what flags mean and where they are situated. (beware this DOC is outdated a bit)
This flag indicates that the object has a valid non-public IVX field value. It can only be set for value type SvIV or subtypes of it.
UPD
pIOK
is howDevel::Peek
represents the bit corresponding to bit maskSVp_IOK
. Thep
indicates a "private" flag, and it forms a pair with "public" flagIOK
(bit maskSVf_IOK
)The exact meaning of the private flags has changed across perl versions, but in general terms they mean that the
IV
(orNV
orPV
) field of theSV
is "inaccurate" in some wayThe most common situation where
pIOK
is set on its own (pIOK
is always set ifIOK
is set) is where aPV
has been converted to a numericNV
value. TheNV
andIV
fields are both populated, but if theIV
value isn't an accurate representation of the number (i.e. it has been truncated) thenpIOK
is set butIOK
is clearedThis code shows a way to reach that state. Variable
$pi_str
is set to a string value for π and it is converted to a floating-point value by adding 0.0 and storing it into$pi_num
.Devel::Peek
now shows thatNOK/pNOK
andPOK/pPOK
are set, but onlypIOK
whileIOK
remains clear. Looking at theIV
value we can see why: it is set to 3, which is the cached value ofint $pi_str
in case we need it again, but it is not an accurate representation of the string"3.14159"
in integer formoutput
Perl v5.16 and before used to use the flag to indicate "magic" variables (such as tied values) because the value in the
IV
field could not be used directly. That was changed in v5.18 and later, and magic values now usepIOK
in the same way as any other value