summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPanu Matilainen <pmatilai@redhat.com>2009-09-30 12:11:43 +0300
committerPanu Matilainen <pmatilai@redhat.com>2009-09-30 12:11:43 +0300
commitb53f5995969554211dde0b235c648f8d2e1cb0a6 (patch)
treecd4630c75f8bbfbcbf42a382bd369b5788f32fb7
parent945bbf49f52c50b53f0d407e91ec46febd56d948 (diff)
downloadrpm-b53f5995969554211dde0b235c648f8d2e1cb0a6.tar.gz
rpm-b53f5995969554211dde0b235c648f8d2e1cb0a6.tar.bz2
rpm-b53f5995969554211dde0b235c648f8d2e1cb0a6.zip
Turn hdrGetHeader() into argument parsing converter interface
-rw-r--r--python/header-py.c12
-rw-r--r--python/header-py.h2
-rw-r--r--python/rpmds-py.c13
-rw-r--r--python/rpmfi-py.c8
-rw-r--r--python/rpmts-py.c8
5 files changed, 25 insertions, 18 deletions
diff --git a/python/header-py.c b/python/header-py.c
index af7c1cdf8..32ec7bd1b 100644
--- a/python/header-py.c
+++ b/python/header-py.c
@@ -378,7 +378,7 @@ static PyObject *hdr_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)
if (obj == NULL) {
h = headerNew();
} else if (hdrObject_Check(obj)) {
- h = headerCopy(hdrGetHeader((hdrObject*) obj));
+ h = headerCopy(((hdrObject*) obj)->h);
} else if (PyString_Check(obj)) {
h = headerCopyLoad(PyString_AsString(obj));
} else if (rpmFdFromPyObject(obj, &fd)) {
@@ -527,9 +527,15 @@ PyObject * hdr_Wrap(PyTypeObject *subtype, Header h)
return (PyObject *) hdr;
}
-Header hdrGetHeader(hdrObject * s)
+int hdrFromPyObject(PyObject *item, Header *hptr)
{
- return s->h;
+ if (hdrObject_Check(item)) {
+ *hptr = ((hdrObject *) item)->h;
+ return 1;
+ } else {
+ PyErr_SetString(PyExc_TypeError, "header object expected");
+ return 0;
+ }
}
/**
diff --git a/python/header-py.h b/python/header-py.h
index faebc4823..ad16e013c 100644
--- a/python/header-py.h
+++ b/python/header-py.h
@@ -18,7 +18,7 @@ extern PyObject * pyrpmError;
PyObject * hdr_Wrap(PyTypeObject *subtype, Header h);
-Header hdrGetHeader(hdrObject * h);
+int hdrFromPyObject(PyObject *item, Header *h);
int tagNumFromPyObject (PyObject *item, rpmTag *tagp);
diff --git a/python/rpmds-py.c b/python/rpmds-py.c
index ab227c41d..67904ba9a 100644
--- a/python/rpmds-py.c
+++ b/python/rpmds-py.c
@@ -418,17 +418,17 @@ static int rpmds_init(rpmdsObject * s, PyObject *args, PyObject *kwds)
static PyObject * rpmds_new(PyTypeObject * subtype, PyObject *args, PyObject *kwds)
{
- hdrObject * ho = NULL;
+ Header h = NULL;
rpmTag tagN = RPMTAG_REQUIRENAME;
rpmsenseFlags flags = 0;
rpmds ds = NULL;
char * kwlist[] = {"header", "tag", "flags", NULL};
- if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!|O&i:rpmds_new", kwlist,
- &hdr_Type, &ho, tagNumFromPyObject, &tagN, &flags))
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&|O&i:rpmds_new", kwlist,
+ hdrFromPyObject, &h, tagNumFromPyObject, &tagN, &flags))
return NULL;
- ds = rpmdsNew(hdrGetHeader(ho), tagN, 0);
+ ds = rpmdsNew(h, tagN, 0);
return rpmds_Wrap(subtype, ds);
}
@@ -523,9 +523,10 @@ PyObject * hdr_dsFromHeader(PyObject * s, PyObject * args, PyObject * kwds)
PyObject * hdr_dsOfHeader(PyObject * s)
{
- hdrObject * ho = (hdrObject *)s;
+ Header h = NULL;
rpmTag tagN = RPMTAG_PROVIDENAME;
rpmsenseFlags Flags = RPMSENSE_EQUAL;
+ if (!hdrFromPyObject(s, &h)) return NULL;
- return rpmds_Wrap(&rpmds_Type, rpmdsThis(hdrGetHeader(ho), tagN, Flags));
+ return rpmds_Wrap(&rpmds_Type, rpmdsThis(h, tagN, Flags));
}
diff --git a/python/rpmfi-py.c b/python/rpmfi-py.c
index ee20904f7..6d034dbd7 100644
--- a/python/rpmfi-py.c
+++ b/python/rpmfi-py.c
@@ -296,18 +296,18 @@ static int rpmfi_init(rpmfiObject * s, PyObject *args, PyObject *kwds)
static PyObject * rpmfi_new(PyTypeObject * subtype, PyObject *args, PyObject *kwds)
{
- hdrObject * ho = NULL;
PyObject * to = NULL;
+ Header h = NULL;
rpmfi fi = NULL;
rpmTag tagN = RPMTAG_BASENAMES;
int flags = 0;
char * kwlist[] = {"header", "tag", "flags", NULL};
- if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!|Oi:rpmfi_init", kwlist,
- &hdr_Type, &ho, &to, &flags))
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&|Oi:rpmfi_init", kwlist,
+ hdrFromPyObject, &h, &to, &flags))
return NULL;
- fi = rpmfiNew(NULL, hdrGetHeader(ho), tagN, flags);
+ fi = rpmfiNew(NULL, h, tagN, flags);
return rpmfi_Wrap(subtype, fi);
}
diff --git a/python/rpmts-py.c b/python/rpmts-py.c
index 59605e9f8..5c38485d3 100644
--- a/python/rpmts-py.c
+++ b/python/rpmts-py.c
@@ -173,15 +173,15 @@ static void die(PyObject *cb)
static PyObject *
rpmts_AddInstall(rpmtsObject * s, PyObject * args, PyObject * kwds)
{
- hdrObject * h;
+ Header h = NULL;
PyObject * key;
char * how = "u"; /* XXX default to upgrade element if missing */
int isUpgrade = 0;
char * kwlist[] = {"header", "key", "how", NULL};
int rc = 0;
- if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!O|s:AddInstall", kwlist,
- &hdr_Type, &h, &key, &how))
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&O|s:AddInstall", kwlist,
+ hdrFromPyObject, &h, &key, &how))
return NULL;
if (how && !rstreq(how, "u") && !rstreq(how, "i")) {
@@ -190,7 +190,7 @@ rpmts_AddInstall(rpmtsObject * s, PyObject * args, PyObject * kwds)
} else if (how && rstreq(how, "u"))
isUpgrade = 1;
- rc = rpmtsAddInstallElement(s->ts, hdrGetHeader(h), key, isUpgrade, NULL);
+ rc = rpmtsAddInstallElement(s->ts, h, key, isUpgrade, NULL);
if (rc) {
PyErr_SetString(pyrpmError, "adding package to transaction failed");
return NULL;