Python fastdispatch error message improvements
When overloaded C++ methods are called, the fastdispatch mode sometimes optimises out the generation of the typecheck typemap code, resulting in the 'Possible C/C++ prototypes' information not being in the error message. Now when a TypeError is thrown, the exception message is modified to contain the 'Possible C/C++ prototypes'. See issue #1293
This commit is contained in:
parent
e0b23969d0
commit
4f7406624d
6 changed files with 79 additions and 16 deletions
|
|
@ -71,3 +71,33 @@ SWIG_Python_AddErrorMsg(const char* mesg)
|
|||
PyErr_SetString(PyExc_RuntimeError, mesg);
|
||||
}
|
||||
}
|
||||
|
||||
SWIGRUNTIME int
|
||||
SWIG_Python_TypeErrorOccurred(PyObject *obj)
|
||||
{
|
||||
PyObject *error;
|
||||
if (obj)
|
||||
return 0;
|
||||
error = PyErr_Occurred();
|
||||
return error && PyErr_GivenExceptionMatches(error, PyExc_TypeError);
|
||||
}
|
||||
|
||||
SWIGRUNTIME void
|
||||
SWIG_Python_RaiseOrModifyTypeError(const char *message)
|
||||
{
|
||||
if (SWIG_Python_TypeErrorOccurred(NULL)) {
|
||||
/* Use existing TypeError to preserve stacktrace and enhance with given message */
|
||||
PyObject *type = NULL, *value = NULL, *traceback = NULL;
|
||||
PyErr_Fetch(&type, &value, &traceback);
|
||||
#if PY_VERSION_HEX >= 0x03000000
|
||||
PyObject *newvalue = PyUnicode_FromFormat("%S\nAdditional Information:\n%s", value, message);
|
||||
#else
|
||||
PyObject *newvalue = PyString_FromFormat("%s\nAdditional Information:\n%s", PyString_AsString(value), message);
|
||||
#endif
|
||||
Py_XDECREF(value);
|
||||
PyErr_Restore(type, newvalue, traceback);
|
||||
} else {
|
||||
/* Raise TypeError using given message */
|
||||
PyErr_SetString(PyExc_TypeError, message);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue