Skip to content

Commit

Permalink
Check for Python errors upon return from overloaded virtual methods
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinD42 committed Sep 6, 2019
1 parent 3bce916 commit 059e1be
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
7 changes: 6 additions & 1 deletion etg/dataview.py
Expand Up @@ -279,7 +279,12 @@ def _fixupTypeParam(klass):
# an out parameter.
m.virtualCatcherCode = """\
PyObject *sipResObj = sipCallMethod(&sipIsErr, sipMethod, "D", editor, sipType_wxWindow, NULL);
if (sipResObj == Py_None) {
if (sipResObj == NULL) {
if (PyErr_Occurred())
PyErr_Print();
sipRes = false;
}
else if (sipResObj == Py_None) {
sipRes = false;
} else {
sipRes = true;
Expand Down
16 changes: 13 additions & 3 deletions etg/grid.py
Expand Up @@ -243,14 +243,19 @@ def fixEditorClass(name):
result = sipCallMethod(0, sipMethod, "iiDN", row, col,
const_cast<wxGrid *>(grid),sipType_wxGrid,NULL,
new wxString(oldval),sipType_wxString,NULL);
if (result == Py_None) {
if (result == NULL) {
if (PyErr_Occurred())
PyErr_Print();
sipRes = false;
}
else if (result == Py_None) {
sipRes = false;
}
else {
sipRes = true;
*newval = Py2wxString(result);
}
Py_DECREF(result);
Py_XDECREF(result);
""" if pureVirtual else "", # only used with the base class
)

Expand Down Expand Up @@ -337,7 +342,12 @@ def fixEditorClass(name):
m.virtualCatcherCode = """\
// virtualCatcherCode for GridTableBase.GetValue
PyObject *result = sipCallMethod(&sipIsErr, sipMethod, "ii", row, col);
if (result == Py_None) {
if (result == NULL) {
if (PyErr_Occurred())
PyErr_Print();
sipRes = "";
}
else if (result == Py_None) {
sipRes = "";
}
else {
Expand Down
7 changes: 6 additions & 1 deletion etg/propgrideditors.py
Expand Up @@ -57,7 +57,12 @@ def run():
PyObject *sipResObj = sipCallMethod(&sipIsErr, sipMethod, "DD",
property, sipType_wxPGProperty, NULL,
ctrl, sipType_wxWindow, NULL);
if (sipResObj == Py_None) {
if (sipResObj == NULL) {
if (PyErr_Occurred())
PyErr_Print();
sipRes = false;
}
else if (sipResObj == Py_None) {
sipRes = false;
} else if (sipResObj && !sipIsErr) {
sipParseResult(&sipIsErr, sipMethod, sipResObj, "(bH5)", &sipRes, sipType_wxPGVariant, &variant);
Expand Down
3 changes: 2 additions & 1 deletion etg/taskbar.py
Expand Up @@ -60,7 +60,8 @@ def run():
method.virtualCatcherCode = """\
// VirtualCatcherCode for wxTaskBarIcon.CreatePopupMenu
PyObject *sipResObj = sipCallMethod(0, sipMethod, "");
sipParseResult(0, sipMethod, sipResObj, "H0", sipType_wxMenu, &sipRes);
if (!sipResObj || sipParseResult(0, sipMethod, sipResObj, "H0", sipType_wxMenu, &sipRes) < 0)
PyErr_Print();
if (sipRes) {
sipTransferTo(sipResObj, Py_None);
}
Expand Down

0 comments on commit 059e1be

Please sign in to comment.