Browse Source

interrogate: Export Python entry points with EXPORT_CLASS

Closes #505
Sam Edwards 7 years ago
parent
commit
0c890f059d

+ 2 - 14
dtool/src/interrogate/interfaceMakerPythonNative.cxx

@@ -1532,13 +1532,7 @@ write_module(ostream &out, ostream *out_h, InterrogateModuleDef *def) {
       << "  nullptr, nullptr, nullptr, nullptr\n"
       << "};\n"
       << "\n"
-      << "#ifdef _WIN32\n"
-      << "extern \"C\" __declspec(dllexport) PyObject *PyInit_" << def->module_name << "();\n"
-      << "#elif __GNUC__ >= 4\n"
-      << "extern \"C\" __attribute__((visibility(\"default\"))) PyObject *PyInit_" << def->module_name << "();\n"
-      << "#else\n"
-      << "extern \"C\" PyObject *PyInit_" << def->module_name << "();\n"
-      << "#endif\n"
+      << "extern \"C\" EXPORT_CLASS PyObject *PyInit_" << def->module_name << "();\n"
       << "\n"
       << "PyObject *PyInit_" << def->module_name << "() {\n"
       << "  LibraryDef *refs[] = {&" << def->library_name << "_moddef, nullptr};\n"
@@ -1549,13 +1543,7 @@ write_module(ostream &out, ostream *out_h, InterrogateModuleDef *def) {
       << "\n"
       << "#else  // Python 2 case\n"
       << "\n"
-      << "#ifdef _WIN32\n"
-      << "extern \"C\" __declspec(dllexport) void init" << def->module_name << "();\n"
-      << "#elif __GNUC__ >= 4\n"
-      << "extern \"C\" __attribute__((visibility(\"default\"))) void init" << def->module_name << "();\n"
-      << "#else\n"
-      << "extern \"C\" void init" << def->module_name << "();\n"
-      << "#endif\n"
+      << "extern \"C\" EXPORT_CLASS void init" << def->module_name << "();\n"
       << "\n"
       << "void init" << def->module_name << "() {\n"
       << "  LibraryDef *refs[] = {&" << def->library_name << "_moddef, nullptr};\n"

+ 3 - 34
dtool/src/interrogate/interrogate_module.cxx

@@ -295,24 +295,10 @@ int write_python_table_native(std::ostream &out) {
 
   out.put('\n');
 
-  out << "#if PY_MAJOR_VERSION >= 3 || !defined(NDEBUG)\n"
-      << "#ifdef _WIN32\n"
-      << "extern \"C\" __declspec(dllexport) PyObject *PyInit_" << library_name << "();\n"
-      << "#elif __GNUC__ >= 4\n"
-      << "extern \"C\" __attribute__((visibility(\"default\"))) PyObject *PyInit_" << library_name << "();\n"
-      << "#else\n"
-      << "extern \"C\" PyObject *PyInit_" << library_name << "();\n"
-      << "#endif\n"
-      << "#endif\n";
-
-  out << "#if PY_MAJOR_VERSION < 3 || !defined(NDEBUG)\n"
-      << "#ifdef _WIN32\n"
-      << "extern \"C\" __declspec(dllexport) void init" << library_name << "();\n"
-      << "#elif __GNUC__ >= 4\n"
-      << "extern \"C\" __attribute__((visibility(\"default\"))) void init" << library_name << "();\n"
+  out << "#if PY_MAJOR_VERSION >= 3\n"
+      << "extern \"C\" EXPORT_CLASS PyObject *PyInit_" << library_name << "();\n"
       << "#else\n"
-      << "extern \"C\" void init" << library_name << "();\n"
-      << "#endif\n"
+      << "extern \"C\" EXPORT_CLASS void init" << library_name << "();\n"
       << "#endif\n";
 
   out << "\n"
@@ -361,14 +347,6 @@ int write_python_table_native(std::ostream &out) {
       << "}\n"
       << "\n"
 
-      << "#ifndef NDEBUG\n"
-      << "void init" << library_name << "() {\n"
-      << "  PyErr_SetString(PyExc_ImportError, \"" << module_name << " was "
-      << "compiled for Python \" PY_VERSION \", which is incompatible "
-      << "with Python 2\");\n"
-      << "}\n"
-      << "#endif\n"
-
       << "#else  // Python 2 case\n"
       << "\n"
       << "void init" << library_name << "() {\n";
@@ -402,15 +380,6 @@ int write_python_table_native(std::ostream &out) {
 
   out << "  }\n"
       << "}\n"
-      << "\n"
-      << "#ifndef NDEBUG\n"
-      << "PyObject *PyInit_" << library_name << "() {\n"
-      << "  PyErr_SetString(PyExc_ImportError, \"" << module_name << " was "
-      << "compiled for Python \" PY_VERSION \", which is incompatible "
-      << "with Python 3\");\n"
-      << "  return nullptr;\n"
-      << "}\n"
-      << "#endif\n"
       << "#endif\n"
       << "\n";