/*[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 */
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);
}
exit:
return return_value;
}
-/*[clinic end generated code: output=7ce97b2194eecaf7 input=a9049054013a1b77]*/
+
+static int
+random_init_impl(RandomObject *self, PyObject *seed);
+
+static int
+random_init(PyObject *self, PyObject *args, PyObject *kwargs)
+{
+ int return_value = -1;
+ PyTypeObject *base_tp = (PyTypeObject *)_randomstate_type(Py_TYPE(self))->Random_Type;
+ PyObject *seed = NULL;
+
+ if ((Py_IS_TYPE(self, base_tp) ||
+ Py_TYPE(self)->tp_new == base_tp->tp_new) &&
+ !_PyArg_NoKeywords("Random", kwargs)) {
+ goto exit;
+ }
+ if (!_PyArg_CheckPositional("Random", PyTuple_GET_SIZE(args), 0, 1)) {
+ goto exit;
+ }
+ if (PyTuple_GET_SIZE(args) < 1) {
+ goto skip_optional;
+ }
+ seed = PyTuple_GET_ITEM(args, 0);
+skip_optional:
+ Py_BEGIN_CRITICAL_SECTION(self);
+ return_value = random_init_impl((RandomObject *)self, seed);
+ Py_END_CRITICAL_SECTION();
+
+exit:
+ return return_value;
+}
+/*[clinic end generated code: output=ec95f7df0c3f3c19 input=a9049054013a1b77]*/