Sisyphus <[EMAIL PROTECTED]> writes:
>Hi,
>
>I have an XS function that receives an SV* arg. That arg can have been 
>blessed into any one of a number of packages - and the function needs to 
>know just which package that arg was blessed into.
>
>How do I get hold of the package name (from within the XS function) ?

The "easy" way to find this stuff out is ask yourself how would 
I do it in perl, what do those perl ops do?

So here you would use ref($obj) and pp_ref calls sv_reftype.

Looking at sv_reftype confirms below, wbhich I did the other way #
round looking to see what sv_bless() did ;-)

1. Follow the SvRV() to get the object SV.
2. SvSTASH() of that is the HV for the package stash. 
3. HvNAME of that is the package name.

So ignoring possibility of nulls and non-objects :

char *classname = HvNAME(SvSTASH(SvRV(sv)));

You may be able to use  sv_reftype(sv,1)


>
>Cheers,
>Rob

Reply via email to