Merge pull request #1716 from ZackerySpytz/Python-utf8-cache
Use PyUnicode_AsUTF8() for Python >= 3.3
diff --git a/Lib/python/pyhead.swg b/Lib/python/pyhead.swg
index 9a55d76..b3bd39d 100644
--- a/Lib/python/pyhead.swg
+++ b/Lib/python/pyhead.swg
@@ -37,7 +37,9 @@
SWIGINTERN char*
SWIG_Python_str_AsChar(PyObject *str)
{
-#if PY_VERSION_HEX >= 0x03000000
+#if PY_VERSION_HEX >= 0x03030000
+ return (char *)PyUnicode_AsUTF8(str);
+#elif PY_VERSION_HEX >= 0x03000000
char *newstr = 0;
str = PyUnicode_AsUTF8String(str);
if (str) {
@@ -56,10 +58,10 @@
#endif
}
-#if PY_VERSION_HEX >= 0x03000000
-# define SWIG_Python_str_DelForPy3(x) free( (void*) (x) )
+#if PY_VERSION_HEX >= 0x03030000 || PY_VERSION_HEX < 0x03000000
+# define SWIG_Python_str_DelForPy3(x)
#else
-# define SWIG_Python_str_DelForPy3(x)
+# define SWIG_Python_str_DelForPy3(x) free( (void*) (x) )
#endif