aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2021-11-23 19:36:43 +0100
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2022-04-06 12:01:58 +0200
commit3501530b89792bfdce64e0a86ae828d8c092ace3 (patch)
treec5ea7a087ae54f82b2d1d1df8c2c0a0683236878
parent3b7c475dc52f20d0da6f07c699bffbca7876972f (diff)
shiboken6: Split out a function to write the nbbool function
CppGenerator::generateClass() is already quite big. Task-number: PYSIDE-454 Change-Id: I2f3991f9a41e0a987827bb15e76c6d58cc5fb8fe Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io> (cherry picked from commit 0dfdd99163c2d02e4459392a53d15b476c57979d) Reviewed-by: Shyamnath Premnadh <Shyamnath.Premnadh@qt.io> Reviewed-by: Christian Tismer <tismer@stackless.com>
-rw-r--r--sources/shiboken6/generator/shiboken/cppgenerator.cpp50
-rw-r--r--sources/shiboken6/generator/shiboken/cppgenerator.h4
2 files changed, 32 insertions, 22 deletions
diff --git a/sources/shiboken6/generator/shiboken/cppgenerator.cpp b/sources/shiboken6/generator/shiboken/cppgenerator.cpp
index 8143fd54f..4c6ed1711 100644
--- a/sources/shiboken6/generator/shiboken/cppgenerator.cpp
+++ b/sources/shiboken6/generator/shiboken/cppgenerator.cpp
@@ -692,28 +692,8 @@ void CppGenerator::generateClass(TextStream &s, const GeneratorContext &classCon
writeSetattroFunction(s, attroCheck, classContext);
}
- const auto f = boolCast(metaClass);
- if (!f.isNull()) {
- ErrorCode errorCode(-1);
- s << "static int " << cpythonBaseName(metaClass) << "___nb_bool(PyObject *self)\n"
- << "{\n" << indent;
- writeCppSelfDefinition(s, classContext);
-
- const bool allowThread = f->allowThread();
- if (allowThread)
- s << "int result;\n" << BEGIN_ALLOW_THREADS << "\nresult = ";
- else
- s << "return ";
-
- if (f->isOperatorBool())
- s << '*' << CPP_SELF_VAR << " ? 1 : 0;\n";
- else
- s << CPP_SELF_VAR << "->isNull() ? 0 : 1;\n";
-
- if (allowThread)
- s << END_ALLOW_THREADS << "\nreturn result;\n";
- s << outdent << "}\n\n";
- }
+ if (const auto f = boolCast(metaClass) ; !f.isNull())
+ writeNbBoolFunction(classContext, f, s);
if (supportsNumberProtocol(metaClass) && !metaClass->typeEntry()->isSmartPointer()) {
const QList<AbstractMetaFunctionCList> opOverloads = filterGroupedOperatorFunctions(
@@ -6133,6 +6113,32 @@ PyErr_Format(PyExc_AttributeError,
<< "return tmp;\n" << outdent << "}\n\n";
}
+void CppGenerator::writeNbBoolFunction(const GeneratorContext &context,
+ const AbstractMetaFunctionCPtr &f,
+ TextStream &s) const
+{
+ ErrorCode errorCode(-1);
+
+ s << "static int " << cpythonBaseName(context.metaClass()) << "___nb_bool(PyObject *self)\n"
+ << "{\n" << indent;
+ writeCppSelfDefinition(s, context);
+
+ const bool allowThread = f->allowThread();
+ if (allowThread)
+ s << "int result;\n" << BEGIN_ALLOW_THREADS << "\nresult = ";
+ else
+ s << "return ";
+
+ if (f->isOperatorBool())
+ s << '*' << CPP_SELF_VAR << " ? 1 : 0;\n";
+ else
+ s << CPP_SELF_VAR << "->isNull() ? 0 : 1;\n";
+
+ if (allowThread)
+ s << END_ALLOW_THREADS << "\nreturn result;\n";
+ s << outdent << "}\n\n";
+}
+
// Write declaration and invocation of the init function for the module init
// function.
void CppGenerator::writeInitFunc(TextStream &declStr, TextStream &callStr,
diff --git a/sources/shiboken6/generator/shiboken/cppgenerator.h b/sources/shiboken6/generator/shiboken/cppgenerator.h
index b5de61eab..e226feec9 100644
--- a/sources/shiboken6/generator/shiboken/cppgenerator.h
+++ b/sources/shiboken6/generator/shiboken/cppgenerator.h
@@ -157,6 +157,10 @@ private:
const GeneratorContext &context) const;
QString qObjectGetAttroFunction() const;
+ void writeNbBoolFunction(const GeneratorContext &context,
+ const AbstractMetaFunctionCPtr &f,
+ TextStream &s) const;
+
/**
* Writes Python to C++ conversions for arguments on Python wrappers.
* If implicit conversions, and thus new object allocation, are needed,