summaryrefslogtreecommitdiffstats
path: root/pyuno
diff options
context:
space:
mode:
Diffstat (limited to 'pyuno')
-rw-r--r--pyuno/inc/pyuno.hxx1
-rw-r--r--pyuno/source/loader/pythonloader.py4
-rw-r--r--pyuno/source/loader/pyuno_loader.cxx14
-rw-r--r--pyuno/source/module/pyuno.cxx28
-rw-r--r--pyuno/source/module/pyuno_callable.cxx19
-rw-r--r--pyuno/source/module/pyuno_iterator.cxx40
-rw-r--r--pyuno/source/module/pyuno_runtime.cxx45
-rw-r--r--pyuno/source/module/pyuno_struct.cxx19
-rw-r--r--pyuno/source/module/pyuno_type.cxx4
9 files changed, 154 insertions, 20 deletions
diff --git a/pyuno/inc/pyuno.hxx b/pyuno/inc/pyuno.hxx
index 04c42de6e93f..2838fa504e4d 100644
--- a/pyuno/inc/pyuno.hxx
+++ b/pyuno/inc/pyuno.hxx
@@ -275,6 +275,7 @@ public:
class LO_DLLPUBLIC_PYUNO PyThreadAttach
{
PyThreadState *tstate;
+ bool m_isNewState;
PyThreadAttach ( const PyThreadAttach & ) = delete;
PyThreadAttach & operator = ( const PyThreadAttach & ) = delete;
public:
diff --git a/pyuno/source/loader/pythonloader.py b/pyuno/source/loader/pythonloader.py
index ddb9001fc0e6..a6b75003d4c8 100644
--- a/pyuno/source/loader/pythonloader.py
+++ b/pyuno/source/loader/pythonloader.py
@@ -19,7 +19,7 @@
import uno
import unohelper
import sys
-import imp
+import types
import os
from com.sun.star.uno import Exception,RuntimeException
from com.sun.star.loader import XImplementationLoader
@@ -82,7 +82,7 @@ class Loader( XImplementationLoader, XServiceInfo, unohelper.Base ):
# did we load the module already ?
mod = g_loadedComponents.get( url )
if not mod:
- mod = imp.new_module("uno_component")
+ mod = types.ModuleType("uno_component")
# check for pythonpath.zip beside .py files
checkForPythonPathBesideComponent( url[0:url.rfind('/')] )
diff --git a/pyuno/source/loader/pyuno_loader.cxx b/pyuno/source/loader/pyuno_loader.cxx
index 31b4f8f494f9..db8eda2547eb 100644
--- a/pyuno/source/loader/pyuno_loader.cxx
+++ b/pyuno/source/loader/pyuno_loader.cxx
@@ -146,6 +146,7 @@ static void setPythonHome ( const OUString & pythonHome )
static void prependPythonPath( const OUString & pythonPathBootstrap )
{
OUStringBuffer bufPYTHONPATH( 256 );
+ bool bAppendSep = false;
sal_Int32 nIndex = 0;
while( true )
{
@@ -161,15 +162,24 @@ static void prependPythonPath( const OUString & pythonPathBootstrap )
}
OUString systemPath;
osl_getSystemPathFromFileURL( fileUrl.pData, &(systemPath.pData) );
- bufPYTHONPATH.append( systemPath );
- bufPYTHONPATH.append( static_cast<sal_Unicode>(SAL_PATHSEPARATOR) );
+ if (!systemPath.isEmpty())
+ {
+ if (bAppendSep)
+ bufPYTHONPATH.append(static_cast<sal_Unicode>(SAL_PATHSEPARATOR));
+ bufPYTHONPATH.append(systemPath);
+ bAppendSep = true;
+ }
if( nNew == -1 )
break;
nIndex = nNew + 1;
}
const char * oldEnv = getenv( "PYTHONPATH");
if( oldEnv )
+ {
+ if (bAppendSep)
+ bufPYTHONPATH.append( static_cast<sal_Unicode>(SAL_PATHSEPARATOR) );
bufPYTHONPATH.append( OUString(oldEnv, strlen(oldEnv), osl_getThreadTextEncoding()) );
+ }
OUString envVar("PYTHONPATH");
OUString envValue(bufPYTHONPATH.makeStringAndClear());
diff --git a/pyuno/source/module/pyuno.cxx b/pyuno/source/module/pyuno.cxx
index dc73a754609d..96b3a0d247ba 100644
--- a/pyuno/source/module/pyuno.cxx
+++ b/pyuno/source/module/pyuno.cxx
@@ -337,13 +337,14 @@ int lcl_PySlice_GetIndicesEx( PyObject *pObject, sal_Int32 nLen, sal_Int32 *nSta
{
Py_ssize_t nStart_ssize, nStop_ssize, nStep_ssize, nSliceLength_ssize;
- int nResult = PySlice_GetIndicesEx(
+ int nResult =
#if PY_VERSION_HEX >= 0x030200f0
- pObject,
+ PySlice_GetIndicesEx(pObject,
+ nLen, &nStart_ssize, &nStop_ssize, &nStep_ssize, &nSliceLength_ssize );
#else
- reinterpret_cast<PySliceObject*>(pObject),
-#endif
+ PySlice_GetIndicesEx(reinterpret_cast<PySliceObject*>(pObject),
nLen, &nStart_ssize, &nStop_ssize, &nStep_ssize, &nSliceLength_ssize );
+#endif
if (nResult == -1)
return -1;
@@ -1637,7 +1638,11 @@ static PyTypeObject PyUNOType =
sizeof (PyUNO),
0,
PyUNO_del,
- nullptr,
+#if PY_VERSION_HEX >= 0x03080000
+ 0, // Py_ssize_t tp_vectorcall_offset
+#else
+ nullptr, // printfunc tp_print
+#endif
PyUNO_getattr,
PyUNO_setattr,
/* this type does not exist in Python 3: (cmpfunc) */ nullptr,
@@ -1681,6 +1686,19 @@ static PyTypeObject PyUNOType =
, 0
#if PY_VERSION_HEX >= 0x03040000
, nullptr
+#if PY_VERSION_HEX >= 0x03080000
+ , nullptr // vectorcallfunc tp_vectorcall
+#if PY_VERSION_HEX < 0x03090000
+#if defined __clang__
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+#endif
+ , nullptr // tp_print
+#if defined __clang__
+#pragma clang diagnostic pop
+#endif
+#endif
+#endif
#endif
};
diff --git a/pyuno/source/module/pyuno_callable.cxx b/pyuno/source/module/pyuno_callable.cxx
index 2075fc7e372f..d7bc8fecf30f 100644
--- a/pyuno/source/module/pyuno_callable.cxx
+++ b/pyuno/source/module/pyuno_callable.cxx
@@ -180,7 +180,11 @@ static PyTypeObject PyUNO_callable_Type =
sizeof (PyUNO_callable),
0,
::pyuno::PyUNO_callable_del,
- nullptr,
+#if PY_VERSION_HEX >= 0x03080000
+ 0, // Py_ssize_t tp_vectorcall_offset
+#else
+ nullptr, // printfunc tp_print
+#endif
nullptr,
nullptr,
nullptr,
@@ -224,6 +228,19 @@ static PyTypeObject PyUNO_callable_Type =
, 0
#if PY_VERSION_HEX >= 0x03040000
, nullptr
+#if PY_VERSION_HEX >= 0x03080000
+ , nullptr // vectorcallfunc tp_vectorcall
+#if PY_VERSION_HEX < 0x03090000
+#if defined __clang__
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+#endif
+ , nullptr // tp_print
+#if defined __clang__
+#pragma clang diagnostic pop
+#endif
+#endif
+#endif
#endif
};
diff --git a/pyuno/source/module/pyuno_iterator.cxx b/pyuno/source/module/pyuno_iterator.cxx
index 5a36a32d516d..6c1b01c295be 100644
--- a/pyuno/source/module/pyuno_iterator.cxx
+++ b/pyuno/source/module/pyuno_iterator.cxx
@@ -111,7 +111,6 @@ PyObject* PyUNO_iterator_next( PyObject *self )
return nullptr;
}
-
static PyTypeObject PyUNO_iterator_Type =
{
PyVarObject_HEAD_INIT( &PyType_Type, 0 )
@@ -119,7 +118,11 @@ static PyTypeObject PyUNO_iterator_Type =
sizeof (PyUNO_iterator),
0,
PyUNO_iterator_del,
- nullptr,
+#if PY_VERSION_HEX >= 0x03080000
+ 0, // Py_ssize_t tp_vectorcall_offset
+#else
+ nullptr, // printfunc tp_print
+#endif
nullptr,
nullptr,
nullptr,
@@ -163,6 +166,19 @@ static PyTypeObject PyUNO_iterator_Type =
0
#if PY_VERSION_HEX >= 0x03040000
, nullptr
+#if PY_VERSION_HEX >= 0x03080000
+ , nullptr // vectorcallfunc tp_vectorcall
+#if PY_VERSION_HEX < 0x03090000
+#if defined __clang__
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+#endif
+ , nullptr // tp_print
+#if defined __clang__
+#pragma clang diagnostic pop
+#endif
+#endif
+#endif
#endif
};
@@ -241,7 +257,6 @@ PyObject* PyUNO_list_iterator_next( PyObject *self )
return nullptr;
}
-
static PyTypeObject PyUNO_list_iterator_Type =
{
PyVarObject_HEAD_INIT( &PyType_Type, 0 )
@@ -249,7 +264,11 @@ static PyTypeObject PyUNO_list_iterator_Type =
sizeof (PyUNO_list_iterator),
0,
PyUNO_list_iterator_del,
- nullptr,
+#if PY_VERSION_HEX >= 0x03080000
+ 0, // Py_ssize_t tp_vectorcall_offset
+#else
+ nullptr, // printfunc tp_print
+#endif
nullptr,
nullptr,
nullptr,
@@ -293,6 +312,19 @@ static PyTypeObject PyUNO_list_iterator_Type =
0
#if PY_VERSION_HEX >= 0x03040000
, nullptr
+#if PY_VERSION_HEX >= 0x03080000
+ , nullptr // vectorcallfunc tp_vectorcall
+#if PY_VERSION_HEX < 0x03090000
+#if defined __clang__
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+#endif
+ , nullptr // tp_print
+#if defined __clang__
+#pragma clang diagnostic pop
+#endif
+#endif
+#endif
#endif
};
diff --git a/pyuno/source/module/pyuno_runtime.cxx b/pyuno/source/module/pyuno_runtime.cxx
index 751c104dca04..4f115d44e5bc 100644
--- a/pyuno/source/module/pyuno_runtime.cxx
+++ b/pyuno/source/module/pyuno_runtime.cxx
@@ -74,7 +74,11 @@ static PyTypeObject RuntimeImpl_Type =
sizeof (RuntimeImpl),
0,
RuntimeImpl::del,
- nullptr,
+#if PY_VERSION_HEX >= 0x03080000
+ 0, // Py_ssize_t tp_vectorcall_offset
+#else
+ nullptr, // printfunc tp_print
+#endif
nullptr,
nullptr,
nullptr,
@@ -118,6 +122,19 @@ static PyTypeObject RuntimeImpl_Type =
, 0
#if PY_VERSION_HEX >= 0x03040000
, nullptr
+#if PY_VERSION_HEX >= 0x03080000
+ , nullptr // vectorcallfunc tp_vectorcall
+#if PY_VERSION_HEX < 0x03090000
+#if defined __clang__
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+#endif
+ , nullptr // tp_print
+#if defined __clang__
+#pragma clang diagnostic pop
+#endif
+#endif
+#endif
#endif
};
@@ -969,8 +986,16 @@ Any Runtime::extractUnoException( const PyRef & excType, const PyRef &excValue,
PyThreadAttach::PyThreadAttach( PyInterpreterState *interp)
+ : m_isNewState(false)
{
- tstate = PyThreadState_New( interp );
+ // note: *may* be called recursively, with PyThreadDetach between - in
+ // that case, don't create *new* PyThreadState but reuse!
+ tstate = PyGILState_GetThisThreadState(); // from TLS, possibly detached
+ if (!tstate)
+ {
+ m_isNewState = true;
+ tstate = PyThreadState_New( interp );
+ }
if( !tstate )
throw RuntimeException( "Couldn't create a pythreadstate" );
PyEval_AcquireThread( tstate);
@@ -978,9 +1003,19 @@ PyThreadAttach::PyThreadAttach( PyInterpreterState *interp)
PyThreadAttach::~PyThreadAttach()
{
- PyThreadState_Clear( tstate );
- PyEval_ReleaseThread( tstate );
- PyThreadState_Delete( tstate );
+ if (m_isNewState)
+ { // Clear needs GIL!
+ PyThreadState_Clear( tstate );
+ }
+ if (m_isNewState)
+ { // note: PyThreadState_Delete(tstate) cannot be called, it will assert
+ // because it requires a PyThreadState to be set, but not the tstate!
+ PyThreadState_DeleteCurrent();
+ }
+ else
+ {
+ PyEval_ReleaseThread( tstate );
+ }
}
PyThreadDetach::PyThreadDetach()
diff --git a/pyuno/source/module/pyuno_struct.cxx b/pyuno/source/module/pyuno_struct.cxx
index 2fbb81350387..e9093ee1376f 100644
--- a/pyuno/source/module/pyuno_struct.cxx
+++ b/pyuno/source/module/pyuno_struct.cxx
@@ -299,7 +299,11 @@ static PyTypeObject PyUNOStructType =
sizeof (PyUNO),
0,
PyUNOStruct_del,
- nullptr,
+#if PY_VERSION_HEX >= 0x03080000
+ 0, // Py_ssize_t tp_vectorcall_offset
+#else
+ nullptr, // printfunc tp_print
+#endif
PyUNOStruct_getattr,
PyUNOStruct_setattr,
/* this type does not exist in Python 3: (cmpfunc) */ nullptr,
@@ -343,6 +347,19 @@ static PyTypeObject PyUNOStructType =
, 0
#if PY_VERSION_HEX >= 0x03040000
, nullptr
+#if PY_VERSION_HEX >= 0x03080000
+ , nullptr // vectorcallfunc tp_vectorcall
+#if PY_VERSION_HEX < 0x03090000
+#if defined __clang__
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+#endif
+ , nullptr // tp_print
+#if defined __clang__
+#pragma clang diagnostic pop
+#endif
+#endif
+#endif
#endif
};
diff --git a/pyuno/source/module/pyuno_type.cxx b/pyuno/source/module/pyuno_type.cxx
index 80505d85bbd1..fc6385e2be1b 100644
--- a/pyuno/source/module/pyuno_type.cxx
+++ b/pyuno/source/module/pyuno_type.cxx
@@ -135,7 +135,11 @@ sal_Unicode PyChar2Unicode( PyObject *obj )
"attribute value of uno.Char is not a unicode string" );
}
+#if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 3
+ if( PyUnicode_GetLength( value.get() ) < 1 )
+#else
if( PyUnicode_GetSize( value.get() ) < 1 )
+#endif
{
throw RuntimeException(
"uno.Char contains an empty unicode string");