From 0f31394ec0025674f4bb5a8a88b5a075fb32f151 Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Sat, 12 Dec 2015 08:55:15 +1100 Subject: [PATCH] Make sure python compares/hashes panes properly. Two python objects for the same pane must compare and hash the same. Signed-off-by: NeilBrown --- lang-python.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lang-python.c b/lang-python.c index 2714bb3c..17dee29a 100644 --- a/lang-python.c +++ b/lang-python.c @@ -376,6 +376,16 @@ static PyObject *pane_repr(Pane *p) return Py_BuildValue("s", buf); } +static long pane_hash(Pane *p) +{ + return (long)p->pane; +} + +static long pane_cmp(Pane *p1, Pane *p2) +{ + return (long)p1->pane - (long)p2->pane; +} + static PyGetSetDef pane_getseters[] = { {"x", (getter)pane_getnum, (setter)pane_setnum, @@ -417,12 +427,12 @@ static PyTypeObject PaneType = { 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ - 0, /*tp_compare*/ + (cmpfunc)pane_cmp, /*tp_compare*/ (reprfunc)pane_repr, /*tp_repr*/ 0, /*tp_as_number*/ 0, /*tp_as_sequence*/ 0, /*tp_as_mapping*/ - 0, /*tp_hash */ + (hashfunc)pane_hash, /*tp_hash */ 0, /*tp_call*/ 0, /*tp_str*/ 0, /*tp_getattro*/ -- 2.39.5