From: jbj Date: Wed, 30 Apr 2003 21:05:20 +0000 (+0000) Subject: Create rpmrng module. X-Git-Tag: rpm-4.4-release~561 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=44fd5be7f9107a77882afee663a1030e08077cc0;p=platform%2Fupstream%2Frpm.git Create rpmrng module. CVS patchset: 6798 CVS date: 2003/04/30 21:05:20 --- diff --git a/python/Makefile.am b/python/Makefile.am index b4091f2..5698b1c 100644 --- a/python/Makefile.am +++ b/python/Makefile.am @@ -24,8 +24,9 @@ INCLUDES = -I. \ @INCPATH@ noinst_HEADERS = header-py.h \ - rpmal-py.h rpmbc-py.h rpmds-py.h rpmdb-py.h rpmfd-py.h rpmfts-py.h \ - rpmfi-py.h rpmmi-py.h rpmmpw-py.h rpmrc-py.h rpmte-py.h rpmts-py.h + rpmbc-py.h rpmmpw-py.h rpmrng-py.h \ + rpmal-py.h rpmds-py.h rpmdb-py.h rpmfd-py.h rpmfts-py.h \ + rpmfi-py.h rpmmi-py.h rpmrc-py.h rpmte-py.h rpmts-py.h mylibs= \ $(top_builddir)/lib/.libs/librpm.so \ @@ -55,8 +56,9 @@ poptmodule_so_LDFLAGS = $(mylibs) $(LIBS) -shared -Wl,-soname,poptmodule.so noinst_LTLIBRARIES = librpmmodule.la librpmmodule_la_SOURCES = rpmmodule.c header-py.c \ - rpmal-py.c rpmbc-py.c rpmds-py.c rpmdb-py.c rpmfd-py.c rpmfts-py.c \ - rpmfi-py.c rpmmi-py.c rpmmpw-py.c rpmrc-py.c rpmte-py.c rpmts-py.c + rpmbc-py.c rpmmpw-py.c rpmrng-py.c \ + rpmal-py.c rpmds-py.c rpmdb-py.c rpmfd-py.c rpmfts-py.c \ + rpmfi-py.c rpmmi-py.c rpmrc-py.c rpmte-py.c rpmts-py.c rpmmodule.so$(EXEEXT): $(librpmmodule_la_OBJECTS) $(CC) -o $@ $(librpmmodule_la_OBJECTS) $(rpmmodule_so_LDFLAGS) @@ -72,8 +74,9 @@ poptmodule.so$(EXEEXT): poptmodule.lo # rpmrc-py.c rpmte-py.c rpmts-py.c # rpmmodule.c header-py.c splint_srcs = \ - rpmal-py.c rpmbc-py.c rpmds-py.c rpmdb-py.c rpmfd-py.c rpmfts-py.c \ - rpmfi-py.c rpmmi-py.c rpmmpw-py.c rpmrc-py.c rpmte-py.c rpmts-py.c + rpmbc-py.c rpmmpw-py.c rpmrng-py.c \ + rpmal-py.c rpmds-py.c rpmdb-py.c rpmfd-py.c rpmfts-py.c \ + rpmfi-py.c rpmmi-py.c rpmrc-py.c rpmte-py.c rpmts-py.c .PHONY: lint lint: diff --git a/python/rpmdebug-py.c b/python/rpmdebug-py.c index 75f4134..8d1d9c2 100644 --- a/python/rpmdebug-py.c +++ b/python/rpmdebug-py.c @@ -18,6 +18,7 @@ extern PyTypeObject PyFrame_Type; #include "rpmmi-py.h" /* XXX debug only */ #include "rpmmpw-py.h" /* XXX debug only */ #include "rpmrc-py.h" /* XXX debug only */ +#include "rpmrng-py.h" /* XXX debug only */ #include "rpmte-py.h" /* XXX debug only */ #include "rpmts-py.h" /* XXX debug only */ @@ -61,6 +62,7 @@ static const char * lbl(void * s) if (o->ob_type == &hdr_Type) return "hdr"; if (o->ob_type == &mpw_Type) return "mpw"; + if (o->ob_type == &rng_Type) return "rng"; if (o->ob_type == &rpmal_Type) return "rpmal"; if (o->ob_type == &rpmbc_Type) return "rpmbc"; if (o->ob_type == &rpmds_Type) return "rpmds"; diff --git a/python/rpmmodule.c b/python/rpmmodule.c index 1038dc5..3292e04 100644 --- a/python/rpmmodule.c +++ b/python/rpmmodule.c @@ -19,14 +19,16 @@ #include "header_internal.h" #include "header-py.h" -#include "rpmal-py.h" #include "rpmbc-py.h" +#include "rpmmpw-py.h" +#include "rpmrng-py.h" + +#include "rpmal-py.h" #include "rpmds-py.h" #include "rpmfd-py.h" #include "rpmfts-py.h" #include "rpmfi-py.h" #include "rpmmi-py.h" -#include "rpmmpw-py.h" #include "rpmrc-py.h" #include "rpmte-py.h" #include "rpmts-py.h" @@ -173,6 +175,8 @@ void initrpm(void) #if Py_TPFLAGS_HAVE_ITER /* XXX backport to python-1.5.2 */ if (PyType_Ready(&hdr_Type) < 0) return; + if (PyType_Ready(&mpw_Type) < 0) return; + if (PyType_Ready(&rng_Type) < 0) return; if (PyType_Ready(&rpmal_Type) < 0) return; if (PyType_Ready(&rpmbc_Type) < 0) return; if (PyType_Ready(&rpmds_Type) < 0) return; @@ -180,7 +184,6 @@ void initrpm(void) if (PyType_Ready(&rpmfts_Type) < 0) return; if (PyType_Ready(&rpmfi_Type) < 0) return; if (PyType_Ready(&rpmmi_Type) < 0) return; - if (PyType_Ready(&mpw_Type) < 0) return; rpmrc_Type.tp_base = &PyDict_Type; if (PyType_Ready(&rpmrc_Type) < 0) return; @@ -214,6 +217,9 @@ void initrpm(void) Py_INCREF(&mpw_Type); PyModule_AddObject(m, "mpw", (PyObject *) &mpw_Type); + Py_INCREF(&rng_Type); + PyModule_AddObject(m, "rng", (PyObject *) &rng_Type); + Py_INCREF(&rpmal_Type); PyModule_AddObject(m, "al", (PyObject *) &rpmal_Type); @@ -245,6 +251,8 @@ void initrpm(void) PyModule_AddObject(m, "ts", (PyObject *) &rpmts_Type); #else hdr_Type.ob_type = &PyType_Type; + mpw_Type.ob_type = &PyType_Type; + rng_Type.ob_type = &PyType_Type; rpmal_Type.ob_type = &PyType_Type; rpmbc_Type.ob_type = &PyType_Type; rpmds_Type.ob_type = &PyType_Type; diff --git a/python/rpmmpw-py.c b/python/rpmmpw-py.c index a5d01cd..93fe294 100644 --- a/python/rpmmpw-py.c +++ b/python/rpmmpw-py.c @@ -1,5 +1,5 @@ /** \ingroup py_c - * \file python/mpw-py.c + * \file python/rpmmpw-py.c */ #include "system.h" @@ -848,7 +848,7 @@ fprintf(stderr, "*** mpw_str(%p): \"%s\"\n", a, PyString_AS_STRING(so)); /** \ingroup py_c */ -static int mpw_init(mpwObject * z, PyObject *args, PyObject *kwds) +static int mpw_init(mpwObject * s, PyObject *args, PyObject *kwds) /*@modifies z @*/ { PyObject * o = NULL; @@ -858,8 +858,8 @@ static int mpw_init(mpwObject * z, PyObject *args, PyObject *kwds) if (!PyArg_ParseTuple(args, "|O:Cvt", &o)) return -1; if (o == NULL) { - if (z->n.data == NULL) - mpnsetw(&z->n, 0); + if (s->n.data == NULL) + mpnsetw(&s->n, 0); } else if (PyInt_Check(o)) { l = PyInt_AsLong(o); words = sizeof(l)/sizeof(words); @@ -874,34 +874,34 @@ static int mpw_init(mpwObject * z, PyObject *args, PyObject *kwds) } else if (PyString_Check(o)) { const unsigned char * hex = PyString_AsString(o); /* XXX TODO: check for hex. */ - mpnsethex(&z->n, hex); + mpnsethex(&s->n, hex); } else if (is_mpw(o)) { mpwObject *a = (mpwObject *)o; - mpnsize(&z->n, a->n.size); + mpnsize(&s->n, a->n.size); if (a->n.size > 0) - mpsetx(z->n.size, z->n.data, a->n.size, a->n.data); + mpsetx(s->n.size, s->n.data, a->n.size, a->n.data); } else { PyErr_SetString(PyExc_TypeError, "non-numeric coercion failed (mpw_init)"); return -1; } if (words > 0) { - mpnsize(&z->n, words); + mpnsize(&s->n, words); switch (words) { case 2: /*@-shiftimplementation @*/ - z->n.data[0] = (l >> 32) & 0xffffffff; + s->n.data[0] = (l >> 32) & 0xffffffff; /*@=shiftimplementation @*/ - z->n.data[1] = (l ) & 0xffffffff; + s->n.data[1] = (l ) & 0xffffffff; break; case 1: - z->n.data[0] = (l ) & 0xffffffff; + s->n.data[0] = (l ) & 0xffffffff; break; } } if (_mpw_debug) -fprintf(stderr, "*** mpw_init(%p[%s],%p[%s],%p[%s]):\t", z, lbl(z), args, lbl(args), kwds, lbl(kwds)), mpprintln(stderr, z->n.size, z->n.data); +fprintf(stderr, "*** mpw_init(%p[%s],%p[%s],%p[%s]):\t", s, lbl(s), args, lbl(args), kwds, lbl(kwds)), mpprintln(stderr, s->n.size, s->n.data); return 0; } @@ -943,8 +943,8 @@ fprintf(stderr, "*** mpw_new(%p[%s],%p[%s],%p[%s]) ret %p[%s]\n", subtype, lbl(s return ns; } -static mpwObject * -mpw_New(void) +static mpwObject * mpw_New(void) + /*@*/ { mpwObject * ns = PyObject_New(mpwObject, &mpw_Type); @@ -953,10 +953,11 @@ mpw_New(void) } /** \ingroup py_c - * Convert integer to mp. + * Convert integer to mpw. */ static mpwObject * mpw_i2mpw(PyObject * o) + /*@*/ { if (is_mpw(o)) { Py_INCREF(o); diff --git a/python/rpmmpw-py.h b/python/rpmmpw-py.h index 230f545..a7c024c 100644 --- a/python/rpmmpw-py.h +++ b/python/rpmmpw-py.h @@ -4,7 +4,7 @@ #include "rpmio_internal.h" /** \ingroup py_c - * \file python/rpmbc-py.h + * \file python/rpmmpw-py.h */ /** diff --git a/python/rpmrng-py.c b/python/rpmrng-py.c new file mode 100644 index 0000000..945d4a4 --- /dev/null +++ b/python/rpmrng-py.c @@ -0,0 +1,201 @@ +/** \ingroup py_c + * \file python/rpmrng-py.c + */ + +#include "system.h" + +#include "Python.h" +#ifdef __LCLINT__ +#undef PyObject_HEAD +#define PyObject_HEAD int _PyObjectHead; +#endif + +#include "rpmrng-py.h" + +#include "rpmdebug-py.c" + +#include "debug.h" + +/*@unchecked@*/ +static int _rng_debug = 0; + +#define is_rng(o) ((o)->ob_type == &rng_Type) + +/*@unchecked@*/ /*@observer@*/ +static const char initialiser_name[] = "rpm.rng"; + +/* ---------- */ + +static void +rng_dealloc(rngObject * s) + /*@modifies s @*/ +{ +if (_rng_debug < -1) +fprintf(stderr, "*** rng_dealloc(%p)\n", s); + + randomGeneratorContextFree(&s->rngc); + PyObject_Del(s); +} + +static int +rng_print(rngObject * s, FILE * fp, /*@unused@*/ int flags) + /*@globals fileSystem @*/ + /*@modifies fp, fileSystem @*/ +{ +if (_rng_debug < -1) +fprintf(stderr, "*** rng_print(%p)\n", s); + return 0; +} + +/** \ingroup py_c + */ +static int rng_init(rngObject * s, PyObject *args, PyObject *kwds) + /*@modifies s @*/ +{ + PyObject * o = NULL; + + if (!PyArg_ParseTuple(args, "|O:Cvt", &o)) return -1; + + if (randomGeneratorContextInit(&s->rngc, randomGeneratorDefault()) != 0) + return -1; + +if (_rng_debug) +fprintf(stderr, "*** rng_init(%p[%s],%p[%s],%p[%s])\n", s, lbl(s), args, lbl(args), kwds, lbl(kwds)); + + return 0; +} + +/** \ingroup py_c + */ +static void rng_free(/*@only@*/ rngObject * s) + /*@modifies s @*/ +{ +if (_rng_debug) +fprintf(stderr, "*** rng_free(%p[%s])\n", s, lbl(s)); + randomGeneratorContextFree(&s->rngc); + PyObject_Del(s); +} + +/** \ingroup py_c + */ +static PyObject * rng_alloc(PyTypeObject * subtype, int nitems) + /*@*/ +{ + PyObject * ns = PyType_GenericAlloc(subtype, nitems); + +if (_rng_debug) +fprintf(stderr, "*** rng_alloc(%p[%s},%d) ret %p[%s]\n", subtype, lbl(subtype), nitems, ns, lbl(ns)); + return (PyObject *) ns; +} + +static PyObject * +rng_new(PyTypeObject * subtype, PyObject *args, PyObject *kwds) + /*@*/ +{ + PyObject * ns = (PyObject *) PyObject_New(rngObject, &rng_Type); + +if (_rng_debug < -1) +fprintf(stderr, "*** rng_new(%p[%s],%p[%s],%p[%s]) ret %p[%s]\n", subtype, lbl(subtype), args, lbl(args), kwds, lbl(kwds), ns, lbl(ns)); + return ns; +} + +static rngObject * +rng_New(void) +{ + rngObject * ns = PyObject_New(rngObject, &rng_Type); + + return ns; +} + +/* ---------- */ + +/** \ingroup py_c + */ +static PyObject * +rng_Debug(/*@unused@*/ rngObject * s, PyObject * args) + /*@globals _Py_NoneStruct @*/ + /*@modifies _Py_NoneStruct @*/ +{ + if (!PyArg_ParseTuple(args, "i:Debug", &_rng_debug)) return NULL; + +if (_rng_debug < 0) +fprintf(stderr, "*** rng_Debug(%p)\n", s); + + Py_INCREF(Py_None); + return Py_None; +} + +/*@-fullinitblock@*/ +/*@unchecked@*/ /*@observer@*/ +static struct PyMethodDef rng_methods[] = { + {"Debug", (PyCFunction)rng_Debug, METH_VARARGS, + NULL}, + {NULL, NULL} /* sentinel */ +}; +/*@=fullinitblock@*/ + +static PyObject * +rng_getattr(PyObject * s, char * name) + /*@*/ +{ + return Py_FindMethod(rng_methods, s, name); +} + +/* ---------- */ + +/** + */ +/*@unchecked@*/ /*@observer@*/ +static char rng_doc[] = +""; + +/*@-fullinitblock@*/ +PyTypeObject rng_Type = { + PyObject_HEAD_INIT(&PyType_Type) + 0, /* ob_size */ + "rpm.rng", /* tp_name */ + sizeof(rngObject), /* tp_basicsize */ + 0, /* tp_itemsize */ + /* methods */ + (destructor) rng_dealloc, /* tp_dealloc */ + (printfunc) rng_print, /* tp_print */ + (getattrfunc) rng_getattr, /* tp_getattr */ + (setattrfunc) 0, /* tp_setattr */ + (cmpfunc) 0, /* tp_compare */ + (reprfunc) 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + (hashfunc) 0, /* tp_hash */ + (ternaryfunc) 0, /* tp_call */ + (reprfunc) 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT, /* tp_flags */ + rng_doc, /* tp_doc */ +#if Py_TPFLAGS_HAVE_ITER + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + (getiterfunc) 0, /* tp_iter */ + (iternextfunc) 0, /* tp_iternext */ + rng_methods, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc) rng_init, /* tp_init */ + (allocfunc) rng_alloc, /* tp_alloc */ + (newfunc) rng_new, /* tp_new */ + (destructor) rng_free, /* tp_free */ + 0, /* tp_is_gc */ +#endif +}; +/*@=fullinitblock@*/ + +/* ---------- */ diff --git a/python/rpmrng-py.h b/python/rpmrng-py.h new file mode 100644 index 0000000..3c6c3fa --- /dev/null +++ b/python/rpmrng-py.h @@ -0,0 +1,23 @@ +#ifndef H_RPMRNG_PY +#define H_RPMRNG_PY + +#include "rpmio_internal.h" + +/** \ingroup py_c + * \file python/rpmrng-py.h + */ + +/** + */ +typedef struct rngObject_s { + PyObject_HEAD + PyObject *md_dict; /*!< to look like PyModuleObject */ + randomGeneratorContext rngc; +} rngObject; + +/** + */ +/*@unchecked@*/ +extern PyTypeObject rng_Type; + +#endif