diff options
author | Panu Matilainen <Panu Matilainen pmatilai@redhat.com> | 2011-07-06 08:16:12 +0300 |
---|---|---|
committer | Panu Matilainen <Panu Matilainen pmatilai@redhat.com> | 2011-07-06 08:16:12 +0300 |
commit | a71a7981cc9f7c8f107e5a14c51e1963375da5b8 (patch) | |
tree | 7989ed773ac6bc56c98193d2e5b89a31542e81cc /python | |
parent | ba2401f74620618ee7d3161888be71328f6e3c4c (diff) | |
download | librpm-tizen-a71a7981cc9f7c8f107e5a14c51e1963375da5b8.tar.gz librpm-tizen-a71a7981cc9f7c8f107e5a14c51e1963375da5b8.tar.bz2 librpm-tizen-a71a7981cc9f7c8f107e5a14c51e1963375da5b8.zip |
Revert the ds, ts, fi and spec python object creation commits
- Hasty push-finger syndrom, while its not exactly plain wrong to
do things this way, it doesn't really make sense for these types
either. Python's own file object permits reinitialization though,
so leaving rpm.fd() the way it is now.
- This reverts the following commits:
d056df28c38e602d82b4f9b527c686037074e660
3f77c3146da46a49f44b17fa66139fbe2dd9e45c
7214b2e0a271b7a7b3df312c58593878cbf56504
dc50fb2863c81159fb4cc8b25ce3862720c0cce5
Diffstat (limited to 'python')
-rw-r--r-- | python/rpmds-py.c | 24 | ||||
-rw-r--r-- | python/rpmfi-py.c | 27 | ||||
-rw-r--r-- | python/rpmfi-py.h | 2 | ||||
-rw-r--r-- | python/rpmts-py.c | 24 | ||||
-rw-r--r-- | python/spec-py.c | 44 | ||||
-rw-r--r-- | python/spec-py.h | 3 |
6 files changed, 77 insertions, 47 deletions
diff --git a/python/rpmds-py.c b/python/rpmds-py.c index 4fb0fb323..30fb908fb 100644 --- a/python/rpmds-py.c +++ b/python/rpmds-py.c @@ -254,6 +254,12 @@ static PyMappingMethods rpmds_as_mapping = { (objobjargproc)0, /* mp_ass_subscript */ }; +static int rpmds_init(rpmdsObject * s, PyObject *args, PyObject *kwds) +{ + s->active = 0; + return 0; +} + static int depflags(PyObject *o, rpmsenseFlags *senseFlags) { int ok = 0; @@ -293,7 +299,7 @@ static int depflags(PyObject *o, rpmsenseFlags *senseFlags) return ok; } -static int rpmds_init(rpmdsObject *s, PyObject *args, PyObject *kwds) +static PyObject * rpmds_new(PyTypeObject * subtype, PyObject *args, PyObject *kwds) { PyObject *obj; rpmTagVal tagN = RPMTAG_REQUIRENAME; @@ -303,7 +309,7 @@ static int rpmds_init(rpmdsObject *s, PyObject *args, PyObject *kwds) if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO&:rpmds_new", kwlist, &obj, tagNumFromPyObject, &tagN)) - return -1; + return NULL; if (PyTuple_Check(obj)) { const char *name = NULL; @@ -314,7 +320,7 @@ static int rpmds_init(rpmdsObject *s, PyObject *args, PyObject *kwds) ds = rpmdsSingle(tagN, name, evr, flags); } else { PyErr_SetString(PyExc_ValueError, "invalid dependency tuple"); - return -1; + return NULL; } } else if (hdrFromPyObject(obj, &h)) { if (tagN == RPMTAG_NEVR) { @@ -324,14 +330,10 @@ static int rpmds_init(rpmdsObject *s, PyObject *args, PyObject *kwds) } } else { PyErr_SetString(PyExc_TypeError, "header or tuple expected"); - return -1; + return NULL; } - - rpmdsFree(s->ds); - s->ds = ds; - s->active = 0; - - return 0; + + return rpmds_Wrap(subtype, ds); } static char rpmds_doc[] = @@ -376,7 +378,7 @@ PyTypeObject rpmds_Type = { 0, /* tp_dictoffset */ (initproc) rpmds_init, /* tp_init */ 0, /* tp_alloc */ - PyType_GenericNew, /* tp_new */ + (newfunc) rpmds_new, /* tp_new */ 0, /* tp_free */ 0, /* tp_is_gc */ }; diff --git a/python/rpmfi-py.c b/python/rpmfi-py.c index 7dcf25d0e..a43fee323 100644 --- a/python/rpmfi-py.c +++ b/python/rpmfi-py.c @@ -288,20 +288,26 @@ static PyMappingMethods rpmfi_as_mapping = { static int rpmfi_init(rpmfiObject * s, PyObject *args, PyObject *kwds) { - PyObject * to = NULL; /* unused */ + s->active = 0; + return 0; +} + +static PyObject * rpmfi_new(PyTypeObject * subtype, PyObject *args, PyObject *kwds) +{ + PyObject * to = NULL; Header h = NULL; + rpmfi fi = NULL; + rpmTagVal tagN = RPMTAG_BASENAMES; int flags = 0; char * kwlist[] = {"header", "tag", "flags", NULL}; if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&|Oi:rpmfi_init", kwlist, hdrFromPyObject, &h, &to, &flags)) - return -1; + return NULL; - rpmfiFree(s->fi); - s->fi = rpmfiNew(NULL, h, RPMTAG_BASENAMES, flags); - s->active = 0; + fi = rpmfiNew(NULL, h, tagN, flags); - return 0; + return rpmfi_Wrap(subtype, fi); } static char rpmfi_doc[] = @@ -346,11 +352,18 @@ PyTypeObject rpmfi_Type = { 0, /* tp_dictoffset */ (initproc) rpmfi_init, /* tp_init */ 0, /* tp_alloc */ - PyType_GenericNew, /* tp_new */ + (newfunc) rpmfi_new, /* tp_new */ 0, /* tp_free */ 0, /* tp_is_gc */ }; +/* ---------- */ + +rpmfi fiFromFi(rpmfiObject * s) +{ + return s->fi; +} + PyObject * rpmfi_Wrap(PyTypeObject *subtype, rpmfi fi) { rpmfiObject *s = (rpmfiObject *)subtype->tp_alloc(subtype, 0); diff --git a/python/rpmfi-py.h b/python/rpmfi-py.h index bf7d05b13..604bf716d 100644 --- a/python/rpmfi-py.h +++ b/python/rpmfi-py.h @@ -9,6 +9,8 @@ extern PyTypeObject rpmfi_Type; #define rpmfiObject_Check(v) ((v)->ob_type == &rpmfi_Type) +rpmfi fiFromFi(rpmfiObject * fi); + PyObject * rpmfi_Wrap(PyTypeObject *subtype, rpmfi fi); #endif diff --git a/python/rpmts-py.c b/python/rpmts-py.c index 276dbd532..cabea1c90 100644 --- a/python/rpmts-py.c +++ b/python/rpmts-py.c @@ -726,6 +726,18 @@ static void rpmts_dealloc(rpmtsObject * s) Py_TYPE(s)->tp_free((PyObject *)s); } +static PyObject * rpmts_new(PyTypeObject * subtype, PyObject *args, PyObject *kwds) +{ + rpmtsObject * s = (rpmtsObject *)subtype->tp_alloc(subtype, 0); + if (s == NULL) return NULL; + + s->ts = rpmtsCreate(); + s->scriptFd = NULL; + s->tsi = NULL; + s->keyList = PyList_New(0); + return (PyObject *) s; +} + static int rpmts_init(rpmtsObject *s, PyObject *args, PyObject *kwds) { char * rootDir = "/"; @@ -736,16 +748,6 @@ static int rpmts_init(rpmtsObject *s, PyObject *args, PyObject *kwds) &rootDir, &vsflags)) return -1; - rpmtsiFree(s->tsi); - rpmtsFree(s->ts); - Py_XDECREF(s->scriptFd); - Py_XDECREF(s->keyList); - - s->ts = rpmtsCreate(); - s->scriptFd = NULL; - s->tsi = NULL; - s->keyList = PyList_New(0); - (void) rpmtsSetRootDir(s->ts, rootDir); /* XXX: make this use common code with rpmts_SetVSFlags() to check the * python objects */ @@ -895,7 +897,7 @@ PyTypeObject rpmts_Type = { 0, /* tp_dictoffset */ (initproc) rpmts_init, /* tp_init */ 0, /* tp_alloc */ - PyType_GenericNew, /* tp_new */ + (newfunc) rpmts_new, /* tp_new */ 0, /* tp_free */ 0, /* tp_is_gc */ }; diff --git a/python/spec-py.c b/python/spec-py.c index 925608068..a8295390c 100644 --- a/python/spec-py.c +++ b/python/spec-py.c @@ -169,15 +169,6 @@ static PyObject * spec_get_sources(specObject *s, void *closure) } -static PyObject * specPkg_Wrap(PyTypeObject *subtype, rpmSpecPkg pkg) -{ - specPkgObject * s = (specPkgObject *)subtype->tp_alloc(subtype, 0); - if (s == NULL) return NULL; - - s->pkg = pkg; - return (PyObject *) s; -} - static PyObject * spec_get_packages(specObject *s, void *closure) { rpmSpecPkg pkg; @@ -211,7 +202,7 @@ static PyGetSetDef spec_getseters[] = { {NULL} /* Sentinel */ }; -static int spec_init(specObject *self, PyObject *args, PyObject *kwds) +static PyObject *spec_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds) { char * kwlist[] = {"specfile", "flags", NULL}; const char * specfile; @@ -221,17 +212,15 @@ static int spec_init(specObject *self, PyObject *args, PyObject *kwds) if (!PyArg_ParseTupleAndKeywords(args, kwds, "s|i:spec_new", kwlist, &specfile, &flags)) - return -1; + return NULL; spec = rpmSpecParse(specfile, flags, NULL); - if (spec != NULL) { - rpmSpecFree(self->spec); - self->spec = spec; - } else { + if (spec == NULL) { PyErr_SetString(PyExc_ValueError, "can't parse specfile\n"); + return NULL; } - return (spec == NULL) ? -1 : 0; + return spec_Wrap(subtype, spec); } static PyObject * spec_doBuild(specObject *self, PyObject *args, PyObject *kwds) @@ -287,10 +276,29 @@ PyTypeObject spec_Type = { 0, /* tp_descr_get */ 0, /* tp_descr_set */ 0, /* tp_dictoffset */ - (initproc) spec_init, /* tp_init */ + 0, /* tp_init */ 0, /* tp_alloc */ - PyType_GenericNew, /* tp_new */ + spec_new, /* tp_new */ 0, /* tp_free */ 0, /* tp_is_gc */ }; +PyObject * +spec_Wrap(PyTypeObject *subtype, rpmSpec spec) +{ + specObject * s = (specObject *)subtype->tp_alloc(subtype, 0); + if (s == NULL) return NULL; + + s->spec = spec; + return (PyObject *) s; +} + +PyObject * specPkg_Wrap(PyTypeObject *subtype, rpmSpecPkg pkg) +{ + specPkgObject * s = (specPkgObject *)subtype->tp_alloc(subtype, 0); + if (s == NULL) return NULL; + + s->pkg = pkg; + return (PyObject *) s; +} + diff --git a/python/spec-py.h b/python/spec-py.h index 28a5ee7bf..558fbf207 100644 --- a/python/spec-py.h +++ b/python/spec-py.h @@ -12,4 +12,7 @@ extern PyTypeObject specPkg_Type; #define specObject_Check(v) ((v)->ob_type == &spec_Type) #define specPkgObject_Check(v) ((v)->ob_type == &specPkg_Type) +PyObject * spec_Wrap(PyTypeObject *subtype, rpmSpec spec); +PyObject * specPkg_Wrap(PyTypeObject *subtype, rpmSpecPkg pkg); + #endif /* RPMPYTHON_SPEC */ |