On Thu, 31 Jan 2002, Mike Wong wrote:
> On Thu, 2002-01-31 at 18:10, Steven N. Hirsch wrote:
>
> > Stop right there.. Have you defined what these objects should look like
> > to Perl? That's the first step.
> >
> > A Perl object is a blessed reference. Period. It's up to you to define
> > the form of the object (i.e. blessed scalar, array, hash?)
>
> Yes, I've defined the llist_node * as O_OBJECT, with appropriate INPUTs
> and OUTPUTs defined in the typemap. But it seems that the typemap only
> applies between the Perl to C interface (ie. as valid RETVAL values),
> and not internally.
Where do the objects on the linked list originate? Are these C structs
created with malloc()? Do you want them to be opaque to Perl, or do you
need to pick member values out of them in Perl?
>
> That is, I need a way to create an SV from llist_node *. Creating an SV
> (mySV) and calling sv_setref_pv( mySV, "LList", (void *) node ) didn't
> do the trick for me. (It segfaulted). If you know how this can be done,
> it would help a lot! Then I can pass the created SV to PUSHs() and call
> it a day.
Assuming you want *llist_node to be opaque, this should work:
/* Create empty SV */
SV *mySV = newSVsv( &PL_sv_undef );
sv_setref_iv( mySV, "LList", (IV) node );
^^^
|_ Note: you are storing an anonymous (to Perl) pointer,
not a character string!
PUSHs( sv_2mortal(mySV) );
>
> My current known-good workaround is to traverse down the linked list in
> Perl, and push each returned LList object onto an array and return that
> array. However, I'd really like to traverse down the linked list in C
> through my XSUB.
>
> - m.
>