diff options
author | Andrew Bartlett <abartlet@samba.org> | 2009-07-06 09:31:38 +1000 |
---|---|---|
committer | Andrew Bartlett <abartlet@samba.org> | 2009-07-06 09:50:47 +1000 |
commit | f45a9d63e5a1697a7e85b123b535d2dc05f9fd8c (patch) | |
tree | 6ed175c9269cb78ad6b05f78bf9d2fdb34cc6bc8 /source4 | |
parent | da45d5215d1da2a1ff1b72b9bc3f10ec2192fba9 (diff) | |
download | samba-f45a9d63e5a1697a7e85b123b535d2dc05f9fd8c.tar.gz samba-f45a9d63e5a1697a7e85b123b535d2dc05f9fd8c.tar.bz2 samba-f45a9d63e5a1697a7e85b123b535d2dc05f9fd8c.zip |
s4:ldb Rework use of talloc and ldif objects in python wrapper
The talloc hirarchy here was a bit odd - we would both steal the
parsed ldif onto 'NULL', then reference it onto a python talloc
wrapper.
Now we just leave the reference, after we complete building the object.
Andrew Bartlett
Diffstat (limited to 'source4')
-rw-r--r-- | source4/lib/ldb/pyldb.c | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/source4/lib/ldb/pyldb.c b/source4/lib/ldb/pyldb.c index 9bdd71db18..2e0f4fdf36 100644 --- a/source4/lib/ldb/pyldb.c +++ b/source4/lib/ldb/pyldb.c @@ -790,7 +790,6 @@ static PyObject *ldb_ldif_to_pyobject(struct ldb_ldif *ldif) Py_RETURN_NONE; } else { /* We don't want this attached to the 'ldb' any more */ - talloc_steal(NULL, ldif); return Py_BuildValue(discard_const_p(char, "(iO)"), ldif->changetype, PyLdbMessage_FromMessage(ldif->msg)); @@ -804,13 +803,29 @@ static PyObject *py_ldb_parse_ldif(PyLdbObject *self, PyObject *args) struct ldb_ldif *ldif; const char *s; + TALLOC_CTX *mem_ctx; + if (!PyArg_ParseTuple(args, "s", &s)) return NULL; + mem_ctx = talloc_new(NULL); + if (!mem_ctx) { + Py_RETURN_NONE; + } + list = PyList_New(0); - while ((ldif = ldb_ldif_read_string(self->ldb_ctx, &s)) != NULL) { - PyList_Append(list, ldb_ldif_to_pyobject(ldif)); + while (s && *s != '\0') { + ldif = ldb_ldif_read_string(self->ldb_ctx, &s); + talloc_steal(mem_ctx, ldif); + if (ldif) { + PyList_Append(list, ldb_ldif_to_pyobject(ldif)); + } else { + PyErr_SetString(PyExc_ValueError, "unable to parse ldif string"); + talloc_free(mem_ctx); + return NULL; + } } + talloc_free(mem_ctx); /* The pyobject already has a reference to the things it needs */ return PyObject_GetIter(list); } |