Merge branch 'python-type-error'
* python-type-error: Python fastdispatch error message improvements Correct PyErr_Fetch/PyErr_Restore variable names Overloaded C++ function Python wrappers now raise a TypeError instead of NotImplementedError
This commit is contained in:
commit
36a7c49b1e
12 changed files with 117 additions and 35 deletions
|
|
@ -436,15 +436,15 @@ SwigPyBuiltin_destructor_closure(SwigPyWrapperFunction wrapper, const char *wrap
|
|||
Py_XDECREF(sobj->dict);
|
||||
if (sobj->own) {
|
||||
PyObject *o;
|
||||
PyObject *val = 0, *type = 0, *tb = 0;
|
||||
PyErr_Fetch(&val, &type, &tb);
|
||||
PyObject *type = 0, *value = 0, *traceback = 0;
|
||||
PyErr_Fetch(&type, &value, &traceback);
|
||||
o = wrapper(a, NULL);
|
||||
if (!o) {
|
||||
PyObject *deallocname = PyString_FromString(wrappername);
|
||||
PyErr_WriteUnraisable(deallocname);
|
||||
Py_DECREF(deallocname);
|
||||
}
|
||||
PyErr_Restore(val, type, tb);
|
||||
PyErr_Restore(type, value, traceback);
|
||||
Py_XDECREF(o);
|
||||
}
|
||||
if (PyType_IS_GC(a->ob_type)) {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -530,8 +530,8 @@ SwigPyObject_dealloc(PyObject *v)
|
|||
remain true upon return from SwigPyObject_dealloc. So save
|
||||
and restore. */
|
||||
|
||||
PyObject *val = NULL, *type = NULL, *tb = NULL;
|
||||
PyErr_Fetch(&val, &type, &tb);
|
||||
PyObject *type = NULL, *value = NULL, *traceback = NULL;
|
||||
PyErr_Fetch(&type, &value, &traceback);
|
||||
|
||||
if (data->delargs) {
|
||||
/* we need to create a temporary object to carry the destroy operation */
|
||||
|
|
@ -546,7 +546,7 @@ SwigPyObject_dealloc(PyObject *v)
|
|||
if (!res)
|
||||
PyErr_WriteUnraisable(destroy);
|
||||
|
||||
PyErr_Restore(val, type, tb);
|
||||
PyErr_Restore(type, value, traceback);
|
||||
|
||||
Py_XDECREF(res);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue