Thanks for the kind words, and for picking up the gauntlet, Sam. (I presume you're Sam Vilain, since that's who's released the last several versions of Set::Object.)
I think all that's happening is that at global destruction time, structures aren't cleaned up in the normal way. After all, you still want destructors for objects in circular references to be called. Instead Perl just calls destructors for all objects, and it wouldn't surprise me if it did that without dropping refcnt values first.
/
I'd be cheesed if we were getting all the way through to global destruction! The problem is that Artist::DESTROY is getting called earlier -- specifically, when the $artist scalar is assigned a new value, obliterating the last perl-space reference.
(Your cautionary advice about order of object destruction at globo-destruct-time is taken under advisement nonetheless. If you really need cleanup to proceed according to a strict itinerary, explicit methods are the way to go.)
I also remember having to use the sv2mortal range of macros, perhaps have a look at those too if the above doesn't help.
FWIW, using Inline C means using sv_2mortal() lots. :) Anytime you return an SV* from an Inline C function, it creates an XS wrapper that calls sv_2mortal() on your return value. So it better have a reference count of at least one or Perl will attempt a double free! For illustration, here's the wrapper generated by Inline::C for get_name_from_artist...
XS(XS_main_get_name_from_artist)
{
dXSARGS;
if (items != 1)
Perl_croak(aTHX_ "Usage: main::get_name_from_artist(artist_sv)
+");
PERL_UNUSED_VAR(cv); /* -W */
{
SV * artist_sv = ST(0);
SV * RETVAL;
RETVAL = get_name_from_artist(artist_sv);
ST(0) = RETVAL;
sv_2mortal(ST(0));
}
XSRETURN(1);
}
If I call sv_2mortal() on a return val from a function which is currently returning an SV with a refcount of 1, Perl tries the double free -- bad!
I think my problem arises from conceptual confusion as to which SV* Perl considers the "object"... Despite the fact that in the Devel::Peek Dump, the inner SV* is labeled an OBJECT and has the package attached, it seems that Perl considers that outer SV* the object, and so that's whose refcount has to be incremented. The question is how to do that without creating a circular ref.
|