Stas Bekman wrote:
Philippe M. Chiasson wrote:
Stas Bekman wrote:
So I thought calling either sv_clear/sv_free directly wasn't recommended.Philippe M. Chiasson wrote:
Stas Bekman wrote:
[EMAIL PROTECTED] wrote:
gozer 2004/09/09 15:16:38
+/* XXX: There is no XS accessible splice() */ +static void modperl_av_remove_entry(pTHX_ AV *av, I32 index) +{ + I32 i; + AV *tmpav = newAV(); + + /* stash the entries _before_ the item to delete */ + for (i=0; i<=index; i++) { + av_store(tmpav, i, SvREFCNT_inc(av_shift(av))); + } + + /* make size at the beginning of the array */ + av_unshift(av, index-1); + + /* add stashed entries back */ + for (i=0; i<index; i++) { + av_store(av, i, *av_fetch(tmpav, i, 0)); + } + + SvREFCNT_dec(tmpav);
shouldn't it just be sv_free'd? how do you know when the enclosing scope will force the free'ing when you can safely free it right here.
[...]
But here you know exactly that you have nothing else referencing the sv. I believe that warning in sv_clear about refcnt=0 has to do with the possibility of other svs referencing it. If you look at the perl internals, all the short functions with temp svs are written in this way.
I don't really care either way though.
In fact recently I first wrote this function as you did;
/* prepends the passed sprintf-like arguments to ERRSV, which also * gets stringified on the way */ void modperl_errsv_prepend(pTHX_ const char *pat, ...) { SV *sv; va_list args;
va_start(args, pat); sv = vnewSVpvf(pat, &args); va_end(args);
sv_catsv(sv, ERRSV); sv_copypv(ERRSV, sv); sv_free(sv); /* was: SvREFCNT_dec(sv) */ }
when I showed it to Rafael, he said why don't you use sv_free instead of SvREFCNT_dec.
Cool, changed accordingly.
-- -------------------------------------------------------------------------------- Philippe M. Chiasson m/gozer\@(apache|cpan|ectoplasm)\.org/ GPG KeyID : 88C3A5A5 http://gozer.ectoplasm.org/ F9BF E0C2 480E 7680 1AE5 3631 CB32 A107 88C3A5A5
signature.asc
Description: OpenPGP digital signature