Correct docs and examples to call SWIG_fail after setting a Python error

Although 'return NULL' works, it may miss out on some cleanup and NULL
is the wrong value to return in generated code for overloaded functions.
This commit is contained in:
William S Fulton 2016-10-21 08:02:12 +01:00
commit 129ef8ea8f
7 changed files with 74 additions and 66 deletions

View file

@ -50,7 +50,7 @@ namespace test {
PyComplex_ImagAsDouble($input));
} else {
PyErr_SetString(PyExc_TypeError,"Expected test_complex.\n");
return NULL;
SWIG_fail;
}
}
%typemap(freearg) test::test_complex * {
@ -242,7 +242,7 @@ namespace Split {
$1 = PyInt_AsLong($input);
if ($1 < 0) {
PyErr_SetString(PyExc_ValueError,"domain error\n");
return NULL;
SWIG_fail;
}
}
#endif

View file

@ -11,7 +11,7 @@
argc = PyTuple_Size(varargs);
if (argc > 10) {
PyErr_SetString(PyExc_ValueError, "Too many arguments");
return NULL;
SWIG_fail;
}
for (i = 0; i < argc; i++) {
PyObject *pyobj = PyTuple_GetItem(varargs, i);
@ -20,7 +20,7 @@
PyObject *pystr;
if (!PyUnicode_Check(pyobj)) {
PyErr_SetString(PyExc_ValueError, "Expected a string");
return NULL;
SWIG_fail;
}
pystr = PyUnicode_AsUTF8String(pyobj);
str = strdup(PyBytes_AsString(pystr));
@ -28,7 +28,7 @@
%#else
if (!PyString_Check(pyobj)) {
PyErr_SetString(PyExc_ValueError, "Expected a string");
return NULL;
SWIG_fail;
}
str = PyString_AsString(pyobj);
%#endif