bpo-42008: Fix internal _random.Random() seeding for the one argument case (GH-22668)

This commit is contained in:
AMIR 2020-12-22 03:15:50 +03:30 committed by GitHub
parent 711381dfb0
commit b8fde8b541
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 1 deletions

View file

@ -519,6 +519,7 @@ random_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
RandomObject *self;
PyObject *tmp;
PyObject *arg = NULL;
_randomstate *state = _randomstate_type(type);
if (type == (PyTypeObject*)state->Random_Type &&
@ -529,12 +530,22 @@ random_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
self = (RandomObject *)PyType_GenericAlloc(type, 0);
if (self == NULL)
return NULL;
tmp = random_seed(self, args);
if (PyTuple_GET_SIZE(args) > 1) {
PyErr_SetString(PyExc_TypeError, "Random() requires 0 or 1 argument");
return NULL;
}
if (PyTuple_GET_SIZE(args) == 1)
arg = PyTuple_GET_ITEM(args, 0);
tmp = random_seed(self, arg);
if (tmp == NULL) {
Py_DECREF(self);
return NULL;
}
Py_DECREF(tmp);
return (PyObject *)self;
}