From 0c890f059dd713f60200bd1d60d48a58cabec075 Mon Sep 17 00:00:00 2001 From: Sam Edwards Date: Thu, 3 Jan 2019 12:03:25 +0100 Subject: [PATCH] interrogate: Export Python entry points with EXPORT_CLASS Closes #505 --- .../interfaceMakerPythonNative.cxx | 16 +------- dtool/src/interrogate/interrogate_module.cxx | 37 ++----------------- 2 files changed, 5 insertions(+), 48 deletions(-) diff --git a/dtool/src/interrogate/interfaceMakerPythonNative.cxx b/dtool/src/interrogate/interfaceMakerPythonNative.cxx index 3964cad919..ca2ed7eb8d 100644 --- a/dtool/src/interrogate/interfaceMakerPythonNative.cxx +++ b/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" diff --git a/dtool/src/interrogate/interrogate_module.cxx b/dtool/src/interrogate/interrogate_module.cxx index 6f7bc4bfeb..663e57762f 100644 --- a/dtool/src/interrogate/interrogate_module.cxx +++ b/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" + out << "#if PY_MAJOR_VERSION >= 3\n" + << "extern \"C\" EXPORT_CLASS 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" - << "#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";