I find Swig failed to generate some temporary variables defined in typemap.
Here is the problem: I have defined a typemap as follow.
%define %bound_buffer_input(TYPEMAP, SIZE)
%typemap(in) (TYPEMAP, SIZE)
(int res, Py_ssize_t size = 0, const void *buf = 0) {
res = PyObject_AsReadBuffer($input, &buf, &size);
if (res<0) {
PyErr_Clear();
%argument_fail(res, "(TYPEMAP, SIZE)", $symname, $argnum);
}
$1 = ($1_ltype) buf;
$2 = ($2_ltype) size;
}
%enddef
And it is applied in 2 cases:
%bound_buffer_input(const uint8_t* key, size_t keyLength);
%bound_buffer_input(void* buf, size_t length);
For the first, it works well and generated correct codes. But for the second, it fails to generate correct variable name for the function : void* MF_WriteOne (void * qry, int datatype, void* buf, size_t length);
The code swig generates:
{
res3 = PyObject_AsReadBuffer(obj2, &buf3, &size3);
if (res3<0) {
PyErr_Clear();
SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "MF_WriteOne" "', argument " "3"" of type '" "(void* buf, size_t length)""'");
}
arg3 = (void *) buf;
arg4 = (size_t) size3;
}
In the first line, the variable "buf" is correctly generated with the name "buf3", but for the 6th line the variable has the incorrect name "buf" instead of "buf3".
Later I change the name from "buf to buff" and find the variable are all under correct names.
Why happens such a strange thing?