*/
#include <Python.h>
+#include "replace.h"
#include <tevent.h>
#if PY_MAJOR_VERSION >= 3
return NULL;
}
- if (!PyStr_Check(name)) {
+ if (!(PyStr_Check(name) || PyUnicode_Check(name))) {
PyErr_SetNone(PyExc_TypeError);
Py_DECREF(name);
return NULL;
{
PyObject *callback = private_data, *ret;
- ret = PyObject_CallFunction(callback, "");
+ ret = PyObject_CallFunction(callback, discard_const_p(char, ""));
Py_XDECREF(ret);
}
Py_RETURN_NONE;
}
-#ifdef TEVENT_DEPRECATED
-static bool py_tevent_finished(PyObject *callback)
-{
- PyObject *py_ret;
- bool ret;
-
- py_ret = PyObject_CallFunction(callback, "");
- if (py_ret == NULL)
- return true;
- ret = PyObject_IsTrue(py_ret);
- Py_DECREF(py_ret);
- return ret;
-}
-
-static PyObject *py_tevent_context_loop_until(TeventContext_Object *self, PyObject *args)
-{
- PyObject *callback;
- if (!PyArg_ParseTuple(args, "O", &callback))
- return NULL;
-
- if (tevent_loop_until(self->ev, py_tevent_finished, callback) != 0) {
- PyErr_SetNone(PyExc_RuntimeError);
- return NULL;
- }
-
- if (PyErr_Occurred())
- return NULL;
-
- Py_RETURN_NONE;
-}
-#endif
-
static void py_tevent_signal_handler(struct tevent_context *ev,
struct tevent_signal *se,
int signum,
{
PyObject *callback = (PyObject *)private_data, *ret;
- ret = PyObject_CallFunction(callback, "ii", signum, count);
+ ret = PyObject_CallFunction(callback, discard_const_p(char, "ii"), signum, count);
Py_XDECREF(ret);
}
TeventTimer_Object *self = private_data;
PyObject *ret;
- ret = PyObject_CallFunction(self->callback, "l", te);
+ ret = PyObject_CallFunction(self->callback, discard_const_p(char, "l"), te);
if (ret == NULL) {
/* No Python stack to propagate exception to; just print traceback */
PyErr_PrintEx(0);
struct PyGetSetDef py_tevent_timer_getset[] = {
{
- .name = "active",
+ .name = discard_const_p(char, "active"),
.get = (getter)py_tevent_timer_get_active,
- .doc = "true if the timer is scheduled to run",
+ .doc = discard_const_p(char, "true if the timer is scheduled to run"),
},
{NULL},
};
.tp_flags = Py_TPFLAGS_DEFAULT,
};
-static int timer_destructor(void* ptr)
+struct TeventTimer_Object_ref {
+ TeventTimer_Object *obj;
+};
+
+static int TeventTimer_Object_ref_destructor(struct TeventTimer_Object_ref *ref)
{
- TeventTimer_Object *obj = *(TeventTimer_Object **)ptr;
- obj->timer = NULL;
- Py_DECREF(obj);
+ ref->obj->timer = NULL;
+ Py_DECREF(ref->obj);
return 0;
}
* The Python timer holds a reference to the callback.
*/
TeventTimer_Object *ret;
- TeventTimer_Object **tmp_context;
+ struct TeventTimer_Object_ref *ref;
ret = PyObject_New(TeventTimer_Object, &TeventTimer_Type);
if (ret == NULL) {
PyErr_SetString(PyExc_RuntimeError, "Could not initialize timer");
return NULL;
}
- tmp_context = talloc(ret->timer, TeventTimer_Object*);
- if (tmp_context == NULL) {
+ ref = talloc(ret->timer, struct TeventTimer_Object_ref);
+ if (ref == NULL) {
talloc_free(ret->timer);
Py_DECREF(ret);
PyErr_SetString(PyExc_RuntimeError, "Could not initialize timer");
return NULL;
}
Py_INCREF(ret);
- *tmp_context = ret;
- talloc_set_destructor(tmp_context, timer_destructor);
+ ref->obj = ret;
+
+ talloc_set_destructor(ref, TeventTimer_Object_ref_destructor);
return (PyObject *)ret;
}
{
struct timeval next_event;
PyObject *callback;
- if (!PyArg_ParseTuple(args, "lO", &next_event, &callback))
+ double secs, usecs;
+ if (!PyArg_ParseTuple(args, "dO", &secs, &callback)){
return NULL;
-
+ }
+ next_event.tv_sec = secs;
+ usecs = (secs - next_event.tv_sec) * 1000000.0;
+ next_event.tv_usec = usecs;
return py_tevent_context_add_timer_internal(self, next_event, callback);
}
{
PyObject *callback = private_data, *ret;
- ret = PyObject_CallFunction(callback, "i", flags);
+ ret = PyObject_CallFunction(callback, discard_const_p(char, "i"), flags);
Py_XDECREF(ret);
}
return (PyObject *)ret;
}
-#ifdef TEVENT_DEPRECATED
-static PyObject *py_tevent_context_set_allow_nesting(TeventContext_Object *self)
-{
- tevent_loop_allow_nesting(self->ev);
- Py_RETURN_NONE;
-}
-#endif
-
static PyMethodDef py_tevent_context_methods[] = {
{ "reinitialise", (PyCFunction)py_tevent_context_reinitialise, METH_NOARGS,
"S.reinitialise()" },
METH_NOARGS, "S.loop_wait()" },
{ "loop_once", (PyCFunction)py_tevent_context_loop_once,
METH_NOARGS, "S.loop_once()" },
-#ifdef TEVENT_DEPRECATED
- { "loop_until", (PyCFunction)py_tevent_context_loop_until,
- METH_VARARGS, "S.loop_until(callback)" },
-#endif
{ "add_signal", (PyCFunction)py_tevent_context_add_signal,
METH_VARARGS, "S.add_signal(signum, sa_flags, handler) -> signal" },
{ "add_timer", (PyCFunction)py_tevent_context_add_timer,
METH_VARARGS, "S.add_timer(offset_seconds, handler) -> timer" },
{ "add_fd", (PyCFunction)py_tevent_context_add_fd,
METH_VARARGS, "S.add_fd(fd, flags, handler) -> fd" },
-#ifdef TEVENT_DEPRECATED
- { "allow_nesting", (PyCFunction)py_tevent_context_set_allow_nesting,
- METH_NOARGS, "Whether to allow nested tevent loops." },
-#endif
{ NULL },
};
}
static PyGetSetDef py_tevent_req_getsetters[] = {
- { "in_progress", (getter)py_tevent_req_is_in_progress, NULL,
- "Whether the request is in progress" },
+ {
+ .name = discard_const_p(char, "in_progress"),
+ .get = (getter)py_tevent_req_is_in_progress,
+ .doc = discard_const_p(char, "Whether the request is in progress"),
+ },
{ NULL }
};
}
static PyGetSetDef py_tevent_queue_getsetters[] = {
- { "length", (getter)py_tevent_queue_get_length,
- NULL, "The number of elements in the queue." },
+ {
+ .name = discard_const_p(char, "length"),
+ .get = (getter)py_tevent_queue_get_length,
+ .doc = discard_const_p(char, "The number of elements in the queue."),
+ },
{ NULL },
};
}
static PyGetSetDef py_tevent_context_getsetters[] = {
- { "signal_support", (getter)py_tevent_context_signal_support,
- NULL, "if this platform and tevent context support signal handling" },
+ {
+ .name = discard_const_p(char, "signal_support"),
+ .get = (getter)py_tevent_context_signal_support,
+ .doc = discard_const_p(char, "if this platform and tevent context support signal handling"),
+ },
{ NULL }
};
struct tevent_context *ev;
TeventContext_Object *ret;
- if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|s", kwnames, &name))
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|s", discard_const_p(char *, kwnames), &name))
return NULL;
if (name == NULL) {