mirror of
https://github.com/python/cpython.git
synced 2025-09-25 01:43:11 +00:00
Added proper error checking in event callback handler
This commit is contained in:
parent
ff3a69c4bc
commit
cddfc8736f
2 changed files with 50 additions and 24 deletions
|
@ -64,10 +64,10 @@ includestuff = r"""
|
||||||
|
|
||||||
/* Macro to test whether a weak-loaded CFM function exists */
|
/* Macro to test whether a weak-loaded CFM function exists */
|
||||||
#define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL ) {\
|
#define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL ) {\
|
||||||
PyErr_SetString(PyExc_NotImplementedError, \
|
PyErr_SetString(PyExc_NotImplementedError, \
|
||||||
"Not available in this shared library/OS version"); \
|
"Not available in this shared library/OS version"); \
|
||||||
return; \
|
return; \
|
||||||
}} while(0)
|
}} while(0)
|
||||||
|
|
||||||
|
|
||||||
#define USE_MAC_MP_MULTITHREADING 0
|
#define USE_MAC_MP_MULTITHREADING 0
|
||||||
|
@ -145,24 +145,37 @@ EventHotKeyID_Convert(PyObject *v, EventHotKeyID *out)
|
||||||
|
|
||||||
static EventHandlerUPP myEventHandlerUPP;
|
static EventHandlerUPP myEventHandlerUPP;
|
||||||
|
|
||||||
pascal OSStatus myEventHandler(EventHandlerCallRef handlerRef, EventRef event, void *outPyObject) {
|
static pascal OSStatus
|
||||||
|
myEventHandler(EventHandlerCallRef handlerRef, EventRef event, void *outPyObject) {
|
||||||
PyObject *retValue;
|
PyObject *retValue;
|
||||||
int status;
|
int status;
|
||||||
|
|
||||||
#if USE_MAC_MP_MULTITHREADING
|
#if USE_MAC_MP_MULTITHREADING
|
||||||
MPEnterCriticalRegion(reentrantLock, kDurationForever);
|
MPEnterCriticalRegion(reentrantLock, kDurationForever);
|
||||||
PyEval_RestoreThread(_save);
|
PyEval_RestoreThread(_save);
|
||||||
#endif /* USE_MAC_MP_MULTITHREADING */
|
#endif /* USE_MAC_MP_MULTITHREADING */
|
||||||
|
|
||||||
retValue = PyObject_CallFunction((PyObject *)outPyObject, "O&O&", EventHandlerCallRef_New, handlerRef, EventRef_New, event);
|
retValue = PyObject_CallFunction((PyObject *)outPyObject, "O&O&", EventHandlerCallRef_New, handlerRef, EventRef_New, event);
|
||||||
status = PyInt_AsLong(retValue);
|
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
|
#if USE_MAC_MP_MULTITHREADING
|
||||||
_save = PyEval_SaveThread();
|
_save = PyEval_SaveThread();
|
||||||
MPExitCriticalRegion(reentrantLock);
|
MPExitCriticalRegion(reentrantLock);
|
||||||
#endif /* USE_MAC_MP_MULTITHREADING */
|
#endif /* USE_MAC_MP_MULTITHREADING */
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
/******** end myEventHandler ***********/
|
/******** end myEventHandler ***********/
|
||||||
|
|
|
@ -15,10 +15,10 @@
|
||||||
|
|
||||||
/* Macro to test whether a weak-loaded CFM function exists */
|
/* Macro to test whether a weak-loaded CFM function exists */
|
||||||
#define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL ) {\
|
#define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL ) {\
|
||||||
PyErr_SetString(PyExc_NotImplementedError, \
|
PyErr_SetString(PyExc_NotImplementedError, \
|
||||||
"Not available in this shared library/OS version"); \
|
"Not available in this shared library/OS version"); \
|
||||||
return; \
|
return; \
|
||||||
}} while(0)
|
}} while(0)
|
||||||
|
|
||||||
|
|
||||||
#define USE_MAC_MP_MULTITHREADING 0
|
#define USE_MAC_MP_MULTITHREADING 0
|
||||||
|
@ -96,24 +96,37 @@ EventHotKeyID_Convert(PyObject *v, EventHotKeyID *out)
|
||||||
|
|
||||||
static EventHandlerUPP myEventHandlerUPP;
|
static EventHandlerUPP myEventHandlerUPP;
|
||||||
|
|
||||||
pascal OSStatus myEventHandler(EventHandlerCallRef handlerRef, EventRef event, void *outPyObject) {
|
static pascal OSStatus
|
||||||
|
myEventHandler(EventHandlerCallRef handlerRef, EventRef event, void *outPyObject) {
|
||||||
PyObject *retValue;
|
PyObject *retValue;
|
||||||
int status;
|
int status;
|
||||||
|
|
||||||
#if USE_MAC_MP_MULTITHREADING
|
#if USE_MAC_MP_MULTITHREADING
|
||||||
MPEnterCriticalRegion(reentrantLock, kDurationForever);
|
MPEnterCriticalRegion(reentrantLock, kDurationForever);
|
||||||
PyEval_RestoreThread(_save);
|
PyEval_RestoreThread(_save);
|
||||||
#endif /* USE_MAC_MP_MULTITHREADING */
|
#endif /* USE_MAC_MP_MULTITHREADING */
|
||||||
|
|
||||||
retValue = PyObject_CallFunction((PyObject *)outPyObject, "O&O&", EventHandlerCallRef_New, handlerRef, EventRef_New, event);
|
retValue = PyObject_CallFunction((PyObject *)outPyObject, "O&O&", EventHandlerCallRef_New, handlerRef, EventRef_New, event);
|
||||||
status = PyInt_AsLong(retValue);
|
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
|
#if USE_MAC_MP_MULTITHREADING
|
||||||
_save = PyEval_SaveThread();
|
_save = PyEval_SaveThread();
|
||||||
MPExitCriticalRegion(reentrantLock);
|
MPExitCriticalRegion(reentrantLock);
|
||||||
#endif /* USE_MAC_MP_MULTITHREADING */
|
#endif /* USE_MAC_MP_MULTITHREADING */
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
/******** end myEventHandler ***********/
|
/******** end myEventHandler ***********/
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue