summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2011-01-02 22:34:26 +0100
committerJelmer Vernooij <jelmer@samba.org>2011-01-03 01:48:05 +0100
commit0346f5163227f52d8656a923b86099770609dff4 (patch)
tree6eac72d3a995dc8070fbec1abb27b409fb48c8d2
parentfdb0aa2b04a5be5f13c39fd42818f898b839ef0f (diff)
downloadsamba-0346f5163227f52d8656a923b86099770609dff4.tar.gz
samba-0346f5163227f52d8656a923b86099770609dff4.tar.bz2
samba-0346f5163227f52d8656a923b86099770609dff4.zip
pyldb: Always return -1, 0, or 1 in tp_compare functions.
-rw-r--r--source4/lib/ldb/pyldb.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/source4/lib/ldb/pyldb.c b/source4/lib/ldb/pyldb.c
index e74cae2d20..47d12b928d 100644
--- a/source4/lib/ldb/pyldb.c
+++ b/source4/lib/ldb/pyldb.c
@@ -60,6 +60,8 @@ typedef intargfunc ssizeargfunc;
#define Py_RETURN_NONE return Py_INCREF(Py_None), Py_None
#endif
+#define SIGN(a) (((a) == 0)?0:((a) < 0?-1:1))
+
static void PyErr_SetLdbError(PyObject *error, int ret, struct ldb_context *ldb_ctx)
{
if (ret == LDB_ERR_PYTHON_EXCEPTION)
@@ -1868,8 +1870,9 @@ static PySequenceMethods py_ldb_msg_element_seq = {
static int py_ldb_msg_element_cmp(PyLdbMessageElementObject *self, PyLdbMessageElementObject *other)
{
- return ldb_msg_element_compare(PyLdbMessageElement_AsMessageElement(self),
- PyLdbMessageElement_AsMessageElement(other));
+ int ret = ldb_msg_element_compare(PyLdbMessageElement_AsMessageElement(self),
+ PyLdbMessageElement_AsMessageElement(other));
+ return SIGN(ret);
}
static PyObject *py_ldb_msg_element_iter(PyLdbMessageElementObject *self)
@@ -2372,26 +2375,26 @@ static int py_ldb_msg_compare(PyLdbMessageObject *py_msg1,
if ((msg1->dn != NULL) || (msg2->dn != NULL)) {
ret = ldb_dn_compare(msg1->dn, msg2->dn);
if (ret != 0) {
- return ret;
+ return SIGN(ret);
}
}
ret = msg1->num_elements - msg2->num_elements;
if (ret != 0) {
- return ret;
+ return SIGN(ret);
}
for (i = 0; i < msg1->num_elements; i++) {
ret = ldb_msg_element_compare_name(&msg1->elements[i],
&msg2->elements[i]);
if (ret != 0) {
- return ret;
+ return SIGN(ret);
}
ret = ldb_msg_element_compare(&msg1->elements[i],
&msg2->elements[i]);
if (ret != 0) {
- return ret;
+ return SIGN(ret);
}
}