]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
talloc: remove Python 2 #if clauses
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Fri, 10 Feb 2023 02:53:10 +0000 (15:53 +1300)
committerAndreas Schneider <asn@cryptomilk.org>
Fri, 17 Feb 2023 14:52:26 +0000 (14:52 +0000)
Also fix an obsolete related comment.

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andreas Schneider <asn@samba.org>
Autobuild-User(master): Andreas Schneider <asn@cryptomilk.org>
Autobuild-Date(master): Fri Feb 17 14:52:26 UTC 2023 on atb-devel-224

lib/talloc/pytalloc.c
lib/talloc/test_pytalloc.c

index 41decc45f613750d3e5a9315ab7f481190fba6a6..9d62eed455e3618f1c495475bd110116f900682e 100644 (file)
@@ -101,9 +101,9 @@ static void pytalloc_dealloc(PyObject* self)
 }
 
 /**
- * Default (but only slightly more useful than the default) implementation of cmp.
+ * Default objects do not support ordered comparisons, but talloc
+ * objects do, sorting by pointers clustered by type.
  */
-#if PY_MAJOR_VERSION >= 3
 static PyObject *pytalloc_default_richcmp(PyObject *obj1, PyObject *obj2, int op)
 {
        void *ptr1;
@@ -131,17 +131,6 @@ static PyObject *pytalloc_default_richcmp(PyObject *obj1, PyObject *obj2, int op
        Py_INCREF(Py_NotImplemented);
        return Py_NotImplemented;
 }
-#else
-static int pytalloc_default_cmp(PyObject *_obj1, PyObject *_obj2)
-{
-       pytalloc_Object *obj1 = (pytalloc_Object *)_obj1,
-                                        *obj2 = (pytalloc_Object *)_obj2;
-       if (obj1->ob_type != obj2->ob_type)
-               return ((char *)obj1->ob_type - (char *)obj2->ob_type);
-
-       return ((char *)pytalloc_get_ptr(obj1) - (char *)pytalloc_get_ptr(obj2));
-}
-#endif
 
 static PyTypeObject TallocObject_Type = {
        .tp_name = "talloc.Object",
@@ -150,11 +139,7 @@ static PyTypeObject TallocObject_Type = {
        .tp_dealloc = (destructor)pytalloc_dealloc,
        .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
        .tp_repr = pytalloc_default_repr,
-#if PY_MAJOR_VERSION >= 3
        .tp_richcompare = pytalloc_default_richcmp,
-#else
-       .tp_compare = pytalloc_default_cmp,
-#endif
 };
 
 /**
@@ -181,9 +166,9 @@ static void pytalloc_base_dealloc(PyObject* self)
 }
 
 /**
- * Default (but only slightly more useful than the default) implementation of cmp.
+ * Default objects do not support ordered comparisons, but talloc
+ * objects do, sorting by pointers clustered by type.
  */
-#if PY_MAJOR_VERSION >= 3
 static PyObject *pytalloc_base_default_richcmp(PyObject *obj1, PyObject *obj2, int op)
 {
        void *ptr1;
@@ -211,17 +196,6 @@ static PyObject *pytalloc_base_default_richcmp(PyObject *obj1, PyObject *obj2, i
        Py_INCREF(Py_NotImplemented);
        return Py_NotImplemented;
 }
-#else
-static int pytalloc_base_default_cmp(PyObject *_obj1, PyObject *_obj2)
-{
-       pytalloc_BaseObject *obj1 = (pytalloc_BaseObject *)_obj1,
-                                        *obj2 = (pytalloc_BaseObject *)_obj2;
-       if (obj1->ob_type != obj2->ob_type)
-               return ((char *)obj1->ob_type - (char *)obj2->ob_type);
-
-       return ((char *)pytalloc_get_ptr(obj1) - (char *)pytalloc_get_ptr(obj2));
-}
-#endif
 
 static PyTypeObject TallocBaseObject_Type = {
        .tp_name = "talloc.BaseObject",
@@ -230,11 +204,7 @@ static PyTypeObject TallocBaseObject_Type = {
        .tp_dealloc = (destructor)pytalloc_base_dealloc,
        .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
        .tp_repr = pytalloc_base_default_repr,
-#if PY_MAJOR_VERSION >= 3
        .tp_richcompare = pytalloc_base_default_richcmp,
-#else
-       .tp_compare = pytalloc_base_default_cmp,
-#endif
 };
 
 static PyTypeObject TallocGenericObject_Type = {
@@ -247,7 +217,6 @@ static PyTypeObject TallocGenericObject_Type = {
 
 #define MODULE_DOC PyDoc_STR("Python wrapping of talloc-maintained objects.")
 
-#if PY_MAJOR_VERSION >= 3
 static struct PyModuleDef moduledef = {
     PyModuleDef_HEAD_INIT,
     .m_name = "talloc",
@@ -255,7 +224,6 @@ static struct PyModuleDef moduledef = {
     .m_size = -1,
     .m_methods = talloc_methods,
 };
-#endif
 
 static PyObject *module_init(void);
 static PyObject *module_init(void)
@@ -271,11 +239,7 @@ static PyObject *module_init(void)
        if (PyType_Ready(&TallocGenericObject_Type) < 0)
                return NULL;
 
-#if PY_MAJOR_VERSION >= 3
        m = PyModule_Create(&moduledef);
-#else
-       m = Py_InitModule3("talloc", talloc_methods, MODULE_DOC);
-#endif
        if (m == NULL)
                return NULL;
 
@@ -298,16 +262,8 @@ err:
        return NULL;
 }
 
-#if PY_MAJOR_VERSION >= 3
 PyMODINIT_FUNC PyInit_talloc(void);
 PyMODINIT_FUNC PyInit_talloc(void)
 {
        return module_init();
 }
-#else
-void inittalloc(void);
-void inittalloc(void)
-{
-       module_init();
-}
-#endif
index 3b0484b2274f06432694b03f9189dcecb30ced4d..aa05d8c342b8b0f1015966e8cb6790b8714d8f57 100644 (file)
@@ -181,7 +181,6 @@ static PyTypeObject DBaseObject_Type = {
 
 #define MODULE_DOC PyDoc_STR("Test utility module for pytalloc")
 
-#if PY_MAJOR_VERSION >= 3
 static struct PyModuleDef moduledef = {
     PyModuleDef_HEAD_INIT,
     .m_name = "_test_pytalloc",
@@ -189,7 +188,6 @@ static struct PyModuleDef moduledef = {
     .m_size = -1,
     .m_methods = test_talloc_methods,
 };
-#endif
 
 static PyObject *module_init(void);
 static PyObject *module_init(void)
@@ -207,11 +205,7 @@ static PyObject *module_init(void)
                return NULL;
        }
 
-#if PY_MAJOR_VERSION >= 3
        m = PyModule_Create(&moduledef);
-#else
-       m = Py_InitModule3("_test_pytalloc", test_talloc_methods, MODULE_DOC);
-#endif
 
        if (m == NULL) {
                return NULL;
@@ -229,16 +223,8 @@ static PyObject *module_init(void)
 }
 
 
-#if PY_MAJOR_VERSION >= 3
 PyMODINIT_FUNC PyInit__test_pytalloc(void);
 PyMODINIT_FUNC PyInit__test_pytalloc(void)
 {
        return module_init();
 }
-#else
-void init_test_pytalloc(void);
-void init_test_pytalloc(void)
-{
-       module_init();
-}
-#endif