commit 39dc7185a8dea4ee8d865916295f2fafd7347c68
Author: Ronan Dunklau <ronan.dunklau@dalibo.com>
Date:   Tue Apr 12 09:03:19 2016 +0200

    Fix string conversion compat layer for Python 3
    
    Many thanks to Christoph Berg for the initial report and the
    help provided in debugging this.

diff --git a/src/python.c b/src/python.c
index 152b4ad..3d9c8b6 100644
--- a/src/python.c
+++ b/src/python.c
@@ -174,7 +174,6 @@ PyString_AsString(PyObject *unicode)
 {
 	char	   *rv;
 	PyObject   *o = PyUnicode_AsEncodedString(unicode, GetDatabaseEncodingName(), NULL);
-
 	errorCheck();
 	rv = pstrdup(PyBytes_AsString(o));
 	Py_XDECREF(o);
@@ -186,12 +185,14 @@ PyString_AsStringAndSize(PyObject *obj, char **buffer, Py_ssize_t *length)
 {
 	PyObject   *o;
 	int			rv;
+	char *tempbuffer;
 
 	if (PyUnicode_Check(obj))
 	{
 		o = PyUnicode_AsEncodedString(obj, GetDatabaseEncodingName(), NULL);
 		errorCheck();
-		rv = PyBytes_AsStringAndSize(o, buffer, length);
+		rv = PyBytes_AsStringAndSize(o, &tempbuffer, length);
+		*buffer = pstrdup(tempbuffer);
 		Py_XDECREF(o);
 		return rv;
 	}
