bpo-23867: Argument Clinic: inline parsing code for a single positional parameter. (GH-9689)

This commit is contained in:
Serhiy Storchaka 2018-12-25 13:23:47 +02:00 committed by GitHub
parent 65ce60aef1
commit 32d96a2b5b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
49 changed files with 1677 additions and 275 deletions

View file

@ -66,7 +66,11 @@ bytes_partition(PyBytesObject *self, PyObject *arg)
PyObject *return_value = NULL;
Py_buffer sep = {NULL, NULL};
if (!PyArg_Parse(arg, "y*:partition", &sep)) {
if (PyObject_GetBuffer(arg, &sep, PyBUF_SIMPLE) != 0) {
goto exit;
}
if (!PyBuffer_IsContiguous(&sep, 'C')) {
_PyArg_BadArgument("partition", "contiguous buffer", arg);
goto exit;
}
return_value = bytes_partition_impl(self, &sep);
@ -105,7 +109,11 @@ bytes_rpartition(PyBytesObject *self, PyObject *arg)
PyObject *return_value = NULL;
Py_buffer sep = {NULL, NULL};
if (!PyArg_Parse(arg, "y*:rpartition", &sep)) {
if (PyObject_GetBuffer(arg, &sep, PyBUF_SIMPLE) != 0) {
goto exit;
}
if (!PyBuffer_IsContiguous(&sep, 'C')) {
_PyArg_BadArgument("rpartition", "contiguous buffer", arg);
goto exit;
}
return_value = bytes_rpartition_impl(self, &sep);
@ -491,12 +499,17 @@ bytes_fromhex(PyTypeObject *type, PyObject *arg)
PyObject *return_value = NULL;
PyObject *string;
if (!PyArg_Parse(arg, "U:fromhex", &string)) {
if (!PyUnicode_Check(arg)) {
_PyArg_BadArgument("fromhex", "str", arg);
goto exit;
}
if (PyUnicode_READY(arg) == -1) {
goto exit;
}
string = arg;
return_value = bytes_fromhex_impl(type, string);
exit:
return return_value;
}
/*[clinic end generated code: output=07b33ac65362301b input=a9049054013a1b77]*/
/*[clinic end generated code: output=dc9aa04f0007ab11 input=a9049054013a1b77]*/