chiark / gitweb /
*.c: Use the new `Py_TYPE' and `Py_SIZE' macros; define them if necessary.
[pyke] / pyke.h
diff --git a/pyke.h b/pyke.h
index 293454377ddc0a89c89b1006f639903faf49026f..e6d465ef080b522f48d09e5c585417f2bc6a76b3 100644 (file)
--- a/pyke.h
+++ b/pyke.h
 
 PRIVATE_SYMBOLS;
 
+/*----- Python version compatibility hacks --------------------------------*/
+
+/* The handy `Py_TYPE' and `Py_SIZE' macros turned up in 2.6.  Define them if
+ * they're not already here.
+ */
+#ifndef Py_TYPE
+#  define Py_TYPE(obj) (((PyObject *)(obj))->ob_type)
+#endif
+#ifndef Py_SIZE
+#  define Py_SIZE(obj) (((PyVarObject *)(obj))->ob_size)
+#endif
+
 /*----- Utilities for returning values and exceptions ---------------------*/
 
 /* Returning values. */
@@ -153,8 +165,7 @@ extern PyObject *getulong(unsigned long); /* any kind of unsigned integer */
 
 /*----- Miscellaneous utilities -------------------------------------------*/
 
-#define FREEOBJ(obj)                                                   \
-  (((PyObject *)(obj))->ob_type->tp_free((PyObject *)(obj)))
+#define FREEOBJ(obj) (Py_TYPE(obj)->tp_free((PyObject *)(obj)))
   /* Actually free OBJ, e.g., in a deallocation function. */
 
 extern PyObject *abstract_pynew(PyTypeObject *, PyObject *, PyObject *);