|
15 | 15 |
|
16 | 16 | /* Macro to test whether a weak-loaded CFM function exists */ |
17 | 17 | #define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL ) {\ |
18 | | - PyErr_SetString(PyExc_NotImplementedError, \ |
19 | | - "Not available in this shared library/OS version"); \ |
20 | | - return; \ |
21 | | - }} while(0) |
| 18 | + PyErr_SetString(PyExc_NotImplementedError, \ |
| 19 | + "Not available in this shared library/OS version"); \ |
| 20 | + return; \ |
| 21 | + }} while(0) |
22 | 22 |
|
23 | 23 |
|
24 | 24 | #define USE_MAC_MP_MULTITHREADING 0 |
@@ -96,24 +96,37 @@ EventHotKeyID_Convert(PyObject *v, EventHotKeyID *out) |
96 | 96 |
|
97 | 97 | static EventHandlerUPP myEventHandlerUPP; |
98 | 98 |
|
99 | | -pascal OSStatus myEventHandler(EventHandlerCallRef handlerRef, EventRef event, void *outPyObject) { |
| 99 | +static pascal OSStatus |
| 100 | +myEventHandler(EventHandlerCallRef handlerRef, EventRef event, void *outPyObject) { |
100 | 101 | PyObject *retValue; |
101 | 102 | int status; |
102 | 103 |
|
103 | 104 | #if USE_MAC_MP_MULTITHREADING |
104 | | - MPEnterCriticalRegion(reentrantLock, kDurationForever); |
105 | | - PyEval_RestoreThread(_save); |
| 105 | + MPEnterCriticalRegion(reentrantLock, kDurationForever); |
| 106 | + PyEval_RestoreThread(_save); |
106 | 107 | #endif /* USE_MAC_MP_MULTITHREADING */ |
107 | 108 |
|
108 | | - retValue = PyObject_CallFunction((PyObject *)outPyObject, "O&O&", EventHandlerCallRef_New, handlerRef, EventRef_New, event); |
109 | | - status = PyInt_AsLong(retValue); |
| 109 | + retValue = PyObject_CallFunction((PyObject *)outPyObject, "O&O&", EventHandlerCallRef_New, handlerRef, EventRef_New, event); |
| 110 | + if (retValue == NULL) { |
| 111 | + PySys_WriteStderr("Error in event handler callback:\n"); |
| 112 | + PyErr_Print(); /* this also clears the error */ |
| 113 | + status = noErr; /* complain? how? */ |
| 114 | + } else { |
| 115 | + if (retValue == Py_None) |
| 116 | + status = noErr; |
| 117 | + else if (PyInt_Check(retValue)) { |
| 118 | + status = PyInt_AsLong(retValue); |
| 119 | + } else |
| 120 | + status = noErr; /* wrong object type, complain? */ |
| 121 | + Py_DECREF(retValue); |
| 122 | + } |
110 | 123 |
|
111 | 124 | #if USE_MAC_MP_MULTITHREADING |
112 | | - _save = PyEval_SaveThread(); |
113 | | - MPExitCriticalRegion(reentrantLock); |
| 125 | + _save = PyEval_SaveThread(); |
| 126 | + MPExitCriticalRegion(reentrantLock); |
114 | 127 | #endif /* USE_MAC_MP_MULTITHREADING */ |
115 | 128 |
|
116 | | - return status; |
| 129 | + return status; |
117 | 130 | } |
118 | 131 |
|
119 | 132 | /******** end myEventHandler ***********/ |
|
0 commit comments