Keep counted reference to module
authorGregory Ewing <greg.ewing@canterbury.ac.nz>
Mon, 26 Nov 2007 09:49:11 +0000 (22:49 +1300)
committerGregory Ewing <greg.ewing@canterbury.ac.nz>
Mon, 26 Nov 2007 09:49:11 +0000 (22:49 +1300)
+
+    - A counted reference was not kept to the module, so if the entry
+        in sys.modules was replaced, the module was freed prematurely.
+        [Franck Pommerau]

Cython/Compiler/ModuleNode.py

index 99065b6132484dc54bc8c831836b648177a50770..c86204fb5902f5226eb49e1acdeae5eacf003d4e 100644 (file)
@@ -1543,6 +1543,9 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
             "if (!%s) %s;" % (
                 env.module_cname,
                 code.error_goto(self.pos)));
+        code.putln(
+            "Py_INCREF(%s);" %
+                env.module_cname)
         code.putln(
             '%s = PyImport_AddModule(__Pyx_BUILTIN_MODULE_NAME);' %
                 Naming.builtins_cname)