diff options
| author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2024-09-10 09:27:06 +0200 |
|---|---|---|
| committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2024-09-11 11:21:16 +0200 |
| commit | 8b08cebf577964e164c9fe2fa776e18d53cfe8d6 (patch) | |
| tree | a6aa6c1050567de8c09d9e56c8213290cde8c235 /sources/pyside6/PySide6/glue/qtgui.cpp | |
| parent | 69fe90716f0142e95fa43243500c4970e078d12b (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/PySide6/glue/qtgui.cpp')
| -rw-r--r-- | sources/pyside6/PySide6/glue/qtgui.cpp | 14 |
1 files changed, 9 insertions, 5 deletions
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); |
