Testcase and fix for bug 1163440: vararg typemaps.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12639 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
71a7a52b16
commit
8f07b3f851
5 changed files with 67 additions and 11 deletions
|
|
@ -510,7 +510,8 @@ C_TEST_CASES += \
|
|||
typedef_struct \
|
||||
typemap_subst \
|
||||
union_parameter \
|
||||
unions
|
||||
unions \
|
||||
varargs_typemap
|
||||
|
||||
|
||||
# Multi-module C++ test cases . (Can be run individually using make testcase.multicpptest)
|
||||
|
|
|
|||
4
Examples/test-suite/python/varargs_typemap_runme.py
Normal file
4
Examples/test-suite/python/varargs_typemap_runme.py
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
import varargs_typemap
|
||||
|
||||
if (varargs_typemap.testfunc(1, 2.0, "three") != "three") :
|
||||
raise RuntimeError("testfunc failed!")
|
||||
43
Examples/test-suite/varargs_typemap.i
Normal file
43
Examples/test-suite/varargs_typemap.i
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
%module varargs_typemap
|
||||
|
||||
/* The typemap and action are taken from the "Variable length arguments"
|
||||
* chapter of the SWIG manual.
|
||||
*/
|
||||
|
||||
%typemap(in) (...)(char *args[10]) {
|
||||
int i;
|
||||
int argc;
|
||||
for (i = 0; i < 10; i++) args[i] = 0;
|
||||
argc = PyTuple_Size(varargs);
|
||||
if (argc > 10) {
|
||||
PyErr_SetString(PyExc_ValueError,"Too many arguments");
|
||||
return NULL;
|
||||
}
|
||||
for (i = 0; i < argc; i++) {
|
||||
PyObject *o = PyTuple_GetItem(varargs,i);
|
||||
if (!PyString_Check(o)) {
|
||||
PyErr_SetString(PyExc_ValueError,"Expected a string");
|
||||
return NULL;
|
||||
}
|
||||
args[i] = PyString_AsString(o);
|
||||
}
|
||||
$1 = (void *) args;
|
||||
}
|
||||
|
||||
%feature("action") testfunc {
|
||||
char **args = (char **) arg3;
|
||||
result = testfunc(arg1, arg2, args[0], args[1], args[2], args[3], args[4],
|
||||
args[5],args[6],args[7],args[8],args[9], NULL);
|
||||
}
|
||||
|
||||
%inline {
|
||||
char* testfunc (int arg1, double arg2, ...)
|
||||
{
|
||||
va_list ap;
|
||||
char *c;
|
||||
va_start(ap, arg2);
|
||||
c = va_arg(ap, char*);
|
||||
va_end(ap);
|
||||
return c;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue