This is an automated email from the ASF dual-hosted git repository.

mseidel pushed a commit to branch AOO42X
in repository https://gitbox.apache.org/repos/asf/openoffice.git

commit 3df2737ca010ccdeca49710afd6535548f04954b
Author: Pedro Giffuni <[email protected]>
AuthorDate: Tue Jan 14 21:38:18 2020 -0500

    Workaround most of the Python 3 issues.
    
    (cherry picked from commit d1c4de67fb18833166e1ea82395d623806d5e7a6)
---
 main/pyuno/source/loader/pyuno_loader.cxx | 9 +++++++++
 main/pyuno/source/module/pyuno.cxx        | 6 +++---
 main/pyuno/source/module/pyuno_util.cxx   | 2 +-
 3 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/main/pyuno/source/loader/pyuno_loader.cxx 
b/main/pyuno/source/loader/pyuno_loader.cxx
index f8884d7..62b8460 100644
--- a/main/pyuno/source/loader/pyuno_loader.cxx
+++ b/main/pyuno/source/loader/pyuno_loader.cxx
@@ -113,8 +113,17 @@ static void setPythonHome ( const OUString & pythonHome )
     OUString systemPythonHome;
     osl_getSystemPathFromFileURL( pythonHome.pData, &(systemPythonHome.pData) 
);
     OString o = rtl::OUStringToOString( systemPythonHome, 
osl_getThreadTextEncoding() );
+#if PY_MAJOR_VERSION < 3 || PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION <= 4
     rtl_string_acquire(o.pData); // leak this string (thats the api!)
     Py_SetPythonHome( o.pData->buffer);
+#else
+    wchar_t *wpath = Py_DecodeLocale(o.pData->buffer, NULL);
+    if (wpath == NULL) {
+       PyErr_SetString(PyExc_SystemError, "Cannot decode python home path");
+       return;
+    }
+    Py_SetPythonHome(wpath);
+#endif
 }
 
 static void prependPythonPath( const OUString & pythonPathBootstrap )
diff --git a/main/pyuno/source/module/pyuno.cxx 
b/main/pyuno/source/module/pyuno.cxx
index 38f5782..30506b5 100644
--- a/main/pyuno/source/module/pyuno.cxx
+++ b/main/pyuno/source/module/pyuno.cxx
@@ -450,7 +450,7 @@ PyObject* PyUNO_getattr (PyObject* self, char* name)
 {
     PyUNO* me;
 
-#if PY_VERSION_HEX >= 0x03030000
+#if PY_VERSION_HEX >= 0x03030000 && PY_VERSION_HEX < 0x03060000
     char *name = PyUnicode_AsUTF8(attr_name);
 #elif PY_MAJOR_VERSION >= 3
     PyRef pUtf8(PyUnicode_AsUTF8String(attr_name), SAL_NO_ACQUIRE);
@@ -568,7 +568,7 @@ int PyUNO_setattr (PyObject* self, char* name, PyObject* 
value)
 {
     PyUNO* me;
 
-#if PY_VERSION_HEX >= 0x03030000
+#if PY_VERSION_HEX >= 0x03030000 && PY_VERSION_HEX < 0x03060000
     char *name = PyUnicode_AsUTF8(attr_name);
 #elif PY_MAJOR_VERSION >= 3
     PyRef pUtf8(PyUnicode_AsUTF8String(attr_name), SAL_NO_ACQUIRE);
@@ -818,7 +818,7 @@ static PyTypeObject PyUNOType =
     NULL,
     NULL,
     (destructor)0
-#if PY_VERSION_HEX >= 0x02060000
+#if PY_VERSION_HEX >= 0x02060000 && PY_VERSION_HEX < 0x03060000
     , 0
 #endif
 };
diff --git a/main/pyuno/source/module/pyuno_util.cxx 
b/main/pyuno/source/module/pyuno_util.cxx
index 77df033..6cdd7ec 100644
--- a/main/pyuno/source/module/pyuno_util.cxx
+++ b/main/pyuno/source/module/pyuno_util.cxx
@@ -86,7 +86,7 @@ OUString pyString2ustring( PyObject *pystr )
 #if Py_UNICODE_SIZE == 2
        ret = OUString( (sal_Unicode * ) PyUnicode_AS_UNICODE( pystr ) );
 #else
-#if PY_VERSION_HEX >= 0x03030000
+#if PY_VERSION_HEX >= 0x03030000 && PY_VERSION_HEX < 0x03060000
     Py_ssize_t size;
     char *pUtf8 = PyUnicode_AsUTF8AndSize(pystr, &size);
     ret = OUString(pUtf8, size, RTL_TEXTENCODING_UTF8);

Reply via email to