[Python-checkins] CVS: python/dist/src/Mac/Modules/carbonevt CarbonEvtsupport.py,1.5,1.6 _CarbonEvtmodule.c,1.2,1.3
Just van Rossum
jvr@users.sourceforge.net
2001年12月12日 13:48:03 -0800
Update of /cvsroot/python/python/dist/src/Mac/Modules/carbonevt
In directory usw-pr-cvs1:/tmp/cvs-serv5843
Modified Files:
CarbonEvtsupport.py _CarbonEvtmodule.c
Log Message:
Added proper error checking in event callback handler
Index: CarbonEvtsupport.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Mac/Modules/carbonevt/CarbonEvtsupport.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** CarbonEvtsupport.py 2001年12月12日 20:48:53 1.5
--- CarbonEvtsupport.py 2001年12月12日 21:48:00 1.6
***************
*** 65,72 ****
/* 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)
--- 65,72 ----
/* 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)
***************
*** 146,167 ****
static EventHandlerUPP myEventHandlerUPP;
! pascal OSStatus 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);
! status = PyInt_AsLong(retValue);
#if USE_MAC_MP_MULTITHREADING
! _save = PyEval_SaveThread();
! MPExitCriticalRegion(reentrantLock);
#endif /* USE_MAC_MP_MULTITHREADING */
! return status;
}
--- 146,180 ----
static EventHandlerUPP myEventHandlerUPP;
! static pascal OSStatus
! 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);
! 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();
! MPExitCriticalRegion(reentrantLock);
#endif /* USE_MAC_MP_MULTITHREADING */
! return status;
}
Index: _CarbonEvtmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Mac/Modules/carbonevt/_CarbonEvtmodule.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** _CarbonEvtmodule.c 2001年12月12日 20:48:53 1.2
--- _CarbonEvtmodule.c 2001年12月12日 21:48:00 1.3
***************
*** 16,23 ****
/* 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)
--- 16,23 ----
/* 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)
***************
*** 97,118 ****
static EventHandlerUPP myEventHandlerUPP;
! pascal OSStatus 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);
! status = PyInt_AsLong(retValue);
#if USE_MAC_MP_MULTITHREADING
! _save = PyEval_SaveThread();
! MPExitCriticalRegion(reentrantLock);
#endif /* USE_MAC_MP_MULTITHREADING */
! return status;
}
--- 97,131 ----
static EventHandlerUPP myEventHandlerUPP;
! static pascal OSStatus
! 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);
! 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();
! MPExitCriticalRegion(reentrantLock);
#endif /* USE_MAC_MP_MULTITHREADING */
! return status;
}