| 1343 | " None: Mutates the buffer slice in place."; |
| 1344 | |
| 1345 | static PyObject *Str_like_fill_random(PyObject *self, PyObject *const *args, Py_ssize_t positional_args_count, |
| 1346 | PyObject *args_names_tuple) { |
| 1347 | int is_member = self != NULL && PyObject_TypeCheck(self, &StrType); |
| 1348 | if (positional_args_count < !is_member || positional_args_count > !is_member + 3) { |
| 1349 | PyErr_SetString(PyExc_TypeError, "fill_random() expects 1 to 4 positional arguments"); |
| 1350 | return NULL; |
| 1351 | } |
| 1352 | |
| 1353 | PyObject *buffer_obj = is_member ? self : args[0]; |
| 1354 | PyObject *nonce_obj = positional_args_count > !is_member ? args[!is_member] : NULL; |
| 1355 | PyObject *start_obj = positional_args_count > !is_member + 1 ? args[!is_member + 1] : NULL; |
| 1356 | PyObject *end_obj = positional_args_count > !is_member + 2 ? args[!is_member + 2] : NULL; |
| 1357 | PyObject *alphabet_obj = NULL; |
| 1358 | |
| 1359 | // Optional keyword arguments |
| 1360 | if (args_names_tuple) { |
| 1361 | Py_ssize_t kw_count = PyTuple_GET_SIZE(args_names_tuple); |
| 1362 | for (Py_ssize_t i = 0; i < kw_count; ++i) { |
| 1363 | PyObject *key = PyTuple_GET_ITEM(args_names_tuple, i); |
| 1364 | PyObject *value = args[positional_args_count + i]; |
| 1365 | if (PyUnicode_CompareWithASCIIString(key, "nonce") == 0 && !nonce_obj) nonce_obj = value; |
| 1366 | else if (PyUnicode_CompareWithASCIIString(key, "alphabet") == 0 && !alphabet_obj) |
| 1367 | alphabet_obj = value; |
| 1368 | else if (PyUnicode_CompareWithASCIIString(key, "start") == 0 && !start_obj) |
| 1369 | start_obj = value; |
| 1370 | else if (PyUnicode_CompareWithASCIIString(key, "end") == 0 && !end_obj) |
| 1371 | end_obj = value; |
| 1372 | else { |
| 1373 | PyErr_Format(PyExc_TypeError, "unexpected keyword argument: %S", key); |
| 1374 | return NULL; |
| 1375 | } |
| 1376 | } |
| 1377 | } |
| 1378 | |
| 1379 | // Parse start/end |
| 1380 | Py_ssize_t start = 0, end = PY_SSIZE_T_MAX; |
| 1381 | if (start_obj && ((start = PyLong_AsSsize_t(start_obj)) == -1 && PyErr_Occurred())) { |
| 1382 | PyErr_SetString(PyExc_TypeError, "start must be an integer"); |
| 1383 | return NULL; |
| 1384 | } |
| 1385 | if (end_obj && ((end = PyLong_AsSsize_t(end_obj)) == -1 && PyErr_Occurred())) { |
| 1386 | PyErr_SetString(PyExc_TypeError, "end must be an integer"); |
| 1387 | return NULL; |
| 1388 | } |
| 1389 | |
| 1390 | // Parse nonce |
| 1391 | sz_u64_t nonce = 0; |
| 1392 | if (nonce_obj) { |
| 1393 | if (!PyLong_Check(nonce_obj)) { |
| 1394 | PyErr_SetString(PyExc_TypeError, "nonce must be an integer"); |
| 1395 | return NULL; |
| 1396 | } |
| 1397 | nonce = PyLong_AsUnsignedLongLong(nonce_obj); |
| 1398 | if (PyErr_Occurred()) return NULL; |
| 1399 | } |
| 1400 | |
| 1401 | // Parse alphabet |
| 1402 | sz_string_view_t alphabet; |
nothing calls this directly
no test coverage detected
searching dependent graphs…