|
Perl typemaps for byte arrays: msg#00174programming.swig
For the archive, here are an in and an out Perl typemaps for bytearrays where the first int (4 bytes) is the length of the array: %typemap(in) (unsigned char * x) { $1 = (unsigned char *)SvPV_nolen($input); } %typemap(out) unsigned char * myFunction { int *iptr; iptr = (int *)$1; int len = *iptr; $result = newSVpv((char *)$1, len); sv_2mortal($result); argvi++; delete [] $1; } I had to do a copy of the bytearray into a perl variable on the out, I don't think there's a way to avoid the copy. The in typemap is cleaner with a simple creation of a pointer into the perl variable. Apologies if this seems straightforward and obvious. H _______________________________________________ Swig maillist - Swig@xxxxxxxxxxxxxxx http://mailman.cs.uchicago.edu/mailman/listinfo/swig |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: bug while wrapping const char arrays without an explicitly defined size: 00174, Marcelo Matus |
|---|---|
| Next by Date: | SWIG_ConvertPtrFromString bug in SWIG 1.3.20 & 1.3.21: 00174, Abhinandan Jain |
| Previous by Thread: | Re: bug while wrapping const char arrays without an explicitly defined sizei: 00174, Marcelo Matus |
| Next by Thread: | RE: bug while wrapping const char arrays without an explicitly defined size: 00174, William . Fulton |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |