Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
cddfc873
Commit
cddfc873
authored
Dec 12, 2001
by
Just van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added proper error checking in event callback handler
parent
ff3a69c4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
24 deletions
+50
-24
Mac/Modules/carbonevt/CarbonEvtsupport.py
Mac/Modules/carbonevt/CarbonEvtsupport.py
+25
-12
Mac/Modules/carbonevt/_CarbonEvtmodule.c
Mac/Modules/carbonevt/_CarbonEvtmodule.c
+25
-12
No files found.
Mac/Modules/carbonevt/CarbonEvtsupport.py
View file @
cddfc873
...
...
@@ -64,10 +64,10 @@ includestuff = r"""
/* 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; \
}} while(0)
#define USE_MAC_MP_MULTITHREADING 0
...
...
@@ -145,24 +145,37 @@ EventHotKeyID_Convert(PyObject *v, EventHotKeyID *out)
static EventHandlerUPP myEventHandlerUPP;
pascal OSStatus myEventHandler(EventHandlerCallRef handlerRef, EventRef event, void *outPyObject) {
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);
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);
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);
_save = PyEval_SaveThread();
MPExitCriticalRegion(reentrantLock);
#endif /* USE_MAC_MP_MULTITHREADING */
return status;
return status;
}
/******** end myEventHandler ***********/
...
...
Mac/Modules/carbonevt/_CarbonEvtmodule.c
View file @
cddfc873
...
...
@@ -15,10 +15,10 @@
/* 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; \
}} while(0)
#define USE_MAC_MP_MULTITHREADING 0
...
...
@@ -96,24 +96,37 @@ EventHotKeyID_Convert(PyObject *v, EventHotKeyID *out)
static
EventHandlerUPP
myEventHandlerUPP
;
pascal
OSStatus
myEventHandler
(
EventHandlerCallRef
handlerRef
,
EventRef
event
,
void
*
outPyObject
)
{
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
);
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
);
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
);
_save
=
PyEval_SaveThread
();
MPExitCriticalRegion
(
reentrantLock
);
#endif
/* USE_MAC_MP_MULTITHREADING */
return
status
;
return
status
;
}
/******** end myEventHandler ***********/
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment