Module is main flag for embedded mode.
authorRobert Bradshaw <robertwb@math.washington.edu>
Thu, 14 May 2009 09:01:48 +0000 (02:01 -0700)
committerRobert Bradshaw <robertwb@math.washington.edu>
Thu, 14 May 2009 09:01:48 +0000 (02:01 -0700)
Cython/Compiler/ModuleNode.py
Cython/Compiler/Naming.py

index f8012865836682f41ab27444a491d8edb622d83f..ed80ae1ceb7db837cd7829529222dfa42610c3f7 100644 (file)
@@ -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"));' % (
index 7864efdb61f1319223bf16df17a26d7fb8852f59..e12a40480ddd28f0520a75e47630853f55cc330e 100644 (file)
@@ -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"