ajaffres has asked for the wisdom of the Perl Monks concerning the following question:

Thank you very much Perl Monks for helping me recently. I have made some progress now.

The problem is: I need the address of a string (binary) to be passed to/from a C function of this type
(void MyFunction(unsigned char *input, unsigned char *output) without giving the length (the length is dealt within the C function. My function just need the address to work fine.

I managed to convert a Perl SV* to an unsigned char* thanks to this typemap:
%typemap(in) (unsigned char *string1) { $1 = (unsigned char *)SvPV_nolen($input); }
Now I need to do the opposite, it should look like this:
%typemap(out) (unsigned char *output, const size_t output_length) { $result = newSVpv((char *)$1, $2); sv_2mortal($result); argvi++; delete $1; }
but I don't need the length and even with the length I tried this example without success.

Would anyone know how to write this second typemap in order to convert an unsigned char * into a *SV?

Thanks a lot in advance.

Arnaud

Edited by Chady -- added code tags.

Replies are listed 'Best First'.
Re: typemap problem
by Anonymous Monk on May 20, 2005 at 11:22 UTC
    See the typemap that comes with perl (.../lib/ExtUtils/typemap),
    unsigned char T_U_CHAR
      I saw this line there, OK. Thank you. But I still don't know how to write my typemap...
        oh sorry, did you see T_PV? Thats the one
Re: typemap problem
by Anonymous Monk on May 20, 2005 at 11:38 UTC
    What kind of typemap is that? SWIG?
      yes, it's SWIG.