From: Robert Bradshaw Date: Thu, 14 May 2009 09:01:48 +0000 (-0700) Subject: Module is main flag for embedded mode. X-Git-Tag: 0.11.2.rc1~10^2~15 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=77b60f7b924ba190eaa23e52599fd8497f2e1b1c;p=cython.git Module is main flag for embedded mode. --- diff --git a/Cython/Compiler/ModuleNode.py b/Cython/Compiler/ModuleNode.py index f8012865..ed80ae1c 100644 --- a/Cython/Compiler/ModuleNode.py +++ b/Cython/Compiler/ModuleNode.py @@ -265,6 +265,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("") code.putln("/* Implementation of %s */" % env.qualified_name) self.generate_const_definitions(env, code) @@ -1835,12 +1836,13 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): env.module_cname, Naming.builtins_cname, code.error_goto(self.pos))) - if Options.embed: - code.putln( - 'if (__Pyx_SetAttrString(%s, "__name__", %s) < 0) %s;' % ( - env.module_cname, - self.__main__cname, - code.error_goto(self.pos))) + code.putln("if (%s%s) {" % (Naming.module_is_main, self.full_module_name.replace('.', '__'))) + code.putln( + 'if (__Pyx_SetAttrString(%s, "__name__", %s) < 0) %s;' % ( + env.module_cname, + self.__main__cname, + code.error_goto(self.pos))) + code.putln("}") if Options.pre_import is not None: code.putln( '%s = PyImport_AddModule(__Pyx_NAMESTR("%s"));' % ( diff --git a/Cython/Compiler/Naming.py b/Cython/Compiler/Naming.py index 7864efdb..e12a4048 100644 --- a/Cython/Compiler/Naming.py +++ b/Cython/Compiler/Naming.py @@ -43,6 +43,7 @@ vtabptr_prefix = pyrex_prefix + "vtabptr_" vtabstruct_prefix = pyrex_prefix + "vtabstruct_" opt_arg_prefix = pyrex_prefix + "opt_args_" convert_func_prefix = pyrex_prefix + "convert_" +module_is_main = pyrex_prefix + "module_is_main_" args_cname = pyrex_prefix + "args" pykwdlist_cname = pyrex_prefix + "pyargnames"