Skip to content

Commit 00d7cd8

Browse files
authored
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.
1 parent 8510f43 commit 00d7cd8

File tree

3 files changed

+4
-5
lines changed

3 files changed

+4
-5
lines changed

Lib/test/test_random.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class MySeed(object):
4242
def __hash__(self):
4343
return -1729
4444
for arg in [None, 0, 1, -1, 10**20, -(10**20),
45-
3.14, 'a']:
45+
False, True, 3.14, 'a']:
4646
self.gen.seed(arg)
4747

4848
for arg in [1+2j, tuple('abc'), MySeed()]:
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix the :meth:`random.Random.seed` method when a :class:`bool` is passed as the
2+
seed.

Modules/_randommodule.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,6 @@ random_seed(RandomObject *self, PyObject *arg)
264264
uint32_t *key = NULL;
265265
size_t bits, keyused;
266266
int res;
267-
PyObject *args[1];
268267

269268
if (arg == NULL || arg == Py_None) {
270269
if (random_seed_urandom(self) < 0) {
@@ -286,9 +285,7 @@ random_seed(RandomObject *self, PyObject *arg)
286285
} else if (PyLong_Check(arg)) {
287286
/* Calling int.__abs__() prevents calling arg.__abs__(), which might
288287
return an invalid value. See issue #31478. */
289-
args[0] = arg;
290-
n = PyObject_Vectorcall(_randomstate_global->Long___abs__, args, 0,
291-
NULL);
288+
n = PyObject_CallOneArg(_randomstate_global->Long___abs__, arg);
292289
}
293290
else {
294291
Py_hash_t hash = PyObject_Hash(arg);

0 commit comments

Comments
 (0)