From 7214b2e0a271b7a7b3df312c58593878cbf56504 Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Fri, 1 Jul 2011 13:37:48 +0300 Subject: [PATCH] Fix/sanitize rpm.fi python object creation a bit - Move all actual initialization work into tp_init, permit reinitialization without leaking and use PyType_GenericNew for tp_new, eliminate internal rpmfi_Wrap() use. There's one user for rpmfi_Wrap() in rpmte-py.c which needs fixing later... - Remove unused fiFromFi() helper function --- python/rpmfi-py.c | 27 +++++++-------------------- python/rpmfi-py.h | 2 -- 2 files changed, 7 insertions(+), 22 deletions(-) diff --git a/python/rpmfi-py.c b/python/rpmfi-py.c index a43fee3..7dcf25d 100644 --- a/python/rpmfi-py.c +++ b/python/rpmfi-py.c @@ -288,26 +288,20 @@ static PyMappingMethods rpmfi_as_mapping = { static int rpmfi_init(rpmfiObject * s, PyObject *args, PyObject *kwds) { - s->active = 0; - return 0; -} - -static PyObject * rpmfi_new(PyTypeObject * subtype, PyObject *args, PyObject *kwds) -{ - PyObject * to = NULL; + PyObject * to = NULL; /* unused */ 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 NULL; + return -1; - fi = rpmfiNew(NULL, h, tagN, flags); + rpmfiFree(s->fi); + s->fi = rpmfiNew(NULL, h, RPMTAG_BASENAMES, flags); + s->active = 0; - return rpmfi_Wrap(subtype, fi); + return 0; } static char rpmfi_doc[] = @@ -352,18 +346,11 @@ PyTypeObject rpmfi_Type = { 0, /* tp_dictoffset */ (initproc) rpmfi_init, /* tp_init */ 0, /* tp_alloc */ - (newfunc) rpmfi_new, /* tp_new */ + PyType_GenericNew, /* 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 604bf71..bf7d05b 100644 --- a/python/rpmfi-py.h +++ b/python/rpmfi-py.h @@ -9,8 +9,6 @@ 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 -- 2.7.4