From c499cd119c15536c0d4742077fa8c73fa92dace6 Mon Sep 17 00:00:00 2001 From: jbj Date: Fri, 19 Jul 2002 20:26:38 +0000 Subject: [PATCH] Remove foo.iter() method, use tp_iter mechanism, for rpmmi/rpmds/rpmfi. CVS patchset: 5559 CVS date: 2002/07/19 20:26:38 --- doc/gendiff.1 | 6 +-- lib/rpmlib.h | 2 +- python/rpmds-py.c | 106 ++++++++++++++++++++++++++++++-------------- python/rpmds-py.h | 2 + python/rpmfi-py.c | 128 ++++++++++++++++++++++++++++++++++++++++++----------- python/rpmfi-py.h | 2 + python/rpmmi-py.c | 41 ++++++++++++----- python/rpmmodule.c | 12 +++++ python/rpmts-py.c | 6 +++ rpmio/rpmerr.h | 2 +- 10 files changed, 231 insertions(+), 76 deletions(-) diff --git a/doc/gendiff.1 b/doc/gendiff.1 index 3a56e32..fd49943 100644 --- a/doc/gendiff.1 +++ b/doc/gendiff.1 @@ -26,10 +26,10 @@ Then edit the first copy (somefile.cpp). .PP After editing all the files you need to edit in this fashion, enter the directory one level above where your source code resides, and then type -.SP -.NF +.sp +.nf $ gendiff somedirectory .fix > mydiff-fix.patch -.FI +.fi .PP You should redirect the output to a file (as illustrated) unless you want to see the results on stdout. diff --git a/lib/rpmlib.h b/lib/rpmlib.h index 406b1e7..7024ffc 100644 --- a/lib/rpmlib.h +++ b/lib/rpmlib.h @@ -865,7 +865,7 @@ rpmRC rpmInstallSourcePackage(rpmts ts, FD_t fd, typedef enum rpmtransFlags_e { RPMTRANS_FLAG_NONE = 0, RPMTRANS_FLAG_TEST = (1 << 0), /*!< from --test */ - RPMTRANS_FLAG_BUILD_PROBS = (1 << 1), /*!< @todo Document. */ + RPMTRANS_FLAG_BUILD_PROBS = (1 << 1), /*!< don't process payload */ RPMTRANS_FLAG_NOSCRIPTS = (1 << 2), /*!< from --noscripts */ RPMTRANS_FLAG_JUSTDB = (1 << 3), /*!< from --justdb */ RPMTRANS_FLAG_NOTRIGGERS = (1 << 4), /*!< from --notriggers */ diff --git a/python/rpmds-py.c b/python/rpmds-py.c index 8ec6275..6ba9ab2 100644 --- a/python/rpmds-py.c +++ b/python/rpmds-py.c @@ -92,14 +92,28 @@ rpmds_compare(rpmdsObject * a, rpmdsObject * b) return rpmdsCompare(a->ds, b->ds); } -#if Py_TPFLAGS_HAVE_ITER static PyObject * -rpmds_Next(rpmdsObject * s) +rpmds_iter(rpmdsObject * s) + /*@modifies s @*/ +{ + Py_INCREF(s); + return (PyObject *)s; +} + +static PyObject * +rpmds_iternext(rpmdsObject * s) /*@globals _Py_NoneStruct @*/ /*@modifies s, _Py_NoneStruct @*/ { PyObject * result = NULL; + /* Reset loop indices on 1st entry. */ + if (!s->active) { + rpmdsInit(s->ds); + s->active = 1; + } + + /* If more to do, return a (N, EVR, Flags) tuple. */ if (rpmdsNext(s->ds) >= 0) { const char * N = rpmdsN(s->ds); const char * EVR = rpmdsEVR(s->ds); @@ -117,39 +131,50 @@ rpmds_Next(rpmdsObject * s) PyTuple_SET_ITEM(result, 2, PyInt_FromLong(Flags)); } - } + } else + s->active = 0; + return result; } static PyObject * -rpmds_Iter(rpmdsObject * s) - /*@modifies s @*/ +rpmds_Next(rpmdsObject * s, PyObject *args) + /*@globals _Py_NoneStruct @*/ + /*@modifies s, _Py_NoneStruct @*/ { - rpmdsInit(s->ds); - Py_INCREF(s); - return (PyObject *)s; + PyObject * result; + + if (!PyArg_ParseTuple(args, ":Next")) + return NULL; + + result = rpmds_iternext(s); + + if (result == NULL) { + Py_INCREF(Py_None); + return Py_None; + } + return result; } -#endif #ifdef NOTYET static PyObject * rpmds_Notify(rpmdsObject * s, PyObject * args) /*@*/ { - if (!PyArg_ParseTuple(args, ":Notify")) - return NULL; - Py_INCREF(Py_None); - return Py_None; + if (!PyArg_ParseTuple(args, ":Notify")) + return NULL; + Py_INCREF(Py_None); + return Py_None; } static PyObject * rpmds_Problem(rpmdsObject * s, PyObject * args) /*@*/ { - if (!PyArg_ParseTuple(args, ":Problem")) - return NULL; - Py_INCREF(Py_None); - return Py_None; + if (!PyArg_ParseTuple(args, ":Problem")) + return NULL; + Py_INCREF(Py_None); + return Py_None; } #endif @@ -172,12 +197,9 @@ static struct PyMethodDef rpmds_methods[] = { "ds.Flags -> Flags - Return current Flags.\n" }, {"TagN", (PyCFunction)rpmds_TagN, METH_VARARGS, "ds.TagN -> TagN - Return current TagN.\n" }, -#if Py_TPFLAGS_HAVE_ITER {"next", (PyCFunction)rpmds_Next, METH_VARARGS, - NULL}, - {"iter", (PyCFunction)rpmds_Iter, METH_VARARGS, - NULL}, -#endif +"ds.next() -> (N, EVR, Flags)\n\ +- Retrieve next dependency triple.\n" }, #ifdef NOTYET {"Notify", (PyCFunction)rpmds_Notify, METH_VARARGS, NULL}, @@ -286,8 +308,8 @@ PyTypeObject rpmds_Type = { 0, /* tp_clear */ 0, /* tp_richcompare */ 0, /* tp_weaklistoffset */ - (getiterfunc) rpmds_Iter, /* tp_iter */ - (iternextfunc) rpmds_Next, /* tp_iternext */ + (getiterfunc) rpmds_iter, /* tp_iter */ + (iternextfunc) rpmds_iternext, /* tp_iternext */ rpmds_methods, /* tp_methods */ 0, /* tp_members */ 0, /* tp_getset */ @@ -315,46 +337,64 @@ rpmds dsFromDs(rpmdsObject * s) rpmdsObject * rpmds_Wrap(rpmds ds) { - rpmdsObject *s = PyObject_NEW(rpmdsObject, &rpmds_Type); + rpmdsObject * s = PyObject_NEW(rpmdsObject, &rpmds_Type); + if (s == NULL) return NULL; s->ds = ds; + s->active = 0; return s; } rpmdsObject * rpmds_Single(/*@unused@*/ PyObject * s, PyObject * args) { + PyObject * to = NULL; int tagN = RPMTAG_PROVIDENAME; const char * N; const char * EVR = NULL; int Flags = 0; - if (!PyArg_ParseTuple(args, "is|si:Single", &tagN, &N, &EVR, &Flags)) + if (!PyArg_ParseTuple(args, "Os|si:Single", &to, &N, &EVR, &Flags)) return NULL; + if (to != NULL) { + tagN = tagNumFromPyObject(to); + if (tagN == -1) { + PyErr_SetString(PyExc_KeyError, "unknown header tag"); + return NULL; + } + } return rpmds_Wrap( rpmdsSingle(tagN, N, EVR, Flags) ); } rpmdsObject * -hdr_dsFromHeader(/*@unused@*/ PyObject * s, PyObject * args) +hdr_dsFromHeader(PyObject * s, PyObject * args) { - hdrObject * ho; - int tagN = RPMTAG_REQUIRENAME; + hdrObject * ho = (hdrObject *)s; + PyObject * to = NULL; + rpmTag tagN = RPMTAG_REQUIRENAME; int scareMem = 0; - if (!PyArg_ParseTuple(args, "O!|i:dsFromHeader", &hdr_Type, &ho, &tagN)) + if (!PyArg_ParseTuple(args, "|O:dsFromHeader", &to)) return NULL; + if (to != NULL) { + tagN = tagNumFromPyObject(to); + if (tagN == -1) { + PyErr_SetString(PyExc_KeyError, "unknown header tag"); + return NULL; + } + } return rpmds_Wrap( rpmdsNew(hdrGetHeader(ho), tagN, scareMem) ); } rpmdsObject * -hdr_dsOfHeader(/*@unused@*/ PyObject * s, PyObject * args) +hdr_dsOfHeader(PyObject * s, PyObject * args) { - hdrObject * ho; + hdrObject * ho = (hdrObject *)s; int tagN = RPMTAG_PROVIDENAME; int Flags = RPMSENSE_EQUAL; - if (!PyArg_ParseTuple(args, "O!:dsOfHeader", &hdr_Type, &ho)) + if (!PyArg_ParseTuple(args, ":dsOfHeader")) return NULL; return rpmds_Wrap( rpmdsThis(hdrGetHeader(ho), tagN, Flags) ); } diff --git a/python/rpmds-py.h b/python/rpmds-py.h index 9a540e1..56f1b5c 100644 --- a/python/rpmds-py.h +++ b/python/rpmds-py.h @@ -11,6 +11,8 @@ */ typedef struct rpmdsObject_s { PyObject_HEAD + int active; +/*@null@*/ rpmds ds; } rpmdsObject; diff --git a/python/rpmfi-py.c b/python/rpmfi-py.c index f2551cb..dec9e10 100644 --- a/python/rpmfi-py.c +++ b/python/rpmfi-py.c @@ -185,39 +185,106 @@ rpmfi_FGroup(rpmfiObject * s, PyObject * args) #if Py_TPFLAGS_HAVE_ITER static PyObject * -rpmfi_Next(rpmfiObject * s, /*@unused@*/ PyObject * args) +rpmfi_iter(rpmfiObject * s, /*@unused@*/ PyObject * args) + /*@modifies s @*/ +{ + Py_INCREF(s); + return (PyObject *)s; +} +#endif + +static PyObject * +rpmfi_iternext(rpmfiObject * s) /*@modifies s @*/ { PyObject * result = NULL; + /* Reset loop indices on 1st entry. */ + if (!s->active) { + rpmfiInit(s->fi, 0); + s->active = 1; + } + + /* If more to do, return the file tuple. */ if (rpmfiNext(s->fi) >= 0) { const char * FN = rpmfiFN(s->fi); int FSize = rpmfiFSize(s->fi); int FMode = rpmfiFMode(s->fi); int FMtime = rpmfiFMtime(s->fi); int FFlags = rpmfiFFlags(s->fi); + int FRdev = rpmfiFRdev(s->fi); + int FInode = rpmfiFInode(s->fi); + int FNlink = rpmfiFNlink(s->fi); + int FState = rpmfiFState(s->fi); + int VFlags = rpmfiVFlags(s->fi); + const char * FUser = rpmfiFUser(s->fi); + const char * FGroup = rpmfiFGroup(s->fi); + const unsigned char * md5 = rpmfiMD5(s->fi), *s = md5; + char FMD5[2*16+1], *t = FMD5; + static const char hex[] = "0123456789abcdef"; + int gotmd5, i; + + gotmd5 = 0; + if (s) + for (i = 0; i < 16; i++) { + gotmd5 |= *s; + *t++ = hex[ (*s >> 4) & 0xf ]; + *t++ = hex[ (*s++ ) & 0xf ]; + } + *t = '\0'; + + result = PyTuple_New(13); + if (FN == NULL) { + Py_INCREF(Py_None); + PyTuple_SET_ITEM(result, 0, Py_None); + } else + PyTuple_SET_ITEM(result, 0, Py_BuildValue("s", FN)); + PyTuple_SET_ITEM(result, 1, PyInt_FromLong(FSize)); + PyTuple_SET_ITEM(result, 2, PyInt_FromLong(FMode)); + PyTuple_SET_ITEM(result, 3, PyInt_FromLong(FMtime)); + PyTuple_SET_ITEM(result, 4, PyInt_FromLong(FFlags)); + PyTuple_SET_ITEM(result, 5, PyInt_FromLong(FRdev)); + PyTuple_SET_ITEM(result, 6, PyInt_FromLong(FInode)); + PyTuple_SET_ITEM(result, 7, PyInt_FromLong(FNlink)); + PyTuple_SET_ITEM(result, 8, PyInt_FromLong(FState)); + PyTuple_SET_ITEM(result, 9, PyInt_FromLong(VFlags)); + if (FUser == NULL) { + Py_INCREF(Py_None); + PyTuple_SET_ITEM(result, 10, Py_None); + } else + PyTuple_SET_ITEM(result, 10, Py_BuildValue("s", FUser)); + if (FGroup == NULL) { + Py_INCREF(Py_None); + PyTuple_SET_ITEM(result, 11, Py_None); + } else + PyTuple_SET_ITEM(result, 11, Py_BuildValue("s", FGroup)); + if (!gotmd5) { + Py_INCREF(Py_None); + PyTuple_SET_ITEM(result, 12, Py_None); + } else + PyTuple_SET_ITEM(result, 12, Py_BuildValue("s", FMD5)); + + } else + s->active = 0; - result = PyTuple_New(5); - PyTuple_SET_ITEM(result, 0, Py_BuildValue("s", FN)); - PyTuple_SET_ITEM(result, 1, PyInt_FromLong(FSize)); - PyTuple_SET_ITEM(result, 2, PyInt_FromLong(FMode)); - PyTuple_SET_ITEM(result, 3, PyInt_FromLong(FMtime)); - PyTuple_SET_ITEM(result, 4, PyInt_FromLong(FFlags)); - -/* XXX FIXME: more to return */ - } return result; } static PyObject * -rpmfi_Iter(rpmfiObject * s, /*@unused@*/ PyObject * args) +rpmfi_Next(rpmfiObject * s, /*@unused@*/ PyObject * args) /*@modifies s @*/ { - rpmfiInit(s->fi, 0); - Py_INCREF(s); - return (PyObject *)s; + PyObject * result = NULL; + + result = rpmfi_iternext(s); + + if (result == NULL) { + Py_INCREF(Py_None); + return Py_None; + } + + return result; } -#endif #ifdef NOTYET static PyObject * @@ -282,12 +349,9 @@ static struct PyMethodDef rpmfi_methods[] = { NULL}, {"FGroup", (PyCFunction)rpmfi_FGroup, METH_VARARGS, NULL}, -#if Py_TPFLAGS_HAVE_ITER {"next", (PyCFunction)rpmfi_Next, METH_VARARGS, - NULL}, - {"iter", (PyCFunction)rpmfi_Iter, METH_VARARGS, - NULL}, -#endif +"fi.next() -> (FN, FSize, FMode, FMtime, FFlags, FRdev, FInode, FNlink, FState, VFlags, FUser, FGroup, FMD5))\n\ +- Retrieve next file info tuple.\n" }, #ifdef NOTYET {"NextD", (PyCFunction)rpmfi_NextD, METH_VARARGS, NULL}, @@ -397,8 +461,8 @@ PyTypeObject rpmfi_Type = { 0, /* tp_clear */ 0, /* tp_richcompare */ 0, /* tp_weaklistoffset */ - (getiterfunc)rpmfi_Iter, /* tp_iter */ - (iternextfunc)rpmfi_Next, /* tp_iternext */ + (getiterfunc)rpmfi_iter, /* tp_iter */ + (iternextfunc)rpmfi_iternext, /* tp_iternext */ rpmfi_methods, /* tp_methods */ 0, /* tp_members */ 0, /* tp_getset */ @@ -427,18 +491,30 @@ rpmfiObject * rpmfi_Wrap(rpmfi fi) { rpmfiObject *s = PyObject_NEW(rpmfiObject, &rpmfi_Type); + if (s == NULL) return NULL; s->fi = fi; + s->active = 0; return s; } rpmfiObject * -hdr_fiFromHeader(/*@unused@*/ PyObject * s, PyObject * args) +hdr_fiFromHeader(PyObject * s, PyObject * args) { - hdrObject * ho; + hdrObject * ho = (hdrObject *)s; + PyObject * to = NULL; + rpmTag tagN = RPMTAG_BASENAMES; + int scareMem = 0; - if (!PyArg_ParseTuple(args, "O!:fiFromHeader", &hdr_Type, &ho)) + if (!PyArg_ParseTuple(args, "|O:fiFromHeader", &to)) return NULL; - return rpmfi_Wrap( rpmfiNew(NULL, NULL, hdrGetHeader(ho), RPMTAG_BASENAMES, 0) ); + if (to != NULL) { + tagN = tagNumFromPyObject(to); + if (tagN == -1) { + PyErr_SetString(PyExc_KeyError, "unknown header tag"); + return NULL; + } + } + return rpmfi_Wrap( rpmfiNew(NULL, NULL, hdrGetHeader(ho), tagN, scareMem) ); } diff --git a/python/rpmfi-py.h b/python/rpmfi-py.h index b8dd4ad..f6ce8bc 100644 --- a/python/rpmfi-py.h +++ b/python/rpmfi-py.h @@ -9,6 +9,8 @@ typedef struct rpmfiObject_s { PyObject_HEAD + int active; +/*@null@*/ rpmfi fi; } rpmfiObject; diff --git a/python/rpmmi-py.c b/python/rpmmi-py.c index 7345ed8..68a9618 100644 --- a/python/rpmmi-py.c +++ b/python/rpmmi-py.c @@ -82,12 +82,33 @@ */ /*@{*/ +/** \ingroup python + */ +static PyObject * +rpmmi_Next(rpmmiObject * s, PyObject *args) + /*@globals _Py_NoneStruct @*/ + /*@modifies s, _Py_NoneStruct @*/ +{ + Header h; + + if (!PyArg_ParseTuple(args, ":Next")) + return NULL; + + if (s->mi == NULL || (h = rpmdbNextIterator(s->mi)) == NULL) { + if (s->mi) s->mi = rpmdbFreeIterator(s->mi); + Py_INCREF(Py_None); + return Py_None; + } + return (PyObject *) hdr_Wrap(h); +} + #if Py_TPFLAGS_HAVE_ITER +/** \ingroup python + */ static PyObject * -rpmmi_Iter(rpmmiObject * s) +rpmmi_iter(rpmmiObject * s) /*@*/ { -assert(s->mi); Py_INCREF(s); return (PyObject *)s; } @@ -95,16 +116,15 @@ assert(s->mi); /** \ingroup python */ static PyObject * -rpmmi_Next(rpmmiObject * s) +rpmmi_iternext(rpmmiObject * s) /*@globals _Py_NoneStruct @*/ /*@modifies s, _Py_NoneStruct @*/ { Header h; if (s->mi == NULL || (h = rpmdbNextIterator(s->mi)) == NULL) { - if (s->mi) s->mi = rpmdbFreeIterator(s->mi); - Py_INCREF(Py_None); - return Py_None; + s->mi = rpmdbFreeIterator(s->mi); + return NULL; } return (PyObject *) hdr_Wrap(h); } @@ -142,13 +162,9 @@ rpmmi_Pattern(rpmmiObject * s, PyObject * args) /*@-fullinitblock@*/ /*@unchecked@*/ /*@observer@*/ static struct PyMethodDef rpmmi_methods[] = { -#if Py_TPFLAGS_HAVE_ITER - {"iter", (PyCFunction) rpmmi_Iter, METH_VARARGS, - NULL}, {"next", (PyCFunction) rpmmi_Next, METH_VARARGS, "mi.next() -> hdr\n\ - Retrieve next header that matches.\n" }, -#endif {"pattern", (PyCFunction) rpmmi_Pattern, METH_VARARGS, "mi.pattern(TagN, mire_type, pattern)\n\ - Set a secondary match pattern on tags from retrieved header.\n" }, @@ -212,8 +228,8 @@ PyTypeObject rpmmi_Type = { 0, /* tp_clear */ 0, /* tp_richcompare */ 0, /* tp_weaklistoffset */ - (getiterfunc) rpmmi_Iter, /* tp_iter */ - (iternextfunc) rpmmi_Next, /* tp_iternext */ + (getiterfunc) rpmmi_iter, /* tp_iter */ + (iternextfunc) rpmmi_iternext, /* tp_iternext */ rpmmi_methods, /* tp_methods */ 0, /* tp_members */ 0, /* tp_getset */ @@ -234,6 +250,7 @@ PyTypeObject rpmmi_Type = { rpmmiObject * rpmmi_Wrap(rpmdbMatchIterator mi) { rpmmiObject * mio; + if (mi == NULL) { Py_INCREF(Py_None); return (rpmmiObject *) Py_None; diff --git a/python/rpmmodule.c b/python/rpmmodule.c index 49b5c42..3952b09 100644 --- a/python/rpmmodule.c +++ b/python/rpmmodule.c @@ -516,6 +516,8 @@ void initrpm(void) REGISTER_ENUM(RPMSENSE_SCRIPT_CLEAN); REGISTER_ENUM(RPMSENSE_RPMLIB); REGISTER_ENUM(RPMSENSE_TRIGGERPREIN); + REGISTER_ENUM(RPMSENSE_KEYRING); + REGISTER_ENUM(RPMSENSE_PATCHES); REGISTER_ENUM(RPMTRANS_FLAG_TEST); REGISTER_ENUM(RPMTRANS_FLAG_BUILD_PROBS); @@ -526,6 +528,16 @@ void initrpm(void) REGISTER_ENUM(RPMTRANS_FLAG_ALLFILES); REGISTER_ENUM(RPMTRANS_FLAG_KEEPOBSOLETE); REGISTER_ENUM(RPMTRANS_FLAG_MULTILIB); + REGISTER_ENUM(RPMTRANS_FLAG_REPACKAGE); + REGISTER_ENUM(RPMTRANS_FLAG_NOPRE); + REGISTER_ENUM(RPMTRANS_FLAG_NOPOST); + REGISTER_ENUM(RPMTRANS_FLAG_NOTRIGGERIN); + REGISTER_ENUM(RPMTRANS_FLAG_NOTRIGGERUN); + REGISTER_ENUM(RPMTRANS_FLAG_NOPREUN); + REGISTER_ENUM(RPMTRANS_FLAG_NOPOSTUN); + REGISTER_ENUM(RPMTRANS_FLAG_NOTRIGGERPOSTUN); + REGISTER_ENUM(RPMTRANS_FLAG_NOMD5); + REGISTER_ENUM(RPMTRANS_FLAG_NOSUGGEST); REGISTER_ENUM(RPMPROB_FILTER_IGNOREOS); REGISTER_ENUM(RPMPROB_FILTER_IGNOREARCH); diff --git a/python/rpmts-py.c b/python/rpmts-py.c index 6e49e791..f2f76f4 100644 --- a/python/rpmts-py.c +++ b/python/rpmts-py.c @@ -641,16 +641,22 @@ fprintf(stderr, "*** rpmts_Match(%p) ts %p\n", s, s->ts); static struct PyMethodDef rpmts_methods[] = { {"addInstall", (PyCFunction) rpmts_AddInstall, METH_VARARGS, NULL }, +#ifdef _LEGACY_BINDINGS_TOO {"add", (PyCFunction) rpmts_AddInstall, METH_VARARGS, NULL }, +#endif {"addErase", (PyCFunction) rpmts_AddErase, METH_VARARGS, NULL }, +#ifdef _LEGACY_BINDINGS_TOO {"remove", (PyCFunction) rpmts_AddErase, METH_VARARGS, NULL }, +#endif {"check", (PyCFunction) rpmts_Check, METH_VARARGS, NULL }, +#ifdef _LEGACY_BINDINGS_TOO {"depcheck", (PyCFunction) rpmts_Check, METH_VARARGS, NULL }, +#endif {"order", (PyCFunction) rpmts_Order, METH_VARARGS, NULL }, {"clean", (PyCFunction) rpmts_Clean, METH_VARARGS, diff --git a/rpmio/rpmerr.h b/rpmio/rpmerr.h index 7c07fe4..9f99fa3 100644 --- a/rpmio/rpmerr.h +++ b/rpmio/rpmerr.h @@ -132,7 +132,7 @@ typedef enum rpmerrCode_e { RPMDEBUG_UNLINK = _dm(512u+16), /*!< unlink(2) failed */ RPMDEBUG_RMDIR = _dm(512u+17), /*!< rmdir(2) failed */ /*@-enummemuse@*/ - RPMWARN_FLOCK = _wm(512u+27), /*!< locking the database failed */ + RPMWARN_FLOCK = _wm(512u+27) /*!< locking the database failed */ /*@=enummemuse@*/ } rpmerrCode; /*@=typeuse @*/ -- 2.7.4