aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken2/libshiboken/shibokenbuffer.cpp
diff options
context:
space:
mode:
authorSimo Fält <simo.falt@qt.io>2023-05-25 11:12:40 +0300
committerSimo Fält <simo.falt@qt.io>2023-05-25 11:12:40 +0300
commitca0519cb3f6b62e3b61ba74f0c60eac891dd3a15 (patch)
tree46e94d1b9a77648ca080a36b7d266f2322031d67 /sources/shiboken2/libshiboken/shibokenbuffer.cpp
parent72d32f66685fbb7fefc41eee629e63f4824cb10b (diff)
parent7c386888b453b7f2ac78ef1da59d077b25e372b3 (diff)
Merge tag 'v5.15.4-lts' into tqtc/lts-5.15-opensourcev5.15.4-lts-lgpl
Qt For Python Release 5.15.4 Change-Id: I8457501ba90fc481fb9de686eb8a2f880ecc06cd
Diffstat (limited to 'sources/shiboken2/libshiboken/shibokenbuffer.cpp')
-rw-r--r--sources/shiboken2/libshiboken/shibokenbuffer.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/sources/shiboken2/libshiboken/shibokenbuffer.cpp b/sources/shiboken2/libshiboken/shibokenbuffer.cpp
index dd6e46320..8d44878ac 100644
--- a/sources/shiboken2/libshiboken/shibokenbuffer.cpp
+++ b/sources/shiboken2/libshiboken/shibokenbuffer.cpp
@@ -74,6 +74,29 @@ void *Shiboken::Buffer::getPointer(PyObject *pyObj, Py_ssize_t *size)
return const_cast<void *>(buffer);
}
+void *Shiboken::Buffer::copyData(PyObject *pyObj, Py_ssize_t *sizeIn)
+{
+ void *result = nullptr;
+ Py_ssize_t size = 0;
+
+ Py_buffer view;
+ if (PyObject_GetBuffer(pyObj, &view, PyBUF_ND) == 0) {
+ size = view.len;
+ if (size) {
+ result = std::malloc(size);
+ if (result != nullptr)
+ std::memcpy(result, view.buf, size);
+ else
+ size = 0;
+ }
+ PyBuffer_Release(&view);
+ }
+
+ if (sizeIn != nullptr)
+ *sizeIn = size;
+ return result;
+}
+
PyObject *Shiboken::Buffer::newObject(void *memory, Py_ssize_t size, Type type)
{
if (size == 0)