Move python ts element key refcounting back to C-side of things
authorPanu Matilainen <pmatilai@redhat.com>
Thu, 17 Dec 2009 08:38:08 +0000 (10:38 +0200)
committerPanu Matilainen <pmatilai@redhat.com>
Thu, 17 Dec 2009 08:38:08 +0000 (10:38 +0200)
- it's really the C-side that needs this, doing it in C avoids nasty
  surprises when subclassing rpm.ts
- partial revert of commit 92d18d1d7139b37065ea742cfe0e8cee5e9c3500

python/rpm/transaction.py
python/rpmts-py.c

index 359d62c..ba8c5b0 100644 (file)
@@ -6,8 +6,6 @@ from rpm._rpm import ts as _rpmts
 # TODO: migrate relevant documentation from C-side
 class TransactionSet(_rpmts):
     _probFilter = 0
-    # FIXME: kludge for keeping refcounts on transaction element keys
-    _keyList = []
 
     def _wrapSetGet(self, attr, val):
         oval = getattr(self, attr)
@@ -62,7 +60,6 @@ class TransactionSet(_rpmts):
 
         if not _rpmts.addInstall(self, header, key, upgrade):
             raise rpm.error("adding package to transaction failed")
-        self._keyList.append(key)
 
     def addErase(self, item):
         hdrs = []
index 745b526..72c039b 100644 (file)
@@ -138,6 +138,7 @@ struct rpmtsObject_s {
     PyObject_HEAD
     PyObject *md_dict;         /*!< to look like PyModuleObject */
     rpmfdObject *scriptFd;
+    PyObject *keyList;
     rpmts      ts;
     rpmtsi tsi;
 };
@@ -180,6 +181,9 @@ rpmts_AddInstall(rpmtsObject * s, PyObject * args)
        return NULL;
 
     rc = rpmtsAddInstallElement(s->ts, h, key, how, NULL);
+    if (key && rc == 0) {
+       PyList_Append(s->keyList, key);
+    }
     return PyBool_FromLong((rc == 0));
 }
 
@@ -692,6 +696,7 @@ static void rpmts_dealloc(rpmtsObject * s)
 
     s->ts = rpmtsFree(s->ts);
     Py_XDECREF(s->scriptFd);
+    Py_XDECREF(s->keyList);
     Py_TYPE(s)->tp_free((PyObject *)s);
 }
 
@@ -703,6 +708,7 @@ static PyObject * rpmts_new(PyTypeObject * subtype, PyObject *args, PyObject *kw
     s->ts = rpmtsCreate();
     s->scriptFd = NULL;
     s->tsi = NULL;
+    s->keyList = PyList_New(0);
     return (PyObject *) s;
 }