aboutsummaryrefslogtreecommitdiffstats
path: root/sources
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2023-01-11 14:00:56 +0100
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2023-03-17 15:37:11 +0100
commit8bc82e7f09fe08b74e626c98cc54f178022dcc2c (patch)
treecb7cf3e7b1342f0c0b3f2b483064574cfff4e49e /sources
parent660b5c899b871017d91bb375ccfa0628df15efce (diff)
shiboken6: Prevent span instantiation
std::span cannot be instantiated since it is a non-owning container. Task-number: PYSIDE-2174 Change-Id: Iaf3ca97c29f28edba9a6ab469e953da16a477c4a Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'sources')
-rw-r--r--sources/shiboken6/generator/shiboken/cppgenerator_container.cpp3
-rw-r--r--sources/shiboken6/libshiboken/sbkcontainer.h8
2 files changed, 10 insertions, 1 deletions
diff --git a/sources/shiboken6/generator/shiboken/cppgenerator_container.cpp b/sources/shiboken6/generator/shiboken/cppgenerator_container.cpp
index a080a83f5..9632fd940 100644
--- a/sources/shiboken6/generator/shiboken/cppgenerator_container.cpp
+++ b/sources/shiboken6/generator/shiboken/cppgenerator_container.cpp
@@ -196,7 +196,8 @@ CppGenerator::OpaqueContainerData
const QString slotsList = result.name + u"_slots"_s;
s << "static PyType_Slot " << slotsList << "[] = {\n" << indent;
writeSlot(s, privateObjType, "Py_tp_init", "tpInit");
- writeSlot(s, privateObjType, "Py_tp_new", "tpNew");
+ const auto *tpNew = containerTypeEntry->viewOn() == nullptr ? "tpNew" : "tpNewInvalid";
+ writeSlot(s, privateObjType, "Py_tp_new", tpNew);
writeSlot(s, privateObjType, "Py_tp_free", "tpFree");
writeSlot(s, "Py_tp_dealloc", "Sbk_object_dealloc"); // FIXME?
writeSlot(s, "Py_tp_methods", methods.toUtf8().constData());
diff --git a/sources/shiboken6/libshiboken/sbkcontainer.h b/sources/shiboken6/libshiboken/sbkcontainer.h
index 6767e11f2..96faf95ee 100644
--- a/sources/shiboken6/libshiboken/sbkcontainer.h
+++ b/sources/shiboken6/libshiboken/sbkcontainer.h
@@ -71,6 +71,14 @@ public:
return reinterpret_cast<PyObject *>(me);
}
+ static PyObject *tpNewInvalid(PyTypeObject * /* subtype */, PyObject * /* args */, PyObject * /* kwds */)
+ {
+ PyErr_Format(PyExc_NotImplementedError,
+ "Opaque containers of type '%s' cannot be instantiated.",
+ typeid(SequenceContainer).name());
+ return nullptr;
+ }
+
static int tpInit(PyObject * /* self */, PyObject * /* args */, PyObject * /* kwds */)
{
return 0;