diff options
-rw-r--r-- | sources/pyside6/PySide6/glue/qtcore.cpp | 4 | ||||
-rw-r--r-- | sources/pyside6/tests/QtCore/qbytearray_test.py | 8 |
2 files changed, 10 insertions, 2 deletions
diff --git a/sources/pyside6/PySide6/glue/qtcore.cpp b/sources/pyside6/PySide6/glue/qtcore.cpp index 1759fc044..4d755606c 100644 --- a/sources/pyside6/PySide6/glue/qtcore.cpp +++ b/sources/pyside6/PySide6/glue/qtcore.cpp @@ -802,10 +802,10 @@ static int SbkQByteArray_getbufferproc(PyObject *obj, Py_buffer *view, int flags view->len = cppSelf->size(); view->readonly = 0; view->itemsize = 1; - view->format = const_cast<char *>("c"); + view->format = (flags & PyBUF_FORMAT) == PyBUF_FORMAT ? const_cast<char *>("B") : nullptr; view->ndim = 1; view->shape = (flags & PyBUF_ND) == PyBUF_ND ? &(view->len) : nullptr; - view->strides = &view->itemsize; + view->strides = (flags & PyBUF_STRIDES) == PyBUF_STRIDES ? &(view->itemsize) : nullptr; view->suboffsets = nullptr; view->internal = nullptr; diff --git a/sources/pyside6/tests/QtCore/qbytearray_test.py b/sources/pyside6/tests/QtCore/qbytearray_test.py index c00674859..1a870fcde 100644 --- a/sources/pyside6/tests/QtCore/qbytearray_test.py +++ b/sources/pyside6/tests/QtCore/qbytearray_test.py @@ -6,6 +6,7 @@ import ctypes import os import pickle +import struct import sys import unittest @@ -255,6 +256,13 @@ class QByteArraySliceAssignment(unittest.TestCase): actual_bytes = bytes(byte_array) self.assertEqual(orig_bytes, actual_bytes) + def testUnpack(self): + b = QByteArray(b'\x19\x00\x00\x00\xc4\t\x00\x00') + t = struct.unpack('<ii', b) + self.assertEqual(len(t), 2) + self.assertEqual(t[0], 25) + self.assertEqual(t[1], 2500) + if __name__ == '__main__': unittest.main() |