summaryrefslogtreecommitdiffstats
path: root/Objects/clinic
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2019-01-11 14:01:14 (GMT)
committerGitHub <noreply@github.com>2019-01-11 14:01:14 (GMT)
commit4fa9591025b6a098f3d6402e5413ee6740ede6c5 (patch)
treea81280fdd40c6a5b8c00613b0a8903624499afc5 /Objects/clinic
parent5485085b324a45307c1ff4ec7d85b5998d7d5e0d (diff)
downloadcpython-4fa9591025b6a098f3d6402e5413ee6740ede6c5.zip
cpython-4fa9591025b6a098f3d6402e5413ee6740ede6c5.tar.gz
cpython-4fa9591025b6a098f3d6402e5413ee6740ede6c5.tar.bz2
bpo-35582: Argument Clinic: inline parsing code for positional parameters. (GH-11313)
Diffstat (limited to 'Objects/clinic')
-rw-r--r--Objects/clinic/bytearrayobject.c.h122
-rw-r--r--Objects/clinic/bytesobject.c.h63
-rw-r--r--Objects/clinic/floatobject.c.h35
-rw-r--r--Objects/clinic/listobject.c.h64
-rw-r--r--Objects/clinic/longobject.c.h4
-rw-r--r--Objects/clinic/tupleobject.c.h19
-rw-r--r--Objects/clinic/typeobject.c.h4
-rw-r--r--Objects/clinic/unicodeobject.c.h152
8 files changed, 412 insertions, 51 deletions
diff --git a/Objects/clinic/bytearrayobject.c.h b/Objects/clinic/bytearrayobject.c.h
index ec35eef..2d7c742 100644
--- a/Objects/clinic/bytearrayobject.c.h
+++ b/Objects/clinic/bytearrayobject.c.h
@@ -100,8 +100,21 @@ bytearray_maketrans(void *null, PyObject *const *args, Py_ssize_t nargs)
Py_buffer frm = {NULL, NULL};
Py_buffer to = {NULL, NULL};
- if (!_PyArg_ParseStack(args, nargs, "y*y*:maketrans",
- &frm, &to)) {
+ if (!_PyArg_CheckPositional("maketrans", nargs, 2, 2)) {
+ goto exit;
+ }
+ if (PyObject_GetBuffer(args[0], &frm, PyBUF_SIMPLE) != 0) {
+ goto exit;
+ }
+ if (!PyBuffer_IsContiguous(&frm, 'C')) {
+ _PyArg_BadArgument("maketrans", 1, "contiguous buffer", args[0]);
+ goto exit;
+ }
+ if (PyObject_GetBuffer(args[1], &to, PyBUF_SIMPLE) != 0) {
+ goto exit;
+ }
+ if (!PyBuffer_IsContiguous(&to, 'C')) {
+ _PyArg_BadArgument("maketrans", 2, "contiguous buffer", args[1]);
goto exit;
}
return_value = bytearray_maketrans_impl(&frm, &to);
@@ -147,10 +160,44 @@ bytearray_replace(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t nar
Py_buffer new = {NULL, NULL};
Py_ssize_t count = -1;
- if (!_PyArg_ParseStack(args, nargs, "y*y*|n:replace",
- &old, &new, &count)) {
+ if (!_PyArg_CheckPositional("replace", nargs, 2, 3)) {
+ goto exit;
+ }
+ if (PyObject_GetBuffer(args[0], &old, PyBUF_SIMPLE) != 0) {
+ goto exit;
+ }
+ if (!PyBuffer_IsContiguous(&old, 'C')) {
+ _PyArg_BadArgument("replace", 1, "contiguous buffer", args[0]);
+ goto exit;
+ }
+ if (PyObject_GetBuffer(args[1], &new, PyBUF_SIMPLE) != 0) {
+ goto exit;
+ }
+ if (!PyBuffer_IsContiguous(&new, 'C')) {
+ _PyArg_BadArgument("replace", 2, "contiguous buffer", args[1]);
+ goto exit;
+ }
+ if (nargs < 3) {
+ goto skip_optional;
+ }
+ if (PyFloat_Check(args[2])) {
+ PyErr_SetString(PyExc_TypeError,
+ "integer argument expected, got float" );
goto exit;
}
+ {
+ Py_ssize_t ival = -1;
+ PyObject *iobj = PyNumber_Index(args[2]);
+ if (iobj != NULL) {
+ ival = PyLong_AsSsize_t(iobj);
+ Py_DECREF(iobj);
+ }
+ if (ival == -1 && PyErr_Occurred()) {
+ goto exit;
+ }
+ count = ival;
+ }
+skip_optional:
return_value = bytearray_replace_impl(self, &old, &new, count);
exit:
@@ -323,8 +370,27 @@ bytearray_insert(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t narg
Py_ssize_t index;
int item;
- if (!_PyArg_ParseStack(args, nargs, "nO&:insert",
- &index, _getbytevalue, &item)) {
+ if (!_PyArg_CheckPositional("insert", nargs, 2, 2)) {
+ goto exit;
+ }
+ if (PyFloat_Check(args[0])) {
+ PyErr_SetString(PyExc_TypeError,
+ "integer argument expected, got float" );
+ goto exit;
+ }
+ {
+ Py_ssize_t ival = -1;
+ PyObject *iobj = PyNumber_Index(args[0]);
+ if (iobj != NULL) {
+ ival = PyLong_AsSsize_t(iobj);
+ Py_DECREF(iobj);
+ }
+ if (ival == -1 && PyErr_Occurred()) {
+ goto exit;
+ }
+ index = ival;
+ }
+ if (!_getbytevalue(args[1], &item)) {
goto exit;
}
return_value = bytearray_insert_impl(self, index, item);
@@ -399,10 +465,30 @@ bytearray_pop(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t nargs)
PyObject *return_value = NULL;
Py_ssize_t index = -1;
- if (!_PyArg_ParseStack(args, nargs, "|n:pop",
- &index)) {
+ if (!_PyArg_CheckPositional("pop", nargs, 0, 1)) {
goto exit;
}
+ if (nargs < 1) {
+ goto skip_optional;
+ }
+ if (PyFloat_Check(args[0])) {
+ PyErr_SetString(PyExc_TypeError,
+ "integer argument expected, got float" );
+ goto exit;
+ }
+ {
+ Py_ssize_t ival = -1;
+ PyObject *iobj = PyNumber_Index(args[0]);
+ if (iobj != NULL) {
+ ival = PyLong_AsSsize_t(iobj);
+ Py_DECREF(iobj);
+ }
+ if (ival == -1 && PyErr_Occurred()) {
+ goto exit;
+ }
+ index = ival;
+ }
+skip_optional:
return_value = bytearray_pop_impl(self, index);
exit:
@@ -641,7 +727,7 @@ bytearray_fromhex(PyTypeObject *type, PyObject *arg)
PyObject *string;
if (!PyUnicode_Check(arg)) {
- _PyArg_BadArgument("fromhex", "str", arg);
+ _PyArg_BadArgument("fromhex", 0, "str", arg);
goto exit;
}
if (PyUnicode_READY(arg) == -1) {
@@ -690,10 +776,22 @@ bytearray_reduce_ex(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t n
PyObject *return_value = NULL;
int proto = 0;
- if (!_PyArg_ParseStack(args, nargs, "|i:__reduce_ex__",
- &proto)) {
+ if (!_PyArg_CheckPositional("__reduce_ex__", nargs, 0, 1)) {
+ goto exit;
+ }
+ if (nargs < 1) {
+ goto skip_optional;
+ }
+ if (PyFloat_Check(args[0])) {
+ PyErr_SetString(PyExc_TypeError,
+ "integer argument expected, got float" );
+ goto exit;
+ }
+ proto = _PyLong_AsInt(args[0]);
+ if (proto == -1 && PyErr_Occurred()) {
goto exit;
}
+skip_optional:
return_value = bytearray_reduce_ex_impl(self, proto);
exit:
@@ -717,4 +815,4 @@ bytearray_sizeof(PyByteArrayObject *self, PyObject *Py_UNUSED(ignored))
{
return bytearray_sizeof_impl(self);
}
-/*[clinic end generated code: output=cd3e13a1905a473c input=a9049054013a1b77]*/
+/*[clinic end generated code: output=010e281b823d7df1 input=a9049054013a1b77]*/
diff --git a/Objects/clinic/bytesobject.c.h b/Objects/clinic/bytesobject.c.h
index 1345b64..4e754d9 100644
--- a/Objects/clinic/bytesobject.c.h
+++ b/Objects/clinic/bytesobject.c.h
@@ -70,7 +70,7 @@ bytes_partition(PyBytesObject *self, PyObject *arg)
goto exit;
}
if (!PyBuffer_IsContiguous(&sep, 'C')) {
- _PyArg_BadArgument("partition", "contiguous buffer", arg);
+ _PyArg_BadArgument("partition", 0, "contiguous buffer", arg);
goto exit;
}
return_value = bytes_partition_impl(self, &sep);
@@ -113,7 +113,7 @@ bytes_rpartition(PyBytesObject *self, PyObject *arg)
goto exit;
}
if (!PyBuffer_IsContiguous(&sep, 'C')) {
- _PyArg_BadArgument("rpartition", "contiguous buffer", arg);
+ _PyArg_BadArgument("rpartition", 0, "contiguous buffer", arg);
goto exit;
}
return_value = bytes_rpartition_impl(self, &sep);
@@ -338,8 +338,21 @@ bytes_maketrans(void *null, PyObject *const *args, Py_ssize_t nargs)
Py_buffer frm = {NULL, NULL};
Py_buffer to = {NULL, NULL};
- if (!_PyArg_ParseStack(args, nargs, "y*y*:maketrans",
- &frm, &to)) {
+ if (!_PyArg_CheckPositional("maketrans", nargs, 2, 2)) {
+ goto exit;
+ }
+ if (PyObject_GetBuffer(args[0], &frm, PyBUF_SIMPLE) != 0) {
+ goto exit;
+ }
+ if (!PyBuffer_IsContiguous(&frm, 'C')) {
+ _PyArg_BadArgument("maketrans", 1, "contiguous buffer", args[0]);
+ goto exit;
+ }
+ if (PyObject_GetBuffer(args[1], &to, PyBUF_SIMPLE) != 0) {
+ goto exit;
+ }
+ if (!PyBuffer_IsContiguous(&to, 'C')) {
+ _PyArg_BadArgument("maketrans", 2, "contiguous buffer", args[1]);
goto exit;
}
return_value = bytes_maketrans_impl(&frm, &to);
@@ -385,10 +398,44 @@ bytes_replace(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs)
Py_buffer new = {NULL, NULL};
Py_ssize_t count = -1;
- if (!_PyArg_ParseStack(args, nargs, "y*y*|n:replace",
- &old, &new, &count)) {
+ if (!_PyArg_CheckPositional("replace", nargs, 2, 3)) {
+ goto exit;
+ }
+ if (PyObject_GetBuffer(args[0], &old, PyBUF_SIMPLE) != 0) {
goto exit;
}
+ if (!PyBuffer_IsContiguous(&old, 'C')) {
+ _PyArg_BadArgument("replace", 1, "contiguous buffer", args[0]);
+ goto exit;
+ }
+ if (PyObject_GetBuffer(args[1], &new, PyBUF_SIMPLE) != 0) {
+ goto exit;
+ }
+ if (!PyBuffer_IsContiguous(&new, 'C')) {
+ _PyArg_BadArgument("replace", 2, "contiguous buffer", args[1]);
+ goto exit;
+ }
+ if (nargs < 3) {
+ goto skip_optional;
+ }
+ if (PyFloat_Check(args[2])) {
+ PyErr_SetString(PyExc_TypeError,
+ "integer argument expected, got float" );
+ goto exit;
+ }
+ {
+ Py_ssize_t ival = -1;
+ PyObject *iobj = PyNumber_Index(args[2]);
+ if (iobj != NULL) {
+ ival = PyLong_AsSsize_t(iobj);
+ Py_DECREF(iobj);
+ }
+ if (ival == -1 && PyErr_Occurred()) {
+ goto exit;
+ }
+ count = ival;
+ }
+skip_optional:
return_value = bytes_replace_impl(self, &old, &new, count);
exit:
@@ -500,7 +547,7 @@ bytes_fromhex(PyTypeObject *type, PyObject *arg)
PyObject *string;
if (!PyUnicode_Check(arg)) {
- _PyArg_BadArgument("fromhex", "str", arg);
+ _PyArg_BadArgument("fromhex", 0, "str", arg);
goto exit;
}
if (PyUnicode_READY(arg) == -1) {
@@ -512,4 +559,4 @@ bytes_fromhex(PyTypeObject *type, PyObject *arg)
exit:
return return_value;
}
-/*[clinic end generated code: output=dc9aa04f0007ab11 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=810c8dfc72520ca4 input=a9049054013a1b77]*/
diff --git a/Objects/clinic/floatobject.c.h b/Objects/clinic/floatobject.c.h
index 28b24d0..741ca3b 100644
--- a/Objects/clinic/floatobject.c.h
+++ b/Objects/clinic/floatobject.c.h
@@ -229,7 +229,7 @@ float___getformat__(PyTypeObject *type, PyObject *arg)
const char *typestr;
if (!PyUnicode_Check(arg)) {
- _PyArg_BadArgument("__getformat__", "str", arg);
+ _PyArg_BadArgument("__getformat__", 0, "str", arg);
goto exit;
}
Py_ssize_t typestr_length;
@@ -279,8 +279,33 @@ float___set_format__(PyTypeObject *type, PyObject *const *args, Py_ssize_t nargs
const char *typestr;
const char *fmt;
- if (!_PyArg_ParseStack(args, nargs, "ss:__set_format__",
- &typestr, &fmt)) {
+ if (!_PyArg_CheckPositional("__set_format__", nargs, 2, 2)) {
+ goto exit;
+ }
+ if (!PyUnicode_Check(args[0])) {
+ _PyArg_BadArgument("__set_format__", 1, "str", args[0]);
+ goto exit;
+ }
+ Py_ssize_t typestr_length;
+ typestr = PyUnicode_AsUTF8AndSize(args[0], &typestr_length);
+ if (typestr == NULL) {
+ goto exit;
+ }
+ if (strlen(typestr) != (size_t)typestr_length) {
+ PyErr_SetString(PyExc_ValueError, "embedded null character");
+ goto exit;
+ }
+ if (!PyUnicode_Check(args[1])) {
+ _PyArg_BadArgument("__set_format__", 2, "str", args[1]);
+ goto exit;
+ }
+ Py_ssize_t fmt_length;
+ fmt = PyUnicode_AsUTF8AndSize(args[1], &fmt_length);
+ if (fmt == NULL) {
+ goto exit;
+ }
+ if (strlen(fmt) != (size_t)fmt_length) {
+ PyErr_SetString(PyExc_ValueError, "embedded null character");
goto exit;
}
return_value = float___set_format___impl(type, typestr, fmt);
@@ -308,7 +333,7 @@ float___format__(PyObject *self, PyObject *arg)
PyObject *format_spec;
if (!PyUnicode_Check(arg)) {
- _PyArg_BadArgument("__format__", "str", arg);
+ _PyArg_BadArgument("__format__", 0, "str", arg);
goto exit;
}
if (PyUnicode_READY(arg) == -1) {
@@ -320,4 +345,4 @@ float___format__(PyObject *self, PyObject *arg)
exit:
return return_value;
}
-/*[clinic end generated code: output=e8f8be828462d58b input=a9049054013a1b77]*/
+/*[clinic end generated code: output=2631a60701a8f7d4 input=a9049054013a1b77]*/
diff --git a/Objects/clinic/listobject.c.h b/Objects/clinic/listobject.c.h
index 0097481..3617458 100644
--- a/Objects/clinic/listobject.c.h
+++ b/Objects/clinic/listobject.c.h
@@ -21,10 +21,27 @@ list_insert(PyListObject *self, PyObject *const *args, Py_ssize_t nargs)
Py_ssize_t index;
PyObject *object;
- if (!_PyArg_ParseStack(args, nargs, "nO:insert",
- &index, &object)) {
+ if (!_PyArg_CheckPositional("insert", nargs, 2, 2)) {
goto exit;
}
+ if (PyFloat_Check(args[0])) {
+ PyErr_SetString(PyExc_TypeError,
+ "integer argument expected, got float" );
+ goto exit;
+ }
+ {
+ Py_ssize_t ival = -1;
+ PyObject *iobj = PyNumber_Index(args[0]);
+ if (iobj != NULL) {
+ ival = PyLong_AsSsize_t(iobj);
+ Py_DECREF(iobj);
+ }
+ if (ival == -1 && PyErr_Occurred()) {
+ goto exit;
+ }
+ index = ival;
+ }
+ object = args[1];
return_value = list_insert_impl(self, index, object);
exit:
@@ -105,10 +122,30 @@ list_pop(PyListObject *self, PyObject *const *args, Py_ssize_t nargs)
PyObject *return_value = NULL;
Py_ssize_t index = -1;
- if (!_PyArg_ParseStack(args, nargs, "|n:pop",
- &index)) {
+ if (!_PyArg_CheckPositional("pop", nargs, 0, 1)) {
goto exit;
}
+ if (nargs < 1) {
+ goto skip_optional;
+ }
+ if (PyFloat_Check(args[0])) {
+ PyErr_SetString(PyExc_TypeError,
+ "integer argument expected, got float" );
+ goto exit;
+ }
+ {
+ Py_ssize_t ival = -1;
+ PyObject *iobj = PyNumber_Index(args[0]);
+ if (iobj != NULL) {
+ ival = PyLong_AsSsize_t(iobj);
+ Py_DECREF(iobj);
+ }
+ if (ival == -1 && PyErr_Occurred()) {
+ goto exit;
+ }
+ index = ival;
+ }
+skip_optional:
return_value = list_pop_impl(self, index);
exit:
@@ -187,10 +224,23 @@ list_index(PyListObject *self, PyObject *const *args, Py_ssize_t nargs)
Py_ssize_t start = 0;
Py_ssize_t stop = PY_SSIZE_T_MAX;
- if (!_PyArg_ParseStack(args, nargs, "O|O&O&:index",
- &value, _PyEval_SliceIndexNotNone, &start, _PyEval_SliceIndexNotNone, &stop)) {
+ if (!_PyArg_CheckPositional("index", nargs, 1, 3)) {
+ goto exit;
+ }
+ value = args[0];
+ if (nargs < 2) {
+ goto skip_optional;
+ }
+ if (!_PyEval_SliceIndexNotNone(args[1], &start)) {
+ goto exit;
+ }
+ if (nargs < 3) {
+ goto skip_optional;
+ }
+ if (!_PyEval_SliceIndexNotNone(args[2], &stop)) {
goto exit;
}
+skip_optional:
return_value = list_index_impl(self, value, start, stop);
exit:
@@ -285,4 +335,4 @@ list___reversed__(PyListObject *self, PyObject *Py_UNUSED(ignored))
{
return list___reversed___impl(self);
}
-/*[clinic end generated code: output=652ae4ee63a9de71 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=1f641f5aef3f886f input=a9049054013a1b77]*/
diff --git a/Objects/clinic/longobject.c.h b/Objects/clinic/longobject.c.h
index 27cdf9e..6770023 100644
--- a/Objects/clinic/longobject.c.h
+++ b/Objects/clinic/longobject.c.h
@@ -59,7 +59,7 @@ int___format__(PyObject *self, PyObject *arg)
PyObject *format_spec;
if (!PyUnicode_Check(arg)) {
- _PyArg_BadArgument("__format__", "str", arg);
+ _PyArg_BadArgument("__format__", 0, "str", arg);
goto exit;
}
if (PyUnicode_READY(arg) == -1) {
@@ -244,4 +244,4 @@ int_from_bytes(PyTypeObject *type, PyObject *const *args, Py_ssize_t nargs, PyOb
exit:
return return_value;
}
-/*[clinic end generated code: output=7436b5f4decdcf9d input=a9049054013a1b77]*/
+/*[clinic end generated code: output=3b91cda9d83abaa2 input=a9049054013a1b77]*/
diff --git a/Objects/clinic/tupleobject.c.h b/Objects/clinic/tupleobject.c.h
index 67d9f34..0096f0c 100644
--- a/Objects/clinic/tupleobject.c.h
+++ b/Objects/clinic/tupleobject.c.h
@@ -25,10 +25,23 @@ tuple_index(PyTupleObject *self, PyObject *const *args, Py_ssize_t nargs)
Py_ssize_t start = 0;
Py_ssize_t stop = PY_SSIZE_T_MAX;
- if (!_PyArg_ParseStack(args, nargs, "O|O&O&:index",
- &value, _PyEval_SliceIndexNotNone, &start, _PyEval_SliceIndexNotNone, &stop)) {
+ if (!_PyArg_CheckPositional("index", nargs, 1, 3)) {
goto exit;
}
+ value = args[0];
+ if (nargs < 2) {
+ goto skip_optional;
+ }
+ if (!_PyEval_SliceIndexNotNone(args[1], &start)) {
+ goto exit;
+ }
+ if (nargs < 3) {
+ goto skip_optional;
+ }
+ if (!_PyEval_SliceIndexNotNone(args[2], &stop)) {
+ goto exit;
+ }
+skip_optional:
return_value = tuple_index_impl(self, value, start, stop);
exit:
@@ -95,4 +108,4 @@ tuple___getnewargs__(PyTupleObject *self, PyObject *Py_UNUSED(ignored))
{
return tuple___getnewargs___impl(self);
}
-/*[clinic end generated code: output=0a6ebd2d16b09c5d input=a9049054013a1b77]*/
+/*[clinic end generated code: output=5312868473a41cfe input=a9049054013a1b77]*/
diff --git a/Objects/clinic/typeobject.c.h b/Objects/clinic/typeobject.c.h
index 115a218..fbe1261 100644
--- a/Objects/clinic/typeobject.c.h
+++ b/Objects/clinic/typeobject.c.h
@@ -200,7 +200,7 @@ object___format__(PyObject *self, PyObject *arg)
PyObject *format_spec;
if (!PyUnicode_Check(arg)) {
- _PyArg_BadArgument("__format__", "str", arg);
+ _PyArg_BadArgument("__format__", 0, "str", arg);
goto exit;
}
if (PyUnicode_READY(arg) == -1) {
@@ -248,4 +248,4 @@ object___dir__(PyObject *self, PyObject *Py_UNUSED(ignored))
{
return object___dir___impl(self);
}
-/*[clinic end generated code: output=09f3453839e60136 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=ea5734413064fa7e input=a9049054013a1b77]*/
diff --git a/Objects/clinic/unicodeobject.c.h b/Objects/clinic/unicodeobject.c.h
index 744a6eb..21e54f1 100644
--- a/Objects/clinic/unicodeobject.c.h
+++ b/Objects/clinic/unicodeobject.c.h
@@ -83,10 +83,33 @@ unicode_center(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
Py_ssize_t width;
Py_UCS4 fillchar = ' ';
- if (!_PyArg_ParseStack(args, nargs, "n|O&:center",
- &width, convert_uc, &fillchar)) {
+ if (!_PyArg_CheckPositional("center", nargs, 1, 2)) {
goto exit;
}
+ if (PyFloat_Check(args[0])) {
+ PyErr_SetString(PyExc_TypeError,
+ "integer argument expected, got float" );
+ goto exit;
+ }
+ {
+ Py_ssize_t ival = -1;
+ PyObject *iobj = PyNumber_Index(args[0]);
+ if (iobj != NULL) {
+ ival = PyLong_AsSsize_t(iobj);
+ Py_DECREF(iobj);
+ }
+ if (ival == -1 && PyErr_Occurred()) {
+ goto exit;
+ }
+ width = ival;
+ }
+ if (nargs < 2) {
+ goto skip_optional;
+ }
+ if (!convert_uc(args[1], &fillchar)) {
+ goto exit;
+ }
+skip_optional:
return_value = unicode_center_impl(self, width, fillchar);
exit:
@@ -452,10 +475,33 @@ unicode_ljust(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
Py_ssize_t width;
Py_UCS4 fillchar = ' ';
- if (!_PyArg_ParseStack(args, nargs, "n|O&:ljust",
- &width, convert_uc, &fillchar)) {
+ if (!_PyArg_CheckPositional("ljust", nargs, 1, 2)) {
+ goto exit;
+ }
+ if (PyFloat_Check(args[0])) {
+ PyErr_SetString(PyExc_TypeError,
+ "integer argument expected, got float" );
goto exit;
}
+ {
+ Py_ssize_t ival = -1;
+ PyObject *iobj = PyNumber_Index(args[0]);
+ if (iobj != NULL) {
+ ival = PyLong_AsSsize_t(iobj);
+ Py_DECREF(iobj);
+ }
+ if (ival == -1 && PyErr_Occurred()) {
+ goto exit;
+ }
+ width = ival;
+ }
+ if (nargs < 2) {
+ goto skip_optional;
+ }
+ if (!convert_uc(args[1], &fillchar)) {
+ goto exit;
+ }
+skip_optional:
return_value = unicode_ljust_impl(self, width, fillchar);
exit:
@@ -601,10 +647,46 @@ unicode_replace(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
PyObject *new;
Py_ssize_t count = -1;
- if (!_PyArg_ParseStack(args, nargs, "UU|n:replace",
- &old, &new, &count)) {
+ if (!_PyArg_CheckPositional("replace", nargs, 2, 3)) {
+ goto exit;
+ }
+ if (!PyUnicode_Check(args[0])) {
+ _PyArg_BadArgument("replace", 1, "str", args[0]);
+ goto exit;
+ }
+ if (PyUnicode_READY(args[0]) == -1) {
+ goto exit;
+ }
+ old = args[0];
+ if (!PyUnicode_Check(args[1])) {
+ _PyArg_BadArgument("replace", 2, "str", args[1]);
+ goto exit;
+ }
+ if (PyUnicode_READY(args[1]) == -1) {
goto exit;
}
+ new = args[1];
+ if (nargs < 3) {
+ goto skip_optional;
+ }
+ if (PyFloat_Check(args[2])) {
+ PyErr_SetString(PyExc_TypeError,
+ "integer argument expected, got float" );
+ goto exit;
+ }
+ {
+ Py_ssize_t ival = -1;
+ PyObject *iobj = PyNumber_Index(args[2]);
+ if (iobj != NULL) {
+ ival = PyLong_AsSsize_t(iobj);
+ Py_DECREF(iobj);
+ }
+ if (ival == -1 && PyErr_Occurred()) {
+ goto exit;
+ }
+ count = ival;
+ }
+skip_optional:
return_value = unicode_replace_impl(self, old, new, count);
exit:
@@ -632,10 +714,33 @@ unicode_rjust(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
Py_ssize_t width;
Py_UCS4 fillchar = ' ';
- if (!_PyArg_ParseStack(args, nargs, "n|O&:rjust",
- &width, convert_uc, &fillchar)) {
+ if (!_PyArg_CheckPositional("rjust", nargs, 1, 2)) {
goto exit;
}
+ if (PyFloat_Check(args[0])) {
+ PyErr_SetString(PyExc_TypeError,
+ "integer argument expected, got float" );
+ goto exit;
+ }
+ {
+ Py_ssize_t ival = -1;
+ PyObject *iobj = PyNumber_Index(args[0]);
+ if (iobj != NULL) {
+ ival = PyLong_AsSsize_t(iobj);
+ Py_DECREF(iobj);
+ }
+ if (ival == -1 && PyErr_Occurred()) {
+ goto exit;
+ }
+ width = ival;
+ }
+ if (nargs < 2) {
+ goto skip_optional;
+ }
+ if (!convert_uc(args[1], &fillchar)) {
+ goto exit;
+ }
+skip_optional:
return_value = unicode_rjust_impl(self, width, fillchar);
exit:
@@ -833,10 +938,33 @@ unicode_maketrans(void *null, PyObject *const *args, Py_ssize_t nargs)
PyObject *y = NULL;
PyObject *z = NULL;
- if (!_PyArg_ParseStack(args, nargs, "O|UU:maketrans",
- &x, &y, &z)) {
+ if (!_PyArg_CheckPositional("maketrans", nargs, 1, 3)) {
+ goto exit;
+ }
+ x = args[0];
+ if (nargs < 2) {
+ goto skip_optional;
+ }
+ if (!PyUnicode_Check(args[1])) {
+ _PyArg_BadArgument("maketrans", 2, "str", args[1]);
+ goto exit;
+ }
+ if (PyUnicode_READY(args[1]) == -1) {
+ goto exit;
+ }
+ y = args[1];
+ if (nargs < 3) {
+ goto skip_optional;
+ }
+ if (!PyUnicode_Check(args[2])) {
+ _PyArg_BadArgument("maketrans", 3, "str", args[2]);
+ goto exit;
+ }
+ if (PyUnicode_READY(args[2]) == -1) {
goto exit;
}
+ z = args[2];
+skip_optional:
return_value = unicode_maketrans_impl(x, y, z);
exit:
@@ -940,7 +1068,7 @@ unicode___format__(PyObject *self, PyObject *arg)
PyObject *format_spec;
if (!PyUnicode_Check(arg)) {
- _PyArg_BadArgument("__format__", "str", arg);
+ _PyArg_BadArgument("__format__", 0, "str", arg);
goto exit;
}
if (PyUnicode_READY(arg) == -1) {
@@ -970,4 +1098,4 @@ unicode_sizeof(PyObject *self, PyObject *Py_UNUSED(ignored))
{
return unicode_sizeof_impl(self);
}
-/*[clinic end generated code: output=ff6acd5abd1998eb input=a9049054013a1b77]*/
+/*[clinic end generated code: output=73ad9670e00a2490 input=a9049054013a1b77]*/