Change rpmTagGetNames() interface to more like that of headerGet()
authorPanu Matilainen <pmatilai@redhat.com>
Mon, 2 Jun 2008 13:10:19 +0000 (16:10 +0300)
committerPanu Matilainen <pmatilai@redhat.com>
Mon, 2 Jun 2008 13:10:19 +0000 (16:10 +0300)
- instead of returning a newly allocated rpmtd, take container to use
  as argument
- return number of tags found, 0 on error (pretty arbitrary, just to
  return something...)

lib/query.c
lib/rpmtag.h
lib/tagname.c
python/rpmmodule.c

index 983a31b..fc59261 100644 (file)
@@ -258,7 +258,8 @@ void rpmDisplayQueryTags(FILE * fp)
        "string", "blob", "argv", "i18nstring"
     };
     const char *tname, *sname;
-    rpmtd names = rpmTagGetNames(1);
+    rpmtd names = rpmtdNew();
+    (void) rpmTagGetNames(names, 1);
 
     while ((tname = rpmtdNextString(names))) {
        sname = tname + strlen("RPMTAG_");
index d85e05a..9e1653e 100644 (file)
@@ -374,10 +374,11 @@ rpmTag rpmTagGetValue(const char * tagstr);
 
 /** \ingroup rpmtag
  * Return known rpm tag names, sorted by name.
+ * @retval tagnames    tag container of string array type
  * @param fullname     return short or full name
- * @return             tag container of string array type
+ * @return             number of tag names, 0 on error
  */
-rpmtd rpmTagGetNames(int fullname);
+int rpmTagGetNames(rpmtd tagnames, int fullname);
 
 #ifdef __cplusplus
 }
index c8c51dc..2a844d6 100644 (file)
@@ -299,24 +299,26 @@ rpmTag rpmTagGetValue(const char * tagstr)
     return ((*rpmTags->tagValue)(tagstr));
 }
 
-rpmtd rpmTagGetNames(int fullname)
+int rpmTagGetNames(rpmtd tagnames, int fullname)
 {
     const char **names;
     const char *name;
-    rpmtd td = rpmtdNew();
 
     if (_rpmTags.byName == NULL)
        tagLoadIndex(&_rpmTags.byName, &_rpmTags.byNameSize, tagCmpName);
+    if (tagnames == NULL ||_rpmTags.byName == NULL)
+       return 0;
 
-    td->count = _rpmTags.byNameSize;
-    td->data = names = xmalloc(td->count * sizeof(*names));
-    td->type = RPM_STRING_ARRAY_TYPE;
-    td->flags = RPMTD_ALLOCED | RPMTD_IMMUTABLE;
+    rpmtdReset(tagnames);
+    tagnames->count = _rpmTags.byNameSize;
+    tagnames->data = names = xmalloc(tagnames->count * sizeof(*names));
+    tagnames->type = RPM_STRING_ARRAY_TYPE;
+    tagnames->flags = RPMTD_ALLOCED | RPMTD_IMMUTABLE;
 
-    for (int i = 0; i < td->count; i++) {
+    for (int i = 0; i < tagnames->count; i++) {
        name = fullname ? _rpmTags.byName[i]->name : 
                          _rpmTags.byName[i]->shortname;
        names[i] = name;
     }
-    return td;
+    return tagnames->count;
 }
index 7527b64..ac344ba 100644 (file)
@@ -319,7 +319,8 @@ void init_rpm(void)
 
     dict = PyDict_New();
     {  const char *tname, *sname;
-       rpmtd names = rpmTagGetNames(1);
+       rpmtd names = rpmtdNew();
+       rpmTagGetNames(names, 1);
 
        while ((tname = rpmtdNextString(names))) {
            sname = tname + strlen("RPMTAG_");
@@ -330,6 +331,8 @@ void init_rpm(void)
            PyDict_SetItem(dict, tag, o);
            Py_DECREF(o);
        }
+       rpmtdFreeData(names);
+       rpmtdFree(names);
     }  
     PyDict_SetItemString(d, "tagnames", dict);
     Py_DECREF(dict);