diff options
author | Panu Matilainen <pmatilai@redhat.com> | 2011-07-01 12:55:53 +0300 |
---|---|---|
committer | Panu Matilainen <pmatilai@redhat.com> | 2011-07-01 12:55:53 +0300 |
commit | dc50fb2863c81159fb4cc8b25ce3862720c0cce5 (patch) | |
tree | ecb5d5ac9f5d16aecaa6ba66c3009bdc24642702 /python | |
parent | 3464e60aa8635b63213e65724e19d263b9c6645d (diff) | |
download | librpm-tizen-dc50fb2863c81159fb4cc8b25ce3862720c0cce5.tar.gz librpm-tizen-dc50fb2863c81159fb4cc8b25ce3862720c0cce5.tar.bz2 librpm-tizen-dc50fb2863c81159fb4cc8b25ce3862720c0cce5.zip |
Fix/sanitize rpm.spec python object creation
- Specs are not really immutable, move the initialization work into
tp_init and use PyType_GenericNew for tp_new since we're not
doing anything special there.
- Eliminate the stupid spec_Wrap() thing and hide specPkg_Wrap()
out of side (TODO later...)
Diffstat (limited to 'python')
-rw-r--r-- | python/spec-py.c | 44 | ||||
-rw-r--r-- | python/spec-py.h | 3 |
2 files changed, 18 insertions, 29 deletions
diff --git a/python/spec-py.c b/python/spec-py.c index a8295390c..925608068 100644 --- a/python/spec-py.c +++ b/python/spec-py.c @@ -169,6 +169,15 @@ 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; @@ -202,7 +211,7 @@ static PyGetSetDef spec_getseters[] = { {NULL} /* Sentinel */ }; -static PyObject *spec_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds) +static int spec_init(specObject *self, PyObject *args, PyObject *kwds) { char * kwlist[] = {"specfile", "flags", NULL}; const char * specfile; @@ -212,15 +221,17 @@ static PyObject *spec_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds) if (!PyArg_ParseTupleAndKeywords(args, kwds, "s|i:spec_new", kwlist, &specfile, &flags)) - return NULL; + return -1; spec = rpmSpecParse(specfile, flags, NULL); - if (spec == NULL) { + if (spec != NULL) { + rpmSpecFree(self->spec); + self->spec = spec; + } else { PyErr_SetString(PyExc_ValueError, "can't parse specfile\n"); - return NULL; } - return spec_Wrap(subtype, spec); + return (spec == NULL) ? -1 : 0; } static PyObject * spec_doBuild(specObject *self, PyObject *args, PyObject *kwds) @@ -276,29 +287,10 @@ PyTypeObject spec_Type = { 0, /* tp_descr_get */ 0, /* tp_descr_set */ 0, /* tp_dictoffset */ - 0, /* tp_init */ + (initproc) spec_init, /* tp_init */ 0, /* tp_alloc */ - spec_new, /* tp_new */ + PyType_GenericNew, /* 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 558fbf207..28a5ee7bf 100644 --- a/python/spec-py.h +++ b/python/spec-py.h @@ -12,7 +12,4 @@ 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 */ |