diff options
author | Victor Stinner <vstinner@python.org> | 2020-03-10 15:15:14 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-10 15:15:14 +0100 |
commit | 00d7cd8ab8db2c1e1f591ade828f88a1a973d70f (patch) | |
tree | 9de12914f0f8d11ef0d776e3d6f5906e84675541 | |
parent | 8510f430781118d9b603c3a2f06945d6ebc5fe42 (diff) | |
download | cpython-git-00d7cd8ab8db2c1e1f591ade828f88a1a973d70f.tar.gz |
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.
-rw-r--r-- | Lib/test/test_random.py | 2 | ||||
-rw-r--r-- | Misc/NEWS.d/next/Library/2020-03-10-12-52-06.bpo-38075.qbESAF.rst | 2 | ||||
-rw-r--r-- | Modules/_randommodule.c | 5 |
3 files changed, 4 insertions, 5 deletions
diff --git a/Lib/test/test_random.py b/Lib/test/test_random.py index 2c8c8e8854..c147105376 100644 --- a/Lib/test/test_random.py +++ b/Lib/test/test_random.py @@ -42,7 +42,7 @@ class TestBasicOps: def __hash__(self): return -1729 for arg in [None, 0, 1, -1, 10**20, -(10**20), - 3.14, 'a']: + False, True, 3.14, 'a']: self.gen.seed(arg) for arg in [1+2j, tuple('abc'), MySeed()]: diff --git a/Misc/NEWS.d/next/Library/2020-03-10-12-52-06.bpo-38075.qbESAF.rst b/Misc/NEWS.d/next/Library/2020-03-10-12-52-06.bpo-38075.qbESAF.rst new file mode 100644 index 0000000000..df52fcc275 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-03-10-12-52-06.bpo-38075.qbESAF.rst @@ -0,0 +1,2 @@ +Fix the :meth:`random.Random.seed` method when a :class:`bool` is passed as the +seed. diff --git a/Modules/_randommodule.c b/Modules/_randommodule.c index f0fdb0382c..7a8871868e 100644 --- a/Modules/_randommodule.c +++ b/Modules/_randommodule.c @@ -264,7 +264,6 @@ random_seed(RandomObject *self, PyObject *arg) uint32_t *key = NULL; size_t bits, keyused; int res; - PyObject *args[1]; if (arg == NULL || arg == Py_None) { if (random_seed_urandom(self) < 0) { @@ -286,9 +285,7 @@ random_seed(RandomObject *self, PyObject *arg) } else if (PyLong_Check(arg)) { /* Calling int.__abs__() prevents calling arg.__abs__(), which might return an invalid value. See issue #31478. */ - args[0] = arg; - n = PyObject_Vectorcall(_randomstate_global->Long___abs__, args, 0, - NULL); + n = PyObject_CallOneArg(_randomstate_global->Long___abs__, arg); } else { Py_hash_t hash = PyObject_Hash(arg); |