diff options
Diffstat (limited to 'sources/shiboken2/generator/shiboken2')
4 files changed, 30 insertions, 10 deletions
diff --git a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp index 455b77c6e..33a161f78 100644 --- a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp +++ b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp @@ -5346,10 +5346,13 @@ bool CppGenerator::finishGeneration() s << endl; s << "// Current module's type array." << endl; - s << "PyTypeObject** " << cppApiVariableName() << ';' << endl; + s << "PyTypeObject** " << cppApiVariableName() << " = nullptr;" << endl; + + s << "// Current module's PyObject pointer." << endl; + s << "PyObject* " << pythonModuleObjectName() << " = nullptr;" << endl; s << "// Current module's converter array." << endl; - s << "SbkConverter** " << convertersVariableName() << ';' << endl; + s << "SbkConverter** " << convertersVariableName() << " = nullptr;" << endl; const CodeSnipList snips = moduleEntry->codeSnips(); @@ -5520,6 +5523,9 @@ bool CppGenerator::finishGeneration() s << moduleName() << "_methods);" << endl; s << "#endif" << endl << endl; + s << INDENT << "// Make module available from global scope" << endl; + s << INDENT << pythonModuleObjectName() << " = module;" << endl << endl; + //s << INDENT << "// Initialize converters for primitive types." << endl; //s << INDENT << "initConverters();" << endl << endl; diff --git a/sources/shiboken2/generator/shiboken2/headergenerator.cpp b/sources/shiboken2/generator/shiboken2/headergenerator.cpp index 755db10e3..a0fbfecf6 100644 --- a/sources/shiboken2/generator/shiboken2/headergenerator.cpp +++ b/sources/shiboken2/generator/shiboken2/headergenerator.cpp @@ -381,6 +381,8 @@ bool HeaderGenerator::finishGeneration() macrosStream << "// This variable stores all Python types exported by this module." << endl; macrosStream << "extern PyTypeObject** " << cppApiVariableName() << ';' << endl << endl; + macrosStream << "// This variable stores the Python module object exported by this module." << endl; + macrosStream << "extern PyObject* " << pythonModuleObjectName() << ';' << endl << endl; macrosStream << "// This variable stores all type converters exported by this module." << endl; macrosStream << "extern SbkConverter** " << convertersVariableName() << ';' << endl << endl; diff --git a/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp b/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp index 60a7725a6..6bdbb5b76 100644 --- a/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp +++ b/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp @@ -2251,9 +2251,7 @@ AbstractMetaClassList ShibokenGenerator::getAllAncestors(const AbstractMetaClass QString ShibokenGenerator::getModuleHeaderFileName(const QString& moduleName) const { - QString result = moduleName.isEmpty() ? packageName() : moduleName; - result.replace(QLatin1Char('.'), QLatin1Char('_')); - return result.toLower() + QLatin1String("_python.h"); + return moduleCppPrefix(moduleName).toLower() + QLatin1String("_python.h"); } bool ShibokenGenerator::isCopyable(const AbstractMetaClass *metaClass) @@ -2544,15 +2542,25 @@ bool ShibokenGenerator::avoidProtectedHack() const return m_avoidProtectedHack; } -QString ShibokenGenerator::cppApiVariableName(const QString& moduleName) const -{ - QString result = moduleName.isEmpty() ? ShibokenGenerator::packageName() : moduleName; +QString ShibokenGenerator::moduleCppPrefix(const QString& moduleName) const + { + QString result = moduleName.isEmpty() ? packageName() : moduleName; result.replace(QLatin1Char('.'), QLatin1Char('_')); - result.prepend(QLatin1String("Sbk")); - result.append(QLatin1String("Types")); return result; } +QString ShibokenGenerator::cppApiVariableName(const QString& moduleName) const +{ + return QLatin1String("Sbk") + moduleCppPrefix(moduleName) + + QLatin1String("Types"); +} + +QString ShibokenGenerator::pythonModuleObjectName(const QString& moduleName) const +{ + return QLatin1String("Sbk") + moduleCppPrefix(moduleName) + + QLatin1String("ModuleObject"); +} + QString ShibokenGenerator::convertersVariableName(const QString& moduleName) const { QString result = cppApiVariableName(moduleName); diff --git a/sources/shiboken2/generator/shiboken2/shibokengenerator.h b/sources/shiboken2/generator/shiboken2/shibokengenerator.h index ed8f1bbfb..d2ae55926 100644 --- a/sources/shiboken2/generator/shiboken2/shibokengenerator.h +++ b/sources/shiboken2/generator/shiboken2/shibokengenerator.h @@ -428,6 +428,7 @@ public: /// Returns true if the generated code should use the "#define protected public" hack. bool avoidProtectedHack() const; QString cppApiVariableName(const QString& moduleName = QString()) const; + QString pythonModuleObjectName(const QString& moduleName = QString()) const; QString convertersVariableName(const QString& moduleName = QString()) const; /** * Returns the type index variable name for a given class. If \p alternativeTemplateName is true @@ -501,6 +502,9 @@ protected: /// Returns a list of converters for the non wrapper types of the current module. QVector<const CustomConversion *> getPrimitiveCustomConversions(); + /// Return a prefix with '_' suitable for names in C++ + QString moduleCppPrefix(const QString& moduleName = QString()) const; + /// Returns true if the Python wrapper for the received OverloadData must accept a list of arguments. static bool pythonFunctionWrapperUsesListOfArguments(const OverloadData& overloadData); |