Commit 611591bf authored by Robert Bradshaw's avatar Robert Bradshaw

__name__ == "__main__" for embedded modules

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