summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorPanu Matilainen <pmatilai@redhat.com>2009-09-24 11:42:17 +0300
committerPanu Matilainen <pmatilai@redhat.com>2009-09-24 11:42:17 +0300
commit36ada6c116e123f5b5b739e12f256201e5cc6fa1 (patch)
tree6f4cb506966ff356c975010caf816c6a70436424 /python
parentab66c9ff47664fcfae6eea2146be65ccbff43195 (diff)
downloadrpm-36ada6c116e123f5b5b739e12f256201e5cc6fa1.tar.gz
rpm-36ada6c116e123f5b5b739e12f256201e5cc6fa1.tar.bz2
rpm-36ada6c116e123f5b5b739e12f256201e5cc6fa1.zip
Make object allocation type agnostic
- pass (sub)type down to wrappers - call subtype tp_alloc() instead of PyObject_New() - preliminaries for allowing subtyping
Diffstat (limited to 'python')
-rw-r--r--python/header-py.c10
-rw-r--r--python/header-py.h2
-rw-r--r--python/rpmds-py.c14
-rw-r--r--python/rpmds-py.h2
-rw-r--r--python/rpmfi-py.c6
-rw-r--r--python/rpmfi-py.h2
-rw-r--r--python/rpmmi-py.c6
-rw-r--r--python/rpmmi-py.h2
-rw-r--r--python/rpmps-py.c6
-rw-r--r--python/rpmps-py.h2
-rw-r--r--python/rpmte-py.c8
-rw-r--r--python/rpmte-py.h2
-rw-r--r--python/rpmts-py.c14
-rw-r--r--python/rpmts-py.h2
-rw-r--r--python/spec-py.c6
-rw-r--r--python/spec-py.h2
16 files changed, 43 insertions, 43 deletions
diff --git a/python/header-py.c b/python/header-py.c
index 66e953227..29a2f7e42 100644
--- a/python/header-py.c
+++ b/python/header-py.c
@@ -396,7 +396,7 @@ static PyObject *hdr_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)
return NULL;
}
- return hdr_Wrap(h);
+ return hdr_Wrap(subtype, h);
}
static void hdr_dealloc(hdrObject * s)
@@ -510,9 +510,9 @@ PyTypeObject hdr_Type = {
0, /* tp_is_gc */
};
-PyObject * hdr_Wrap(Header h)
+PyObject * hdr_Wrap(PyTypeObject *subtype, Header h)
{
- hdrObject * hdr = PyObject_New(hdrObject, &hdr_Type);
+ hdrObject * hdr = (hdrObject *)subtype->tp_alloc(subtype, 0);
if (hdr == NULL) return PyErr_NoMemory();
hdr->h = headerLink(h);
@@ -548,7 +548,7 @@ PyObject * rpmReadHeaders (FD_t fd)
while (h) {
headerConvert(h, HEADERCONV_RETROFIT_V3);
- hdr = hdr_Wrap(h);
+ hdr = hdr_Wrap(&hdr_Type, h);
if (PyList_Append(list, (PyObject *) hdr)) {
Py_DECREF(list);
Py_DECREF(hdr);
@@ -729,7 +729,7 @@ rpmSingleHeaderFromFD(PyObject * self, PyObject * args, PyObject * kwds)
tuple = PyTuple_New(2);
if (h && tuple) {
- PyTuple_SET_ITEM(tuple, 0, hdr_Wrap(h));
+ PyTuple_SET_ITEM(tuple, 0, hdr_Wrap(&hdr_Type, h));
PyTuple_SET_ITEM(tuple, 1, PyLong_FromLong(offset));
h = headerFree(h);
} else {
diff --git a/python/header-py.h b/python/header-py.h
index 7ce1dd8d2..4c3d8abe1 100644
--- a/python/header-py.h
+++ b/python/header-py.h
@@ -16,7 +16,7 @@ extern PyTypeObject hdr_Type;
extern PyObject * pyrpmError;
-PyObject * hdr_Wrap(Header h);
+PyObject * hdr_Wrap(PyTypeObject *subtype, Header h);
Header hdrGetHeader(hdrObject * h);
diff --git a/python/rpmds-py.c b/python/rpmds-py.c
index 7514bdd24..dccd9a79e 100644
--- a/python/rpmds-py.c
+++ b/python/rpmds-py.c
@@ -198,7 +198,7 @@ rpmds_iternext(rpmdsObject * s)
rpmTag tagN = rpmdsTagN(s->ds);
rpmsenseFlags Flags = rpmdsFlags(s->ds);
- result = rpmds_Wrap( rpmdsSingle(tagN, N, EVR, Flags) );
+ result = rpmds_Wrap(s->ob_type, rpmdsSingle(tagN, N, EVR, Flags) );
} else
s->active = 0;
@@ -299,7 +299,7 @@ static PyObject * rpmds_Rpmlib(rpmdsObject * s)
/* XXX check return code, permit arg (NULL uses system default). */
xx = rpmdsRpmlib(&ds, NULL);
- return rpmds_Wrap( ds );
+ return rpmds_Wrap(&rpmds_Type, ds);
}
@@ -439,7 +439,7 @@ static PyObject * rpmds_new(PyTypeObject * subtype, PyObject *args, PyObject *kw
ds = rpmdsNew(hdrGetHeader(ho), tagN, 0);
- return rpmds_Wrap(ds);
+ return rpmds_Wrap(subtype, ds);
}
static char rpmds_doc[] =
@@ -498,9 +498,9 @@ rpmds dsFromDs(rpmdsObject * s)
return s->ds;
}
-PyObject * rpmds_Wrap(rpmds ds)
+PyObject * rpmds_Wrap(PyTypeObject *subtype, rpmds ds)
{
- rpmdsObject * s = PyObject_New(rpmdsObject, &rpmds_Type);
+ rpmdsObject * s = (rpmdsObject *)subtype->tp_alloc(subtype, 0);
if (s == NULL) return PyErr_NoMemory();
s->ds = ds;
@@ -520,7 +520,7 @@ PyObject * rpmds_Single(PyObject * s, PyObject * args, PyObject * kwds)
tagNumFromPyObject, &tagN, &N, &EVR, &Flags))
return NULL;
- return rpmds_Wrap( rpmdsSingle(tagN, N, EVR, Flags) );
+ return rpmds_Wrap(&rpmds_Type, rpmdsSingle(tagN, N, EVR, Flags));
}
PyObject * hdr_dsFromHeader(PyObject * s, PyObject * args, PyObject * kwds)
@@ -535,5 +535,5 @@ PyObject * hdr_dsOfHeader(PyObject * s)
rpmTag tagN = RPMTAG_PROVIDENAME;
rpmsenseFlags Flags = RPMSENSE_EQUAL;
- return rpmds_Wrap( rpmdsThis(hdrGetHeader(ho), tagN, Flags) );
+ return rpmds_Wrap(&rpmds_Type, rpmdsThis(hdrGetHeader(ho), tagN, Flags));
}
diff --git a/python/rpmds-py.h b/python/rpmds-py.h
index a00eb7db1..b24f2b099 100644
--- a/python/rpmds-py.h
+++ b/python/rpmds-py.h
@@ -11,7 +11,7 @@ extern PyTypeObject rpmds_Type;
rpmds dsFromDs(rpmdsObject * ds);
-PyObject * rpmds_Wrap(rpmds ds);
+PyObject * rpmds_Wrap(PyTypeObject *subtype, rpmds ds);
PyObject * rpmds_Single(PyObject * s, PyObject * args, PyObject * kwds);
diff --git a/python/rpmfi-py.c b/python/rpmfi-py.c
index 673d40569..9a27e0476 100644
--- a/python/rpmfi-py.c
+++ b/python/rpmfi-py.c
@@ -318,7 +318,7 @@ static PyObject * rpmfi_new(PyTypeObject * subtype, PyObject *args, PyObject *kw
fi = rpmfiNew(NULL, hdrGetHeader(ho), tagN, flags);
- return rpmfi_Wrap(fi);
+ return rpmfi_Wrap(subtype, fi);
}
static char rpmfi_doc[] =
@@ -376,9 +376,9 @@ rpmfi fiFromFi(rpmfiObject * s)
return s->fi;
}
-PyObject * rpmfi_Wrap(rpmfi fi)
+PyObject * rpmfi_Wrap(PyTypeObject *subtype, rpmfi fi)
{
- rpmfiObject *s = PyObject_New(rpmfiObject, &rpmfi_Type);
+ rpmfiObject *s = (rpmfiObject *)subtype->tp_alloc(subtype, 0);
if (s == NULL) return PyErr_NoMemory();
s->fi = fi;
diff --git a/python/rpmfi-py.h b/python/rpmfi-py.h
index 8029acd65..604bf716d 100644
--- a/python/rpmfi-py.h
+++ b/python/rpmfi-py.h
@@ -11,6 +11,6 @@ extern PyTypeObject rpmfi_Type;
rpmfi fiFromFi(rpmfiObject * fi);
-PyObject * rpmfi_Wrap(rpmfi fi);
+PyObject * rpmfi_Wrap(PyTypeObject *subtype, rpmfi fi);
#endif
diff --git a/python/rpmmi-py.c b/python/rpmmi-py.c
index 5da2644ff..0fa1ab395 100644
--- a/python/rpmmi-py.c
+++ b/python/rpmmi-py.c
@@ -76,7 +76,7 @@ rpmmi_iternext(rpmmiObject * s)
s->mi = rpmdbFreeIterator(s->mi);
return NULL;
}
- return hdr_Wrap(h);
+ return hdr_Wrap(&hdr_Type, h);
}
static PyObject *
@@ -185,9 +185,9 @@ PyTypeObject rpmmi_Type = {
0, /* tp_is_gc */
};
-PyObject * rpmmi_Wrap(rpmdbMatchIterator mi, PyObject *s)
+PyObject * rpmmi_Wrap(PyTypeObject *subtype, rpmdbMatchIterator mi, PyObject *s)
{
- rpmmiObject * mio = PyObject_New(rpmmiObject, &rpmmi_Type);
+ rpmmiObject * mio = (rpmmiObject *)subtype->tp_alloc(subtype, 0);
if (mio == NULL) return PyErr_NoMemory();
mio->mi = mi;
diff --git a/python/rpmmi-py.h b/python/rpmmi-py.h
index e5410d6f3..ef07c72f8 100644
--- a/python/rpmmi-py.h
+++ b/python/rpmmi-py.h
@@ -7,6 +7,6 @@ extern PyTypeObject rpmmi_Type;
#define rpmmiObject_Check(v) ((v)->ob_type == &rpmmi_Type)
-PyObject * rpmmi_Wrap(rpmdbMatchIterator mi, PyObject *s);
+PyObject * rpmmi_Wrap(PyTypeObject *subtype, rpmdbMatchIterator mi, PyObject *s);
#endif
diff --git a/python/rpmps-py.c b/python/rpmps-py.c
index 2adbdeb60..82422c0d1 100644
--- a/python/rpmps-py.c
+++ b/python/rpmps-py.c
@@ -119,7 +119,7 @@ static void rpmps_free(rpmpsObject * s)
static PyObject * rpmps_new(PyTypeObject * subtype, PyObject *args, PyObject *kwds)
{
rpmps ps = rpmpsCreate();
- return rpmps_Wrap(ps);
+ return rpmps_Wrap(subtype, ps);
}
static char rpmps_doc[] =
@@ -175,9 +175,9 @@ rpmps psFromPs(rpmpsObject * s)
return s->ps;
}
-PyObject * rpmps_Wrap(rpmps ps)
+PyObject * rpmps_Wrap(PyTypeObject *subtype, rpmps ps)
{
- rpmpsObject * s = PyObject_New(rpmpsObject, &rpmps_Type);
+ rpmpsObject * s = (rpmpsObject *)subtype->tp_alloc(subtype, 0);
if (s == NULL) return PyErr_NoMemory();
s->ps = ps; /* XXX refcounts? */
diff --git a/python/rpmps-py.h b/python/rpmps-py.h
index de7af0915..b1494baa6 100644
--- a/python/rpmps-py.h
+++ b/python/rpmps-py.h
@@ -11,6 +11,6 @@ extern PyTypeObject rpmps_Type;
rpmps psFromPs(rpmpsObject * ps);
-PyObject * rpmps_Wrap(rpmps ps);
+PyObject * rpmps_Wrap(PyTypeObject *subtype, rpmps ps);
#endif
diff --git a/python/rpmte-py.c b/python/rpmte-py.c
index 3d1a3057c..55a26c9e4 100644
--- a/python/rpmte-py.c
+++ b/python/rpmte-py.c
@@ -192,7 +192,7 @@ rpmte_DS(rpmteObject * s, PyObject * args, PyObject * kwds)
Py_RETURN_NONE;
#endif
}
- return rpmds_Wrap(rpmdsLink(ds, RPMDBG_M("rpmte_DS")));
+ return rpmds_Wrap(&rpmds_Type, rpmdsLink(ds, RPMDBG_M("rpmte_DS")));
}
static PyObject *
@@ -204,7 +204,7 @@ rpmte_FI(rpmteObject * s, PyObject * args, PyObject * kwds)
if (fi == NULL) {
Py_RETURN_NONE;
}
- return rpmfi_Wrap(rpmfiLink(fi, RPMDBG_M("rpmte_FI")));
+ return rpmfi_Wrap(&rpmfi_Type, rpmfiLink(fi, RPMDBG_M("rpmte_FI")));
}
static struct PyMethodDef rpmte_methods[] = {
@@ -314,9 +314,9 @@ PyTypeObject rpmte_Type = {
0, /* tp_is_gc */
};
-PyObject * rpmte_Wrap(rpmte te)
+PyObject * rpmte_Wrap(PyTypeObject *subtype, rpmte te)
{
- rpmteObject *s = PyObject_New(rpmteObject, &rpmte_Type);
+ rpmteObject *s = (rpmteObject *)subtype->tp_alloc(subtype, 0);
if (s == NULL) return PyErr_NoMemory();
s->te = te;
diff --git a/python/rpmte-py.h b/python/rpmte-py.h
index 0a273ed1d..28bc0e32e 100644
--- a/python/rpmte-py.h
+++ b/python/rpmte-py.h
@@ -9,6 +9,6 @@ extern PyTypeObject rpmte_Type;
#define rpmteObject_Check(v) ((v)->ob_type == &rpmte_Type)
-PyObject * rpmte_Wrap(rpmte te);
+PyObject * rpmte_Wrap(PyTypeObject *subtype, rpmte te);
#endif
diff --git a/python/rpmts-py.c b/python/rpmts-py.c
index ed33ab354..2ade49285 100644
--- a/python/rpmts-py.c
+++ b/python/rpmts-py.c
@@ -463,7 +463,7 @@ rpmts_HdrFromFdno(rpmtsObject * s, PyObject * args, PyObject * kwds)
switch (rpmrc) {
case RPMRC_OK:
if (h)
- result = Py_BuildValue("N", hdr_Wrap(h));
+ result = Py_BuildValue("N", hdr_Wrap(&hdr_Type, h));
h = headerFree(h); /* XXX ref held by result */
break;
@@ -749,7 +749,7 @@ rpmts_SetProbFilter(rpmtsObject * s, PyObject * args, PyObject * kwds)
static PyObject *
rpmts_Problems(rpmtsObject * s)
{
- return rpmps_Wrap( rpmtsProblems(s->ts) );
+ return rpmps_Wrap(&rpmps_Type, rpmtsProblems(s->ts));
}
static PyObject *
@@ -829,7 +829,7 @@ rpmts_iternext(rpmtsObject * s)
te = rpmtsiNext(s->tsi, s->tsiFilter);
if (te != NULL) {
- result = rpmte_Wrap(te);
+ result = rpmte_Wrap(&rpmte_Type, te);
} else {
s->tsi = rpmtsiFree(s->tsi);
s->tsiFilter = 0;
@@ -889,7 +889,7 @@ rpmts_Match(rpmtsObject * s, PyObject * args, PyObject * kwds)
}
}
- return rpmmi_Wrap( rpmtsInitIterator(s->ts, tag, key, len), (PyObject*)s);
+ return rpmmi_Wrap(&rpmmi_Type, rpmtsInitIterator(s->ts, tag, key, len), (PyObject*)s);
}
static struct PyMethodDef rpmts_methods[] = {
@@ -1045,7 +1045,7 @@ static PyObject * rpmts_new(PyTypeObject * subtype, PyObject *args, PyObject *kw
* python objects */
(void) rpmtsSetVSFlags(ts, vsflags);
- return rpmts_Wrap(ts);
+ return rpmts_Wrap(subtype, ts);
}
static char rpmts_doc[] =
@@ -1101,9 +1101,9 @@ rpmts_Create(PyObject * self, PyObject * args, PyObject * kwds)
return PyObject_Call((PyObject *) &rpmts_Type, args, kwds);
}
-PyObject * rpmts_Wrap(rpmts ts)
+PyObject * rpmts_Wrap(PyTypeObject *subtype, rpmts ts)
{
- rpmtsObject * s = PyObject_New(rpmtsObject, &rpmts_Type);
+ rpmtsObject * s = (rpmtsObject *)subtype->tp_alloc(subtype, 0);
if (s == NULL) return PyErr_NoMemory();
s->ts = ts;
diff --git a/python/rpmts-py.h b/python/rpmts-py.h
index 956a11b38..2cd3399a1 100644
--- a/python/rpmts-py.h
+++ b/python/rpmts-py.h
@@ -15,7 +15,7 @@ enum {
RPMDEP_SENSE_CONFLICTS /*!< conflict was found. */
};
-PyObject * rpmts_Wrap(rpmts ts);
+PyObject * rpmts_Wrap(PyTypeObject *subtype, rpmts ts);
PyObject * rpmts_Create(PyObject * s, PyObject * args, PyObject * kwds);
diff --git a/python/spec-py.c b/python/spec-py.c
index 4739d3471..d4d13b313 100644
--- a/python/spec-py.c
+++ b/python/spec-py.c
@@ -172,7 +172,7 @@ static PyObject *spec_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)
}
rpmtsFree(ts);
- return spec ? spec_Wrap(spec) : NULL;
+ return spec ? spec_Wrap(subtype, spec) : NULL;
}
PyTypeObject spec_Type = {
@@ -225,9 +225,9 @@ rpmSpec specFromSpec(specObject *s)
}
PyObject *
-spec_Wrap(rpmSpec spec)
+spec_Wrap(PyTypeObject *subtype, rpmSpec spec)
{
- specObject * s = PyObject_New(specObject, &spec_Type);
+ specObject * s = (specObject *)subtype->tp_alloc(subtype, 0);
if (s == NULL) return PyErr_NoMemory();
s->spec = spec;
diff --git a/python/spec-py.h b/python/spec-py.h
index 25eac76f3..30c5cd977 100644
--- a/python/spec-py.h
+++ b/python/spec-py.h
@@ -11,6 +11,6 @@ extern PyTypeObject spec_Type;
rpmSpec specFromSpec(specObject * spec);
-PyObject * spec_Wrap(rpmSpec spec);
+PyObject * spec_Wrap(PyTypeObject *subtype, rpmSpec spec);
#endif /* RPMPYTHON_SPEC */