I wrote a function which packs the c data structure into a perl object:

SV*
perl_xmmsclient_new_sv_from_ptr(void* ptr, const char* class) {
        SV* obj;
        SV* sv;
        HV* stash;

        obj = (SV*)newHV();
        sv_magic(obj, 0, PERL_MAGIC_ext, (const char*)ptr, 0);
        sv = newRV_inc(obj);
        stash = gv_stashpv(class, 1);
        sv_bless(sv, stash);

        return sv;
}

Ok - is there a reason why you are using a HV? If not, then you should use a SV via a typemap to simplify the whole object creation process - the typemap would use sv_setref_pv - to create the blessed object in one step.

Cheers,

jez.


Reply via email to