summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2015-06-11 09:51:19 +0200
committerStefan Metzmacher <metze@samba.org>2015-06-12 17:08:19 +0200
commit93ee074f912da02d4c1f1584df9b107364b639be (patch)
tree9a75e5096b3de42b28cb27cac9edbf993d8696d3 /lib
parentfb04f0f4190005ff21817b79d02897af23ddc7ee (diff)
downloadsamba-93ee074f912da02d4c1f1584df9b107364b639be.tar.gz
pytevent: add a TeventTimer_Object_ref helper structure to make the code clearer
This gives talloc_set_destructor to verify the type, which removes a compiler warning. Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Michael Adam <obnox@samba.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/tevent/pytevent.c22
1 files changed, 13 insertions, 9 deletions
diff --git a/lib/tevent/pytevent.c b/lib/tevent/pytevent.c
index 03d18589aff..10d8a22a8cf 100644
--- a/lib/tevent/pytevent.c
+++ b/lib/tevent/pytevent.c
@@ -401,11 +401,14 @@ static PyTypeObject TeventTimer_Type = {
.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;
}
@@ -440,7 +443,7 @@ static PyObject *py_tevent_context_add_timer_internal(TeventContext_Object *self
* 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) {
@@ -456,16 +459,17 @@ static PyObject *py_tevent_context_add_timer_internal(TeventContext_Object *self
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;
}