mirror of https://github.com/python/cpython
Complete format code support in getargs.c::skipitem(), which is called when
evaluating keyword arguments.
This commit is contained in:
parent
8ee3e5aa93
commit
6dd14619bb
102
Python/getargs.c
102
Python/getargs.c
|
@ -453,7 +453,9 @@ float_argument_error(PyObject *arg)
|
||||||
or a string with a message describing the failure. The message is
|
or a string with a message describing the failure. The message is
|
||||||
formatted as "must be <desired type>, not <actual type>".
|
formatted as "must be <desired type>, not <actual type>".
|
||||||
When failing, an exception may or may not have been raised.
|
When failing, an exception may or may not have been raised.
|
||||||
Don't call if a tuple is expected.
|
Don't call if a tuple is expected.
|
||||||
|
|
||||||
|
When you add new format codes, please don't forget poor skipitem() below.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
|
@ -1406,73 +1408,52 @@ skipitem(char **p_format, va_list *p_va)
|
||||||
char c = *format++;
|
char c = *format++;
|
||||||
|
|
||||||
switch (c) {
|
switch (c) {
|
||||||
|
|
||||||
|
/* simple codes
|
||||||
|
* The individual types (second arg of va_arg) are irrelevant */
|
||||||
|
|
||||||
case 'b': /* byte -- very short int */
|
case 'b': /* byte -- very short int */
|
||||||
case 'B': /* byte as bitfield */
|
case 'B': /* byte as bitfield */
|
||||||
{
|
|
||||||
(void) va_arg(*p_va, char *);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case 'h': /* short int */
|
case 'h': /* short int */
|
||||||
{
|
|
||||||
(void) va_arg(*p_va, short *);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case 'H': /* short int as bitfield */
|
case 'H': /* short int as bitfield */
|
||||||
{
|
|
||||||
(void) va_arg(*p_va, unsigned short *);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case 'i': /* int */
|
case 'i': /* int */
|
||||||
{
|
case 'I': /* int sized bitfield */
|
||||||
(void) va_arg(*p_va, int *);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case 'l': /* long int */
|
case 'l': /* long int */
|
||||||
{
|
case 'k': /* long int sized bitfield */
|
||||||
(void) va_arg(*p_va, long *);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef HAVE_LONG_LONG
|
#ifdef HAVE_LONG_LONG
|
||||||
case 'L': /* PY_LONG_LONG int */
|
case 'L': /* PY_LONG_LONG */
|
||||||
{
|
case 'K': /* PY_LONG_LONG sized bitfield */
|
||||||
(void) va_arg(*p_va, PY_LONG_LONG *);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
case 'f': /* float */
|
case 'f': /* float */
|
||||||
{
|
|
||||||
(void) va_arg(*p_va, float *);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case 'd': /* double */
|
case 'd': /* double */
|
||||||
{
|
|
||||||
(void) va_arg(*p_va, double *);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifndef WITHOUT_COMPLEX
|
#ifndef WITHOUT_COMPLEX
|
||||||
case 'D': /* complex double */
|
case 'D': /* complex double */
|
||||||
{
|
#endif
|
||||||
(void) va_arg(*p_va, Py_complex *);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
#endif /* WITHOUT_COMPLEX */
|
|
||||||
|
|
||||||
case 'c': /* char */
|
case 'c': /* char */
|
||||||
{
|
{
|
||||||
(void) va_arg(*p_va, char *);
|
(void) va_arg(*p_va, void *);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* string codes */
|
||||||
|
|
||||||
|
case 'e': /* string with encoding */
|
||||||
|
{
|
||||||
|
(void) va_arg(*p_va, const char *);
|
||||||
|
if (!(*format == 's' || *format == 't'))
|
||||||
|
/* after 'e', only 's' and 't' is allowed */
|
||||||
|
goto err;
|
||||||
|
format++;
|
||||||
|
/* explicit fallthrough to string cases */
|
||||||
|
}
|
||||||
|
|
||||||
case 's': /* string */
|
case 's': /* string */
|
||||||
|
case 'z': /* string or None */
|
||||||
|
#ifdef Py_USING_UNICODE
|
||||||
|
case 'u': /* unicode string */
|
||||||
|
#endif
|
||||||
|
case 't': /* buffer, read-only */
|
||||||
|
case 'w': /* buffer, read-write */
|
||||||
{
|
{
|
||||||
(void) va_arg(*p_va, char **);
|
(void) va_arg(*p_va, char **);
|
||||||
if (*format == '#') {
|
if (*format == '#') {
|
||||||
|
@ -1481,18 +1462,13 @@ skipitem(char **p_format, va_list *p_va)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'z': /* string */
|
/* object codes */
|
||||||
{
|
|
||||||
(void) va_arg(*p_va, char **);
|
|
||||||
if (*format == '#') {
|
|
||||||
(void) va_arg(*p_va, int *);
|
|
||||||
format++;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case 'S': /* string object */
|
case 'S': /* string object */
|
||||||
|
#ifdef Py_USING_UNICODE
|
||||||
|
case 'U': /* unicode string object */
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
(void) va_arg(*p_va, PyObject **);
|
(void) va_arg(*p_va, PyObject **);
|
||||||
break;
|
break;
|
||||||
|
@ -1528,9 +1504,13 @@ skipitem(char **p_format, va_list *p_va)
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
err:
|
||||||
return "impossible<bad format char>";
|
return "impossible<bad format char>";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* The "(...)" format code for tuples is not handled here because
|
||||||
|
* it is not allowed with keyword args. */
|
||||||
|
|
||||||
*p_format = format;
|
*p_format = format;
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
Loading…
Reference in New Issue