summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Doc/whatsnew/3.8.rst10
-rw-r--r--Misc/NEWS.d/next/C API/2019-03-20-22-02-40.bpo-36381.xlzDJ2.rst2
-rw-r--r--Python/getargs.c15
-rw-r--r--Python/modsupport.c21
4 files changed, 43 insertions, 5 deletions
diff --git a/Doc/whatsnew/3.8.rst b/Doc/whatsnew/3.8.rst
index 18ec2c2f66..3855d3604e 100644
--- a/Doc/whatsnew/3.8.rst
+++ b/Doc/whatsnew/3.8.rst
@@ -708,6 +708,16 @@ Changes in the Python API
set for regular user accounts.
+Changes in the C API
+--------------------
+
+* Use of ``#`` variants of formats in parsing or building value (e.g.
+ :c:func:`PyArg_ParseTuple`, :c:func:`Py_BuildValue`, :c:func:`PyObject_CallFunction`,
+ etc.) without ``PY_SSIZE_T_CLEAN`` defined raises ``DeprecationWarning`` now.
+ It will be removed in 3.10 or 4.0. Read :ref:`arg-parsing` for detail.
+ (Contributed by Inada Naoki in :issue:`36381`.)
+
+
CPython bytecode changes
------------------------
diff --git a/Misc/NEWS.d/next/C API/2019-03-20-22-02-40.bpo-36381.xlzDJ2.rst b/Misc/NEWS.d/next/C API/2019-03-20-22-02-40.bpo-36381.xlzDJ2.rst
new file mode 100644
index 0000000000..66982aa7ea
--- /dev/null
+++ b/Misc/NEWS.d/next/C API/2019-03-20-22-02-40.bpo-36381.xlzDJ2.rst
@@ -0,0 +1,2 @@
+Raise ``DeprecationWarning`` when '#' formats are used for building or
+parsing values without ``PY_SSIZE_T_CLEAN``.
diff --git a/Python/getargs.c b/Python/getargs.c
index e50f9b5f5c..59f0fdabb7 100644
--- a/Python/getargs.c
+++ b/Python/getargs.c
@@ -681,7 +681,13 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
/* For # codes */
#define FETCH_SIZE int *q=NULL;Py_ssize_t *q2=NULL;\
if (flags & FLAG_SIZE_T) q2=va_arg(*p_va, Py_ssize_t*); \
- else q=va_arg(*p_va, int*);
+ else { \
+ if (PyErr_WarnEx(PyExc_DeprecationWarning, \
+ "PY_SSIZE_T_CLEAN will be required for '#' formats", 1)) { \
+ return NULL; \
+ } \
+ q=va_arg(*p_va, int*); \
+ }
#define STORE_SIZE(s) \
if (flags & FLAG_SIZE_T) \
*q2=s; \
@@ -2591,8 +2597,13 @@ skipitem(const char **p_format, va_list *p_va, int flags)
if (p_va != NULL) {
if (flags & FLAG_SIZE_T)
(void) va_arg(*p_va, Py_ssize_t *);
- else
+ else {
+ if (PyErr_WarnEx(PyExc_DeprecationWarning,
+ "PY_SSIZE_T_CLEAN will be required for '#' formats", 1)) {
+ return NULL;
+ }
(void) va_arg(*p_va, int *);
+ }
}
format++;
} else if ((c == 's' || c == 'z' || c == 'y' || c == 'w')
diff --git a/Python/modsupport.c b/Python/modsupport.c
index 8a77a7b06d..6255822107 100644
--- a/Python/modsupport.c
+++ b/Python/modsupport.c
@@ -342,8 +342,13 @@ do_mkvalue(const char **p_format, va_list *p_va, int flags)
++*p_format;
if (flags & FLAG_SIZE_T)
n = va_arg(*p_va, Py_ssize_t);
- else
+ else {
+ if (PyErr_WarnEx(PyExc_DeprecationWarning,
+ "PY_SSIZE_T_CLEAN will be required for '#' formats", 1)) {
+ return NULL;
+ }
n = va_arg(*p_va, int);
+ }
}
else
n = -1;
@@ -390,8 +395,13 @@ do_mkvalue(const char **p_format, va_list *p_va, int flags)
++*p_format;
if (flags & FLAG_SIZE_T)
n = va_arg(*p_va, Py_ssize_t);
- else
+ else {
+ if (PyErr_WarnEx(PyExc_DeprecationWarning,
+ "PY_SSIZE_T_CLEAN will be required for '#' formats", 1)) {
+ return NULL;
+ }
n = va_arg(*p_va, int);
+ }
}
else
n = -1;
@@ -423,8 +433,13 @@ do_mkvalue(const char **p_format, va_list *p_va, int flags)
++*p_format;
if (flags & FLAG_SIZE_T)
n = va_arg(*p_va, Py_ssize_t);
- else
+ else {
+ if (PyErr_WarnEx(PyExc_DeprecationWarning,
+ "PY_SSIZE_T_CLEAN will be required for '#' formats", 1)) {
+ return NULL;
+ }
n = va_arg(*p_va, int);
+ }
}
else
n = -1;