Skip to content

bpo-38075: Fix random_seed(): use PyObject_CallOneArg() #18897

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Lib/test/test_random.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class MySeed(object):
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()]:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix the :meth:`random.Random.seed` method when a :class:`bool` is passed as the
seed.
5 changes: 1 addition & 4 deletions Modules/_randommodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
Expand Down