55
66
77
8- #include <Carbon/Carbon.h>
9-
10- #include "macglue.h"
8+ #include "pymactoolbox.h"
119
1210/* Macro to test whether a weak-loaded CFM function exists */
1311#define PyMac_PRECHECK (rtn ) do { if ( &rtn == NULL ) {\
14- PyErr_SetString(PyExc_NotImplementedError, \
15- "Not available in this shared library/OS version"); \
16- return; \
17- }} while(0)
18-
12+ PyErr_SetString(PyExc_NotImplementedError, \
13+ "Not available in this shared library/OS version"); \
14+ return NULL; \
15+ }} while(0)
1916
20- #define USE_MAC_MP_MULTITHREADING 0
2117
22- #if USE_MAC_MP_MULTITHREADING
23- static PyThreadState * _save ;
24- static MPCriticalRegionID reentrantLock ;
25- #endif /* USE_MAC_MP_MULTITHREADING */
18+ #include <Carbon/Carbon.h>
2619
2720extern int CFStringRef_New (CFStringRef * );
2821
@@ -99,11 +92,6 @@ myEventHandler(EventHandlerCallRef handlerRef, EventRef event, void *outPyObject
9992 PyObject * retValue ;
10093 int status ;
10194
102- #if USE_MAC_MP_MULTITHREADING
103- MPEnterCriticalRegion (reentrantLock , kDurationForever );
104- PyEval_RestoreThread (_save );
105- #endif /* USE_MAC_MP_MULTITHREADING */
106-
10795 retValue = PyObject_CallFunction ((PyObject * )outPyObject , "O&O&" ,
10896 EventHandlerCallRef_New , handlerRef ,
10997 EventRef_New , event );
@@ -121,11 +109,6 @@ myEventHandler(EventHandlerCallRef handlerRef, EventRef event, void *outPyObject
121109 Py_DECREF (retValue );
122110 }
123111
124- #if USE_MAC_MP_MULTITHREADING
125- _save = PyEval_SaveThread ();
126- MPExitCriticalRegion (reentrantLock );
127- #endif /* USE_MAC_MP_MULTITHREADING */
128-
129112 return status ;
130113}
131114
@@ -1845,6 +1828,17 @@ static PyObject *CarbonEvents_GetEventDispatcherTarget(PyObject *_self, PyObject
18451828 return _res ;
18461829}
18471830
1831+ static PyObject * CarbonEvents_RunApplicationEventLoop (PyObject * _self , PyObject * _args )
1832+ {
1833+ PyObject * _res = NULL ;
1834+ if (!PyArg_ParseTuple (_args , "" ))
1835+ return NULL ;
1836+ RunApplicationEventLoop ();
1837+ Py_INCREF (Py_None );
1838+ _res = Py_None ;
1839+ return _res ;
1840+ }
1841+
18481842static PyObject * CarbonEvents_QuitApplicationEventLoop (PyObject * _self , PyObject * _args )
18491843{
18501844 PyObject * _res = NULL ;
@@ -2042,32 +2036,6 @@ static PyObject *CarbonEvents_RegisterEventHotKey(PyObject *_self, PyObject *_ar
20422036 return _res ;
20432037}
20442038
2045- static PyObject * CarbonEvents_RunApplicationEventLoop (PyObject * _self , PyObject * _args )
2046- {
2047- PyObject * _res = NULL ;
2048-
2049- #if USE_MAC_MP_MULTITHREADING
2050- if (MPCreateCriticalRegion (& reentrantLock ) != noErr ) {
2051- PySys_WriteStderr ("lock failure\n" );
2052- return NULL ;
2053- }
2054- _save = PyEval_SaveThread ();
2055- #endif /* USE_MAC_MP_MULTITHREADING */
2056-
2057- RunApplicationEventLoop ();
2058-
2059- #if USE_MAC_MP_MULTITHREADING
2060- PyEval_RestoreThread (_save );
2061-
2062- MPDeleteCriticalRegion (reentrantLock );
2063- #endif /* USE_MAC_MP_MULTITHREADING */
2064-
2065- Py_INCREF (Py_None );
2066- _res = Py_None ;
2067- return _res ;
2068-
2069- }
2070-
20712039static PyMethodDef CarbonEvents_methods [] = {
20722040 {"GetCurrentEventLoop" , (PyCFunction )CarbonEvents_GetCurrentEventLoop , 1 ,
20732041 PyDoc_STR ("() -> (EventLoopRef _rv)" )},
@@ -2103,6 +2071,8 @@ static PyMethodDef CarbonEvents_methods[] = {
21032071 PyDoc_STR ("() -> (EventTargetRef _rv)" )},
21042072 {"GetEventDispatcherTarget" , (PyCFunction )CarbonEvents_GetEventDispatcherTarget , 1 ,
21052073 PyDoc_STR ("() -> (EventTargetRef _rv)" )},
2074+ {"RunApplicationEventLoop" , (PyCFunction )CarbonEvents_RunApplicationEventLoop , 1 ,
2075+ PyDoc_STR ("() -> None" )},
21062076 {"QuitApplicationEventLoop" , (PyCFunction )CarbonEvents_QuitApplicationEventLoop , 1 ,
21072077 PyDoc_STR ("() -> None" )},
21082078 {"RunAppModalLoopForWindow" , (PyCFunction )CarbonEvents_RunAppModalLoopForWindow , 1 ,
@@ -2127,8 +2097,6 @@ static PyMethodDef CarbonEvents_methods[] = {
21272097 PyDoc_STR ("(WindowPtr inWindow) -> (ControlHandle outControl)" )},
21282098 {"RegisterEventHotKey" , (PyCFunction )CarbonEvents_RegisterEventHotKey , 1 ,
21292099 PyDoc_STR ("(UInt32 inHotKeyCode, UInt32 inHotKeyModifiers, EventHotKeyID inHotKeyID, EventTargetRef inTarget, OptionBits inOptions) -> (EventHotKeyRef outRef)" )},
2130- {"RunApplicationEventLoop" , (PyCFunction )CarbonEvents_RunApplicationEventLoop , 1 ,
2131- PyDoc_STR ("() -> ()" )},
21322100 {NULL , NULL , 0 }
21332101};
21342102
@@ -2142,7 +2110,6 @@ void init_CarbonEvt(void)
21422110
21432111
21442112
2145- PyMac_PRECHECK (NewEventHandlerUPP ); /* This can fail if CarbonLib is too old */
21462113 myEventHandlerUPP = NewEventHandlerUPP (myEventHandler );
21472114
21482115
0 commit comments