Commit cddfc873 authored by Just van Rossum's avatar Just van Rossum

Added proper error checking in event callback handler

parent ff3a69c4
......@@ -145,7 +145,8 @@ EventHotKeyID_Convert(PyObject *v, EventHotKeyID *out)
static EventHandlerUPP myEventHandlerUPP;
pascal OSStatus myEventHandler(EventHandlerCallRef handlerRef, EventRef event, void *outPyObject) {
static pascal OSStatus
myEventHandler(EventHandlerCallRef handlerRef, EventRef event, void *outPyObject) {
PyObject *retValue;
int status;
......@@ -155,7 +156,19 @@ pascal OSStatus myEventHandler(EventHandlerCallRef handlerRef, EventRef event, v
#endif /* USE_MAC_MP_MULTITHREADING */
retValue = PyObject_CallFunction((PyObject *)outPyObject, "O&O&", EventHandlerCallRef_New, handlerRef, EventRef_New, event);
if (retValue == NULL) {
PySys_WriteStderr("Error in event handler callback:\n");
PyErr_Print(); /* this also clears the error */
status = noErr; /* complain? how? */
} else {
if (retValue == Py_None)
status = noErr;
else if (PyInt_Check(retValue)) {
status = PyInt_AsLong(retValue);
} else
status = noErr; /* wrong object type, complain? */
Py_DECREF(retValue);
}
#if USE_MAC_MP_MULTITHREADING
_save = PyEval_SaveThread();
......
......@@ -96,7 +96,8 @@ EventHotKeyID_Convert(PyObject *v, EventHotKeyID *out)
static EventHandlerUPP myEventHandlerUPP;
pascal OSStatus myEventHandler(EventHandlerCallRef handlerRef, EventRef event, void *outPyObject) {
static pascal OSStatus
myEventHandler(EventHandlerCallRef handlerRef, EventRef event, void *outPyObject) {
PyObject *retValue;
int status;
......@@ -106,7 +107,19 @@ pascal OSStatus myEventHandler(EventHandlerCallRef handlerRef, EventRef event, v
#endif /* USE_MAC_MP_MULTITHREADING */
retValue = PyObject_CallFunction((PyObject *)outPyObject, "O&O&", EventHandlerCallRef_New, handlerRef, EventRef_New, event);
if (retValue == NULL) {
PySys_WriteStderr("Error in event handler callback:\n");
PyErr_Print(); /* this also clears the error */
status = noErr; /* complain? how? */
} else {
if (retValue == Py_None)
status = noErr;
else if (PyInt_Check(retValue)) {
status = PyInt_AsLong(retValue);
} else
status = noErr; /* wrong object type, complain? */
Py_DECREF(retValue);
}
#if USE_MAC_MP_MULTITHREADING
_save = PyEval_SaveThread();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment