mirror of
https://github.com/python/cpython.git
synced 2025-10-07 15:42:02 +00:00
bpo-38075: Fix random_seed(): use PyObject_CallOneArg() (GH-18897)
Fix the random.Random.seed() method when a bool is passed as the seed. PyObject_Vectorcall() was misused: use PyObject_CallOneArg() instead.
This commit is contained in:
parent
8510f43078
commit
00d7cd8ab8
3 changed files with 4 additions and 5 deletions
|
@ -42,7 +42,7 @@ class TestBasicOps:
|
||||||
def __hash__(self):
|
def __hash__(self):
|
||||||
return -1729
|
return -1729
|
||||||
for arg in [None, 0, 1, -1, 10**20, -(10**20),
|
for arg in [None, 0, 1, -1, 10**20, -(10**20),
|
||||||
3.14, 'a']:
|
False, True, 3.14, 'a']:
|
||||||
self.gen.seed(arg)
|
self.gen.seed(arg)
|
||||||
|
|
||||||
for arg in [1+2j, tuple('abc'), MySeed()]:
|
for arg in [1+2j, tuple('abc'), MySeed()]:
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
Fix the :meth:`random.Random.seed` method when a :class:`bool` is passed as the
|
||||||
|
seed.
|
|
@ -264,7 +264,6 @@ random_seed(RandomObject *self, PyObject *arg)
|
||||||
uint32_t *key = NULL;
|
uint32_t *key = NULL;
|
||||||
size_t bits, keyused;
|
size_t bits, keyused;
|
||||||
int res;
|
int res;
|
||||||
PyObject *args[1];
|
|
||||||
|
|
||||||
if (arg == NULL || arg == Py_None) {
|
if (arg == NULL || arg == Py_None) {
|
||||||
if (random_seed_urandom(self) < 0) {
|
if (random_seed_urandom(self) < 0) {
|
||||||
|
@ -286,9 +285,7 @@ random_seed(RandomObject *self, PyObject *arg)
|
||||||
} else if (PyLong_Check(arg)) {
|
} else if (PyLong_Check(arg)) {
|
||||||
/* Calling int.__abs__() prevents calling arg.__abs__(), which might
|
/* Calling int.__abs__() prevents calling arg.__abs__(), which might
|
||||||
return an invalid value. See issue #31478. */
|
return an invalid value. See issue #31478. */
|
||||||
args[0] = arg;
|
n = PyObject_CallOneArg(_randomstate_global->Long___abs__, arg);
|
||||||
n = PyObject_Vectorcall(_randomstate_global->Long___abs__, args, 0,
|
|
||||||
NULL);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Py_hash_t hash = PyObject_Hash(arg);
|
Py_hash_t hash = PyObject_Hash(arg);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue