Skip to content

Commit

Permalink
mypyc: ignore deprecation (#9107)
Browse files Browse the repository at this point in the history
PyUnicode_AsUnicodeAndSize has been deprecated since 3.3

Python 3.9 has compiler warnings for this deprecated function, and we
compile with Werror, causing Python 3.9 builds to fail.

I've just copied over the relevant deprecation ignoring code from the
original getargs.c (including the TODO, but I can remove that)

Co-authored-by: hauntsaninja <>
  • Loading branch information
hauntsaninja authored Jul 31, 2020
1 parent f049560 commit da44301
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions mypyc/lib-rt/getargs.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,29 @@
* and is responsible for decrefing them.
*/

// These macro definitions are copied from pyport.h in Python 3.9 and later
// https://bugs.python.org/issue19569
#if defined(__clang__)
#define _Py_COMP_DIAG_PUSH _Pragma("clang diagnostic push")
#define _Py_COMP_DIAG_IGNORE_DEPR_DECLS \
_Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"")
#define _Py_COMP_DIAG_POP _Pragma("clang diagnostic pop")
#elif defined(__GNUC__) \
&& ((__GNUC__ >= 5) || (__GNUC__ == 4) && (__GNUC_MINOR__ >= 6))
#define _Py_COMP_DIAG_PUSH _Pragma("GCC diagnostic push")
#define _Py_COMP_DIAG_IGNORE_DEPR_DECLS \
_Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
#define _Py_COMP_DIAG_POP _Pragma("GCC diagnostic pop")
#elif defined(_MSC_VER)
#define _Py_COMP_DIAG_PUSH __pragma(warning(push))
#define _Py_COMP_DIAG_IGNORE_DEPR_DECLS __pragma(warning(disable: 4996))
#define _Py_COMP_DIAG_POP __pragma(warning(pop))
#else
#define _Py_COMP_DIAG_PUSH
#define _Py_COMP_DIAG_IGNORE_DEPR_DECLS
#define _Py_COMP_DIAG_POP
#endif

#include "Python.h"
#include "pythonsupport.h"

Expand Down Expand Up @@ -756,6 +779,9 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
case 'u': /* raw unicode buffer (Py_UNICODE *) */
case 'Z': /* raw unicode buffer or None */
{
// TODO: Raise DeprecationWarning
_Py_COMP_DIAG_PUSH
_Py_COMP_DIAG_IGNORE_DEPR_DECLS
Py_UNICODE **p = va_arg(*p_va, Py_UNICODE **);

if (*format == '#') {
Expand Down Expand Up @@ -795,6 +821,7 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
arg, msgbuf, bufsize);
}
break;
_Py_COMP_DIAG_POP
}

case 'e': {/* encoded string */
Expand Down

0 comments on commit da44301

Please sign in to comment.