aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken2
diff options
context:
space:
mode:
Diffstat (limited to 'sources/shiboken2')
-rw-r--r--sources/shiboken2/libshiboken/bufferprocs_py37.cpp2
-rw-r--r--sources/shiboken2/libshiboken/pep384impl.cpp2
-rw-r--r--sources/shiboken2/libshiboken/pep384impl.h37
-rw-r--r--sources/shiboken2/libshiboken/pep384impl_doc.rst6
-rw-r--r--sources/shiboken2/libshiboken/sbkpython.h2
-rw-r--r--sources/shiboken2/libshiboken/sbkstring.cpp2
6 files changed, 38 insertions, 13 deletions
diff --git a/sources/shiboken2/libshiboken/bufferprocs_py37.cpp b/sources/shiboken2/libshiboken/bufferprocs_py37.cpp
index ddb07390e..da6bb00a3 100644
--- a/sources/shiboken2/libshiboken/bufferprocs_py37.cpp
+++ b/sources/shiboken2/libshiboken/bufferprocs_py37.cpp
@@ -47,7 +47,7 @@
#ifdef Py_LIMITED_API
-#include "pep384impl.h"
+#include "sbkpython.h"
/* Buffer C-API for Python 3.0 */
int
diff --git a/sources/shiboken2/libshiboken/pep384impl.cpp b/sources/shiboken2/libshiboken/pep384impl.cpp
index 622efd201..9939bb410 100644
--- a/sources/shiboken2/libshiboken/pep384impl.cpp
+++ b/sources/shiboken2/libshiboken/pep384impl.cpp
@@ -37,7 +37,7 @@
**
****************************************************************************/
-#include "pep384impl.h"
+#include "sbkpython.h"
#include "autodecref.h"
#include "sbkstaticstrings.h"
#include "sbkstaticstrings_p.h"
diff --git a/sources/shiboken2/libshiboken/pep384impl.h b/sources/shiboken2/libshiboken/pep384impl.h
index 6d0fa2450..c18f00804 100644
--- a/sources/shiboken2/libshiboken/pep384impl.h
+++ b/sources/shiboken2/libshiboken/pep384impl.h
@@ -40,8 +40,6 @@
#ifndef PEP384IMPL_H
#define PEP384IMPL_H
-#include "sbkpython.h"
-
extern "C"
{
@@ -204,17 +202,40 @@ LIBSHIBOKEN_API int Pep_GetVerboseFlag(void);
* RESOLVED: unicodeobject.h
*
*/
-#ifdef Py_LIMITED_API
-
-LIBSHIBOKEN_API char *_PepUnicode_AsString(PyObject *);
+///////////////////////////////////////////////////////////////////////
+//
+// PYSIDE-813: About The Length Of Unicode Objects
+// -----------------------------------------------
+//
+// In Python 2 and before Python 3.3, the macro PyUnicode_GET_SIZE
+// worked fine and really like a macro.
+//
+// Meanwhile, the unicode objects have changed their layout very much,
+// and the former cheap macro call has become a real function call
+// that converts objects and needs PyMemory.
+// PyUnicode_GET_SIZE was retained for compatibility reasons.
+//
+// That is not only inefficient, but also requires the GIL!
+// This problem was visible by debug Python and qdatastream_test.py .
+// It was found while fixing the refcount problem of PYSIDE-813 which
+// needed a debug Python.
+//
+
+// PyUnicode_GetSize is deprecated in favor of PyUnicode_GetLength.
+// We undefine the PyUnicode_GET_SIZE macro, to be sure that it is not used
+// by accident. Only PepUnicode_GetLength should be used.
+#undef PyUnicode_GET_SIZE
#if PY_VERSION_HEX < 0x03000000
-#define PyUnicode_GET_SIZE(op) PyUnicode_GetSize((PyObject *)(op))
+#define PepUnicode_GetLength(op) PyUnicode_GetSize((PyObject *)(op))
#else
-// PyUnicode_GetSize is deprecated in favor of PyUnicode_GetLength
-#define PyUnicode_GET_SIZE(op) PyUnicode_GetLength((PyObject *)(op))
+#define PepUnicode_GetLength(op) PyUnicode_GetLength((PyObject *)(op))
#endif
+#ifdef Py_LIMITED_API
+
+LIBSHIBOKEN_API char *_PepUnicode_AsString(PyObject *);
+
#else
#define _PepUnicode_AsString PyUnicode_AsUTF8
#endif
diff --git a/sources/shiboken2/libshiboken/pep384impl_doc.rst b/sources/shiboken2/libshiboken/pep384impl_doc.rst
index 2f3b7ea97..ac4b053a7 100644
--- a/sources/shiboken2/libshiboken/pep384impl_doc.rst
+++ b/sources/shiboken2/libshiboken/pep384impl_doc.rst
@@ -70,8 +70,10 @@ supported. We redefined it as macro ``Py_VerboseFlag`` which calls ``Pep_Verbose
unicodeobject.h
---------------
-The macro ``PyUnicode_GET_SIZE`` was redefined to call into ``PyUnicode_GetSize``
-for Python 2, and ``PyUnicode_GetLength`` for Python 3.
+The macro ``PyUnicode_GET_SIZE`` was removed and replaced by ``PepUnicode_GetLength``
+which evaluates to ``PyUnicode_GetSize`` for Python 2 and ``PyUnicode_GetLength`` for Python 3.
+Since Python 3.3, ``PyUnicode_GetSize`` would have the bad side effect of requiring the GIL!
+
Function ``_PyUnicode_AsString`` is unavailable and was replaced by a macro
that calls ``_PepUnicode_AsString``. The implementation was a bit involved,
and it would be better to change the code and replace this function.
diff --git a/sources/shiboken2/libshiboken/sbkpython.h b/sources/shiboken2/libshiboken/sbkpython.h
index f06b0b19e..9dd1e712e 100644
--- a/sources/shiboken2/libshiboken/sbkpython.h
+++ b/sources/shiboken2/libshiboken/sbkpython.h
@@ -72,6 +72,7 @@ extern "C" {
// Now we have the usual variables from Python.h .
# include "python25compat.h"
# include "shibokenmacros.h"
+// "pep384impl.h" may nowhere be included but in this file.
# include "pep384impl.h"
# include "typespec.h"
# pragma pop_macro("slots")
@@ -98,6 +99,7 @@ extern "C" {
// Now we have the usual variables from Python.h .
# include "python25compat.h"
# include "shibokenmacros.h"
+// "pep384impl.h" may nowhere be included but in this file.
# include "pep384impl.h"
# include "typespec.h"
#endif
diff --git a/sources/shiboken2/libshiboken/sbkstring.cpp b/sources/shiboken2/libshiboken/sbkstring.cpp
index 4a441222f..38bb105d0 100644
--- a/sources/shiboken2/libshiboken/sbkstring.cpp
+++ b/sources/shiboken2/libshiboken/sbkstring.cpp
@@ -202,7 +202,7 @@ Py_ssize_t len(PyObject *str)
return 0;
if (PyUnicode_Check(str))
- return PyUnicode_GET_SIZE(str);
+ return PepUnicode_GetLength(str);
if (PyBytes_Check(str))
return PyBytes_GET_SIZE(str);