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?
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.