Python 3.2 portability fixes
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12663 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
34e7c82631
commit
d2dd14e628
2 changed files with 71 additions and 37 deletions
|
|
@ -470,12 +470,25 @@ like this:
|
|||
return NULL;
|
||||
}
|
||||
for (i = 0; i < argc; i++) {
|
||||
PyObject *o = PyTuple_GetItem(varargs,i);
|
||||
if (!PyString_Check(o)) {
|
||||
PyObject *pyobj = PyTuple_GetItem(varargs, i);
|
||||
char *str = 0;
|
||||
%#if PY_VERSION_HEX>=0x03000000
|
||||
PyObject *pystr;
|
||||
if (!PyUnicode_Check(pyobj)) {
|
||||
PyErr_SetString(PyExc_ValueError, "Expected a string");
|
||||
return NULL;
|
||||
}
|
||||
args[i] = PyString_AsString(o);
|
||||
pystr = PyUnicode_AsUTF8String(pyobj);
|
||||
str = PyBytes_AsString(pystr);
|
||||
Py_XDECREF(pystr);
|
||||
%#else
|
||||
if (!PyString_Check(pyobj)) {
|
||||
PyErr_SetString(PyExc_ValueError, "Expected a string");
|
||||
return NULL;
|
||||
}
|
||||
str = PyString_AsString(pyobj);
|
||||
%#endif
|
||||
args[i] = str;
|
||||
}
|
||||
$1 = (void *) args;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,9 @@
|
|||
* chapter of the SWIG manual.
|
||||
*/
|
||||
|
||||
%{
|
||||
%}
|
||||
|
||||
%typemap(in) (...)(char *args[10]) {
|
||||
int i;
|
||||
int argc;
|
||||
|
|
@ -14,12 +17,25 @@
|
|||
return NULL;
|
||||
}
|
||||
for (i = 0; i < argc; i++) {
|
||||
PyObject *o = PyTuple_GetItem(varargs,i);
|
||||
if (!PyString_Check(o)) {
|
||||
PyObject *pyobj = PyTuple_GetItem(varargs, i);
|
||||
char *str = 0;
|
||||
%#if PY_VERSION_HEX>=0x03000000
|
||||
PyObject *pystr;
|
||||
if (!PyUnicode_Check(pyobj)) {
|
||||
PyErr_SetString(PyExc_ValueError, "Expected a string");
|
||||
return NULL;
|
||||
}
|
||||
args[i] = PyString_AsString(o);
|
||||
pystr = PyUnicode_AsUTF8String(pyobj);
|
||||
str = PyBytes_AsString(pystr);
|
||||
Py_XDECREF(pystr);
|
||||
%#else
|
||||
if (!PyString_Check(pyobj)) {
|
||||
PyErr_SetString(PyExc_ValueError, "Expected a string");
|
||||
return NULL;
|
||||
}
|
||||
str = PyString_AsString(pyobj);
|
||||
%#endif
|
||||
args[i] = str;
|
||||
}
|
||||
$1 = (void *) args;
|
||||
}
|
||||
|
|
@ -41,3 +57,8 @@ char* testfunc (int arg1, double arg2, ...)
|
|||
return c;
|
||||
}
|
||||
}
|
||||
|
||||
%inline %{
|
||||
char *doublecheck(char *inputval) { return inputval; }
|
||||
%}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue