10000 bpo-36381: warn when no PY_SSIZE_T_CLEAN defined (GH-12473) · python/cpython@d3c72a2 · GitHub
[go: up one dir, main page]

Skip to content

Commit d3c72a2

Browse files
authored
bpo-36381: warn when no PY_SSIZE_T_CLEAN defined (GH-12473)
We will remove int support from 3.10 or 4.0.
1 parent d60f658 commit d3c72a2

File tree

4 files changed

+43
-5
lines changed

4 files changed

+43
-5
lines changed

Doc/whatsnew/3.8.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,16 @@ Changes in the Python API
708708
set for regular user accounts.
709709

710710

711+
Changes in the C API
712+
--------------------
713+
714+
* Use of ``#`` variants of formats in parsing or building value (e.g.
715+
:c:func:`PyArg_ParseTuple`, :c:func:`Py_BuildValue`, :c:func:`PyObject_CallFunction`,
716+
etc.) without ``PY_SSIZE_T_CLEAN`` defined raises ``DeprecationWarning`` now.
717+
It will be removed in 3.10 or 4.0. Read :ref:`arg-parsing` for detail.
718+
(Contributed by Inada Naoki in :issue:`36381`.)
719+
720+
711721
CPython bytecode changes
712722
------------------------
713723

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Raise ``DeprecationWarning`` when '#' formats are used for building or
2+
parsing values without ``PY_SSIZE_T_CLEAN``.

Python/getargs.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,13 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
681681
/* For # codes */
682682
#define FETCH_SIZE int *q=NULL;Py_ssize_t *q2=NULL;\
683683
if (flags & FLAG_SIZE_T) q2=va_arg(*p_va, Py_ssize_t*); \
684-
else q=va_arg(*p_va, int*);
684+
else { \
685+
if (PyErr_WarnEx(PyExc_DeprecationWarning, \
686+
"PY_SSIZE_T_CLEAN will be required for '#' formats", 1)) { \
687+
return NULL; \
688+
} \
689+
q=va_arg(*p_va, int*); \
690+
}
685691
#define STORE_SIZE(s) \
686692
if (flags & FLAG_SIZE_T) \
687693
*q2=s; \
@@ -2591,8 +2597,13 @@ skipitem(const char **p_format, va_list *p_va, int flags)
25912597
if (p_va != NULL) {
25922598
if (flags & FLAG_SIZE_T)
25932599
(void) va_arg(*p_va, Py_ssize_t *);
2594-
else
2600+
else {
2601+
if (PyErr_WarnEx(PyExc_DeprecationWarning,
2602+
"PY_SSIZE_T_CLEAN will be required for '#' formats", 1)) {
2603+
return NULL;
2604+
}
25952605
(void) va_arg(*p_va, int *);
2606+
}
25962607
}
25972608
format++;
25982609
} else if ((c == 's' || c == 'z' || c == 'y' || c == 'w')

Python/modsupport.c

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -342,8 +342,13 @@ do_mkvalue(const char **p_format, va_list *p_va, int flags)
342342
++*p_format;
343343
if (flags & FLAG_SIZE_T)
344344
n = va_arg(*p_va, Py_ssize_t);
345-
else
345+
else {
346+
if (PyErr_WarnEx(PyExc_DeprecationWarning,
347+
"PY_SSIZE_T_CLEAN will be required for '#' formats", 1)) {
348+
return NULL;
349+
}
346350
n = va_arg(*p_va, int);
351+
}
347352
}
348353
else
349354
n = -1;
@@ -390,8 +395,13 @@ do_mkvalue(const char **p_format, va_list *p_va, int flags)
390395
++*p_format;
391396
if (flags & FLAG_SIZE_T)
392397
n = va_arg(*p_va, Py_ssize_t);
393-
else
398+
else {
399+
if (PyErr_WarnEx(PyExc_DeprecationWarning,
400+
"PY_SSIZE_T_CLEAN will be required for '#' formats", 1)) {
401+
return NULL;
402+
}
394403
n = va_arg(*p_va, int);
404+
}
395405
}
396406
else
397407
n = -1;
@@ -423,8 +433,13 @@ do_mkvalue(const char **p_format, va_list *p_va, int flags)
423433
++*p_format;
424434
if (flags & FLAG_SIZE_T)
425435
n = va_arg(*p_va, Py_ssize_t);
426-
else
436+
else {
437+
if (PyErr_WarnEx(PyExc_DeprecationWarning,
438+
"PY_SSIZE_T_CLEAN will be required for '#' formats", 1)) {
439+
return NULL;
440+
}
427441
n = va_arg(*p_va, int);
442+
}
428443
}
429444
else
430445
n = -1;

0 commit comments

Comments
 (0)
0