Commit f2aebb86 authored by David Gobbi's avatar David Gobbi
Browse files

Provide py3k module initialization.

This changes the return value of the "real_init" function from void
to PyObject *, in accordance with the new PyInit method.
parent 4f297425
...@@ -8,31 +8,35 @@ static void CreateInitFile(const char *libName, FILE *fout) ...@@ -8,31 +8,35 @@ static void CreateInitFile(const char *libName, FILE *fout)
const char* dllexp = "VTK_ABI_EXPORT "; const char* dllexp = "VTK_ABI_EXPORT ";
fprintf(fout,"// Generated by vtkWrapPythonInit in VTK/Wrapping\n"); fprintf(fout,"// Generated by vtkWrapPythonInit in VTK/Wrapping\n");
fprintf(fout,"#include \"vtkPython.h\"\n");
fprintf(fout,"#include \"vtkPythonCompatibility.h\"\n");
fprintf(fout,"#include \"vtkSystemIncludes.h\"\n"); fprintf(fout,"#include \"vtkSystemIncludes.h\"\n");
fprintf(fout,"// Handle compiler warning messages, etc.\n" fprintf(fout,"// Handle compiler warning messages, etc.\n"
"#if defined( _MSC_VER ) && !defined(VTK_DISPLAY_WIN32_WARNINGS)\n" "#if defined( _MSC_VER ) && !defined(VTK_DISPLAY_WIN32_WARNINGS)\n"
"#pragma warning ( disable : 4706 )\n" "#pragma warning ( disable : 4706 )\n"
"#endif // Windows Warnings \n\n"); "#endif // Windows Warnings\n\n");
fprintf(fout,"extern \"C\" void real_init%s(const char *);\n\n", libName); fprintf(fout,"extern \"C\" { PyObject *real_init%s(const char *); }\n\n", libName);
for (;;) fprintf(fout,"#ifdef VTK_PY3K\n");
{
fprintf(fout,"extern \"C\" { %svoid init%s%s(); }\n\n", dllexp, prefix, libName); fprintf(fout,"extern \"C\" { %sPyObject *PyInit_%s%s(); }\n\n", dllexp, prefix, libName);
fprintf(fout,"void init%s%s()\n{\n", prefix, libName); fprintf(fout,"PyObject *PyInit_%s()\n", libName);
fprintf(fout," real_init%s(NULL);\n}\n\n", libName); fprintf(fout,"{\n");
fprintf(fout," return real_init%s(NULL);\n", libName);
#if defined(__CYGWIN__) || !defined(_WIN32) fprintf(fout,"}\n");
/* add a "lib" prefix for compatibility with old python scripts */
if (strcmp(prefix, "lib") != 0) fprintf(fout,"#else\n");
{
prefix = "lib"; fprintf(fout,"extern \"C\" { %svoid init%s%s(); }\n\n", dllexp, prefix, libName);
continue;
} fprintf(fout,"void init%s()\n", libName);
#endif fprintf(fout,"{\n");
break; fprintf(fout," real_init%s(NULL);\n", libName);
} fprintf(fout,"}\n");
fprintf(fout,"#endif\n");
} }
...@@ -47,7 +51,8 @@ static void CreateImplFile(const char *libName, ...@@ -47,7 +51,8 @@ static void CreateImplFile(const char *libName,
const char* dllexp = "VTK_ABI_EXPORT "; const char* dllexp = "VTK_ABI_EXPORT ";
fprintf(fout,"// Generated by vtkWrapPythonInit in VTK/Wrapping\n"); fprintf(fout,"// Generated by vtkWrapPythonInit in VTK/Wrapping\n");
fprintf(fout,"#include \"vtkPython.h\"\n\n"); fprintf(fout,"#include \"vtkPython.h\"\n");
fprintf(fout,"#include \"vtkPythonCompatibility.h\"\n");
fprintf(fout,"#include \"vtkSystemIncludes.h\"\n"); fprintf(fout,"#include \"vtkSystemIncludes.h\"\n");
fprintf(fout,"#include <string.h>\n"); fprintf(fout,"#include <string.h>\n");
fprintf(fout,"// Handle compiler warning messages, etc.\n" fprintf(fout,"// Handle compiler warning messages, etc.\n"
...@@ -60,17 +65,36 @@ static void CreateImplFile(const char *libName, ...@@ -60,17 +65,36 @@ static void CreateImplFile(const char *libName,
fprintf(fout,"extern \"C\" {%sPyObject *PyVTKAddFile_%s(PyObject *); }\n", dllexp, files[i]); fprintf(fout,"extern \"C\" {%sPyObject *PyVTKAddFile_%s(PyObject *); }\n", dllexp, files[i]);
} }
fprintf(fout,"\nstatic PyMethodDef Py%s_ClassMethods[] = {\n", libName); fprintf(fout,"\nstatic PyMethodDef Py%s_Methods[] = {\n", libName);
fprintf(fout,"{NULL, NULL, 0, NULL}};\n\n"); fprintf(fout,"{NULL, NULL, 0, NULL}};\n\n");
fprintf(fout,"extern \"C\" {%svoid real_init%s(const char *); }\n\n", dllexp, libName); fprintf(fout,"#ifdef VTK_PY3K\n");
fprintf(fout,"static PyModuleDef Py%s_Module = {\n", libName);
fprintf(fout," PyModuleDef_HEAD_INIT,\n");
fprintf(fout," \"%s\", // m_name\n", libName);
fprintf(fout," NULL, // m_doc\n");
fprintf(fout," 0, // m_size\n");
fprintf(fout," Py%s_Methods, //m_methods\n", libName);
fprintf(fout," NULL, // m_reload\n");
fprintf(fout," NULL, // m_traverse\n");
fprintf(fout," NULL, // m_clear\n");
fprintf(fout," NULL // m_free\n");
fprintf(fout,"};\n");
fprintf(fout,"#endif\n\n");
fprintf(fout,"void real_init%s(const char *)\n{\n", libName); fprintf(fout,"extern \"C\" {%sPyObject *real_init%s(const char *); }\n\n", dllexp, libName);
fprintf(fout,"PyObject *real_init%s(const char *)\n{\n", libName);
/* module init function */ /* module init function */
fprintf(fout,"#ifdef VTK_PY3K\n");
fprintf(fout," PyObject *m = PyModule_Create(&Py%s_Module);\n",
libName);
fprintf(fout,"#else\n\n");
fprintf(fout," PyObject *m = Py_InitModule(\"%s\",\n" fprintf(fout," PyObject *m = Py_InitModule(\"%s\",\n"
" Py%s_ClassMethods);\n", " Py%s_Methods);\n",
libName, libName); libName, libName);
fprintf(fout,"#endif\n\n");
fprintf(fout," PyObject *d = PyModule_GetDict(m);\n"); fprintf(fout," PyObject *d = PyModule_GetDict(m);\n");
fprintf(fout," if (!d)\n"); fprintf(fout," if (!d)\n");
...@@ -84,6 +108,9 @@ static void CreateImplFile(const char *libName, ...@@ -84,6 +108,9 @@ static void CreateImplFile(const char *libName,
fprintf(fout," PyVTKAddFile_%s(d);\n", fprintf(fout," PyVTKAddFile_%s(d);\n",
files[i]); files[i]);
} }
fprintf(fout,"\n");
fprintf(fout," return m;\n");
fprintf(fout,"}\n\n"); fprintf(fout,"}\n\n");
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment