From 25d2cec7abc4ee8be391dd13dd7fcd623e81408f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Houz=C3=A9fa=20Abbasbhay?= Date: Mon, 1 Dec 2014 12:21:05 +0100 Subject: [PATCH] Python 3: Defs for int & string related functions --- bindings/python/wrapper_top.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/bindings/python/wrapper_top.c b/bindings/python/wrapper_top.c index c15dc0de..2cc845ec 100644 --- a/bindings/python/wrapper_top.c +++ b/bindings/python/wrapper_top.c @@ -13,6 +13,24 @@ typedef int Py_ssize_t; #define PY_SSIZE_T_MIN INT_MIN #endif +/** @todo Remove Python 3 defines and update the code when Python 2 is out of the picture. */ + +// Python 3 has unified int & long types. +#if PY_MAJOR_VERSION >= 3 +#define PyInt_AS_LONG PyLong_AS_LONG +#define PyInt_Check PyLong_Check +#define PyInt_FromLong PyLong_FromLong +#endif + +// Python 3 has removed PyString and related functions, in favor of PyBytes & PyUnicode. +#if PY_MAJOR_VERSION >= 3 +#define PyString_AsString PyUnicode_AsUnicode +#define PyString_Check PyUnicode_Check +#define PyString_FromFormat PyUnicode_FromFormat +#define PyString_FromString PyUnicode_FromString +#define PyString_Size PyUnicode_GET_LENGTH +#endif + GQuark lasso_wrapper_key; PyMODINIT_FUNC init_lasso(void);