Suppose I have following class implemented with XS
#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);
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*.
So, what is a solution here?
May be I just need to call Safefree(self->set)?
Or get reference to self->set into SV* variable and call SvREFCNT_dec on it?