aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside2/PySide2/glue
diff options
context:
space:
mode:
authorCristián Maureira-Fredes <cristian.maureira-fredes@qt.io>2020-01-29 11:57:05 +0100
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2020-02-05 10:16:52 +0100
commit821480b1f0d0cfb59df427315c29c364096818c4 (patch)
treec033e26734c0ea19081347651ae6425cd5870974 /sources/pyside2/PySide2/glue
parent95ec3e2ca7a0a06c0750f78e0c4e44e09f5347f2 (diff)
Fix PyBuffer interface for QByteArray
For the limited API, properly implement the PyBUF_ND flag (shape requested). Otherwise, use the convenience function PyBuffer_FillInfo() to properly populate the view. Fixes: PYSIDE-1204 Change-Id: I2a4c81885cf49b25c89823577c0d7ee2f2707b87 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'sources/pyside2/PySide2/glue')
-rw-r--r--sources/pyside2/PySide2/glue/qtcore.cpp10
1 files changed, 9 insertions, 1 deletions
diff --git a/sources/pyside2/PySide2/glue/qtcore.cpp b/sources/pyside2/PySide2/glue/qtcore.cpp
index 8bcc315b2..d99a150ad 100644
--- a/sources/pyside2/PySide2/glue/qtcore.cpp
+++ b/sources/pyside2/PySide2/glue/qtcore.cpp
@@ -1046,6 +1046,7 @@ static int SbkQByteArray_getbufferproc(PyObject *obj, Py_buffer *view, int flags
QByteArray * cppSelf = %CONVERTTOCPP[QByteArray *](obj);
//XXX /|\ omitting this space crashes shiboken!
+ #ifdef Py_LIMITED_API
view->obj = obj;
view->buf = reinterpret_cast<void *>(cppSelf->data());
view->len = cppSelf->size();
@@ -1053,13 +1054,20 @@ static int SbkQByteArray_getbufferproc(PyObject *obj, Py_buffer *view, int flags
view->itemsize = 1;
view->format = const_cast<char *>("c");
view->ndim = 1;
- view->shape = NULL;
+ view->shape = (flags & PyBUF_ND) == PyBUF_ND ? &(view->len) : nullptr;
view->strides = &view->itemsize;
view->suboffsets = NULL;
view->internal = NULL;
Py_XINCREF(obj);
return 0;
+#else // Py_LIMITED_API
+ const int result = PyBuffer_FillInfo(view, obj, reinterpret_cast<void *>(cppSelf->data()),
+ cppSelf->size(), 0, flags);
+ if (result == 0)
+ Py_XINCREF(obj);
+ return result;
+#endif
}
#if PY_VERSION_HEX < 0x03000000