From: Mark Lodato Date: Tue, 6 Oct 2009 08:57:48 +0000 (-0700) Subject: set module_is_main = 1 in main(), not globally X-Git-Tag: 0.13.beta0~2^2~121^2~102^2 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=8c6868432253af71eb502895ca3c136d2634537d;p=cython.git 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(-) --- diff --git a/Cython/Compiler/ModuleNode.py b/Cython/Compiler/ModuleNode.py index 0a396c40..0674926c 100644 --- a/Cython/Compiler/ModuleNode.py +++ b/Cython/Compiler/ModuleNode.py @@ -268,7 +268,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): code = globalstate['before_global_var'] 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("/* Implementation of %s */" % env.qualified_name) self.generate_const_definitions(env, code) @@ -1795,7 +1795,8 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): code.putln('}') 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): code.putln("%s();" % Naming.fileinit_cname) @@ -2503,6 +2504,7 @@ int wmain(int argc, wchar_t **argv) { Py_SetProgramName(argv[0]); Py_Initialize(); PySys_SetArgv(argc, argv); + %(module_is_main)s = 1; #if PY_MAJOR_VERSION < 3 init%(module_name)s(); #else