summaryrefslogtreecommitdiffstats
path: root/PC/clinic
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2018-12-25 11:23:47 (GMT)
committerGitHub <noreply@github.com>2018-12-25 11:23:47 (GMT)
commit32d96a2b5bc3136d45a66adbdb45fac351b520ce (patch)
treeacf51c9945f764ab103597c9cba376f154aa600d /PC/clinic
parent65ce60aef150776f884715b4315a10a0d6ae769e (diff)
downloadcpython-32d96a2b5bc3136d45a66adbdb45fac351b520ce.zip
cpython-32d96a2b5bc3136d45a66adbdb45fac351b520ce.tar.gz
cpython-32d96a2b5bc3136d45a66adbdb45fac351b520ce.tar.bz2
bpo-23867: Argument Clinic: inline parsing code for a single positional parameter. (GH-9689)
Diffstat (limited to 'PC/clinic')
-rw-r--r--PC/clinic/msvcrtmodule.c.h66
-rw-r--r--PC/clinic/winreg.c.h12
2 files changed, 64 insertions, 14 deletions
diff --git a/PC/clinic/msvcrtmodule.c.h b/PC/clinic/msvcrtmodule.c.h
index 0466306..b1c588b 100644
--- a/PC/clinic/msvcrtmodule.c.h
+++ b/PC/clinic/msvcrtmodule.c.h
@@ -158,7 +158,13 @@ msvcrt_get_osfhandle(PyObject *module, PyObject *arg)
int fd;
void *_return_value;
- if (!PyArg_Parse(arg, "i:get_osfhandle", &fd)) {
+ if (PyFloat_Check(arg)) {
+ PyErr_SetString(PyExc_TypeError,
+ "integer argument expected, got float" );
+ goto exit;
+ }
+ fd = _PyLong_AsInt(arg);
+ if (fd == -1 && PyErr_Occurred()) {
goto exit;
}
_return_value = msvcrt_get_osfhandle_impl(module, fd);
@@ -319,7 +325,14 @@ msvcrt_putch(PyObject *module, PyObject *arg)
PyObject *return_value = NULL;
char char_value;
- if (!PyArg_Parse(arg, "c:putch", &char_value)) {
+ if (PyBytes_Check(arg) && PyBytes_GET_SIZE(arg) == 1) {
+ char_value = PyBytes_AS_STRING(arg)[0];
+ }
+ else if (PyByteArray_Check(arg) && PyByteArray_GET_SIZE(arg) == 1) {
+ char_value = PyByteArray_AS_STRING(arg)[0];
+ }
+ else {
+ _PyArg_BadArgument("putch", "a byte string of length 1", arg);
goto exit;
}
return_value = msvcrt_putch_impl(module, char_value);
@@ -346,9 +359,18 @@ msvcrt_putwch(PyObject *module, PyObject *arg)
PyObject *return_value = NULL;
int unicode_char;
- if (!PyArg_Parse(arg, "C:putwch", &unicode_char)) {
+ if (!PyUnicode_Check(arg)) {
+ _PyArg_BadArgument("putwch", "a unicode character", arg);
goto exit;
}
+ if (PyUnicode_READY(arg)) {
+ goto exit;
+ }
+ if (PyUnicode_GET_LENGTH(arg) != 1) {
+ _PyArg_BadArgument("putwch", "a unicode character", arg);
+ goto exit;
+ }
+ unicode_char = PyUnicode_READ_CHAR(arg, 0);
return_value = msvcrt_putwch_impl(module, unicode_char);
exit:
@@ -377,7 +399,14 @@ msvcrt_ungetch(PyObject *module, PyObject *arg)
PyObject *return_value = NULL;
char char_value;
- if (!PyArg_Parse(arg, "c:ungetch", &char_value)) {
+ if (PyBytes_Check(arg) && PyBytes_GET_SIZE(arg) == 1) {
+ char_value = PyBytes_AS_STRING(arg)[0];
+ }
+ else if (PyByteArray_Check(arg) && PyByteArray_GET_SIZE(arg) == 1) {
+ char_value = PyByteArray_AS_STRING(arg)[0];
+ }
+ else {
+ _PyArg_BadArgument("ungetch", "a byte string of length 1", arg);
goto exit;
}
return_value = msvcrt_ungetch_impl(module, char_value);
@@ -404,9 +433,18 @@ msvcrt_ungetwch(PyObject *module, PyObject *arg)
PyObject *return_value = NULL;
int unicode_char;
- if (!PyArg_Parse(arg, "C:ungetwch", &unicode_char)) {
+ if (!PyUnicode_Check(arg)) {
+ _PyArg_BadArgument("ungetwch", "a unicode character", arg);
+ goto exit;
+ }
+ if (PyUnicode_READY(arg)) {
+ goto exit;
+ }
+ if (PyUnicode_GET_LENGTH(arg) != 1) {
+ _PyArg_BadArgument("ungetwch", "a unicode character", arg);
goto exit;
}
+ unicode_char = PyUnicode_READ_CHAR(arg, 0);
return_value = msvcrt_ungetwch_impl(module, unicode_char);
exit:
@@ -516,7 +554,13 @@ msvcrt_set_error_mode(PyObject *module, PyObject *arg)
int mode;
long _return_value;
- if (!PyArg_Parse(arg, "i:set_error_mode", &mode)) {
+ if (PyFloat_Check(arg)) {
+ PyErr_SetString(PyExc_TypeError,
+ "integer argument expected, got float" );
+ goto exit;
+ }
+ mode = _PyLong_AsInt(arg);
+ if (mode == -1 && PyErr_Occurred()) {
goto exit;
}
_return_value = msvcrt_set_error_mode_impl(module, mode);
@@ -549,7 +593,13 @@ msvcrt_SetErrorMode(PyObject *module, PyObject *arg)
PyObject *return_value = NULL;
unsigned int mode;
- if (!PyArg_Parse(arg, "I:SetErrorMode", &mode)) {
+ if (PyFloat_Check(arg)) {
+ PyErr_SetString(PyExc_TypeError,
+ "integer argument expected, got float" );
+ goto exit;
+ }
+ mode = (unsigned int)PyLong_AsUnsignedLongMask(arg);
+ if (mode == (unsigned int)-1 && PyErr_Occurred()) {
goto exit;
}
return_value = msvcrt_SetErrorMode_impl(module, mode);
@@ -569,4 +619,4 @@ exit:
#ifndef MSVCRT_SET_ERROR_MODE_METHODDEF
#define MSVCRT_SET_ERROR_MODE_METHODDEF
#endif /* !defined(MSVCRT_SET_ERROR_MODE_METHODDEF) */
-/*[clinic end generated code: output=632089ff9236ac77 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=2530b4ff248563b4 input=a9049054013a1b77]*/
diff --git a/PC/clinic/winreg.c.h b/PC/clinic/winreg.c.h
index a7385a6..3b100f9 100644
--- a/PC/clinic/winreg.c.h
+++ b/PC/clinic/winreg.c.h
@@ -541,7 +541,7 @@ winreg_FlushKey(PyObject *module, PyObject *arg)
PyObject *return_value = NULL;
HKEY key;
- if (!PyArg_Parse(arg, "O&:FlushKey", clinic_HKEY_converter, &key)) {
+ if (!clinic_HKEY_converter(arg, &key)) {
goto exit;
}
return_value = winreg_FlushKey_impl(module, key);
@@ -734,7 +734,7 @@ winreg_QueryInfoKey(PyObject *module, PyObject *arg)
PyObject *return_value = NULL;
HKEY key;
- if (!PyArg_Parse(arg, "O&:QueryInfoKey", clinic_HKEY_converter, &key)) {
+ if (!clinic_HKEY_converter(arg, &key)) {
goto exit;
}
return_value = winreg_QueryInfoKey_impl(module, key);
@@ -1021,7 +1021,7 @@ winreg_DisableReflectionKey(PyObject *module, PyObject *arg)
PyObject *return_value = NULL;
HKEY key;
- if (!PyArg_Parse(arg, "O&:DisableReflectionKey", clinic_HKEY_converter, &key)) {
+ if (!clinic_HKEY_converter(arg, &key)) {
goto exit;
}
return_value = winreg_DisableReflectionKey_impl(module, key);
@@ -1055,7 +1055,7 @@ winreg_EnableReflectionKey(PyObject *module, PyObject *arg)
PyObject *return_value = NULL;
HKEY key;
- if (!PyArg_Parse(arg, "O&:EnableReflectionKey", clinic_HKEY_converter, &key)) {
+ if (!clinic_HKEY_converter(arg, &key)) {
goto exit;
}
return_value = winreg_EnableReflectionKey_impl(module, key);
@@ -1087,7 +1087,7 @@ winreg_QueryReflectionKey(PyObject *module, PyObject *arg)
PyObject *return_value = NULL;
HKEY key;
- if (!PyArg_Parse(arg, "O&:QueryReflectionKey", clinic_HKEY_converter, &key)) {
+ if (!clinic_HKEY_converter(arg, &key)) {
goto exit;
}
return_value = winreg_QueryReflectionKey_impl(module, key);
@@ -1095,4 +1095,4 @@ winreg_QueryReflectionKey(PyObject *module, PyObject *arg)
exit:
return return_value;
}
-/*[clinic end generated code: output=ff2cc1951ab1a56c input=a9049054013a1b77]*/
+/*[clinic end generated code: output=82bd56c524c6c3dd input=a9049054013a1b77]*/