Mangle naming for cleanup function.
authorRobert Bradshaw <robertwb@math.washington.edu>
Fri, 1 Feb 2008 19:43:33 +0000 (11:43 -0800)
committerRobert Bradshaw <robertwb@math.washington.edu>
Fri, 1 Feb 2008 19:43:33 +0000 (11:43 -0800)
Cython/Compiler/CmdLine.py
Cython/Compiler/ModuleNode.py
Cython/Compiler/Naming.py

index 1689b21f673f843b5e57d4b784f1406c4b63b979..703ea2c11ea12e13abd83d632fb024fff39c4ea2 100644 (file)
@@ -24,6 +24,8 @@ Options:
                                  "from <module> import *" at the top of the file. 
   --incref-local-binop           Force local an extra incref on local variables before
                                  performing any binary operations.
+  --cleanup <level>              Release interned objects on python exit, for memory debugging. 
+                                 Level indicates aggressiveness, default 0 releases nothing. 
   -D, --no-docstrings            Remove docstrings.
   -a, --annotate                 Produce an colorized version of the source.
   --convert-range                Convert for loops using range() function to for...from loops. 
index 55bbbda63ce8af422117113f8d290e4ca0602c3c..5e529b592a105535f8df34f56eb44475f42b27a9 100644 (file)
@@ -1339,10 +1339,12 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
         env.use_utility_code(import_module_utility_code)
         env.use_utility_code(register_cleanup_utility_code)
         code.putln()
-        code.putln('static PyObject* cleanup(PyObject *self, PyObject *unused) {')
+        code.putln('static PyObject* %s(PyObject *self, PyObject *unused) {' % Naming.cleanup_cname)
         if Options.generate_cleanup_code >= 2:
             code.putln("/*--- Global cleanup code ---*/")
-            for entry in reversed(env.var_entries):
+            rev_entries = list(env.var_entries)
+            rev_entries.reverse()
+            for entry in rev_entries:
                 if entry.visibility != 'extern':
                     if entry.type.is_pyobject:
                         code.put_var_decref_clear(entry)
@@ -1790,8 +1792,8 @@ bad:
 register_cleanup_utility_code = [
 """
 static int __Pyx_RegisterCleanup(void); /*proto*/
-static PyObject* cleanup(PyObject *self, PyObject *unused); /*proto*/
-static PyMethodDef cleanup_def = {"__cleanup", (PyCFunction)&cleanup, METH_NOARGS, 0};
+static PyObject* __pyx_module_cleanup(PyObject *self, PyObject *unused); /*proto*/
+static PyMethodDef cleanup_def = {"__cleanup", (PyCFunction)&__pyx_module_cleanup, METH_NOARGS, 0};
 ""","""
 static int __Pyx_RegisterCleanup(void) {
     /* Don't use Py_AtExit because that has a 32-call limit 
index acdd674f4d26406eebc96886697eb9fec875f286..c273d73f08a07bff10a85db3f74fd6f005ff20dc 100644 (file)
@@ -59,6 +59,7 @@ c_api_tab_cname  = pyrex_prefix + "c_api_tab"
 gilstate_cname   = pyrex_prefix + "state"
 skip_dispatch_cname = pyrex_prefix + "skip_dispatch"
 empty_tuple      = pyrex_prefix + "empty_tuple"
+cleanup_cname    = pyrex_prefix + "module_cleanup"
 
 
 extern_c_macro  = pyrex_prefix.upper() + "EXTERN_C"