The number is the address
[1] of the SV
[2], so it's just a question of casting the number into a pointer. To work with it from Perl, you'd need a reference (since it's not necessarily a scalar), so you'd pass the pointer to
newRV_inc.
use Test::More tests => 2;
use Inline C => <<'__EOC__';
SV* addr_to_ref(IV addr) {
return newRV_inc((SV*)addr);
}
__EOC__
{
my @a = qw( a b c );
my $ref = \@a;
my $stringified_ref = "$ref";
my $addr = $stringified_ref =~ /0x([0-9a-f]+)/ ? hex($1) : die;
my $ref2 = addr_to_ref($addr);
is(0+$ref, 0+$ref2);
is("@$ref", "@$ref2");
}
That's assuming the SV is still allocated, of course.
- Numerical representation of a pointer.
- Or AV, HV, etc. For the purposes of this post, I consider these to be subtypes of SV.
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.