Hi,
I have written a dynamic library in c in which I have some functions of this kind:
int MyFunction(unsigned char *input, unsigend char *output);
where input is a pointer to an unsigned char which holds the content of a binary file. Therefore I can't treat it as a pointer to a string (because of the '\0') in which case I may lose some data.
output is as well a pointer to an unsigned char (not a NULL terminated string either).
Now, I would like to call such functions from a Perl program. I am using SWIG in order to wrap these library functions. However, since SWIG can't do the job 100% right, the 'unsigned char *' type is not treated properly. As far as I know, there is a way to overcome this problem, which is (maybe among different methods) to use 'typemap'.
My question: How can I use 'typemap' so that I can receive and return through my function's arguments 'pointers to unsigned char' (or to a string if you prefer) preferably without passing the length of the string? (I found some converstion functions such as SvPV and sv_setpv, but I am not sure that they do exactly what I want). I would like if it possible to make no change at all to my c functions.
Thanks very much for your help ( I am new to Perl and to SWIG)...
Arnaud
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.