aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken2/libshiboken
diff options
context:
space:
mode:
Diffstat (limited to 'sources/shiboken2/libshiboken')
-rw-r--r--sources/shiboken2/libshiboken/basewrapper.cpp2
-rw-r--r--sources/shiboken2/libshiboken/pep384impl.cpp2
-rw-r--r--sources/shiboken2/libshiboken/pep384impl.h2
-rw-r--r--sources/shiboken2/libshiboken/sbkpython.h1
-rw-r--r--sources/shiboken2/libshiboken/sbkstring.cpp10
-rw-r--r--sources/shiboken2/libshiboken/sbkstring.h4
-rw-r--r--sources/shiboken2/libshiboken/voidptr.cpp9
7 files changed, 20 insertions, 10 deletions
diff --git a/sources/shiboken2/libshiboken/basewrapper.cpp b/sources/shiboken2/libshiboken/basewrapper.cpp
index 0e2712ec8..b46fbaef2 100644
--- a/sources/shiboken2/libshiboken/basewrapper.cpp
+++ b/sources/shiboken2/libshiboken/basewrapper.cpp
@@ -545,7 +545,7 @@ void init()
PyEval_InitThreads();
//Init private data
- Pep_Init();
+ Pep384_Init();
Shiboken::ObjectType::initPrivateData(SbkObject_TypeF());
diff --git a/sources/shiboken2/libshiboken/pep384impl.cpp b/sources/shiboken2/libshiboken/pep384impl.cpp
index 2707d3716..d2407444d 100644
--- a/sources/shiboken2/libshiboken/pep384impl.cpp
+++ b/sources/shiboken2/libshiboken/pep384impl.cpp
@@ -910,7 +910,7 @@ PepType_GetNameStr(PyTypeObject *type)
*/
void
-Pep_Init()
+Pep384_Init()
{
check_PepTypeObject_valid();
#ifdef Py_LIMITED_API
diff --git a/sources/shiboken2/libshiboken/pep384impl.h b/sources/shiboken2/libshiboken/pep384impl.h
index fc0e3b40e..69e984816 100644
--- a/sources/shiboken2/libshiboken/pep384impl.h
+++ b/sources/shiboken2/libshiboken/pep384impl.h
@@ -564,7 +564,7 @@ extern LIBSHIBOKEN_API PyTypeObject *PepStaticMethod_TypePtr;
*
*/
-LIBSHIBOKEN_API void Pep_Init(void);
+LIBSHIBOKEN_API void Pep384_Init(void);
} // extern "C"
diff --git a/sources/shiboken2/libshiboken/sbkpython.h b/sources/shiboken2/libshiboken/sbkpython.h
index 5fe364a29..a26c318d1 100644
--- a/sources/shiboken2/libshiboken/sbkpython.h
+++ b/sources/shiboken2/libshiboken/sbkpython.h
@@ -76,7 +76,6 @@
#define SbkNumber_Check(X) \
(PyNumber_Check(X) && (!PyInstance_Check(X) || PyObject_HasAttrString(X, "__trunc__")))
#define SBK_NB_BOOL(x) (x).nb_nonzero
- #define SBK_STR_NAME "str"
#define SBK_PyMethod_New(X, Y) PyMethod_New(X, Y, reinterpret_cast<PyObject *>(Py_TYPE(Y)))
#define Py_hash_t long
diff --git a/sources/shiboken2/libshiboken/sbkstring.cpp b/sources/shiboken2/libshiboken/sbkstring.cpp
index b92674383..6ca35f12e 100644
--- a/sources/shiboken2/libshiboken/sbkstring.cpp
+++ b/sources/shiboken2/libshiboken/sbkstring.cpp
@@ -99,18 +99,24 @@ const char* toCString(PyObject* str, Py_ssize_t* len)
{
if (str == Py_None)
return NULL;
-#ifdef IS_PY3K
if (PyUnicode_Check(str)) {
if (len) {
// We need to encode the unicode string into utf8 to know the size of returned char*.
Shiboken::AutoDecRef uniStr(PyUnicode_AsUTF8String(str));
*len = PyBytes_GET_SIZE(uniStr.object());
}
+#ifdef IS_PY3K
// Return unicode from str instead of uniStr, because the lifetime of the returned pointer
// depends on the lifetime of str.
return _PepUnicode_AsString(str);
- }
+#else
+ str = PyUnicode_AsUTF8String(str);
+ if (str == NULL) {
+ return NULL;
+ }
+ return PyString_AsString(str);
#endif
+ }
if (PyBytes_Check(str)) {
if (len)
*len = PyBytes_GET_SIZE(str);
diff --git a/sources/shiboken2/libshiboken/sbkstring.h b/sources/shiboken2/libshiboken/sbkstring.h
index d437f1c77..a6b5fbeed 100644
--- a/sources/shiboken2/libshiboken/sbkstring.h
+++ b/sources/shiboken2/libshiboken/sbkstring.h
@@ -44,9 +44,9 @@
#include "shibokenmacros.h"
#if PY_MAJOR_VERSION >= 3
- #define SBK_STR_NAME "unicode"
+ #define SBK_BYTES_NAME "bytes"
#else
- #define SBK_STR_NAME "str"
+ #define SBK_BYTES_NAME "str"
#endif
namespace Shiboken
diff --git a/sources/shiboken2/libshiboken/voidptr.cpp b/sources/shiboken2/libshiboken/voidptr.cpp
index afb3f4040..94c667598 100644
--- a/sources/shiboken2/libshiboken/voidptr.cpp
+++ b/sources/shiboken2/libshiboken/voidptr.cpp
@@ -55,8 +55,13 @@ typedef struct {
PyObject *SbkVoidPtrObject_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
- SbkVoidPtrObject *self =
- reinterpret_cast<SbkVoidPtrObject *>(PepType(type)->tp_alloc);
+ // PYSIDE-560: It is much safer to first call a function and then do a
+ // type cast than to do everything in one line. The bad construct looked
+ // like this, actual call forgotten:
+ // SbkVoidPtrObject *self =
+ // reinterpret_cast<SbkVoidPtrObject *>(PepType(type)->tp_alloc);
+ PyObject *ob = PepType(type)->tp_alloc(type, 0);
+ SbkVoidPtrObject *self = reinterpret_cast<SbkVoidPtrObject *>(ob);
if (self != 0) {
self->cptr = 0;