[pypy-svn] r78281 - in pypy/branch/leak-finder-more/pypy: annotation module/cpyext

afa at codespeak.net afa at codespeak.net
Tue Oct 26 09:30:03 CEST 2010


Author: afa
Date: Tue Oct 26 09:29:56 2010
New Revision: 78281

Modified:
   pypy/branch/leak-finder-more/pypy/annotation/builtin.py
   pypy/branch/leak-finder-more/pypy/module/cpyext/cdatetime.py
   pypy/branch/leak-finder-more/pypy/module/cpyext/typeobject.py
Log:
Reduce the number of reported leaks in the cpyext module,
and try to fix translation


Modified: pypy/branch/leak-finder-more/pypy/annotation/builtin.py
==============================================================================
--- pypy/branch/leak-finder-more/pypy/annotation/builtin.py	(original)
+++ pypy/branch/leak-finder-more/pypy/annotation/builtin.py	Tue Oct 26 09:29:56 2010
@@ -453,6 +453,9 @@
     #p = lltype.malloc(T, flavor=s_flavor.const)
     #lltype.free(p, flavor=s_flavor.const)
 
+def render_immortal(s_p, s_track_allocation=None):
+    assert s_track_allocation is None or s_track_allocation.is_constant()
+
 def typeOf(s_val):
     lltype = annotation_to_lltype(s_val, info="in typeOf(): ")
     return immutablevalue(lltype)
@@ -520,6 +523,7 @@
 
 BUILTIN_ANALYZERS[lltype.malloc] = malloc
 BUILTIN_ANALYZERS[lltype.free] = free
+BUILTIN_ANALYZERS[lltype.render_immortal] = render_immortal
 BUILTIN_ANALYZERS[lltype.typeOf] = typeOf
 BUILTIN_ANALYZERS[lltype.cast_primitive] = cast_primitive
 BUILTIN_ANALYZERS[lltype.nullptr] = nullptr

Modified: pypy/branch/leak-finder-more/pypy/module/cpyext/cdatetime.py
==============================================================================
--- pypy/branch/leak-finder-more/pypy/module/cpyext/cdatetime.py	(original)
+++ pypy/branch/leak-finder-more/pypy/module/cpyext/cdatetime.py	Tue Oct 26 09:29:56 2010
@@ -4,7 +4,7 @@
 from pypy.module.cpyext.api import (
     cpython_api, CANNOT_FAIL, cpython_struct, PyObjectFields)
 from pypy.module.cpyext.import_ import PyImport_Import
-from pypy.module.cpyext.typeobject import PyTypeObjectPtr
+from pypy.module.cpyext.typeobject import PyTypeObjectPtr, render_immortal
 from pypy.module.cpyext.state import State
 from pypy.interpreter.error import OperationError
 from pypy.tool.sourcetools import func_renamer
@@ -22,25 +22,34 @@
 @cpython_api([], lltype.Ptr(PyDateTime_CAPI),
              error=lltype.nullptr(PyDateTime_CAPI))
 def _PyDateTime_Import(space):
-    datetimeAPI = lltype.malloc(PyDateTime_CAPI, flavor='raw')
+    datetimeAPI = lltype.malloc(PyDateTime_CAPI, flavor='raw',
+                                track_allocation=False)
 
     if not we_are_translated():
         datetimeAPI_dealloc(space)
         space.fromcache(State).datetimeAPI = datetimeAPI
 
     w_datetime = PyImport_Import(space, space.wrap("datetime"))
+
     w_type = space.getattr(w_datetime, space.wrap("date"))
     datetimeAPI.c_DateType = rffi.cast(
         PyTypeObjectPtr, make_ref(space, w_type))
+    render_immortal(datetimeAPI.c_DateType, w_type)
+
     w_type = space.getattr(w_datetime, space.wrap("datetime"))
     datetimeAPI.c_DateTimeType = rffi.cast(
         PyTypeObjectPtr, make_ref(space, w_type))
+    render_immortal(datetimeAPI.c_DateTimeType, w_type)
+
     w_type = space.getattr(w_datetime, space.wrap("time"))
     datetimeAPI.c_TimeType = rffi.cast(
         PyTypeObjectPtr, make_ref(space, w_type))
+    render_immortal(datetimeAPI.c_TimeType, w_type)
+
     w_type = space.getattr(w_datetime, space.wrap("timedelta"))
     datetimeAPI.c_DeltaType = rffi.cast(
         PyTypeObjectPtr, make_ref(space, w_type))
+    render_immortal(datetimeAPI.c_DeltaType, w_type)
 
     return datetimeAPI
 

Modified: pypy/branch/leak-finder-more/pypy/module/cpyext/typeobject.py
==============================================================================
--- pypy/branch/leak-finder-more/pypy/module/cpyext/typeobject.py	(original)
+++ pypy/branch/leak-finder-more/pypy/module/cpyext/typeobject.py	Tue Oct 26 09:29:56 2010
@@ -538,12 +538,23 @@
     w_obj.ready()
 
     finish_type_2(space, py_type, w_obj)
+    render_immortal(py_type, w_obj)
 
     state = space.fromcache(RefcountState)
     state.non_heaptypes_w.append(w_obj)
 
     return w_obj
 
+def render_immortal(py_type, w_obj):
+    lltype.render_immortal(py_type.c_tp_bases)
+    lltype.render_immortal(py_type.c_tp_mro)
+
+    assert isinstance(w_obj, W_TypeObject)
+    if w_obj.is_cpytype():
+        lltype.render_immortal(py_type.c_tp_dict)
+    else:
+        lltype.render_immortal(py_type.c_tp_name)
+
 def finish_type_1(space, pto):
     """
     Sets up tp_bases, necessary before creating the interpreter type.



More information about the Pypy-commit mailing list