Hi,
As revealed in this demo by Devel::Peek::Dump(), calling foo($sv) can make significant alterations to the internals of $sv:
use strict;
use warnings;
use Devel::Peek;
use Inline C =><<'EOC';
void foo(SV * sv) {
printf("\n%s\n\n", SvPV_nolen(sv));
/*
SvPOK_off(sv);
SvPV_set(sv, NULL);
*/
}
EOC
my $sv = 12345;
Dump $sv;
foo($sv);
Dump($sv);
__END__
Outputs:
SV = IV(0x4ecd70) at 0x4ecd80
REFCNT = 1
FLAGS = (IOK,pIOK)
IV = 12345
12345
SV = PVIV(0x4f0088) at 0x4ecd80
REFCNT = 1
FLAGS = (IOK,POK,pIOK,pPOK)
IV = 12345
PV = 0x25a4448 "12345"\0
CUR = 5
LEN = 10
Inside that XS sub foo() is there a simple way that, having called SVPV_nolen(), the internals of the provided argument can be restored to the states they held just prior to the calling of foo($sv) ?
Inclusion of the commented-out C-code in foo() goes some way to doing that ... but not all the way.
It will change the second Dump() to:
SV = PVIV(0x4f0088) at 0x4ecd80
REFCNT = 1
FLAGS = (IOK,pIOK)
IV = 12345
PV = 0
That looks about right except that the SV is still PVIV, and the PV slot, although cleared, is still being displayed.
Perhaps the PV slot is being displayed simply because the SV is PVIV, and the solution lies in getting the "PVIV" to revert to "IV".
Cheers,
Rob
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.