summaryrefslogtreecommitdiffstats
path: root/Python/modsupport.c
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2020-06-19 09:45:31 (GMT)
committerGitHub <noreply@github.com>2020-06-19 09:45:31 (GMT)
commit37bb2895561d3e63a631f10875567b4e33b30c07 (patch)
tree25afc8f4882caeaef5f14e09499a5e949f218b0c /Python/modsupport.c
parent01ece63d42b830df106948db0aefa6c1ba24416a (diff)
downloadcpython-37bb2895561d3e63a631f10875567b4e33b30c07.zip
cpython-37bb2895561d3e63a631f10875567b4e33b30c07.tar.gz
cpython-37bb2895561d3e63a631f10875567b4e33b30c07.tar.bz2
bpo-40943: PY_SSIZE_T_CLEAN required for '#' formats (GH-20784)
The PY_SSIZE_T_CLEAN macro must now be defined to use PyArg_ParseTuple() and Py_BuildValue() "#" formats: "es#", "et#", "s#", "u#", "y#", "z#", "U#" and "Z#". See the PEP 353. Update _testcapi.test_buildvalue_issue38913().
Diffstat (limited to 'Python/modsupport.c')
-rw-r--r--Python/modsupport.c33
1 files changed, 18 insertions, 15 deletions
diff --git a/Python/modsupport.c b/Python/modsupport.c
index 845bdcb..2637039 100644
--- a/Python/modsupport.c
+++ b/Python/modsupport.c
@@ -283,6 +283,13 @@ do_mktuple(const char **p_format, va_list *p_va, char endchar, Py_ssize_t n, int
static PyObject *
do_mkvalue(const char **p_format, va_list *p_va, int flags)
{
+#define ERROR_NEED_PY_SSIZE_T_CLEAN \
+ { \
+ PyErr_SetString(PyExc_SystemError, \
+ "PY_SSIZE_T_CLEAN macro must be defined for '#' formats"); \
+ return NULL; \
+ }
+
for (;;) {
switch (*(*p_format)++) {
case '(':
@@ -341,14 +348,12 @@ do_mkvalue(const char **p_format, va_list *p_va, int flags)
Py_ssize_t n;
if (**p_format == '#') {
++*p_format;
- if (flags & FLAG_SIZE_T)
+ if (flags & FLAG_SIZE_T) {
n = va_arg(*p_va, Py_ssize_t);
+ }
else {
n = va_arg(*p_va, int);
- if (PyErr_WarnEx(PyExc_DeprecationWarning,
- "PY_SSIZE_T_CLEAN will be required for '#' formats", 1)) {
- return NULL;
- }
+ ERROR_NEED_PY_SSIZE_T_CLEAN;
}
}
else
@@ -394,14 +399,12 @@ do_mkvalue(const char **p_format, va_list *p_va, int flags)
Py_ssize_t n;
if (**p_format == '#') {
++*p_format;
- if (flags & FLAG_SIZE_T)
+ if (flags & FLAG_SIZE_T) {
n = va_arg(*p_va, Py_ssize_t);
+ }
else {
n = va_arg(*p_va, int);
- if (PyErr_WarnEx(PyExc_DeprecationWarning,
- "PY_SSIZE_T_CLEAN will be required for '#' formats", 1)) {
- return NULL;
- }
+ ERROR_NEED_PY_SSIZE_T_CLEAN;
}
}
else
@@ -432,14 +435,12 @@ do_mkvalue(const char **p_format, va_list *p_va, int flags)
Py_ssize_t n;
if (**p_format == '#') {
++*p_format;
- if (flags & FLAG_SIZE_T)
+ if (flags & FLAG_SIZE_T) {
n = va_arg(*p_va, Py_ssize_t);
+ }
else {
n = va_arg(*p_va, int);
- if (PyErr_WarnEx(PyExc_DeprecationWarning,
- "PY_SSIZE_T_CLEAN will be required for '#' formats", 1)) {
- return NULL;
- }
+ ERROR_NEED_PY_SSIZE_T_CLEAN;
}
}
else
@@ -507,6 +508,8 @@ do_mkvalue(const char **p_format, va_list *p_va, int flags)
}
}
+
+#undef ERROR_NEED_PY_SSIZE_T_CLEAN
}