static void on_process_exit(uv_process_t *handle, int64_t exit_status, int term_signal) { PyGILState_STATE gstate = PyGILState_Ensure(); Process *self; PyObject *result, *py_exit_status, *py_term_signal; ASSERT(handle); self = PYUV_CONTAINER_OF(handle, Process, process_h); py_exit_status = PyInt_FromLong(exit_status); py_term_signal = PyInt_FromLong(term_signal); if (self->on_exit_cb != Py_None) { result = PyObject_CallFunctionObjArgs(self->on_exit_cb, self, py_exit_status, py_term_signal, NULL); if (result == NULL) { handle_uncaught_exception(HANDLE(self)->loop); } Py_XDECREF(result); Py_DECREF(py_exit_status); Py_DECREF(py_term_signal); } /* Refcount was increased in the spawn function */ Py_DECREF(self); PyGILState_Release(gstate); }
static void pyuv__stream_shutdown_cb(uv_shutdown_t* req, int status) { PyGILState_STATE gstate = PyGILState_Ensure(); stream_shutdown_ctx *ctx; Stream *self; PyObject *callback, *result, *py_errorno; ctx = PYUV_CONTAINER_OF(req, stream_shutdown_ctx, req); self = ctx->obj; callback = ctx->callback; if (callback != Py_None) { if (status < 0) { py_errorno = PyInt_FromLong((long)status); } else { py_errorno = Py_None; Py_INCREF(Py_None); } result = PyObject_CallFunctionObjArgs(callback, self, py_errorno, NULL); if (result == NULL) { handle_uncaught_exception(HANDLE(self)->loop); } Py_XDECREF(result); Py_DECREF(py_errorno); } Py_DECREF(callback); PyMem_Free(req); /* Refcount was increased in the caller function */ Py_DECREF(self); PyGILState_Release(gstate); }
static void pyuv__check_signals(uv_poll_t *handle, int status, int events) { PyGILState_STATE gstate = PyGILState_Ensure(); SignalChecker *self; ASSERT(handle); self = PYUV_CONTAINER_OF(handle, SignalChecker, poll_h); if (status == 0) { ASSERT(events == UV_READABLE); } /* Drain the fd */ if (pyuv__drain_poll_fd(self->fd) != 0) { uv_poll_stop(handle); } /* Check for signals */ PyErr_CheckSignals(); if (PyErr_Occurred()) { handle_uncaught_exception(HANDLE(self)->loop); } Py_DECREF(self); PyGILState_Release(gstate); }
static void on_tcp_client_connection(uv_connect_t *req, int status) { PyGILState_STATE gstate = PyGILState_Ensure(); TCP *self; PyObject *callback, *result, *py_errorno; ASSERT(req); self = PYUV_CONTAINER_OF(req->handle, TCP, tcp_h); callback = (PyObject *)req->data; if (status != 0) { uv_err_t err = uv_last_error(UV_HANDLE_LOOP(self)); py_errorno = PyInt_FromLong(err.code); } else { py_errorno = Py_None; Py_INCREF(Py_None); } result = PyObject_CallFunctionObjArgs(callback, self, py_errorno, NULL); if (result == NULL) { handle_uncaught_exception(HANDLE(self)->loop); } Py_XDECREF(result); Py_DECREF(py_errorno); Py_DECREF(callback); PyMem_Free(req); /* Refcount was increased in the caller function */ Py_DECREF(self); PyGILState_Release(gstate); }
static void on_tcp_connection(uv_stream_t *handle, int status) { PyGILState_STATE gstate = PyGILState_Ensure(); TCP *self; PyObject *result, *py_errorno; ASSERT(handle); self = PYUV_CONTAINER_OF(handle, TCP, tcp_h); /* Object could go out of scope in the callback, increase refcount to avoid it */ Py_INCREF(self); if (status != 0) { uv_err_t err = uv_last_error(UV_HANDLE_LOOP(self)); py_errorno = PyInt_FromLong((long)err.code); } else { py_errorno = Py_None; Py_INCREF(Py_None); } result = PyObject_CallFunctionObjArgs(self->on_new_connection_cb, self, py_errorno, NULL); if (result == NULL) { handle_uncaught_exception(HANDLE(self)->loop); } Py_XDECREF(result); Py_DECREF(py_errorno); Py_DECREF(self); PyGILState_Release(gstate); }
static void on_udp_send(uv_udp_send_t* req, int status) { PyGILState_STATE gstate = PyGILState_Ensure(); int i; udp_send_ctx *ctx; UDP *self; PyObject *callback, *result, *py_errorno; ASSERT(req); ctx = PYUV_CONTAINER_OF(req, udp_send_ctx, req); self = PYUV_CONTAINER_OF(req->handle, UDP, udp_h); callback = ctx->callback; ASSERT(self); if (callback != Py_None) { if (status < 0) { py_errorno = PyInt_FromLong((long)status); } else { py_errorno = Py_None; Py_INCREF(Py_None); } result = PyObject_CallFunctionObjArgs(callback, self, py_errorno, NULL); if (result == NULL) { handle_uncaught_exception(HANDLE(self)->loop); } Py_XDECREF(result); Py_DECREF(py_errorno); } Py_DECREF(callback); for (i = 0; i < ctx->view_count; i++) { PyBuffer_Release(&ctx->views[i]); } if (ctx->views != ctx->view) { PyMem_Free(ctx->views); } PyMem_Free(ctx); /* Refcount was increased in the caller function */ Py_DECREF(self); PyGILState_Release(gstate); }
static void on_udp_read(uv_udp_t* handle, int nread, const uv_buf_t* buf, struct sockaddr* addr, unsigned flags) { PyGILState_STATE gstate = PyGILState_Ensure(); Loop *loop; UDP *self; PyObject *result, *address_tuple, *data, *py_errorno; ASSERT(handle); ASSERT(flags == 0); self = PYUV_CONTAINER_OF(handle, UDP, udp_h); /* Object could go out of scope in the callback, increase refcount to avoid it */ Py_INCREF(self); if (nread == 0) { goto done; } if (nread > 0) { ASSERT(addr); address_tuple = makesockaddr(addr, sizeof(*addr)); data = PyBytes_FromStringAndSize(buf->base, nread); py_errorno = Py_None; Py_INCREF(Py_None); } else { address_tuple = Py_None; Py_INCREF(Py_None); data = Py_None; Py_INCREF(Py_None); py_errorno = PyInt_FromLong((long)nread); } result = PyObject_CallFunctionObjArgs(self->on_read_cb, self, address_tuple, PyInt_FromLong((long)flags), data, py_errorno, NULL); if (result == NULL) { handle_uncaught_exception(HANDLE(self)->loop); } Py_XDECREF(result); Py_DECREF(address_tuple); Py_DECREF(data); Py_DECREF(py_errorno); done: /* data has been read, unlock the buffer */ loop = handle->loop->data; ASSERT(loop); loop->buffer.in_use = False; Py_DECREF(self); PyGILState_Release(gstate); }
static void on_timer_callback(uv_timer_t *handle) { PyGILState_STATE gstate = PyGILState_Ensure(); Timer *self; PyObject *result; ASSERT(handle); self = PYUV_CONTAINER_OF(handle, Timer, timer_h); /* Object could go out of scope in the callback, increase refcount to avoid it */ Py_INCREF(self); result = PyObject_CallFunctionObjArgs(self->callback, self, NULL); if (result == NULL) { handle_uncaught_exception(HANDLE(self)->loop); } Py_XDECREF(result); Py_DECREF(self); PyGILState_Release(gstate); }