Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Reconstructing an (SV *) when you know the address and the precise structure of the said SV

by asarih (Hermit)
on Sep 19, 2003 at 03:17 UTC ( [id://292571]=perlquestion: print w/replies, xml ) Need Help??

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

In XS:

Given an address in memory, is it possible to reconstruct an RV if you know exactly what it looks like (but none of the values)? The particular case that I am most interested in is a very simple reference to a reference, like so:

SV = RV(0x1f6394) at 0x31d968 REFCNT = 2 FLAGS = (ROK) RV = 0x2dfea0
The routine that will be reconstructing the RV will not know the values of the RV's (i.e., 0x1f6394 and 0x2dfea0 in the above example). Unfortunately, the pointer (say, ptr=0x31d968) is typecast to (char *), so if I simply look at sv_dump(*(SV **)ptr), I get something like:
SV = UNKNOWN(0x31) (0x0) at 0x31d968 REFCNT = 0 FLAGS = ()
Am I asking for the moon? I looked at perlapi and perlguts but couldn't quite figure it out. Apparently I don't know enough C tricks to pull this off. So, help me! Any help is appreciated.
  • Comment on Reconstructing an (SV *) when you know the address and the precise structure of the said SV
  • Select or Download Code

Replies are listed 'Best First'.
Re: Reconstructing an (SV *) when you know the address and the precise structure of the said SV
by diotalevi (Canon) on Sep 19, 2003 at 03:44 UTC

    Devel::Pointer. Neat module. Mostly I use it for stealing lexicals from out of scope locations.

    UPDATE: I also wrote Devel::Pointer::PP which is a bit more capable than the XS version and is pure perl instead of involving XS.

Re: Reconstructing an (SV *) when you know the address and the precise structure of the said SV
by idsfa (Vicar) on Sep 19, 2003 at 05:02 UTC

    Can you cast ptr as a (void **) instead? This will prevent "helpful" attempts to understand the data. You seem to be wanting:

    SV *val = **((void **)(ptr)); sv_dump(val);

    (The contents of the memory location specified by the contents of the memory location stored in ptr is a pointer to an SV)

    Or have I completely missed your question?


    Remember, when you stare long into the abyss, you could have been home eating ice cream.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://292571]
Approved by jdtoronto
Front-paged by Courage
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (7)
As of 2024-04-19 10:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found