aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside6
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2024-09-10 09:27:06 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2024-09-11 11:21:16 +0200
commit8b08cebf577964e164c9fe2fa776e18d53cfe8d6 (patch)
treea6aa6c1050567de8c09d9e56c8213290cde8c235 /sources/pyside6
parent69fe90716f0142e95fa43243500c4970e078d12b (diff)
shiboken6: Refactor __getitem__/__setitem__ code generation
- Introduce a shiboken message with parameters, reducing strings generated into code. - Return nullptr from __getitem__. - Adapt injected code. Task-number: PYSIDE-2859 Task-number: PYSIDE-2701 Change-Id: I4de98e40609cab400e4d7e11fe00f07594702b3a Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'sources/pyside6')
-rw-r--r--sources/pyside6/PySide6/glue/qtcore.cpp31
-rw-r--r--sources/pyside6/PySide6/glue/qtgui.cpp14
-rw-r--r--sources/pyside6/PySide6/glue/qtnetwork.cpp2
3 files changed, 28 insertions, 19 deletions
diff --git a/sources/pyside6/PySide6/glue/qtcore.cpp b/sources/pyside6/PySide6/glue/qtcore.cpp
index 6378c5eda..4f0556d54 100644
--- a/sources/pyside6/PySide6/glue/qtcore.cpp
+++ b/sources/pyside6/PySide6/glue/qtcore.cpp
@@ -548,9 +548,10 @@ return %CPPSELF.size();
// @snippet qbitarray-len
// @snippet qbitarray-getitem
-if (_i < 0 || _i >= %CPPSELF.size()) {
- PyErr_SetString(PyExc_IndexError, "index out of bounds");
- return 0;
+const Py_ssize_t size = %CPPSELF.size();
+if (_i < 0 || _i >= size) {
+ Shiboken::Errors::setIndexOutOfBounds(_i, 0, size);
+ return nullptr;
}
bool ret = %CPPSELF.at(_i);
return %CONVERTTOPYTHON[bool](ret);
@@ -625,8 +626,11 @@ if (ret == nullptr) {
// @snippet qbytearray-mgetitem
if (PyIndex_Check(_key)) {
const Py_ssize_t _i = PyNumber_AsSsize_t(_key, PyExc_IndexError);
- if (_i < 0 || _i >= %CPPSELF.size())
- return PyErr_Format(PyExc_IndexError, "index out of bounds");
+ const Py_ssize_t size = %CPPSELF.size();
+ if (_i < 0 || _i >= size) {
+ Shiboken::Errors::setIndexOutOfBounds(_i, 0, size);
+ return nullptr;
+ }
char res[2] = {%CPPSELF.at(_i), '\0'};
return PyBytes_FromStringAndSize(res, 1);
}
@@ -919,15 +923,16 @@ return %CPPSELF.size();
// @snippet qbytearray-len
// @snippet qbytearray-getitem
-if (_i < 0 || _i >= %CPPSELF.size()) {
- PyErr_SetString(PyExc_IndexError, "index out of bounds");
- return 0;
-} else {
- char res[2];
- res[0] = %CPPSELF.at(_i);
- res[1] = 0;
- return PyBytes_FromStringAndSize(res, 1);
+const Py_ssize_t size = %CPPSELF.size();
+if (_i < 0 || _i >= size) {
+ Shiboken::Errors::setIndexOutOfBounds(_i, 0, size);
+ return nullptr;
}
+
+char res[2];
+res[0] = %CPPSELF.at(_i);
+res[1] = 0;
+return PyBytes_FromStringAndSize(res, 1);
// @snippet qbytearray-getitem
// @snippet qbytearray-setitem
diff --git a/sources/pyside6/PySide6/glue/qtgui.cpp b/sources/pyside6/PySide6/glue/qtgui.cpp
index 5c860a2bf..aacac3508 100644
--- a/sources/pyside6/PySide6/glue/qtgui.cpp
+++ b/sources/pyside6/PySide6/glue/qtgui.cpp
@@ -310,9 +310,10 @@ PyTuple_SET_ITEM(%PYARG_0, 1, %CONVERTTOPYTHON[%ARG1_TYPE](%1));
// @snippet qtextline-cursortox
// @snippet qkeysequence-getitem
-if (_i < 0 || _i >= %CPPSELF.count()) {
- PyErr_SetString(PyExc_IndexError, "index out of bounds");
- return 0;
+const Py_ssize_t size = %CPPSELF.count();
+if (_i < 0 || _i >= size) {
+ Shiboken::Errors::setIndexOutOfBounds(_i, 0, size);
+ return nullptr;
}
QKeyCombination item = (*%CPPSELF)[_i];
return %CONVERTTOPYTHON[QKeyCombination](item);
@@ -912,8 +913,11 @@ return %CPPSELF.rectCount();
// @snippet qregion-len
// @snippet qregion-getitem
-if (_i < 0 || _i >= %CPPSELF.rectCount())
- return PyErr_Format(PyExc_IndexError, "index out of bounds");
+const Py_ssize_t size = %CPPSELF.rectCount();
+if (_i < 0 || _i >= size) {
+ Shiboken::Errors::setIndexOutOfBounds(_i, 0, size);
+ return nullptr;
+}
const QRect cppResult = *(%CPPSELF.cbegin() + _i);
return %CONVERTTOPYTHON[QRect](cppResult);
diff --git a/sources/pyside6/PySide6/glue/qtnetwork.cpp b/sources/pyside6/PySide6/glue/qtnetwork.cpp
index f635f4671..07993f30a 100644
--- a/sources/pyside6/PySide6/glue/qtnetwork.cpp
+++ b/sources/pyside6/PySide6/glue/qtnetwork.cpp
@@ -46,7 +46,7 @@ return 16;
// @snippet qipv6address-getitem
if (_i >= 16) {
PyErr_SetString(PyExc_IndexError, "index out of bounds");
- return 0;
+ return nullptr;
}
if (_i < 0)
_i = 16 - qAbs(_i);