Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^3: Mixing C and perl

by tsee (Curate)
on Jan 17, 2012 at 19:06 UTC ( #948385=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Mixing C and perl
in thread Mixing C and perl

In the Perl-hash-wraps-C-struct setup, an object looks like {foo => 'bar', ... '__cptr' => \2131231231}. Well, with- or without the scalar reference to the number-that-is-a-pointer

What you can do to make the XS methods work appropriately on this construct while being able to store stuff regularly from Perl as well, is to define a typemap that will a) check it got a hashref b) check that the class inherits from your package, c) fetch the __cptr slot of your hash-object, d) check it's a scalar ref, e) use the integer as a pointer, f) cast that into your C type. b), d), e), f) are done in T_PTROBJ already. This would allow you to write XS like with T_PTROBJ. The only downside is that you'd lose the ability to access the outer hash from XS.


Comment on Re^3: Mixing C and perl
Re^4: Mixing C and perl
by salva (Monsignor) on Jan 17, 2012 at 22:13 UTC
    The only downside is that you'd lose the ability to access the outer hash from XSM

    Not really, just keep a pointer to the wrapping hash also inside the C structure, as in the OP sample code.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://948385]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (12)
As of 2014-07-14 09:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (257 votes), past polls