diff options
author | Victor Stinner <vstinner@python.org> | 2020-04-29 16:49:00 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-29 16:49:00 (GMT) |
commit | 2d8757758d0d75882fef0fe0e3c74c4756b3e81e (patch) | |
tree | 676e735cf1076bf60f2a7412e67e394e6b0f7948 /Modules/clinic | |
parent | e3dfb9b967c560f4d094092dcae4a16fc9634681 (diff) | |
download | cpython-2d8757758d0d75882fef0fe0e3c74c4756b3e81e.zip cpython-2d8757758d0d75882fef0fe0e3c74c4756b3e81e.tar.gz cpython-2d8757758d0d75882fef0fe0e3c74c4756b3e81e.tar.bz2 |
bpo-40286: Remove C implementation of Random.randbytes() (GH-19797)
Remove _random.Random.randbytes(): the C implementation of
randbytes(). Implement the method in Python to ease subclassing:
randbytes() now directly reuses getrandbits().
Diffstat (limited to 'Modules/clinic')
-rw-r--r-- | Modules/clinic/_randommodule.c.h | 43 |
1 files changed, 1 insertions, 42 deletions
diff --git a/Modules/clinic/_randommodule.c.h b/Modules/clinic/_randommodule.c.h index dda78f6..a467811 100644 --- a/Modules/clinic/_randommodule.c.h +++ b/Modules/clinic/_randommodule.c.h @@ -114,45 +114,4 @@ _random_Random_getrandbits(RandomObject *self, PyObject *arg) exit: return return_value; } - -PyDoc_STRVAR(_random_Random_randbytes__doc__, -"randbytes($self, n, /)\n" -"--\n" -"\n" -"Generate n random bytes."); - -#define _RANDOM_RANDOM_RANDBYTES_METHODDEF \ - {"randbytes", (PyCFunction)_random_Random_randbytes, METH_O, _random_Random_randbytes__doc__}, - -static PyObject * -_random_Random_randbytes_impl(RandomObject *self, Py_ssize_t n); - -static PyObject * -_random_Random_randbytes(RandomObject *self, PyObject *arg) -{ - PyObject *return_value = NULL; - Py_ssize_t n; - - if (PyFloat_Check(arg)) { - PyErr_SetString(PyExc_TypeError, - "integer argument expected, got float" ); - goto exit; - } - { - Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(arg); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - n = ival; - } - return_value = _random_Random_randbytes_impl(self, n); - -exit: - return return_value; -} -/*[clinic end generated code: output=e515c651860c4001 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=a7feb0c9c8d1b627 input=a9049054013a1b77]*/ |