OlegG has asked for the wisdom of the Perl Monks concerning the following question:
Where I'll use self->set internally, which type is HV*. In the constructor (new) newHV() creates HV with reference count 1. So, as I understand, to be destroyed reference count should be decreased to 0. But as I found we have only SvREFCNT_dec() which argument may be SV* and not HV*.#include "EXTERN.h" #include "perl.h" #include "XSUB.h" #include "ppport.h" typedef struct { HV* set; char foo; } My_Class; MODULE = My::Class PACKAGE = My::Class SV* new(char* class) PREINIT: My_Class *self; CODE: Newx(self, 1, My_Class); self->set = newHV(); self->foo = 0; RETVAL = newSV(0); sv_setref_pv(RETVAL, class, (void *)self); OUTPUT: RETVAL void DESTROY(My_Class *self) CODE: /* HOW TO DESTROY self->set HERE*/ Safefree(self);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: XS: how to destroy HV* that was used internally?
by salva (Canon) on Sep 18, 2014 at 07:49 UTC | |
by OlegG (Monk) on Sep 18, 2014 at 08:43 UTC | |
by ikegami (Patriarch) on Sep 18, 2014 at 14:07 UTC |