summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--configure.ac4
-rw-r--r--python/rng.py9
-rw-r--r--python/rpmmpw-py.c4
-rw-r--r--python/rpmmpw-py.h7
-rw-r--r--python/rpmrng-py.c74
-rw-r--r--python/rpmrng-py.h1
-rw-r--r--system.h2
7 files changed, 92 insertions, 9 deletions
diff --git a/configure.ac b/configure.ac
index 1ba6015c9..5589a1055 100644
--- a/configure.ac
+++ b/configure.ac
@@ -23,8 +23,8 @@ echo "
* *
* This is source code from the development branch of rpm-4.3. *
* *
-* If you want the "production" rpm-4.0.4 or rpm-4.1 code, then you should *
-* either use an rpm-4.0.4 or rpm-4.1 src.rpm. Alternatively, if using a *
+* If you want the "production" rpm-4.2 code, then you should *
+* use an rpm-4.1.1 or rpm-4.2 src.rpm. Alternatively, if using a *
* CVS checkout, do the following: *
* *
* cvs -d :pserver:anonymous@cvs.rpm.org:/cvs/devel login *
diff --git a/python/rng.py b/python/rng.py
index 182f79907..67ff71b0c 100644
--- a/python/rng.py
+++ b/python/rng.py
@@ -1,7 +1,12 @@
import rpm
rpm.rng().Debug(-1);
+#rpm.mpw().Debug(-1);
+
r = rpm.rng()
-m = rpm.mpw(10)
+for i in range(10):
+ print r.next()
-print m.rndm(m,r)
+m = rpm.mpw("800000000000000000000000000000000000000000000000000000000000000000000000")
+for i in range(10):
+ print r.next(m)
diff --git a/python/rpmmpw-py.c b/python/rpmmpw-py.c
index f7d10fee9..3b63c8ab2 100644
--- a/python/rpmmpw-py.c
+++ b/python/rpmmpw-py.c
@@ -20,8 +20,6 @@
/*@unchecked@*/
static int _mpw_debug = 0;
-#define is_mpw(o) ((o)->ob_type == &mpw_Type)
-
/*@unchecked@*/ /*@observer@*/
static const char initialiser_name[] = "rpm.mpw";
@@ -944,7 +942,7 @@ fprintf(stderr, "*** mpw_new(%p[%s],%p[%s],%p[%s]) ret %p[%s]\n", subtype, lbl(s
return ns;
}
-static mpwObject * mpw_New(void)
+mpwObject * mpw_New(void)
/*@*/
{
mpwObject * ns = PyObject_New(mpwObject, &mpw_Type);
diff --git a/python/rpmmpw-py.h b/python/rpmmpw-py.h
index a7c024c8b..44bdb8e05 100644
--- a/python/rpmmpw-py.h
+++ b/python/rpmmpw-py.h
@@ -20,4 +20,11 @@ typedef struct mpwObject_s {
/*@unchecked@*/
extern PyTypeObject mpw_Type;
+#define is_mpw(o) ((o)->ob_type == &mpw_Type)
+
+/**
+ */
+mpwObject * mpw_New(void)
+ /*@*/;
+
#endif
diff --git a/python/rpmrng-py.c b/python/rpmrng-py.c
index 5671c31fe..3a9c665a4 100644
--- a/python/rpmrng-py.c
+++ b/python/rpmrng-py.c
@@ -32,6 +32,7 @@ if (_rng_debug < -1)
fprintf(stderr, "*** rng_dealloc(%p)\n", s);
randomGeneratorContextFree(&s->rngc);
+ mpbfree(&s->b);
PyObject_Del(s);
}
@@ -51,11 +52,22 @@ static int rng_init(rngObject * s, PyObject *args, PyObject *kwds)
/*@modifies s @*/
{
PyObject * o = NULL;
+ const randomGenerator* rng = NULL;
if (!PyArg_ParseTuple(args, "|O:Cvt", &o)) return -1;
- if (randomGeneratorContextInit(&s->rngc, randomGeneratorDefault()) != 0)
+ if (o) {
+ /* XXX "FIPS 186" or "Mersenne Twister" */
+ if (PyString_Check(o))
+ rng = randomGeneratorFind(PyString_AsString(o));
+ }
+
+ if (rng == NULL)
+ rng = randomGeneratorDefault();
+
+ if (randomGeneratorContextInit(&s->rngc, rng) != 0)
return -1;
+ mpbzero(&s->b);
if (_rng_debug)
fprintf(stderr, "*** rng_init(%p[%s],%p[%s],%p[%s])\n", s, lbl(s), args, lbl(args), kwds, lbl(kwds));
@@ -71,6 +83,7 @@ static void rng_free(/*@only@*/ rngObject * s)
if (_rng_debug)
fprintf(stderr, "*** rng_free(%p[%s])\n", s, lbl(s));
randomGeneratorContextFree(&s->rngc);
+ mpbfree(&s->b);
PyObject_Del(s);
}
@@ -123,11 +136,70 @@ fprintf(stderr, "*** rng_Debug(%p)\n", s);
return Py_None;
}
+/** \ingroup py_c
+ */
+static PyObject *
+rng_Seed(rngObject * s, PyObject * args)
+ /*@*/
+{
+ if (!PyArg_ParseTuple(args, ":Seed")) return NULL;
+
+if (_rng_debug < 0)
+fprintf(stderr, "*** rng_Seed(%p)\n", s);
+
+ Py_INCREF(Py_None);
+ return Py_None;
+}
+
+/** \ingroup py_c
+ */
+static PyObject *
+rng_Next(rngObject * s, PyObject * args)
+ /*@*/
+{
+ PyObject * bo = NULL;
+ randomGeneratorContext* rc = &s->rngc;
+ mpbarrett* b = &s->b;
+ mpwObject *z;
+
+ if (!PyArg_ParseTuple(args, "|O:Next", &bo)) return NULL;
+
+ if (bo) {
+ if (is_mpw(bo) && (z = (mpwObject*)bo)->n.size > 0) {
+ b = alloca(sizeof(*b));
+ mpbzero(b);
+ /* XXX z probably needs normalization here. */
+ mpbset(b, z->n.size, z->n.data);
+ } else
+ ; /* XXX error? */
+ }
+
+ z = mpw_New();
+ if (b == NULL || b->size == 0 || b->modl == NULL) {
+ mpw val;
+ rc->rng->next(rc->param, (byte*) &val, sizeof(val));
+ mpnsetw(&z->n, val);
+ } else {
+ mpw* wksp = alloca(b->size*sizeof(*wksp));
+ mpnsize(&z->n, b->size);
+ mpbrnd_w(b, rc, z->n.data, wksp);
+ }
+
+if (_rng_debug)
+fprintf(stderr, "*** rng_Next(%p) %p[%d]\t", s, z->n.data, z->n.size), mpprintln(stderr, z->n.size, z->n.data);
+
+ return (PyObject *)z;
+}
+
/*@-fullinitblock@*/
/*@unchecked@*/ /*@observer@*/
static struct PyMethodDef rng_methods[] = {
{"Debug", (PyCFunction)rng_Debug, METH_VARARGS,
NULL},
+ {"seed", (PyCFunction)rng_Seed, METH_VARARGS,
+ NULL},
+ {"next", (PyCFunction)rng_Next, METH_VARARGS,
+ NULL},
{NULL, NULL} /* sentinel */
};
/*@=fullinitblock@*/
diff --git a/python/rpmrng-py.h b/python/rpmrng-py.h
index 5f1b52902..317d53af3 100644
--- a/python/rpmrng-py.h
+++ b/python/rpmrng-py.h
@@ -13,6 +13,7 @@ typedef struct rngObject_s {
PyObject_HEAD
PyObject *md_dict; /*!< to look like PyModuleObject */
randomGeneratorContext rngc;
+ mpbarrett b;
} rngObject;
/**
diff --git a/system.h b/system.h
index 4a6c47b59..447293524 100644
--- a/system.h
+++ b/system.h
@@ -123,7 +123,7 @@ extern void error(int status, int errnum, const char *format, ...)
#endif
#endif
-if HAVE___SECURE_GETENV && !defined(__LCLINT__)
+#if HAVE___SECURE_GETENV && !defined(__LCLINT__)
#define getenv(_s) __secure_getenv(_s)
#endif