mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 10:22:45 -04:00
PythonTask: don't crash if repr(owner) errors, deal better with bad owners
This commit is contained in:
parent
fd8dd360b2
commit
47d1b4e220
@ -214,6 +214,19 @@ get_upon_death() {
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
void PythonTask::
|
void PythonTask::
|
||||||
set_owner(PyObject *owner) {
|
set_owner(PyObject *owner) {
|
||||||
|
#ifndef NDEBUG
|
||||||
|
if (owner != Py_None) {
|
||||||
|
PyObject *add = PyObject_GetAttrString(owner, "_addTask");
|
||||||
|
PyObject *clear = PyObject_GetAttrString(owner, "_clearTask");
|
||||||
|
|
||||||
|
if (add == NULL || !PyCallable_Check(add) ||
|
||||||
|
clear == NULL || !PyCallable_Check(clear)) {
|
||||||
|
Dtool_Raise_TypeError("owner object should have _addTask and _clearTask methods");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if (_owner != NULL && _owner != Py_None && _state != S_inactive) {
|
if (_owner != NULL && _owner != Py_None && _state != S_inactive) {
|
||||||
unregister_from_owner();
|
unregister_from_owner();
|
||||||
}
|
}
|
||||||
@ -546,10 +559,16 @@ do_python_task() {
|
|||||||
ostringstream strm;
|
ostringstream strm;
|
||||||
#if PY_MAJOR_VERSION >= 3
|
#if PY_MAJOR_VERSION >= 3
|
||||||
PyObject *str = PyObject_ASCII(result);
|
PyObject *str = PyObject_ASCII(result);
|
||||||
|
if (str == NULL) {
|
||||||
|
str = PyUnicode_FromString("<repr error>");
|
||||||
|
}
|
||||||
strm
|
strm
|
||||||
<< *this << " returned " << PyUnicode_AsUTF8(str);
|
<< *this << " returned " << PyUnicode_AsUTF8(str);
|
||||||
#else
|
#else
|
||||||
PyObject *str = PyObject_Repr(result);
|
PyObject *str = PyObject_Repr(result);
|
||||||
|
if (str == NULL) {
|
||||||
|
str = PyString_FromString("<repr error>");
|
||||||
|
}
|
||||||
strm
|
strm
|
||||||
<< *this << " returned " << PyString_AsString(str);
|
<< *this << " returned " << PyString_AsString(str);
|
||||||
#endif
|
#endif
|
||||||
@ -672,18 +691,9 @@ call_owner_method(const char *method_name) {
|
|||||||
if (_owner != Py_None) {
|
if (_owner != Py_None) {
|
||||||
PyObject *func = PyObject_GetAttrString(_owner, (char *)method_name);
|
PyObject *func = PyObject_GetAttrString(_owner, (char *)method_name);
|
||||||
if (func == (PyObject *)NULL) {
|
if (func == (PyObject *)NULL) {
|
||||||
#if PY_MAJOR_VERSION >= 3
|
|
||||||
PyObject *str = PyObject_ASCII(_owner);
|
|
||||||
task_cat.error()
|
task_cat.error()
|
||||||
<< "Owner object " << PyUnicode_AsUTF8(str) << " added to "
|
<< "Owner object added to " << *this << " has no method "
|
||||||
<< *this << " has no method " << method_name << "().\n";
|
<< method_name << "().\n";
|
||||||
#else
|
|
||||||
PyObject *str = PyObject_Repr(_owner);
|
|
||||||
task_cat.error()
|
|
||||||
<< "Owner object " << PyString_AsString(str) << " added to "
|
|
||||||
<< *this << " has no method " << method_name << "().\n";
|
|
||||||
#endif
|
|
||||||
Py_DECREF(str);
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
call_function(func);
|
call_function(func);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user