Commit 0045f57a authored by Stefan Behnel's avatar Stefan Behnel

Simplify and clean up the embedded main import code to make it work how it's...

Simplify and clean up the embedded main import code to make it work how it's officially supposed to work: use the inittab.
parent ee54de79
...@@ -26,32 +26,23 @@ static int __Pyx_main(int argc, wchar_t **argv) { ...@@ -26,32 +26,23 @@ static int __Pyx_main(int argc, wchar_t **argv) {
#endif #endif
if (argc && argv) if (argc && argv)
Py_SetProgramName(argv[0]); Py_SetProgramName(argv[0]);
#if PY_MAJOR_VERSION < 3
if (PyImport_AppendInittab("%(module_name)s", init%(module_name)s) < 0) return 1;
#else
if (PyImport_AppendInittab("%(module_name)s", PyInit_%(module_name)s) < 0) return 1;
#endif
Py_Initialize(); Py_Initialize();
if (argc && argv) if (argc && argv)
PySys_SetArgv(argc, argv); PySys_SetArgv(argc, argv);
{ /* init module '%(module_name)s' as '__main__' */ { /* init module '%(module_name)s' as '__main__' */
PyObject* m = NULL; PyObject* m = NULL;
%(module_is_main)s = 1; %(module_is_main)s = 1;
#if PY_MAJOR_VERSION < 3 m = PyImport_ImportModule("%(module_name)s");
init%(module_name)s();
#elif CYTHON_PEP489_MULTI_PHASE_INIT if (!m && PyErr_Occurred()) {
m = PyInit_%(module_name)s();
if (!PyModule_Check(m)) {
PyModuleDef *mdef = (PyModuleDef *) m;
PyObject *modname = PyUnicode_FromString("__main__");
m = NULL;
if (modname) {
// FIXME: not currently calling PyModule_FromDefAndSpec() here because we do not have a module spec!
// FIXME: not currently setting __file__, __path__, __spec__, ...
m = PyModule_NewObject(modname);
Py_DECREF(modname);
if (m) PyModule_ExecDef(m, mdef);
}
}
#else
m = PyInit_%(module_name)s();
#endif
if (PyErr_Occurred()) {
PyErr_Print(); /* This exits with the right code if SystemExit. */ PyErr_Print(); /* This exits with the right code if SystemExit. */
#if PY_MAJOR_VERSION < 3 #if PY_MAJOR_VERSION < 3
if (Py_FlushLine()) PyErr_Clear(); if (Py_FlushLine()) PyErr_Clear();
......
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