bpo-35582: Argument Clinic: inline parsing code for positional parameters. (GH-11313)
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 @@
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 @@
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 @@
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 @@
exit:
return return_value;
}
-/*[clinic end generated code: output=e8f8be828462d58b input=a9049054013a1b77]*/
+/*[clinic end generated code: output=2631a60701a8f7d4 input=a9049054013a1b77]*/