better error message
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@6708 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
263b2af0c5
commit
5d741fe99f
1 changed files with 24 additions and 6 deletions
|
|
@ -168,14 +168,32 @@ SWIG_Python_addvarlink(PyObject *p, char *name, PyObject *(*get_attr)(void), int
|
||||||
static void
|
static void
|
||||||
SWIG_Python_TypeError(const char *type, PyObject *obj)
|
SWIG_Python_TypeError(const char *type, PyObject *obj)
|
||||||
{
|
{
|
||||||
const char *otype = (obj ? obj->ob_type->tp_name : 0);
|
|
||||||
if (type) {
|
if (type) {
|
||||||
if (otype) {
|
if (!PyCObject_Check(obj)) {
|
||||||
PyErr_Format(PyExc_TypeError, "a '%s' is expected, '%s' is received",
|
const char *otype = (obj ? obj->ob_type->tp_name : 0);
|
||||||
type, otype);
|
if (otype) {
|
||||||
|
PyObject *str = PyObject_Str(obj);
|
||||||
|
const char *cstr = str ? PyString_AsString(str) : 0;
|
||||||
|
if (cstr) {
|
||||||
|
PyErr_Format(PyExc_TypeError, "a '%s' is expected, '%s(%s)' is received",
|
||||||
|
type, otype, cstr);
|
||||||
|
} else {
|
||||||
|
PyErr_Format(PyExc_TypeError, "a '%s' is expected, '%s' is received",
|
||||||
|
type, otype);
|
||||||
|
}
|
||||||
|
Py_DECREF(str);
|
||||||
|
return;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
PyErr_Format(PyExc_TypeError, "a '%s' is expected", type);
|
const char *otype = (char *) PyCObject_GetDesc(obj);
|
||||||
}
|
if (otype) {
|
||||||
|
PyErr_Format(PyExc_TypeError, "a '%s' is expected, 'PyCObject(%s)' is received",
|
||||||
|
type, otype);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
PyErr_Format(PyExc_TypeError, "a '%s' is expected", type);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
PyErr_Format(PyExc_TypeError, "unexpected type is received");
|
PyErr_Format(PyExc_TypeError, "unexpected type is received");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue