Make object allocation type agnostic
- pass (sub)type down to wrappers - call subtype tp_alloc() instead of PyObject_New() - preliminaries for allowing subtyping
This commit is contained in:
parent
ab66c9ff47
commit
36ada6c116
|
@ -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 {
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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? */
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 */
|
||||
|
|
Loading…
Reference in New Issue