[Rpm-maint] PATCH: Accessing file and policy lists from python (and C)

David Malcolm dmalcolm at redhat.com
Mon Sep 24 20:29:31 UTC 2012


On Sat, 2012-09-15 at 16:47 +0200, Alec Leamas wrote:
> When rpm-build parses the specfile, it also parses the file list and 
> (nowadays?) also the policy. These are stored in specPackage objects 
> attached to the spec. However, these items are not visible on the 
> rpm.specPkg interface, neither from C nor from python.
> 
> Is there a particular reason these items aren't visible?
> 
> I have som pronlems with this related to the fedora-review tool [1], 
> which basically forces us to use some hand-crafted specfile parsing , 
> since the file lists are needed. I would certainly prefer using rpmlib's 
> own parsing for that. However, then external access to the fields 
> fileList, fileFile and policyList is needed. The enclosed patch arranges 
> this.
> 
> Would it be possible to solve the access to the mentioned list, perhaps 
> by accepting the patch?

FWIW there are a couple of places in the python binding part of the
patch where it doesn't do error handling:

diff --git a/python/spec-py.c b/python/spec-py.c
index 284f52b..bc28c65 100644
--- a/python/spec-py.c
+++ b/python/spec-py.c
@@ -47,16 +47,51 @@ struct specPkgObject_s {
     rpmSpecPkg pkg;
 };

+static PyObject *argv2list(ARGV_const_t argv)
[...snip...]
+    py_list = PyList_New(size);
PyList_New() can fail returning NULL under low memory conditions;
PyList_SetItem(NULL, ...) will segfault.

+    for (ix = 0, s = argvData((ARGV_t)argv); ix < size; ix++, s++)
+        PyList_SetItem(py_list, ix, PyString_FromString(*s));

PyString_FromString() can fail under low memory conditions (though
PyList_SetItem(list, ix, NULL) won't crash FWIW).

PyList_SetItem steals the new reference from PyString_FromString, so the
reference-counting here looks OK.

Hope this is helpful
Dave



More information about the Rpm-maint mailing list