aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken2/generator
diff options
context:
space:
mode:
authorChristian Tismer <tismer@stackless.com>2020-07-15 15:39:48 +0200
committerChristian Tismer <tismer@stackless.com>2020-07-24 01:19:21 +0200
commit2d44c85faa01c7e805ff27bac4e3e1574ab0f5d3 (patch)
treec0a5359f6a6d001aac596af5b3e520802beef114 /sources/shiboken2/generator
parentb429d2a06bf5acb4b44cd0c7bd599c6d4cc7ebae (diff)
feature-select: allow snake_case instead of camelCase for methods
This is the implementation of the first of a series of dynamically selectable features. The decision depends of the following setting at the beginning of a module after PySide2 import: from __feature__ import snake_case For more info, see the Jira issue, section The Principle Of Selectable Features In PySide The crucial problems that are now solved were: - it is not sufficient to patch a type dict, instead the whole `tp_mro` must be walked to rename everything. - tp_getattro must be changed for every existing type. This is done either in shiboken by a changed PyObject_GenericGetAttr or PyObject_SenericGetAttr, or in the generated tp_(get|set)attro functions. An example is included in sources/pyside2/doc/tutorial/expenses. Task-number: PYSIDE-1019 Change-Id: I5f103190be2c884b0b4ad806187f3fef8e6598c9 Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'sources/shiboken2/generator')
-rw-r--r--sources/shiboken2/generator/shiboken2/cppgenerator.cpp16
1 files changed, 13 insertions, 3 deletions
diff --git a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp
index 069431e59..b10074f79 100644
--- a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp
+++ b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp
@@ -313,6 +313,7 @@ void CppGenerator::generateClass(QTextStream &s, const GeneratorContext &classCo
<< "#include <pysideproperty.h>\n"
<< "#include <pyside.h>\n"
<< "#include <pysideqenum.h>\n"
+ << "#include <feature_select.h>\n"
<< "#include <qapp_macro.h>\n\n"
<< "QT_WARNING_DISABLE_DEPRECATED\n\n";
}
@@ -949,10 +950,10 @@ void CppGenerator::writeVirtualMethodNative(QTextStream &s,
s << INDENT << returnStatement << '\n';
}
- s << INDENT << "static PyObject *pyFuncName = Shiboken::String::createStaticString(\""
- << funcName << "\");\n";
+ s << INDENT << "static PyObject *nameCache[2] = {};\n";
+ s << INDENT << "static const char *funcName = \"" << funcName << "\";\n";
s << INDENT << "Shiboken::AutoDecRef " << PYTHON_OVERRIDE_VAR
- << "(Shiboken::BindingManager::instance().getOverride(this, pyFuncName));\n";
+ << "(Shiboken::BindingManager::instance().getOverride(this, nameCache, funcName));\n";
s << INDENT << "if (" << PYTHON_OVERRIDE_VAR << ".isNull()) {\n";
{
Indentation indentation(INDENT);
@@ -5371,6 +5372,11 @@ void CppGenerator::writeSetattroFunction(QTextStream &s, AttroCheck attroCheck,
Q_ASSERT(!context.forSmartPointer());
const AbstractMetaClass *metaClass = context.metaClass();
writeSetattroDefinition(s, metaClass);
+
+ // PYSIDE-1019: Switch tp_dict before doing tp_setattro.
+ if (usePySideExtensions())
+ s << INDENT << "PySide::Feature::Select(self);\n";
+
// PYSIDE-803: Detect duck-punching; clear cache if a method is set.
if (attroCheck.testFlag(AttroCheckFlag::SetattroMethodOverride)
&& context.useWrapper()) {
@@ -5458,6 +5464,10 @@ void CppGenerator::writeGetattroFunction(QTextStream &s, AttroCheck attroCheck,
const AbstractMetaClass *metaClass = context.metaClass();
writeGetattroDefinition(s, metaClass);
+ // PYSIDE-1019: Switch tp_dict before doing tp_getattro.
+ if (usePySideExtensions())
+ s << INDENT << "PySide::Feature::Select(self);\n";
+
const QString getattrFunc = usePySideExtensions() && metaClass->isQObject()
? qObjectGetAttroFunction() : QLatin1String("PyObject_GenericGetAttr(self, name)");