Commit 8c686843 authored by Mark Lodato's avatar Mark Lodato

set module_is_main = 1 in main(), not globally

From 3ebc39282aa9a8379069df12b0c8cc86a2ac8a25 Mon Sep 17 00:00:00 2001
Date: Mon, 5 Oct 2009 21:17:04 -0400
For --embed mode, always initialize the global variable
__pyx_module_is_main_MODULE to zero, even with --embed, and only set it
to one in main().  This would allow the same code to still work if
compiled as a shared library (main would be ignored) and also make the
code cleaner since all of the --embed stuff would be in one place.
---
 Cython/Compiler/ModuleNode.py |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)
parent 5d8d9abf
...@@ -268,7 +268,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -268,7 +268,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
code = globalstate['before_global_var'] code = globalstate['before_global_var']
code.putln('#define __Pyx_MODULE_NAME "%s"' % self.full_module_name) code.putln('#define __Pyx_MODULE_NAME "%s"' % self.full_module_name)
code.putln("int %s%s = %s;" % (Naming.module_is_main, self.full_module_name.replace('.', '__'), int(Options.embed))) code.putln("int %s%s = 0;" % (Naming.module_is_main, self.full_module_name.replace('.', '__')))
code.putln("") code.putln("")
code.putln("/* Implementation of %s */" % env.qualified_name) code.putln("/* Implementation of %s */" % env.qualified_name)
self.generate_const_definitions(env, code) self.generate_const_definitions(env, code)
...@@ -1795,7 +1795,8 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -1795,7 +1795,8 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
code.putln('}') code.putln('}')
def generate_main_method(self, env, code): def generate_main_method(self, env, code):
code.globalstate.use_utility_code(main_method.specialize(module_name=env.module_name)) module_is_main = "%s%s" % (Naming.module_is_main, self.full_module_name.replace('.', '__'))
code.globalstate.use_utility_code(main_method.specialize(module_name=env.module_name, module_is_main=module_is_main))
def generate_filename_init_call(self, code): def generate_filename_init_call(self, code):
code.putln("%s();" % Naming.fileinit_cname) code.putln("%s();" % Naming.fileinit_cname)
...@@ -2503,6 +2504,7 @@ int wmain(int argc, wchar_t **argv) { ...@@ -2503,6 +2504,7 @@ int wmain(int argc, wchar_t **argv) {
Py_SetProgramName(argv[0]); Py_SetProgramName(argv[0]);
Py_Initialize(); Py_Initialize();
PySys_SetArgv(argc, argv); PySys_SetArgv(argc, argv);
%(module_is_main)s = 1;
#if PY_MAJOR_VERSION < 3 #if PY_MAJOR_VERSION < 3
init%(module_name)s(); init%(module_name)s();
#else #else
......
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