]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-38075: Fix random_seed(): use PyObject_CallOneArg() (GH-18897)
authorVictor Stinner <vstinner@python.org>
Tue, 10 Mar 2020 14:15:14 +0000 (15:15 +0100)
committerGitHub <noreply@github.com>
Tue, 10 Mar 2020 14:15:14 +0000 (15:15 +0100)
Fix the random.Random.seed() method when a bool is passed as the
seed.

PyObject_Vectorcall() was misused: use PyObject_CallOneArg() instead.

Lib/test/test_random.py
Misc/NEWS.d/next/Library/2020-03-10-12-52-06.bpo-38075.qbESAF.rst [new file with mode: 0644]
Modules/_randommodule.c

index 2c8c8e885452ad1edddfa8bea2eabcb2855c4979..c147105376199a1e48688e7d4c16dbe1017033f1 100644 (file)
@@ -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 (file)
index 0000000..df52fcc
--- /dev/null
@@ -0,0 +1,2 @@
+Fix the :meth:`random.Random.seed` method when a :class:`bool` is passed as the
+seed.
index f0fdb0382c5d3501f503fde295336ef237853eef..7a8871868e639b7933495887a01b187171a36b8c 100644 (file)
@@ -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);