T
Tassilo v. Parseval
Also sprach (e-mail address removed):
Is your question how to dereference 'tie' to get to the 'HV*' behind
that? The generic dereference macro in the perlapi is SvRV along with a
cast:
HV *hash = (HV*)SvRV(tie);
You will also usually want to check that it is in fact a reference to a
hash before dereferencing:
HV *hash;
if (SvTYPE(tie) == SVt_RV && SvTYPE(SvRV(tie)) == SVt_PVHV)
hash = (HV*)SvRV(tie);
else
croak("No hash reference");
Tassilo
When writing an xs extension I can allocate a blessed and tied hash
with
static SV *
_perlext_mkwrapper(void *ptr) {
HV *hash;
HV *stash;
SV *tie;
SV* ptrobj = newSViv(ptr);
hash = newHV();
tie = newRV_noinc((SV*)newHV()); << I want to get that hash
hv_store(SvRV(tie), _PERLEXT_CLASS_PTR, strlen(_PERLEXT_CLASS_PTR),
ptrobj, 0);
stash = gv_stashpv(_PERLEXT_CLASS, TRUE);
sv_bless(tie, stash);
hv_magic(hash, (GV*)tie, PERL_MAGIC_tied);
return newRV_noinc(hash);
}
But how can I get back to the tie hash (see mark above) if I get a
reference to svn _perlext_mkwrapper
created?
Is your question how to dereference 'tie' to get to the 'HV*' behind
that? The generic dereference macro in the perlapi is SvRV along with a
cast:
HV *hash = (HV*)SvRV(tie);
You will also usually want to check that it is in fact a reference to a
hash before dereferencing:
HV *hash;
if (SvTYPE(tie) == SVt_RV && SvTYPE(SvRV(tie)) == SVt_PVHV)
hash = (HV*)SvRV(tie);
else
croak("No hash reference");
Tassilo