aboutsummaryrefslogtreecommitdiffstats
path: root/sources
diff options
context:
space:
mode:
authorChristian Tismer <tismer@stackless.com>2022-05-23 12:33:29 +0200
committerChristian Tismer <tismer@stackless.com>2022-06-20 08:44:28 +0200
commitc6a9e5ab96d9221ecd8d445a38349d12c6c0d71e (patch)
treead8d34cff73c5ad9a61af2d89e7d3fdedb6d3879 /sources
parent300f21781b460fcc602e9b42eed4f76e63458558 (diff)
Shiboken: Optimize attribute access a bit more
Some leftover attributes can be turned into statics, too. The StaticMetaObject needs to be moved into Shiboken in preparation of the following enum checkin. Task-number: PYSIDE-1735 Change-Id: I2172bd785ae229ea5637588c53be660477fc2f0e Pick-to: 6.3 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'sources')
-rw-r--r--sources/pyside6/libpyside/pyside.cpp4
-rw-r--r--sources/pyside6/libpyside/pysidestaticstrings.cpp2
-rw-r--r--sources/pyside6/libpyside/pysidestaticstrings.h2
-rw-r--r--sources/shiboken6/generator/shiboken/cppgenerator.cpp5
-rw-r--r--sources/shiboken6/libshiboken/sbkstaticstrings.cpp3
-rw-r--r--sources/shiboken6/libshiboken/sbkstaticstrings.h3
-rw-r--r--sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/mapping.py1
7 files changed, 12 insertions, 8 deletions
diff --git a/sources/pyside6/libpyside/pyside.cpp b/sources/pyside6/libpyside/pyside.cpp
index 44b0dc4b0..b2f03b210 100644
--- a/sources/pyside6/libpyside/pyside.cpp
+++ b/sources/pyside6/libpyside/pyside.cpp
@@ -266,7 +266,7 @@ static bool _setProperty(PyObject *qObj, PyObject *name, PyObject *value, bool *
if (look) {
AutoDecRef propSetter{};
- static PyObject *magicGet = PyMagicName::get();
+ static PyObject *magicGet = Shiboken::PyMagicName::get();
if (found && prop_flag) {
// the indirection of the setter descriptor in a true property
AutoDecRef descr(PyObject_GetAttr(look, PyName::fset()));
@@ -410,7 +410,7 @@ void initDynamicMetaObject(PyTypeObject *type, const QMetaObject *base, std::siz
return;
Shiboken::AutoDecRef pyMetaObject(Shiboken::Conversions::pointerToPython(converter, metaObjectPtr));
PyObject_SetAttr(reinterpret_cast<PyObject *>(type),
- PySide::PyName::qtStaticMetaObject(), pyMetaObject);
+ Shiboken::PyName::qtStaticMetaObject(), pyMetaObject);
}
TypeUserData *retrieveTypeUserData(PyTypeObject *pyTypeObj)
diff --git a/sources/pyside6/libpyside/pysidestaticstrings.cpp b/sources/pyside6/libpyside/pysidestaticstrings.cpp
index 348d05ac6..637e184be 100644
--- a/sources/pyside6/libpyside/pysidestaticstrings.cpp
+++ b/sources/pyside6/libpyside/pysidestaticstrings.cpp
@@ -15,7 +15,6 @@ namespace PySide
{
namespace PyName
{
-STATIC_STRING_IMPL(qtStaticMetaObject, "staticMetaObject")
STATIC_STRING_IMPL(qtConnect, "connect")
STATIC_STRING_IMPL(qtDisconnect, "disconnect")
STATIC_STRING_IMPL(qtEmit, "emit")
@@ -33,7 +32,6 @@ namespace PyMagicName
STATIC_STRING_IMPL(code, "__code__")
STATIC_STRING_IMPL(doc, "__doc__")
STATIC_STRING_IMPL(func, "__func__")
-STATIC_STRING_IMPL(get, "__get__")
STATIC_STRING_IMPL(name, "__name__")
STATIC_STRING_IMPL(property_methods, "__property_methods__")
} // namespace PyMagicName
diff --git a/sources/pyside6/libpyside/pysidestaticstrings.h b/sources/pyside6/libpyside/pysidestaticstrings.h
index 5180ac5b8..eea0813a7 100644
--- a/sources/pyside6/libpyside/pysidestaticstrings.h
+++ b/sources/pyside6/libpyside/pysidestaticstrings.h
@@ -11,7 +11,6 @@ namespace PySide
{
namespace PyName
{
-PYSIDE_API PyObject *qtStaticMetaObject();
PYSIDE_API PyObject *qtConnect();
PYSIDE_API PyObject *qtDisconnect();
PYSIDE_API PyObject *qtEmit();
@@ -29,7 +28,6 @@ namespace PyMagicName
PYSIDE_API PyObject *code();
PYSIDE_API PyObject *doc();
PYSIDE_API PyObject *func();
-PYSIDE_API PyObject *get();
PYSIDE_API PyObject *name();
PYSIDE_API PyObject *property_methods();
} // namespace PyMagicName
diff --git a/sources/shiboken6/generator/shiboken/cppgenerator.cpp b/sources/shiboken6/generator/shiboken/cppgenerator.cpp
index fb2ec9532..7b1e5d993 100644
--- a/sources/shiboken6/generator/shiboken/cppgenerator.cpp
+++ b/sources/shiboken6/generator/shiboken/cppgenerator.cpp
@@ -2245,7 +2245,8 @@ void CppGenerator::writeMethodWrapper(TextStream &s, const OverloadData &overloa
// For custom classes, operations like __radd__ and __rmul__
// will enter an infinite loop.
if (rfunc->isBinaryOperator() && revOpName.contains(u"shift")) {
- s << "Shiboken::AutoDecRef attrName(Py_BuildValue(\"s\", \"" << revOpName << "\"));\n";
+ revOpName = u"Shiboken::PyMagicName::"_s + revOpName.replace(u"__"_s, u""_s) + u"()"_s;
+ s << "static PyObject *attrName = " << revOpName << ";\n";
s << "if (!isReverse\n";
{
Indentation indent(s);
@@ -6530,10 +6531,10 @@ bool CppGenerator::finishGeneration()
// cleanup staticMetaObject attribute
if (usePySideExtensions()) {
s << "void cleanTypesAttributes() {\n" << indent
+ << "static PyObject *attrName = Shiboken::PyName::qtStaticMetaObject();\n"
<< "for (int i = 0, imax = SBK_" << moduleName()
<< "_IDX_COUNT; i < imax; i++) {\n" << indent
<< "PyObject *pyType = reinterpret_cast<PyObject *>(" << cppApiVariableName() << "[i]);\n"
- << "PyObject *attrName = PySide::PyName::qtStaticMetaObject();\n"
<< "if (pyType && PyObject_HasAttr(pyType, attrName))\n" << indent
<< "PyObject_SetAttr(pyType, attrName, Py_None);\n" << outdent
<< outdent << "}\n" << outdent << "}\n";
diff --git a/sources/shiboken6/libshiboken/sbkstaticstrings.cpp b/sources/shiboken6/libshiboken/sbkstaticstrings.cpp
index f7ac6683d..3f2484f31 100644
--- a/sources/shiboken6/libshiboken/sbkstaticstrings.cpp
+++ b/sources/shiboken6/libshiboken/sbkstaticstrings.cpp
@@ -29,6 +29,7 @@ STATIC_STRING_IMPL(result, "result")
STATIC_STRING_IMPL(select_id, "select_id")
STATIC_STRING_IMPL(value, "value")
STATIC_STRING_IMPL(values, "values")
+STATIC_STRING_IMPL(qtStaticMetaObject, "staticMetaObject")
// Internal:
STATIC_STRING_IMPL(classmethod, "classmethod")
@@ -60,6 +61,8 @@ STATIC_STRING_IMPL(qualname, "__qualname__")
STATIC_STRING_IMPL(self, "__self__")
STATIC_STRING_IMPL(select_i, "__self__")
STATIC_STRING_IMPL(code, "__code__")
+STATIC_STRING_IMPL(rlshift, "__rlshift__")
+STATIC_STRING_IMPL(rrshift, "__rrshift__")
// Internal:
STATIC_STRING_IMPL(base, "__base__")
diff --git a/sources/shiboken6/libshiboken/sbkstaticstrings.h b/sources/shiboken6/libshiboken/sbkstaticstrings.h
index 4940049cd..c89fdc9cd 100644
--- a/sources/shiboken6/libshiboken/sbkstaticstrings.h
+++ b/sources/shiboken6/libshiboken/sbkstaticstrings.h
@@ -27,6 +27,7 @@ LIBSHIBOKEN_API PyObject *result();
LIBSHIBOKEN_API PyObject *select_id();
LIBSHIBOKEN_API PyObject *value();
LIBSHIBOKEN_API PyObject *values();
+LIBSHIBOKEN_API PyObject *qtStaticMetaObject();
} // namespace PyName
namespace PyMagicName
@@ -46,6 +47,8 @@ LIBSHIBOKEN_API PyObject *qualname();
LIBSHIBOKEN_API PyObject *self();
LIBSHIBOKEN_API PyObject *opaque_container();
LIBSHIBOKEN_API PyObject *code();
+LIBSHIBOKEN_API PyObject *rlshift();
+LIBSHIBOKEN_API PyObject *rrshift();
} // namespace PyMagicName
} // namespace Shiboken
diff --git a/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/mapping.py b/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/mapping.py
index d6b54bc01..a71210c72 100644
--- a/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/mapping.py
+++ b/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/mapping.py
@@ -383,6 +383,7 @@ def init_sample():
"const char*": str,
"Complex": complex,
"double": float,
+ "ByteArray&": bytes,
"Foo.HANDLE": int,
"HANDLE": int,
"Null": None,