1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-23 17:34:34 +03:00

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>
This commit is contained in:
Stefan Metzmacher 2015-06-11 09:51:19 +02:00
parent fb04f0f419
commit 93ee074f91

View File

@ -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;
}