Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

rsteinke's scratchpad

by rsteinke (Scribe)
on Aug 10, 2004 at 00:09 UTC ( [id://381399]=scratchpad: print w/replies, xml ) Need Help??

# This is typemap code which represents a binary C object as a tied ha +sh in perl. # TestObjImpl is a typedef, # # typedef TestObj TestObjImpl; # # which lets XS know whether you're passing in a tied hash (most of th +e time), # or the bare blessed object (for FETCH, STORE, DESTROY, etc.). In mos +t cases, # usage of TestObjImpl is limited to the .xs file which implements the + TestObj # class, with other .xs files (implementing other classes) taking Test +Obj # as their argument (since they expect to be passed a hash). # The O_OBJECT typemap code is stolen directly from Dean Roehrich's pe TYPEMAP TestObj * T_TIED_HASH TestObjImpl * O_OBJECT INPUT O_OBJECT if( sv_isobject($arg) && (SvTYPE(SvRV($arg)) == SVt_PVMG) ) $var = ($type)SvIV((SV*)SvRV( $arg )); else{ warn( \"${Package}::$func_name() -- $var is not a bles +sed SV reference\" ) ; XSRETURN_UNDEF; } T_TIED_HASH { MAGIC* magic; if( SvROK($arg) && (SvTYPE(SvRV($arg)) == SVt_PVHV) && ((magic = mg_find(SvRV($arg), PERL_MAGIC_ti +ed)) != NULL) && sv_isobject(magic->mg_obj) && (SvTYPE(SvRV(magic->mg_obj)) == SVt_PVMG) ) + { $var = ($type)SvIV((SV*)SvRV(magic->mg_obj)); } else { warn( \"${Package}::$func_name() -- $var is no +t a tied hash refere nce\" ); if(!magic) warn(\"No magic\"); else if (!sv_isobject(magic->mg_obj)) warn(\"No magic object\"); else warn(\"Wrong object type\"); XSRETURN_UNDEF; } } OUTPUT T_TIED_HASH { SV* tie = sv_newmortal(); HV* hash = newHV(); /* Get a blessed reference to the pointer, */ sv_setref_pv(tie, CLASS, (void*)$var); /* and tie it to a hash. */ hv_magic(hash, (GV*)tie, PERL_MAGIC_tied); $arg = sv_2mortal((SV*)newRV_noinc((SV*)hash)); }
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-07-15 18:05 GMT
Find Nodes?
    Voting Booth?

    No recent polls found

    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.