diff options
Diffstat (limited to 'python/spec-py.c')
-rw-r--r-- | python/spec-py.c | 44 |
1 files changed, 26 insertions, 18 deletions
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; +} + |