Added proper error checking in event callback handler

This commit is contained in:
Just van Rossum 2001-12-12 21:48:00 +00:00
parent ff3a69c4bc
commit cddfc8736f
2 changed files with 50 additions and 24 deletions

View File

@ -145,7 +145,8 @@
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 @@
#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();

View File

@ -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();