From 4509276e7147042c753ec7180d1dd8e1f5923906 Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Mon, 21 Oct 2019 00:19:44 +0100 Subject: [PATCH] *.c: Use the new `Py_TYPE' and `Py_SIZE' macros; define them if necessary. Python 2.6 introduced macros to access object header fields, which is handy because Python 3 changes the way object headers are structured. (I think the binary layout is unchanged, but the C-level structuring is definitely different.) This is the start of Python 3 porting work. --- pyke.h | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/pyke.h b/pyke.h index 2934543..e6d465e 100644 --- a/pyke.h +++ b/pyke.h @@ -62,6 +62,18 @@ 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 *); -- 2.11.0