summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Vogt <michael.vogt@ubuntu.com>2007-11-23 13:40:03 +0100
committerMichael Vogt <michael.vogt@ubuntu.com>2007-11-23 13:40:03 +0100
commit3dc72516fe915b5ba3722b11e07fb70211169509 (patch)
treed45474126b6a9bad8c1c1bdf276df186d04ec58f
parent14eafeeba30ccb31676769d708ad0aa681fab219 (diff)
downloadpython-apt-3dc72516fe915b5ba3722b11e07fb70211169509.tar.gz
* python/progress.cc:
- fix refcount problem in OpProgress - fix refcount problem in FetchProgress - fix refcount problem in CdromProgress
-rw-r--r--debian/changelog4
-rw-r--r--python/progress.cc11
-rwxr-xr-xtests/refcount.py35
3 files changed, 48 insertions, 2 deletions
diff --git a/debian/changelog b/debian/changelog
index ef68c616..ca3308c8 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -17,6 +17,10 @@ python-apt (0.7.4) UNRELEASED; urgency=low
* python/sourceslist.cc:
- support new "List" attribute that returns the list of
metaIndex source entries
+ * python/progress.cc:
+ - fix refcount problem in OpProgress
+ - fix refcount problem in FetchProgress
+ - fix refcount problem in CdromProgress
-- Michael Vogt <michael.vogt@ubuntu.com> Mon, 30 Jul 2007 22:33:59 +0200
diff --git a/python/progress.cc b/python/progress.cc
index df9c2ec1..793265db 100644
--- a/python/progress.cc
+++ b/python/progress.cc
@@ -65,10 +65,11 @@ void PyOpProgress::Update()
Py_XDECREF(o);
// Build up the argument list...
- PyObject *arglist = Py_BuildValue("(f)", Percent);
if(CheckChange(0.05))
+ {
+ PyObject *arglist = Py_BuildValue("(f)", Percent);
RunSimpleCallback("update", arglist);
- Py_XDECREF(arglist);
+ }
};
void PyOpProgress::Done()
@@ -163,14 +164,19 @@ bool PyFetchProgress::Pulse(pkgAcquire * Owner)
PyObject *o;
o = Py_BuildValue("f", CurrentCPS);
PyObject_SetAttrString(callbackInst, "currentCPS", o);
+ Py_XDECREF(o);
o = Py_BuildValue("f", CurrentBytes);
PyObject_SetAttrString(callbackInst, "currentBytes", o);
+ Py_XDECREF(o);
o = Py_BuildValue("i", CurrentItems);
PyObject_SetAttrString(callbackInst, "currentItems", o);
+ Py_XDECREF(o);
o = Py_BuildValue("i", TotalItems);
PyObject_SetAttrString(callbackInst, "totalItems", o);
+ Py_XDECREF(o);
o = Py_BuildValue("f", TotalBytes);
PyObject_SetAttrString(callbackInst, "totalBytes", o);
+ Py_XDECREF(o);
PyObject *arglist = Py_BuildValue("()");
PyObject *result;
@@ -306,6 +312,7 @@ void PyCdromProgress::Update(string text, int current)
PyObject *o = Py_BuildValue("i", totalSteps);
PyObject_SetAttrString(callbackInst, "totalSteps", o);
+ Py_XDECREF(o);
RunSimpleCallback("update", arglist);
}
diff --git a/tests/refcount.py b/tests/refcount.py
new file mode 100755
index 00000000..e8bd9c6d
--- /dev/null
+++ b/tests/refcount.py
@@ -0,0 +1,35 @@
+#!/usr/bin/python-dbg
+
+from pprint import pprint,pformat
+import apt
+import sys
+import gc
+import difflib
+
+# get initial cache
+print sys.gettotalrefcount()
+progress= apt.progress.OpTextProgress()
+c = apt.Cache(progress)
+print "refcount after first cache instance: ", sys.gettotalrefcount()
+
+# test open()
+c.open(progress)
+print "refcount after cache open: ", sys.gettotalrefcount()
+#pprint(sys.getobjects(10))
+
+c.open(apt.progress.OpProgress())
+print "refcount after seconf cache open: ", sys.gettotalrefcount()
+#pprint(sys.getobjects(10))
+
+# FIXME: find a way to get a efficient diff
+#before = gc.get_objects()
+#c.open(apt.progress.OpProgress())
+#after = gc.get_objects()
+
+
+# test update()
+print "refcount before cache.update(): ", sys.gettotalrefcount()
+c.update()
+gc.collect()
+print "refcount after cache.update(): ", sys.gettotalrefcount()
+pprint(sys.getobjects(20))