"Thank you" x 100. The segfault is gone. Yay! ::peasants rejoice::
Mik
On Thu, Jul 29, 2004 at 04:01:55PM +0100, Peter Sinnott wrote:
> On Thu, Jul 29, 2004 at 09:59:57AM -0400, Mik Firestone wrote:
> > I am just looking for a URL or an example of how to return a reference to a C
> > structure to perl. I have read the Cookbook, and I can get my code to work if
> > I actually create a blessed reference. I would prefer to bless it - I just
> > want a reference that I can later pass to other C functions.
> >
> > I have looked at the docs for Inline::Struct, and I do not think that is what
> > I want. Again, I do not want a blessed reference, just a reference. I have
> > read perlguts, and believe the call I need to use is newRV_noinc.
> >
> > What follows are two files. The first one is a package that is mostly
> > stolen^wmodeled on the Cookbook OO example. The main difference is that I do
> > not bless the structure, I just try to return a ref to it. The other piece of
> > code exercises my problem -- namely a segfault.
> >
> > What have I missed?
> >
> > Thanks,
> > Mik
> >
>
> Hi,
> I think the problem is newRV_noinc expects a SV* as an argument.
> You need to wrap the pointer with a scalar and then pass that in.
>
> > SV* induct( char *name, char *rank, long serial ) {
> > Soldier* soldier = malloc(sizeof(Soldier));
> >
> > soldier->name = strdup(name);
> > soldier->rank = strdup(rank);
> > soldier->serial = serial;
> >
> > return newRV_noinc((SV*)soldier);
>
> return newRV_noinc(newSViv(soldier));
> > }
> >
>
> --
> Our mission is to seamlessly maintain corporate methods of empowerment
> and completely leverage existing prospective infrastructures for 100% customer
> satisfaction