SWIG typemap for passing binary buffers from Tcl to C

SWIG typemap for passing binary buffers from Tcl to C

Post by liran » Mon, 22 Sep 2003 15:50:05


I would like to pass a binary buffer from Tcl to C. The wrapper
functions are generated by SWIG, and from what I've seen an argument
of (char*) is parsed as a string in these wrappers.

In order to parse the argument as a binary buffer I think I need to
use a typemap to extract the byte array from the argument using
Tcl_GetByteArrayFromObj.

I would appreciate if someone could help me fill the body of the
typemap, as I was unable to do so myself...

%typemap(tcl,in) (char* binBuffer, int length) {
...
}
 
 
 

SWIG typemap for passing binary buffers from Tcl to C

Post by palmtc » Tue, 23 Sep 2003 17:17:35

I think the following should do

%typemap(in) (char *binBuffer, int length) %{
$1 = Tcl_GetByteArrayFromObj($input, &$2);
%}

Look at the generated C wrapper to verify correctness

/Ashok