syphilis has asked for the wisdom of the Perl Monks concerning the following question:
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) ?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
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".SV = PVIV(0x4f0088) at 0x4ecd80 REFCNT = 1 FLAGS = (IOK,pIOK) IV = 12345 PV = 0
|
|---|