aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRenato Filho <renato.filho@openbossa.org>2011-09-23 14:32:01 -0300
committerHugo Parente Lima <hugo.pl@gmail.com>2012-03-08 16:17:16 -0300
commit701466409c3c13ae4573bf73957f6a874ce5ccbf (patch)
treecc7ea48555863e12eaa30c04e0e6cbc9547c0adf
parentd27ed2fea367d787aa7319531d1df1bbd6739e71 (diff)
Create SHIBOKEN MODULE INIT macro.
-rw-r--r--generator/cppgenerator.cpp13
-rw-r--r--libshiboken/sbkpython.h18
2 files changed, 20 insertions, 11 deletions
diff --git a/generator/cppgenerator.cpp b/generator/cppgenerator.cpp
index dfacb4cf2..35e9d2639 100644
--- a/generator/cppgenerator.cpp
+++ b/generator/cppgenerator.cpp
@@ -3940,14 +3940,8 @@ void CppGenerator::finishGeneration()
s << " /* m_clear */ 0," << endl;
s << " /* m_free */ 0" << endl;
s << "};" << endl << endl;
- s << " #define SBK_MODULE_INIT_ERROR 0" << endl;
- s << "extern \"C\" SBK_EXPORT_MODULE PyObject* PyInit_" << moduleName() << "()" << endl;
- s << "#else" << endl;
- s << " #define SBK_MODULE_INIT_ERROR" << endl;
- s << "extern \"C\" SBK_EXPORT_MODULE void init" << moduleName() << "()" << endl;
s << "#endif" << endl;
-
- s << '{' << endl;
+ s << "SBK_MODULE_INIT_FUNCTION_BEGIN(" << moduleName() << ")" << endl;
ErrorCode errorCode("SBK_MODULE_INIT_ERROR");
// module inject-code target/beginning
@@ -4056,10 +4050,7 @@ void CppGenerator::finishGeneration()
s << INDENT << "PySide::registerCleanupFunction(cleanTypesAttributes);" << endl;
}
- s << "#ifdef IS_PY3K" << endl;
- s << INDENT << "return module;" << endl;
- s << "#endif" << endl;
- s << '}' << endl << endl;
+ s << "SBK_MODULE_INIT_FUNCTION_END" << endl;
}
static ArgumentOwner getArgumentOwner(const AbstractMetaFunction* func, int argIndex)
diff --git a/libshiboken/sbkpython.h b/libshiboken/sbkpython.h
index 4c9ab5c76..24b70fe6d 100644
--- a/libshiboken/sbkpython.h
+++ b/libshiboken/sbkpython.h
@@ -43,6 +43,15 @@
#define SBK_PyString_FromCString PyUnicode_FromString
#define SBK_PyString_FromFormat PyUnicode_FromFormat
#define SBK_PyString_CompareWithASCIIString PyUnicode_CompareWithASCIIString
+
+ // Module MACROS
+ #define SBK_MODULE_INIT_ERROR 0
+ #define SBK_MODULE_INIT_FUNCTION_BEGIN(ModuleName) \
+ extern "C" SBK_EXPORT_MODULE PyObject* PyInit_##ModuleName() {
+
+ #define SBK_MODULE_INIT_FUNCTION_END \
+ return module; }
+
#else
// Note: if there wasn't for the old-style classes, only a PyNumber_Check would suffice.
#define SbkNumber_Check(X) \
@@ -53,6 +62,15 @@
#define SBK_PyString_FromCString PyBytes_FromString
#define SBK_PyString_FromFormat PyString_FromFormat
#define SBK_PyString_CompareWithASCIIString(X, Y) strcmp(PyString_AS_STRING(X), Y)
+
+ // Module MACROS
+ #define SBK_MODULE_INIT_ERROR
+ #define SBK_MODULE_INIT_FUNCTION_BEGIN(ModuleName) \
+ extern "C" SBK_EXPORT_MODULE void init##ModuleName()
+
+ #define SBK_MODULE_INIT_FUNCTION_END \
+ }
+
#endif
#endif