summaryrefslogtreecommitdiff
path: root/python/generic.h
diff options
context:
space:
mode:
authorMichael Vogt <michael.vogt@ubuntu.com>2012-10-23 12:41:37 +0200
committerMichael Vogt <michael.vogt@ubuntu.com>2012-10-23 12:41:37 +0200
commitb485b22c8d4caf3e22c65a4b426137d68b8404af (patch)
treef5fd0ac1890e7e127ad59ec06c76d14dde3f1e1c /python/generic.h
parent9f4b8cb3fbf1be70aa22811aad3880306b77058b (diff)
parent6bd628c370b05b80b59552e4bbc970928aca91a1 (diff)
downloadpython-apt-b485b22c8d4caf3e22c65a4b426137d68b8404af.tar.gz
merged from the mvo branch
Diffstat (limited to 'python/generic.h')
-rw-r--r--python/generic.h4
1 files changed, 4 insertions, 0 deletions
diff --git a/python/generic.h b/python/generic.h
index f9680ca5..914456e2 100644
--- a/python/generic.h
+++ b/python/generic.h
@@ -80,10 +80,14 @@ typedef int Py_ssize_t;
static inline const char *PyUnicode_AsString(PyObject *op) {
// Convert to bytes object, using the default encoding.
+#if PY_MAJOR_VERSION >= 3 && PY_MINOR_VERSION >= 3
+ return PyUnicode_AsUTF8(op);
+#else
// Use Python-internal API, there is no other way to do this
// without a memory leak.
PyObject *bytes = _PyUnicode_AsDefaultEncodedString(op, 0);
return bytes ? PyBytes_AS_STRING(bytes) : 0;
+#endif
}
// Convert any type of string based object to a const char.