FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[3.14] gh-149816: Fix a RC in `_random.Random.__init__` method (GH-149824) by miss-islington · Pull Request #149998 · python/cpython · GitHub

/ cpython Public
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .c  (1) .h  (1) .rst  (1) All 3 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix a race condition in ``_random.Random.__init__`` method in free-threading
mode.
35 changes: 14 additions & 21 deletions Modules/_randommodule.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ typedef struct {

/*[clinic input]
module _random
class _random.Random "RandomObject *" "_randomstate_type(type)->Random_Type"
class _random.Random "RandomObject *" "(PyTypeObject *)_randomstate_type(Py_TYPE(self))->Random_Type"
[clinic start generated code]*/
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=70a2c99619474983]*/
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=f04bcbfba61a322e]*/

/* Random methods */

Expand Down Expand Up @@ -549,27 +549,20 @@ _random_Random_getrandbits_impl(RandomObject *self, uint64_t k)
return result;
}

static int
random_init(PyObject *self, PyObject *args, PyObject *kwds)
{
PyObject *arg = NULL;
_randomstate *state = _randomstate_type(Py_TYPE(self));

if ((Py_IS_TYPE(self, (PyTypeObject *)state->Random_Type) ||
Py_TYPE(self)->tp_init == ((PyTypeObject*)state->Random_Type)->tp_init) &&
!_PyArg_NoKeywords("Random", kwds)) {
return -1;
}

if (PyTuple_GET_SIZE(args) > 1) {
PyErr_SetString(PyExc_TypeError, "Random() requires 0 or 1 argument");
return -1;
}
/*[clinic input]
@critical_section
@text_signature "($self, [seed])"
_random.Random.__init__ as random_init

if (PyTuple_GET_SIZE(args) == 1)
arg = PyTuple_GET_ITEM(args, 0);
seed: object = NULL
/
[clinic start generated code]*/

return random_seed(RandomObject_CAST(self), arg);
static int
random_init_impl(RandomObject *self, PyObject *seed)
/*[clinic end generated code: output=260734a3739c394f input=e516bf32e8a05e28]*/
{
return random_seed(self, seed);
}


Expand Down
33 changes: 32 additions & 1 deletion Modules/clinic/_randommodule.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

Back | FazBrowse Home | New Git URL