Commit 2f991d45 authored by Denis Bilenko's avatar Denis Bilenko

prefix gevent functions with "gevent_"

rename argument "arg" to "where" because this is how it's called in other places
skip incref/decref Py_None in gevent_handle_signal_error
parent 1cd43e96
static void handle_error(PyObject* loop, PyObject* arg) { static void gevent_handle_error(PyObject* loop, PyObject* where) {
PyThreadState *tstate; PyThreadState *tstate;
PyObject *type, *value, *traceback, *handler, *result, *tuple; PyObject *type, *value, *traceback, *handler, *result, *tuple;
int reported; int reported;
...@@ -22,8 +22,8 @@ static void handle_error(PyObject* loop, PyObject* arg) { ...@@ -22,8 +22,8 @@ static void handle_error(PyObject* loop, PyObject* arg) {
tuple = PyTuple_New(4); tuple = PyTuple_New(4);
if (tuple) { if (tuple) {
reported = 1; reported = 1;
Py_INCREF(arg); Py_INCREF(where);
PyTuple_SET_ITEM(tuple, 0, arg); PyTuple_SET_ITEM(tuple, 0, where);
PyTuple_SET_ITEM(tuple, 1, type); PyTuple_SET_ITEM(tuple, 1, type);
PyTuple_SET_ITEM(tuple, 2, value); PyTuple_SET_ITEM(tuple, 2, value);
PyTuple_SET_ITEM(tuple, 3, traceback); PyTuple_SET_ITEM(tuple, 3, traceback);
...@@ -51,20 +51,18 @@ static void handle_error(PyObject* loop, PyObject* arg) { ...@@ -51,20 +51,18 @@ static void handle_error(PyObject* loop, PyObject* arg) {
PyErr_Clear(); PyErr_Clear();
} }
static inline void handle_signal_error(PyObject* loop) { static inline void gevent_handle_signal_error(PyObject* loop) {
Py_INCREF(Py_None); gevent_handle_error(loop, Py_None);
handle_error(loop, Py_None);
Py_DECREF(Py_None);
} }
/* Calls callback(watcher, revents) and reports errors. /* Calls callback(watcher, revents) and reports errors.
* Returns 1 on success, 0 on failure * Returns 1 on success, 0 on failure
* */ * */
static inline int _callback(PyObject* callback, PyObject* watcher, int revents, PyObject* loop) { static inline int gevent_callback(PyObject* callback, PyObject* watcher, int revents, PyObject* loop) {
int success; int success;
PyObject *py_revents, *tuple, *result; PyObject *py_revents, *tuple, *result;
PyErr_CheckSignals(); PyErr_CheckSignals();
if (PyErr_Occurred()) handle_signal_error(loop); if (PyErr_Occurred()) gevent_handle_signal_error(loop);
success = 0; success = 0;
...@@ -81,7 +79,7 @@ static inline int _callback(PyObject* callback, PyObject* watcher, int revents, ...@@ -81,7 +79,7 @@ static inline int _callback(PyObject* callback, PyObject* watcher, int revents,
Py_DECREF(result); Py_DECREF(result);
} }
else { else {
handle_error(loop, watcher); gevent_handle_error(loop, watcher);
} }
Py_DECREF(tuple); Py_DECREF(tuple);
} }
...@@ -95,10 +93,10 @@ static inline int _callback(PyObject* callback, PyObject* watcher, int revents, ...@@ -95,10 +93,10 @@ static inline int _callback(PyObject* callback, PyObject* watcher, int revents,
/* Calls callback(*args) and reports errors */ /* Calls callback(*args) and reports errors */
static void _callback_simple(PyObject* callback, PyObject* watcher, PyObject* args, PyObject* loop) { static void gevent_callback_simple(PyObject* callback, PyObject* watcher, PyObject* args, PyObject* loop) {
PyObject* result; PyObject* result;
PyErr_CheckSignals(); PyErr_CheckSignals();
if (PyErr_Occurred()) handle_signal_error(loop); if (PyErr_Occurred()) gevent_handle_signal_error(loop);
result = PyObject_Call(callback, args, NULL); result = PyObject_Call(callback, args, NULL);
...@@ -106,7 +104,7 @@ static void _callback_simple(PyObject* callback, PyObject* watcher, PyObject* ar ...@@ -106,7 +104,7 @@ static void _callback_simple(PyObject* callback, PyObject* watcher, PyObject* ar
Py_DECREF(result); Py_DECREF(result);
} }
else { else {
handle_error(loop, watcher); gevent_handle_error(loop, watcher);
} }
PyErr_Clear(); PyErr_Clear();
} }
...@@ -125,7 +123,7 @@ static void _callback_simple(PyObject* callback, PyObject* watcher, PyObject* ar ...@@ -125,7 +123,7 @@ static void _callback_simple(PyObject* callback, PyObject* watcher, PyObject* ar
#endif #endif
static inline void stop(PyObject* self) { static inline void gevent_stop(PyObject* self) {
PyObject *result, *callable; PyObject *result, *callable;
callable = PyObject_GetAttrString(self, "stop"); callable = PyObject_GetAttrString(self, "stop");
if (callable) { if (callable) {
...@@ -150,7 +148,7 @@ static inline void stop(PyObject* self) { ...@@ -150,7 +148,7 @@ static inline void stop(PyObject* self) {
#define CHECK_OFFSETOF (timer_offsetof == signal_offsetof) && (timer_offsetof == idle_offsetof) && (timer_offsetof == prepare_offsetof) && (timer_offsetof == callback_offsetof) #define CHECK_OFFSETOF (timer_offsetof == signal_offsetof) && (timer_offsetof == idle_offsetof) && (timer_offsetof == prepare_offsetof) && (timer_offsetof == callback_offsetof)
static void simple_callback(struct ev_loop *_loop, void *watcher, int revents) { static void gevent_simple_callback(struct ev_loop *_loop, void *watcher, int revents) {
char STATIC_ASSERTION__same_offsetof[(CHECK_OFFSETOF)?1:-1]; char STATIC_ASSERTION__same_offsetof[(CHECK_OFFSETOF)?1:-1];
struct __pyx_obj_6gevent_4core_timer *self; struct __pyx_obj_6gevent_4core_timer *self;
GIL_ENSURE; GIL_ENSURE;
...@@ -158,40 +156,44 @@ static void simple_callback(struct ev_loop *_loop, void *watcher, int revents) { ...@@ -158,40 +156,44 @@ static void simple_callback(struct ev_loop *_loop, void *watcher, int revents) {
* 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 */
self = ((struct __pyx_obj_6gevent_4core_timer *)(((char *)watcher) - timer_offsetof)); self = ((struct __pyx_obj_6gevent_4core_timer *)(((char *)watcher) - timer_offsetof));
Py_INCREF(self); Py_INCREF(self);
_callback_simple(self->callback, (PyObject*)self, self->args, (PyObject*)self->loop); gevent_callback_simple(self->callback, (PyObject*)self, self->args, (PyObject*)self->loop);
if (!ev_active(watcher)) { if (!ev_active(watcher)) {
stop((PyObject*)self); gevent_stop((PyObject*)self);
} }
Py_DECREF(self); Py_DECREF(self);
GIL_RELEASE; GIL_RELEASE;
} }
static void io_callback(struct ev_loop *loop, struct ev_io *watcher, int revents) { static void gevent_io_callback(struct ev_loop *loop, struct ev_io *watcher, int revents) {
struct __pyx_obj_6gevent_4core_io *self; struct __pyx_obj_6gevent_4core_io *self;
GIL_ENSURE; GIL_ENSURE;
self = GET_OBJECT(watcher, __pyx_obj_6gevent_4core_io, _watcher); self = GET_OBJECT(watcher, __pyx_obj_6gevent_4core_io, _watcher);
Py_INCREF(self); Py_INCREF(self);
if (!_callback(self->callback, (PyObject*)self, revents, (PyObject*)self->loop)) { if (!gevent_callback(self->callback, (PyObject*)self, revents, (PyObject*)self->loop)) {
stop((PyObject*)self); gevent_stop((PyObject*)self);
} }
Py_DECREF(self); Py_DECREF(self);
GIL_RELEASE; GIL_RELEASE;
} }
static void signal_check(struct ev_loop *_loop, void *watcher, int revents) { static void gevent_signal_check(struct ev_loop *_loop, void *watcher, int revents) {
struct __pyx_obj_6gevent_4core_loop *loop; struct __pyx_obj_6gevent_4core_loop *loop;
GIL_ENSURE; GIL_ENSURE;
PyErr_CheckSignals(); PyErr_CheckSignals();
loop = GET_OBJECT(watcher, __pyx_obj_6gevent_4core_loop, _signal_checker); loop = GET_OBJECT(watcher, __pyx_obj_6gevent_4core_loop, _signal_checker);
if (PyErr_Occurred()) handle_signal_error((PyObject*)loop); if (PyErr_Occurred()) gevent_handle_signal_error((PyObject*)loop);
GIL_RELEASE; GIL_RELEASE;
} }
static void periodic_signal_check(struct ev_loop *_loop, void *watcher, int revents) { #if defined(GEVENT_WINDOWS)
static void gevent_periodic_signal_check(struct ev_loop *_loop, void *watcher, int revents) {
struct __pyx_obj_6gevent_4core_loop *loop; struct __pyx_obj_6gevent_4core_loop *loop;
GIL_ENSURE; GIL_ENSURE;
PyErr_CheckSignals(); PyErr_CheckSignals();
loop = GET_OBJECT(watcher, __pyx_obj_6gevent_4core_loop, _periodic_signal_checker); loop = GET_OBJECT(watcher, __pyx_obj_6gevent_4core_loop, _periodic_signal_checker);
if (PyErr_Occurred()) handle_signal_error((PyObject*)loop); if (PyErr_Occurred()) gevent_handle_signal_error((PyObject*)loop);
GIL_RELEASE; GIL_RELEASE;
} }
#endif
static void io_callback(struct ev_loop*, struct ev_io*, int); static void gevent_io_callback(struct ev_loop*, struct ev_io*, int);
static void simple_callback(struct ev_loop *, void *, int); static void gevent_simple_callback(struct ev_loop *, void *, int);
static void signal_check(struct ev_loop *, void *, int); static void gevent_signal_check(struct ev_loop *, void *, int);
static void periodic_signal_check(struct ev_loop *, void *, int);
#if defined(GEVENT_WINDOWS)
static void gevent_periodic_signal_check(struct ev_loop *, void *, int);
#endif
...@@ -23,10 +23,10 @@ cdef extern from "frameobject.h": ...@@ -23,10 +23,10 @@ cdef extern from "frameobject.h":
PyThreadState* PyThreadState_GET() PyThreadState* PyThreadState_GET()
cdef extern from "callbacks.h": cdef extern from "callbacks.h":
void io_callback(libev.ev_loop, libev.ev_io, int) void gevent_io_callback(libev.ev_loop, libev.ev_io, int)
void simple_callback(libev.ev_loop, void*, int) void gevent_simple_callback(libev.ev_loop, void*, int)
void signal_check(libev.ev_loop, void*, int) void gevent_signal_check(libev.ev_loop, void*, int)
void periodic_signal_check(libev.ev_loop, void*, int) void gevent_periodic_signal_check(libev.ev_loop, void*, int)
cdef extern from *: cdef extern from *:
...@@ -180,9 +180,9 @@ cdef class loop: ...@@ -180,9 +180,9 @@ cdef class loop:
def __init__(self, object flags=None, object default=True, size_t ptr=0): def __init__(self, object flags=None, object default=True, size_t ptr=0):
cdef unsigned int c_flags cdef unsigned int c_flags
libev.ev_prepare_init(&self._signal_checker, <void*>signal_check) libev.ev_prepare_init(&self._signal_checker, <void*>gevent_signal_check)
IFDEF_WINDOWS() IFDEF_WINDOWS()
libev.ev_timer_init(&self._periodic_signal_checker, <void*>periodic_signal_check, 0.3, 0.3) libev.ev_timer_init(&self._periodic_signal_checker, <void*>gevent_periodic_signal_check, 0.3, 0.3)
ENDIF() ENDIF()
if ptr: if ptr:
self._ptr = <libev.ev_loop*>ptr self._ptr = <libev.ev_loop*>ptr
...@@ -417,7 +417,7 @@ define(WATCHER, `WATCHER_BASE($1) ...@@ -417,7 +417,7 @@ define(WATCHER, `WATCHER_BASE($1)
define(INIT, `def __init__(self, loop loop$2, object ref=False): define(INIT, `def __init__(self, loop loop$2, object ref=False):
libev.ev_$1_init(&self._watcher, <void *>simple_callback$3) libev.ev_$1_init(&self._watcher, <void *>gevent_simple_callback$3)
self.loop = loop self.loop = loop
if ref: if ref:
self._incref = 1 self._incref = 1
...@@ -479,7 +479,7 @@ cdef class io(watcher): ...@@ -479,7 +479,7 @@ cdef class io(watcher):
IFDEF_WINDOWS() IFDEF_WINDOWS()
fd = _get_fd(fd) fd = _get_fd(fd)
ENDIF() ENDIF()
libev.ev_io_init(&self._watcher, <void *>io_callback, fd, events) libev.ev_io_init(&self._watcher, <void *>gevent_io_callback, fd, events)
self.loop = loop self.loop = loop
if ref: if ref:
self._incref = 1 self._incref = 1
......
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