pytalloc: Add default compare function.
authorJelmer Vernooij <jelmer@samba.org>
Tue, 21 Sep 2010 07:40:17 +0000 (00:40 -0700)
committerJelmer Vernooij <jelmer@samba.org>
Tue, 21 Sep 2010 18:47:03 +0000 (11:47 -0700)
lib/talloc/pytalloc.c
lib/talloc/pytalloc.h
pidl/lib/Parse/Pidl/Samba4/Python.pm

index 054704f42d78e1c869ffd20dd483bb949e6680ec..bea6961efc94d7aa60a39c49a82ee59aba63c058 100644 (file)
@@ -88,7 +88,7 @@ PyObject *py_talloc_reference_ex(PyTypeObject *py_type, TALLOC_CTX *mem_ctx, voi
 }
 
 /**
- * Default (but slightly more useful than the default) implementation of Repr().
+ * Default (but only slightly more useful than the default) implementation of Repr().
  */
 PyObject *py_talloc_default_repr(PyObject *obj)
 {
@@ -99,6 +99,19 @@ PyObject *py_talloc_default_repr(PyObject *obj)
                                   type->tp_name, talloc_obj->ptr);
 }
 
+/**
+ * Default (but only slightly more useful than the default) implementation of cmp.
+ */
+int py_talloc_default_cmp(PyObject *_obj1, PyObject *_obj2)
+{
+       py_talloc_Object *obj1 = (py_talloc_Object *)_obj1,
+                                        *obj2 = (py_talloc_Object *)_obj2;
+       if (obj1->ob_type != obj2->ob_type)
+               return (obj1->ob_type - obj2->ob_type);
+
+       return (py_talloc_get_ptr(obj1) - py_talloc_get_ptr(obj2));
+}
+
 static void py_cobject_talloc_free(void *ptr)
 {
        talloc_free(ptr);
index 478275635223e535dedf7bfd85cfaacb1f7c5718..b17977a46c74a269a4ae6cdcf8d44ff38f9c54f8 100644 (file)
@@ -55,5 +55,6 @@ PyObject *py_talloc_default_repr(PyObject *py_obj);
 PyObject *PyCObject_FromTallocPtr(void *);
 
 PyObject *PyString_FromString_check_null(const char *ptr);
+int py_talloc_default_cmp(PyObject *obj1, PyObject *obj2);
 
 #endif /* _PY_TALLOC_H_ */
index ed43ba4d3e58183bb43858b43c45d0d659ea6e75..bc56f17fea0d353207e45eed96b1e802fc8c5d62 100644 (file)
@@ -325,6 +325,7 @@ sub PythonStruct($$$$$$)
        $self->pidl(".tp_dealloc = py_talloc_dealloc,");
        $self->pidl(".tp_getset = $getsetters,");
        $self->pidl(".tp_repr = py_talloc_default_repr,");
+       $self->pidl(".tp_compare = py_talloc_default_cmp,");
        if ($docstring) {
                $self->pidl(".tp_doc = $docstring,");
        }