in reply to Help needed for Perl XS code

WOuld it be possible rather than allocating memory for the char * return that you could instead return an SV *? You could do away with the the Newz() and strcpy and end up with something like (untested):

SV * TestStringAdd (a,b) char* a char* b CODE: char* c; SV* d; int length; c = StringAdd(a, b); length = strlen(c); d = newSVpv(c,length); // deallocate Memory FreeMemory (c); printf ("Name::%s\n", d); printf ("Length::%d\n", length); RETVAL = d; OUTPUT: RETVAL
This will at the least save dicking around with the allocations and let perl deal with it.

/J\

Replies are listed 'Best First'.
Re^2: Help needed for Perl XS code
by pijush (Scribe) on Jan 14, 2005 at 16:17 UTC
    Thanks. It is working perfectly fine.