On Thu, 28 Feb 2002, Rob Clark wrote:

> int foo(char **buf, int *n , ...)
> 
> The function allocates a buffer and fills with data. Fills in the 
> pointer to it and its length before returning.
> 
> Can someone tell me or point me to a reference showing how to 
> wrap this with perlxs? I'm new to perlxs but can follow the perlxs 
> tutorials.

newSVpvn(char* buf, int len) will copy len bytes from buf and put them 
into a perl scalar (of the string type, but which can hold binary data,
including NUL characters), so in your XS function, you could call foo(),
copy the buffer into the perl scalar, and then do whatever it is you need 
to do to clean up and deallocate the buffer allocated by foo() before 
returning from the XS function. 

It could look something like this (off the top of my head, assuming 
I have understood your problem correctly, not tested, the usual 
disclaimers apply....):
 
SV *foo()      
    PREINIT:
    char **buf
    int    len
    CODE:
    foo(buf, &len);
    RETVAL = newSVpvn( *buf, len );
    free( *buf );
    OUTPUT:
    RETVAL

Modified suitably to take any other args foo will need...

-- 
Vivek

Reply via email to