Commit 9bb23a79 authored by Denis Bilenko's avatar Denis Bilenko

in gevent_callback expect args to be None or non-tuple (check the return value of PyTuple_Size)

parent c285538a
...@@ -74,28 +74,37 @@ static inline void gevent_stop(struct PyGeventTimerObject* watcher) { ...@@ -74,28 +74,37 @@ static inline void gevent_stop(struct PyGeventTimerObject* watcher) {
static void gevent_callback(struct ev_loop *_loop, void *c_watcher, int revents) { static void gevent_callback(struct ev_loop *_loop, void *c_watcher, int revents) {
struct PyGeventTimerObject *watcher; struct PyGeventTimerObject *watcher;
PyObject *result, *py_events; PyObject *result, *py_events, *args;
long length;
GIL_ENSURE; GIL_ENSURE;
/* we use this callback for all watchers, not just timer /* we use this callback for all watchers, not just timer
* we can do this, because layout of struct members is the same for all watchers */ * we can do this, because layout of struct members is the same for all watchers */
watcher = ((struct PyGeventTimerObject *)(((char *)c_watcher) - timer_offsetof)); watcher = ((struct PyGeventTimerObject *)(((char *)c_watcher) - timer_offsetof));
Py_INCREF(watcher); Py_INCREF(watcher);
gevent_check_signals(watcher->loop); gevent_check_signals(watcher->loop);
if (PyTuple_Size(watcher->args) > 0 && PyTuple_GET_ITEM(watcher->args, 0) == GEVENT_CORE_EVENTS) { args = watcher->args;
if (args == Py_None) {
args = __pyx_empty_tuple;
}
length = PyTuple_Size(args);
if (length < 0) {
gevent_handle_error(watcher->loop, (PyObject*)watcher);
goto end;
}
if (length > 0 && PyTuple_GET_ITEM(args, 0) == GEVENT_CORE_EVENTS) {
py_events = PyInt_FromLong(revents); py_events = PyInt_FromLong(revents);
if (py_events) { if (!py_events) {
Py_DECREF(GEVENT_CORE_EVENTS);
PyTuple_SET_ITEM(watcher->args, 0, py_events);
}
else {
gevent_handle_error(watcher->loop, (PyObject*)watcher); gevent_handle_error(watcher->loop, (PyObject*)watcher);
goto end; goto end;
} }
Py_DECREF(GEVENT_CORE_EVENTS);
PyTuple_SET_ITEM(args, 0, py_events);
} }
else { else {
py_events = NULL; py_events = NULL;
} }
result = PyObject_Call(watcher->_callback, watcher->args != Py_None ? watcher->args : __pyx_empty_tuple, NULL); // should incref args?
result = PyObject_Call(watcher->_callback, args, NULL);
if (result) { if (result) {
Py_DECREF(result); Py_DECREF(result);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment