Following up, I belive I have working code, although I'm not sure I'm
writing it the best way. Editing welcome!
What I (think I) do is when I create the parent object I save its address
so that child objects can SvREFCNT_inc() the parent.
# This returns SW_HANDLE
void
new(CLASS, index_file_list )
char *CLASS
char *index_file_list
PREINIT:
SW_HANDLE handle;
PPCODE:
SwishErrorsToStderr();
handle = SwishInit( index_file_list );
ST(0) = sv_newmortal();
sv_setref_pv( ST(0), CLASS, (void *)handle );
SwishSetRefPtr( handle, (void *)SvRV(ST(0)) );
XSRETURN(1);
SwishSetRefPtr() stores the address in the C struct.
Then when creating a child:
SW_SEARCH
New_Search_Object(swish_handle, query = NULL)
SW_HANDLE swish_handle
char *query
PREINIT:
char * CLASS = "SWISH::API::Search";
CODE:
RETVAL = New_Search_Object( swish_handle, query );
if ( RETVAL )
SvREFCNT_inc( (SV *)SwishSearch_parent( RETVAL ) );
OUTPUT:
RETVAL
SwishSearch_parent returns the address saved in SwishSetRefPtr. Then in
the Destroy:
void
DESTROY(search)
SW_SEARCH search
CODE:
if ( search )
{
SV *parent = (SV *)SwishSearch_parent( search );
Free_Search_Object( search );
SvREFCNT_dec( parent );
}
There's two more layers of objects, but basically the same thing. Short
of my choice for function names, is there anything else that could be
cleaned up?
Thanks much,
--
Bill Moseley [EMAIL PROTECTED]