diff options
Diffstat (limited to 'python/gevent/libev/_corecffi_source.c')
-rw-r--r-- | python/gevent/libev/_corecffi_source.c | 36 |
1 files changed, 30 insertions, 6 deletions
diff --git a/python/gevent/libev/_corecffi_source.c b/python/gevent/libev/_corecffi_source.c index d179ce6..63b216e 100644 --- a/python/gevent/libev/_corecffi_source.c +++ b/python/gevent/libev/_corecffi_source.c @@ -13,9 +13,10 @@ static void _gevent_noop(struct ev_loop *_loop, struct ev_timer *w, int revents) { } void (*gevent_noop)(struct ev_loop *, struct ev_timer *, int) = &_gevent_noop; -static int (*python_callback)(void* handle, int revents); -static void (*python_handle_error)(void* handle, int revents); -static void (*python_stop)(void* handle); + +static int python_callback(void* handle, int revents); +static void python_handle_error(void* handle, int revents); +static void python_stop(void* handle); static void _gevent_generic_callback(struct ev_loop* loop, struct ev_watcher* watcher, @@ -30,7 +31,7 @@ static void _gevent_generic_callback(struct ev_loop* loop, // and allowing memory to be freed python_handle_error(handle, revents); break; - case 0: + case 1: // Code to stop the event. Note that if python_callback // has disposed of the last reference to the handle, // `watcher` could now be invalid/disposed memory! @@ -38,8 +39,31 @@ static void _gevent_generic_callback(struct ev_loop* loop, python_stop(handle); } break; - default: - assert(cb_result == 1); + case 2: // watcher is already stopped and dead, nothing to do. + break; + default: + fprintf(stderr, + "WARNING: gevent: Unexpected return value %d from Python callback " + "for watcher %p and handle %d\n", + cb_result, + watcher, handle); + // XXX: Possible leaking of resources here? Should we be + // closing the watcher? } } + +static void gevent_zero_timer(struct ev_timer* handle) +{ + memset(handle, 0, sizeof(struct ev_timer)); +} + +static void gevent_zero_check(struct ev_check* handle) +{ + memset(handle, 0, sizeof(struct ev_check)); +} + +static void gevent_zero_prepare(struct ev_prepare* handle) +{ + memset(handle, 0, sizeof(struct ev_prepare)); +} |