HV* get_hidden_hash(SV* perl_obj) { SV* underlying_hash; MAGIC* mg; HV* hidden_hash; // get the underlying hash that the perl_obj is a reference to // (we can leave it an SV* because we're just using it to find magic) underlying_hash = SvRV(perl_obj); // get the hidden hash linked to the perl_obj mg = mg_find(underlying_hash, PERL_MAGIC_ext); hidden_hash = (HV*)mg->mg_obj; return hidden_hash; }