Permalink
Browse files

Removed SignalChecker

It doesn't work anymore. Signal handles should be used instead for
signal handling. The idea of SignalChecker may return if the behavior
changes inside libuv, but it will not be in its current form.
Anywayit's not a big deal now since a way for proper handling of signals
is provided.
  • Loading branch information...
saghul committed Dec 30, 2012
1 parent 6dad9e5 commit 80c145da91248a0828d30a12453a0e85c132b675
Showing with 0 additions and 347 deletions.
  1. +0 −2 src/error.c
  2. +0 −1 src/pyuv.c
  3. +0 −11 src/pyuv.h
  4. +0 −333 src/signal.c
View
@@ -41,7 +41,6 @@ init_error(void)
PyExc_FSEventError = PyErr_NewException("pyuv.error.FSEventError", PyExc_HandleError, NULL);
PyExc_FSPollError = PyErr_NewException("pyuv.error.FSPollError", PyExc_HandleError, NULL);
PyExc_ProcessError = PyErr_NewException("pyuv.error.ProcessError", PyExc_HandleError, NULL);
- PyExc_SignalCheckerError = PyErr_NewException("pyuv.error.SignalCheckerError", PyExc_UVError, NULL);
PyUVModule_AddType(module, "UVError", (PyTypeObject *)PyExc_UVError);
PyUVModule_AddType(module, "HandleError", (PyTypeObject *)PyExc_HandleError);
@@ -61,7 +60,6 @@ init_error(void)
PyUVModule_AddType(module, "FSEventError", (PyTypeObject *)PyExc_FSEventError);
PyUVModule_AddType(module, "FSPollError", (PyTypeObject *)PyExc_FSPollError);
PyUVModule_AddType(module, "ProcessError", (PyTypeObject *)PyExc_ProcessError);
- PyUVModule_AddType(module, "SignalCheckerError", (PyTypeObject *)PyExc_SignalCheckerError);
return module;
}
View
@@ -180,7 +180,6 @@ init_pyuv(void)
PyUVModule_AddType(pyuv, "Poll", &PollType);
PyUVModule_AddType(pyuv, "StdIO", &StdIOType);
PyUVModule_AddType(pyuv, "Process", &ProcessType);
- PyUVModule_AddType(pyuv, "SignalChecker", &SignalCheckerType);
/* Loop.run modes */
PyModule_AddIntMacro(pyuv, UV_RUN_DEFAULT);
View
@@ -161,16 +161,6 @@ typedef struct {
static PyTypeObject SignalType;
-/* SignalChecker */
-typedef struct {
- PyObject_HEAD
- Loop *loop;
- uv_prepare_t *prepare_handle;
- uv_check_t *check_handle;
-} SignalChecker;
-
-static PyTypeObject SignalCheckerType;
-
/* Stream */
typedef struct {
Handle handle;
@@ -340,7 +330,6 @@ static PyObject* PyExc_PollError;
static PyObject* PyExc_PrepareError;
static PyObject* PyExc_ProcessError;
static PyObject* PyExc_SignalError;
-static PyObject* PyExc_SignalCheckerError;
static PyObject* PyExc_StreamError;
static PyObject* PyExc_TCPError;
static PyObject* PyExc_TimerError;
View
@@ -198,336 +198,3 @@ static PyTypeObject SignalType = {
};
-#define PYUV_CHECK_SIGNALS(handle) \
- do { \
- PyErr_CheckSignals(); \
- if (PyErr_Occurred()) { \
- handle_uncaught_exception(handle->loop); \
- } \
- } while (0) \
-
-
-#define RAISE_IF_SIGNAL_CHECKER_CLOSED(self) \
- do { \
- if (!self->prepare_handle || uv_is_closing((uv_handle_t *)self->prepare_handle) || !self->check_handle || uv_is_closing((uv_handle_t *)self->check_handle)) { \
- PyErr_SetString(PyExc_SignalCheckerError, "Signal checker is closed"); \
- return NULL; \
- } \
- } while (0) \
-
-
-static void
-on_signal_checker_prepare_cb(uv_prepare_t *handle, int status)
-{
- PyGILState_STATE gstate = PyGILState_Ensure();
- SignalChecker *self;
-
- ASSERT(handle);
- self = (SignalChecker *)handle->data;
- ASSERT(self);
-
- PYUV_CHECK_SIGNALS(self);
-
- PyGILState_Release(gstate);
-}
-
-
-static void
-on_signal_checker_check_cb(uv_check_t *handle, int status)
-{
- PyGILState_STATE gstate = PyGILState_Ensure();
- SignalChecker *self;
-
- ASSERT(handle);
- self = (SignalChecker *)handle->data;
- ASSERT(self);
-
- PYUV_CHECK_SIGNALS(self);
-
- PyGILState_Release(gstate);
-}
-
-
-static PyObject *
-SignalChecker_func_start(SignalChecker *self)
-{
- int r;
- Bool error = False;
-
- RAISE_IF_SIGNAL_CHECKER_CLOSED(self);
-
- r = uv_prepare_start(self->prepare_handle, on_signal_checker_prepare_cb);
- if (r != 0) {
- RAISE_UV_EXCEPTION(UV_LOOP(self), PyExc_SignalCheckerError);
- error = True;
- }
- r = uv_check_start(self->check_handle, on_signal_checker_check_cb);
- if (r != 0) {
- if (!error) {
- RAISE_UV_EXCEPTION(UV_LOOP(self), PyExc_SignalCheckerError);
- error = True;
- }
- }
-
- if (error) {
- uv_prepare_stop(self->prepare_handle);
- uv_check_stop(self->check_handle);
- return NULL;
- }
-
- uv_unref((uv_handle_t *)self->prepare_handle);
- uv_unref((uv_handle_t *)self->check_handle);
-
- Py_RETURN_NONE;
-}
-
-
-static PyObject *
-SignalChecker_func_stop(SignalChecker *self)
-{
- int r;
- Bool error = False;
-
- RAISE_IF_SIGNAL_CHECKER_CLOSED(self);
-
- r = uv_prepare_stop(self->prepare_handle);
- if (r != 0) {
- RAISE_UV_EXCEPTION(UV_LOOP(self), PyExc_SignalCheckerError);
- error = True;
- }
- r = uv_check_stop(self->check_handle);
- if (r != 0) {
- if (!error) {
- RAISE_UV_EXCEPTION(UV_LOOP(self), PyExc_SignalCheckerError);
- error = True;
- }
- }
-
- if (error) {
- return NULL;
- }
-
- Py_RETURN_NONE;
-}
-
-
-static PyObject *
-SignalChecker_func_close(SignalChecker *self, PyObject *args)
-{
- RAISE_IF_SIGNAL_CHECKER_CLOSED(self);
-
- Py_DECREF(self->loop);
- self->loop = (Loop *)Py_None;
- Py_INCREF(Py_None);
-
- uv_close((uv_handle_t *)self->prepare_handle, on_handle_dealloc_close);
- uv_close((uv_handle_t *)self->check_handle, on_handle_dealloc_close);
-
- Py_RETURN_NONE;
-}
-
-
-static PyObject *
-SignalChecker_active_get(SignalChecker *self, void *closure)
-{
- UNUSED_ARG(closure);
- if (!self->prepare_handle || !self->check_handle) {
- Py_RETURN_FALSE;
- } else {
- return PyBool_FromLong((long)(uv_is_active((uv_handle_t *)self->prepare_handle) && uv_is_active((uv_handle_t *)self->check_handle)));
- }
-}
-
-
-static PyObject *
-SignalChecker_closed_get(SignalChecker *self, void *closure)
-{
- UNUSED_ARG(closure);
- if (!self->prepare_handle || !self->check_handle) {
- Py_RETURN_TRUE;
- } else {
- return PyBool_FromLong((long)(uv_is_closing((uv_handle_t *)self->prepare_handle) && uv_is_closing((uv_handle_t *)self->check_handle)));
- }
-}
-
-
-static int
-SignalChecker_tp_init(SignalChecker *self, PyObject *args, PyObject *kwargs)
-{
- int r;
- Bool error = False;
- uv_prepare_t *uv_prepare = NULL;
- uv_check_t *uv_check = NULL;
- Loop *loop;
- PyObject *tmp = NULL;
-
- UNUSED_ARG(kwargs);
-
- if (self->prepare_handle || self->check_handle) {
- PyErr_SetString(PyExc_SignalCheckerError, "Object already initialized");
- return -1;
- }
-
- if (!PyArg_ParseTuple(args, "O!:__init__", &LoopType, &loop)) {
- return -1;
- }
-
- tmp = (PyObject *)self->loop;
- Py_INCREF(loop);
- self->loop = loop;
- Py_XDECREF(tmp);
-
- uv_prepare = PyMem_Malloc(sizeof(uv_prepare_t));
- if (!uv_prepare) {
- PyErr_NoMemory();
- goto error;
- }
-
- uv_check = PyMem_Malloc(sizeof(uv_check_t));
- if (!uv_check) {
- PyErr_NoMemory();
- goto error;
- }
-
- r = uv_prepare_init(UV_LOOP(self), uv_prepare);
- if (r != 0) {
- RAISE_UV_EXCEPTION(UV_LOOP(self), PyExc_SignalCheckerError);
- error = True;
- }
- r = uv_check_init(UV_LOOP(self), uv_check);
- if (r != 0) {
- if (!error) {
- RAISE_UV_EXCEPTION(UV_LOOP(self), PyExc_SignalCheckerError);
- error = True;
- }
- }
-
- if (error) {
- goto error;
- }
-
- uv_prepare->data = (void *)self;
- uv_check->data = (void *)self;
- self->prepare_handle = uv_prepare;
- self->check_handle = uv_check;
- return 0;
-
-error:
- if (uv_prepare) {
- PyMem_Free(uv_prepare);
- }
- if (uv_check) {
- PyMem_Free(uv_check);
- }
- Py_DECREF(loop);
- return -1;
-}
-
-
-static PyObject *
-SignalChecker_tp_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
-{
- SignalChecker *self = (SignalChecker *)PyType_GenericNew(type, args, kwargs);
- if (!self) {
- return NULL;
- }
- self->prepare_handle = NULL;
- self->check_handle = NULL;
- return (PyObject *)self;
-}
-
-
-static int
-SignalChecker_tp_traverse(SignalChecker *self, visitproc visit, void *arg)
-{
- Py_VISIT(self->loop);
- return 0;
-}
-
-
-static int
-SignalChecker_tp_clear(SignalChecker *self)
-{
- Py_CLEAR(self->loop);
- return 0;
-}
-
-
-static void
-SignalChecker_tp_dealloc(SignalChecker *self)
-{
- if (self->prepare_handle) {
- uv_close((uv_handle_t *)self->prepare_handle, on_handle_dealloc_close);
- }
- if (self->check_handle) {
- uv_close((uv_handle_t *)self->check_handle, on_handle_dealloc_close);
- }
- Py_TYPE(self)->tp_clear((PyObject *)self);
- Py_TYPE(self)->tp_free((PyObject *)self);
-}
-
-
-static PyMethodDef
-SignalChecker_tp_methods[] = {
- { "start", (PyCFunction)SignalChecker_func_start, METH_NOARGS, "Start the SignalChecker." },
- { "stop", (PyCFunction)SignalChecker_func_stop, METH_NOARGS, "Stop the SignalChecker." },
- { "close", (PyCFunction)SignalChecker_func_close, METH_NOARGS, "Close the SignalChecker." },
- { NULL }
-};
-
-
-static PyMemberDef SignalChecker_tp_members[] = {
- {"loop", T_OBJECT_EX, offsetof(SignalChecker, loop), READONLY, "Loop where this handle belongs."},
- {NULL}
-};
-
-
-static PyGetSetDef SignalChecker_tp_getsets[] = {
- {"active", (getter)SignalChecker_active_get, NULL, "Indicates if this handle is active.", NULL},
- {"closed", (getter)SignalChecker_closed_get, NULL, "Indicates if this handle is closing or already closed.", NULL},
- {NULL}
-};
-
-
-static PyTypeObject SignalCheckerType = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "pyuv.SignalChecker", /*tp_name*/
- sizeof(SignalChecker), /*tp_basicsize*/
- 0, /*tp_itemsize*/
- (destructor)SignalChecker_tp_dealloc, /*tp_dealloc*/
- 0, /*tp_print*/
- 0, /*tp_getattr*/
- 0, /*tp_setattr*/
- 0, /*tp_compare*/
- 0, /*tp_repr*/
- 0, /*tp_as_number*/
- 0, /*tp_as_sequence*/
- 0, /*tp_as_mapping*/
- 0, /*tp_hash */
- 0, /*tp_call*/
- 0, /*tp_str*/
- 0, /*tp_getattro*/
- 0, /*tp_setattro*/
- 0, /*tp_as_buffer*/
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
- 0, /*tp_doc*/
- (traverseproc)SignalChecker_tp_traverse, /*tp_traverse*/
- (inquiry)SignalChecker_tp_clear, /*tp_clear*/
- 0, /*tp_richcompare*/
- 0, /*tp_weaklistoffset*/
- 0, /*tp_iter*/
- 0, /*tp_iternext*/
- SignalChecker_tp_methods, /*tp_methods*/
- SignalChecker_tp_members, /*tp_members*/
- SignalChecker_tp_getsets, /*tp_getsets*/
- 0, /*tp_base*/
- 0, /*tp_dict*/
- 0, /*tp_descr_get*/
- 0, /*tp_descr_set*/
- 0, /*tp_dictoffset*/
- (initproc)SignalChecker_tp_init, /*tp_init*/
- 0, /*tp_alloc*/
- SignalChecker_tp_new, /*tp_new*/
-};
-
-

0 comments on commit 80c145d

Please sign in to comment.