__name__ == "__main__" for embedded modules
authorRobert Bradshaw <robertwb@math.washington.edu>
Tue, 21 Apr 2009 09:11:16 +0000 (02:11 -0700)
committerRobert Bradshaw <robertwb@math.washington.edu>
Tue, 21 Apr 2009 09:11:16 +0000 (02:11 -0700)
Cython/Compiler/CmdLine.py
Cython/Compiler/ModuleNode.py

index f48cfb58456efe56c846dbf01613a504d1424f36..d70223a48a1c84da0b94e8ac5a765ae33c8ee0c7 100644 (file)
@@ -73,7 +73,6 @@ def parse_command_line(args):
     options = CompilationOptions(default_options)
     sources = []
     while args:
-        print args
         if args[0].startswith("-"):
             option = pop_arg()
             if option in ("-V", "--version"):
index 97d5f2180eddaa37c15a6a940efc01efd5eb1ec7..8a6364fc34e2473088a43f87e9244ce8b739e0d2 100644 (file)
@@ -56,6 +56,8 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
         else:
             env.doc = self.doc
         env.directives = self.directives
+        if Options.embed:
+            self.__main__cname = env.intern_identifier(EncodedString("__main__"))
         self.body.analyse_declarations(env)
     
     def process_implementation(self, options, result):
@@ -1803,6 +1805,12 @@ 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)))
         if Options.pre_import is not None:
             code.putln(
                 '%s = PyImport_AddModule(__Pyx_NAMESTR("%s"));' % (
@@ -2459,7 +2467,7 @@ int main(int argc, char** argv) {
 #else
         PyInit_%(module_name)s(name);
 #endif
-    r = PyErr_Occurred();
+    r = PyErr_Occurred() != NULL;
     Py_Finalize();
     return r;
 }