aboutsummaryrefslogtreecommitdiffstats
path: root/generator
diff options
context:
space:
mode:
authorHugo Parente Lima <hugo.pl@gmail.com>2011-08-04 16:10:34 -0300
committerHugo Parente Lima <hugo.pl@gmail.com>2012-03-08 16:17:13 -0300
commit784a4bbb707d132b26bcb177521745575dc0823f (patch)
treef637ef4134445b1cfdd0c33878b7a1ce46f02145 /generator
parent8b1ddcd3ef711bab70bb7cdebc26558a26f42df9 (diff)
Implements PSEP-0106 and fixes bug 902 - "Expose Shiboken functionality through a Python module".
Diffstat (limited to 'generator')
-rw-r--r--generator/cppgenerator.cpp11
-rw-r--r--generator/headergenerator.cpp32
2 files changed, 24 insertions, 19 deletions
diff --git a/generator/cppgenerator.cpp b/generator/cppgenerator.cpp
index a894c79e7..a746dbb92 100644
--- a/generator/cppgenerator.cpp
+++ b/generator/cppgenerator.cpp
@@ -3946,9 +3946,11 @@ void CppGenerator::finishGeneration()
s << INDENT << "}" << endl << endl;
}
- s << INDENT << "// Create an array of wrapper types for the current module." << endl;
- s << INDENT << "static PyTypeObject* cppApi[" << "SBK_" << moduleName() << "_IDX_COUNT" << "];" << endl;
- s << INDENT << cppApiVariableName() << " = cppApi;" << endl << endl;
+ if (getMaxTypeIndex()) {
+ s << INDENT << "// Create an array of wrapper types for the current module." << endl;
+ s << INDENT << "static PyTypeObject* cppApi[" << "SBK_" << moduleName() << "_IDX_COUNT" << "];" << endl;
+ s << INDENT << cppApiVariableName() << " = cppApi;" << endl << endl;
+ }
s << INDENT << "PyObject* module = Shiboken::Module::create(\"" << moduleName() << "\", ";
s << moduleName() << "_methods);" << endl << endl;
@@ -3995,7 +3997,8 @@ void CppGenerator::finishGeneration()
foreach (QByteArray type, typeResolvers)
s << INDENT << typeResolverString(type) << ';' << endl;
- s << endl << INDENT << "Shiboken::Module::registerTypes(module, " << cppApiVariableName() << ");" << endl;
+ if (getMaxTypeIndex())
+ s << endl << INDENT << "Shiboken::Module::registerTypes(module, " << cppApiVariableName() << ");" << endl;
s << endl << INDENT << "if (PyErr_Occurred()) {" << endl;
{
diff --git a/generator/headergenerator.cpp b/generator/headergenerator.cpp
index 7cbf6b2ea..1e2a5b8d7 100644
--- a/generator/headergenerator.cpp
+++ b/generator/headergenerator.cpp
@@ -345,22 +345,24 @@ void HeaderGenerator::finishGeneration()
QTextStream protEnumsSurrogates(&protectedEnumSurrogates);
Indentation indent(INDENT);
-
- macrosStream << "// Type indices" << endl;
AbstractMetaEnumList globalEnums = this->globalEnums();
- foreach (const AbstractMetaClass* metaClass, classes()) {
- writeTypeIndexDefine(macrosStream, metaClass);
- lookForEnumsInClassesNotToBeGenerated(globalEnums, metaClass);
- }
- foreach (const AbstractMetaEnum* metaEnum, globalEnums)
- writeTypeIndexDefineLine(macrosStream, metaEnum->typeEntry());
- macrosStream << "#define ";
- macrosStream.setFieldWidth(60);
- macrosStream << "SBK_"+moduleName()+"_IDX_COUNT";
- macrosStream.setFieldWidth(0);
- macrosStream << ' ' << getMaxTypeIndex() << endl << endl;
- macrosStream << "// This variable stores all python types exported by this module" << endl;
- macrosStream << "extern PyTypeObject** " << cppApiVariableName() << ';' << endl << endl;
+
+ if (getMaxTypeIndex()) {
+ macrosStream << "// Type indices" << endl;
+ foreach (const AbstractMetaClass* metaClass, classes()) {
+ writeTypeIndexDefine(macrosStream, metaClass);
+ lookForEnumsInClassesNotToBeGenerated(globalEnums, metaClass);
+ }
+ foreach (const AbstractMetaEnum* metaEnum, globalEnums)
+ writeTypeIndexDefineLine(macrosStream, metaEnum->typeEntry());
+ macrosStream << "#define ";
+ macrosStream.setFieldWidth(60);
+ macrosStream << "SBK_"+moduleName()+"_IDX_COUNT";
+ macrosStream.setFieldWidth(0);
+ macrosStream << ' ' << getMaxTypeIndex() << endl << endl;
+ macrosStream << "// This variable stores all python types exported by this module" << endl;
+ macrosStream << "extern PyTypeObject** " << cppApiVariableName() << ';' << endl << endl;
+ }
macrosStream << "// Macros for type check" << endl;
foreach (const AbstractMetaEnum* cppEnum, globalEnums) {