Fix how the return value of OnInit is checked, also DECREF the

PyObjects used there.


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_4_BRANCH@19568 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robin Dunn
2003-03-12 08:52:43 +00:00
parent 1b8fa9023e
commit ee6beb764e
4 changed files with 28 additions and 11 deletions

View File

@@ -445,26 +445,35 @@ PyObject* __wxStart(PyObject* /* self */, PyObject* args)
// Call the Python App's OnInit function
arglist = PyTuple_New(0);
result = PyEval_CallObject(onInitFunc, arglist);
Py_DECREF(arglist);
if (!result) { // an exception was raised.
return NULL;
}
if (! PyInt_Check(result)) {
PyObject* pyint = PyNumber_Int(result);
if (! pyint) {
PyErr_SetString(PyExc_TypeError, "OnInit should return a boolean value");
return NULL;
goto error;
}
bResult = PyInt_AS_LONG(result);
bResult = PyInt_AS_LONG(pyint);
if (! bResult) {
PyErr_SetString(PyExc_SystemExit, "OnInit returned FALSE, exiting...");
return NULL;
goto error;
}
#ifdef __WXGTK__
wxTheApp->m_initialized = (wxTopLevelWindows.GetCount() > 0);
#endif
Py_DECREF(result);
Py_DECREF(pyint);
Py_INCREF(Py_None);
return Py_None;
error:
Py_XDECREF(result);
Py_XDECREF(pyint);
return NULL;
}