diff options
author | Jack Jansen <jack.jansen@cwi.nl> | 2003-11-20 13:31:00 (GMT) |
---|---|---|
committer | Jack Jansen <jack.jansen@cwi.nl> | 2003-11-20 13:31:00 (GMT) |
commit | 7107c1aff301a65faed24642cdc08f82a1c41cd4 (patch) | |
tree | 1ce55f300f09be769722831564e22a9f49bbefa5 /Mac/Modules/carbonevt | |
parent | 3305d2487d76a8a24448d825e98f8afb4caa76ab (diff) | |
download | cpython-7107c1aff301a65faed24642cdc08f82a1c41cd4.zip cpython-7107c1aff301a65faed24642cdc08f82a1c41cd4.tar.gz cpython-7107c1aff301a65faed24642cdc08f82a1c41cd4.tar.bz2 |
Got rid of macglue.h, replacing it by pymactoolbox.h where relevant.
Cleaned up various things in the toolbox modules.
Diffstat (limited to 'Mac/Modules/carbonevt')
-rw-r--r-- | Mac/Modules/carbonevt/CarbonEvtscan.py | 1 | ||||
-rw-r--r-- | Mac/Modules/carbonevt/CarbonEvtsupport.py | 56 | ||||
-rwxr-xr-x | Mac/Modules/carbonevt/_CarbonEvtmodule.c | 71 |
3 files changed, 20 insertions, 108 deletions
diff --git a/Mac/Modules/carbonevt/CarbonEvtscan.py b/Mac/Modules/carbonevt/CarbonEvtscan.py index d3088fd..c6bf93f 100644 --- a/Mac/Modules/carbonevt/CarbonEvtscan.py +++ b/Mac/Modules/carbonevt/CarbonEvtscan.py @@ -84,7 +84,6 @@ class CarbonEvents_Scanner(Scanner_OSX): # Wrote by hand "InstallEventHandler", "RemoveEventHandler", - "RunApplicationEventLoop", # Write by hand? "GetEventParameter", diff --git a/Mac/Modules/carbonevt/CarbonEvtsupport.py b/Mac/Modules/carbonevt/CarbonEvtsupport.py index 19d7d6d..3cc1672 100644 --- a/Mac/Modules/carbonevt/CarbonEvtsupport.py +++ b/Mac/Modules/carbonevt/CarbonEvtsupport.py @@ -73,26 +73,9 @@ GrafPtr = OpaqueByValueType("GrafPtr", "GrafObj") MouseTrackingResult = UInt16 -includestuff = r""" +includestuff = includestuff + r""" #include <Carbon/Carbon.h> -#include "macglue.h" - -/* Macro to test whether a weak-loaded CFM function exists */ -#define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL ) {\ - PyErr_SetString(PyExc_NotImplementedError, \ - "Not available in this shared library/OS version"); \ - return; \ - }} while(0) - - -#define USE_MAC_MP_MULTITHREADING 0 - -#if USE_MAC_MP_MULTITHREADING -static PyThreadState *_save; -static MPCriticalRegionID reentrantLock; -#endif /* USE_MAC_MP_MULTITHREADING */ - extern int CFStringRef_New(CFStringRef *); extern int CFStringRef_Convert(PyObject *, CFStringRef *); @@ -168,11 +151,6 @@ myEventHandler(EventHandlerCallRef handlerRef, EventRef event, void *outPyObject PyObject *retValue; int status; -#if USE_MAC_MP_MULTITHREADING - MPEnterCriticalRegion(reentrantLock, kDurationForever); - PyEval_RestoreThread(_save); -#endif /* USE_MAC_MP_MULTITHREADING */ - retValue = PyObject_CallFunction((PyObject *)outPyObject, "O&O&", EventHandlerCallRef_New, handlerRef, EventRef_New, event); @@ -190,11 +168,6 @@ myEventHandler(EventHandlerCallRef handlerRef, EventRef event, void *outPyObject Py_DECREF(retValue); } -#if USE_MAC_MP_MULTITHREADING - _save = PyEval_SaveThread(); - MPExitCriticalRegion(reentrantLock); -#endif /* USE_MAC_MP_MULTITHREADING */ - return status; } @@ -203,7 +176,6 @@ myEventHandler(EventHandlerCallRef handlerRef, EventRef event, void *outPyObject """ initstuff = initstuff + """ -PyMac_PRECHECK(NewEventHandlerUPP); /* This can fail if CarbonLib is too old */ myEventHandlerUPP = NewEventHandlerUPP(myEventHandler); """ module = MacModule('_CarbonEvt', 'CarbonEvents', includestuff, finalstuff, initstuff) @@ -335,32 +307,6 @@ f = ManualGenerator("GetEventParameter", geteventparameter); f.docstring = lambda: "(EventParamName eventName, EventParamType eventType) -> (String eventParamData)" EventRefobject.add(f) -runappeventloop = """ -#if USE_MAC_MP_MULTITHREADING -if (MPCreateCriticalRegion(&reentrantLock) != noErr) { - PySys_WriteStderr("lock failure\\n"); - return NULL; -} -_save = PyEval_SaveThread(); -#endif /* USE_MAC_MP_MULTITHREADING */ - -RunApplicationEventLoop(); - -#if USE_MAC_MP_MULTITHREADING -PyEval_RestoreThread(_save); - -MPDeleteCriticalRegion(reentrantLock); -#endif /* USE_MAC_MP_MULTITHREADING */ - -Py_INCREF(Py_None); -_res = Py_None; -return _res; -""" - -f = ManualGenerator("RunApplicationEventLoop", runappeventloop); -f.docstring = lambda: "() -> ()" -module.add(f) - SetOutputFileName('_CarbonEvtmodule.c') module.generate() diff --git a/Mac/Modules/carbonevt/_CarbonEvtmodule.c b/Mac/Modules/carbonevt/_CarbonEvtmodule.c index 46eb31e..097f11a 100755 --- a/Mac/Modules/carbonevt/_CarbonEvtmodule.c +++ b/Mac/Modules/carbonevt/_CarbonEvtmodule.c @@ -5,24 +5,17 @@ -#include <Carbon/Carbon.h> - -#include "macglue.h" +#include "pymactoolbox.h" /* Macro to test whether a weak-loaded CFM function exists */ #define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL ) {\ - PyErr_SetString(PyExc_NotImplementedError, \ - "Not available in this shared library/OS version"); \ - return; \ - }} while(0) - + PyErr_SetString(PyExc_NotImplementedError, \ + "Not available in this shared library/OS version"); \ + return NULL; \ + }} while(0) -#define USE_MAC_MP_MULTITHREADING 0 -#if USE_MAC_MP_MULTITHREADING -static PyThreadState *_save; -static MPCriticalRegionID reentrantLock; -#endif /* USE_MAC_MP_MULTITHREADING */ +#include <Carbon/Carbon.h> extern int CFStringRef_New(CFStringRef *); @@ -99,11 +92,6 @@ myEventHandler(EventHandlerCallRef handlerRef, EventRef event, void *outPyObject PyObject *retValue; int status; -#if USE_MAC_MP_MULTITHREADING - MPEnterCriticalRegion(reentrantLock, kDurationForever); - PyEval_RestoreThread(_save); -#endif /* USE_MAC_MP_MULTITHREADING */ - retValue = PyObject_CallFunction((PyObject *)outPyObject, "O&O&", EventHandlerCallRef_New, handlerRef, EventRef_New, event); @@ -121,11 +109,6 @@ myEventHandler(EventHandlerCallRef handlerRef, EventRef event, void *outPyObject Py_DECREF(retValue); } -#if USE_MAC_MP_MULTITHREADING - _save = PyEval_SaveThread(); - MPExitCriticalRegion(reentrantLock); -#endif /* USE_MAC_MP_MULTITHREADING */ - return status; } @@ -1845,6 +1828,17 @@ static PyObject *CarbonEvents_GetEventDispatcherTarget(PyObject *_self, PyObject return _res; } +static PyObject *CarbonEvents_RunApplicationEventLoop(PyObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + RunApplicationEventLoop(); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + static PyObject *CarbonEvents_QuitApplicationEventLoop(PyObject *_self, PyObject *_args) { PyObject *_res = NULL; @@ -2042,32 +2036,6 @@ static PyObject *CarbonEvents_RegisterEventHotKey(PyObject *_self, PyObject *_ar return _res; } -static PyObject *CarbonEvents_RunApplicationEventLoop(PyObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - -#if USE_MAC_MP_MULTITHREADING - if (MPCreateCriticalRegion(&reentrantLock) != noErr) { - PySys_WriteStderr("lock failure\n"); - return NULL; - } - _save = PyEval_SaveThread(); -#endif /* USE_MAC_MP_MULTITHREADING */ - - RunApplicationEventLoop(); - -#if USE_MAC_MP_MULTITHREADING - PyEval_RestoreThread(_save); - - MPDeleteCriticalRegion(reentrantLock); -#endif /* USE_MAC_MP_MULTITHREADING */ - - Py_INCREF(Py_None); - _res = Py_None; - return _res; - -} - static PyMethodDef CarbonEvents_methods[] = { {"GetCurrentEventLoop", (PyCFunction)CarbonEvents_GetCurrentEventLoop, 1, PyDoc_STR("() -> (EventLoopRef _rv)")}, @@ -2103,6 +2071,8 @@ static PyMethodDef CarbonEvents_methods[] = { PyDoc_STR("() -> (EventTargetRef _rv)")}, {"GetEventDispatcherTarget", (PyCFunction)CarbonEvents_GetEventDispatcherTarget, 1, PyDoc_STR("() -> (EventTargetRef _rv)")}, + {"RunApplicationEventLoop", (PyCFunction)CarbonEvents_RunApplicationEventLoop, 1, + PyDoc_STR("() -> None")}, {"QuitApplicationEventLoop", (PyCFunction)CarbonEvents_QuitApplicationEventLoop, 1, PyDoc_STR("() -> None")}, {"RunAppModalLoopForWindow", (PyCFunction)CarbonEvents_RunAppModalLoopForWindow, 1, @@ -2127,8 +2097,6 @@ static PyMethodDef CarbonEvents_methods[] = { PyDoc_STR("(WindowPtr inWindow) -> (ControlHandle outControl)")}, {"RegisterEventHotKey", (PyCFunction)CarbonEvents_RegisterEventHotKey, 1, PyDoc_STR("(UInt32 inHotKeyCode, UInt32 inHotKeyModifiers, EventHotKeyID inHotKeyID, EventTargetRef inTarget, OptionBits inOptions) -> (EventHotKeyRef outRef)")}, - {"RunApplicationEventLoop", (PyCFunction)CarbonEvents_RunApplicationEventLoop, 1, - PyDoc_STR("() -> ()")}, {NULL, NULL, 0} }; @@ -2142,7 +2110,6 @@ void init_CarbonEvt(void) - PyMac_PRECHECK(NewEventHandlerUPP); /* This can fail if CarbonLib is too old */ myEventHandlerUPP = NewEventHandlerUPP(myEventHandler); |