}
/**
- * 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;
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",
.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
};
/**
}
/**
- * 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;
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",
.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 = {
#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",
.m_size = -1,
.m_methods = talloc_methods,
};
-#endif
static PyObject *module_init(void);
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;
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
#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",
.m_size = -1,
.m_methods = test_talloc_methods,
};
-#endif
static PyObject *module_init(void);
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;
}
-#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