From 8aafd569c8420d6f05a644bfc72f07d64e22ecf2 Mon Sep 17 00:00:00 2001 From: Michael Pratt Date: Thu, 7 Nov 2013 23:37:52 -0500 Subject: [PATCH] Support PyString_AsString() in Python 3 < 3.3 In Python 3, version 3.3+, PyUnicode_AsUTF8() provides similar functionality to Python 2's PyString_AsString(). In older versions of Python 3, there is no public function to provide the same functionality. However, the "internal" _PyUnicode_AsString() does provide that functionality, so use it to replace PyString_AsString(). With this patch, cv2 should compile for Python 3.[0-2]. --- modules/python/src2/pycompat.hpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/modules/python/src2/pycompat.hpp b/modules/python/src2/pycompat.hpp index c473fff..f4ebea6 100644 --- a/modules/python/src2/pycompat.hpp +++ b/modules/python/src2/pycompat.hpp @@ -56,9 +56,15 @@ // Python3 strings are unicode, these defines mimic the Python2 functionality. #define PyString_Check PyUnicode_Check #define PyString_FromString PyUnicode_FromString -#define PyString_AsString PyUnicode_AsUTF8 #define PyString_FromStringAndSize PyUnicode_FromStringAndSize #define PyString_Size PyUnicode_GET_SIZE + +// PyUnicode_AsUTF8 isn't available until Python 3.3 +#if (PY_VERSION_HEX < 0x03030000) +#define PyString_AsString _PyUnicode_AsString +#else +#define PyString_AsString PyUnicode_AsUTF8 +#endif #endif #endif // END HEADER GUARD -- 2.7.4