From 51ea0995a6f215a4847445caec114eb038ed4d84 Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Fri, 26 Feb 2021 13:17:56 +0900 Subject: [PATCH 1/3] bpo-43321: Fix SystemError in getargs.c --- .../2021-02-26-13-17-52.bpo-43321.TCS3ph.rst | 2 ++ Python/getargs.c | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2021-02-26-13-17-52.bpo-43321.TCS3ph.rst diff --git a/Misc/NEWS.d/next/Core and Builtins/2021-02-26-13-17-52.bpo-43321.TCS3ph.rst b/Misc/NEWS.d/next/Core and Builtins/2021-02-26-13-17-52.bpo-43321.TCS3ph.rst new file mode 100644 index 000000000000000..32c5ce14de51c0d --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2021-02-26-13-17-52.bpo-43321.TCS3ph.rst @@ -0,0 +1,2 @@ +Fix ``SystemError`` raised when ``PyArg_Parse*()`` is used with ``#`` but +without ``PY_SSIZE_T_CLEAN`` defined. diff --git a/Python/getargs.c b/Python/getargs.c index 936eb6a89a39287..b1dafe7fb4b4509 100644 --- a/Python/getargs.c +++ b/Python/getargs.c @@ -658,9 +658,9 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags, /* For # codes */ #define REQUIRE_PY_SSIZE_T_CLEAN \ if (!(flags & FLAG_SIZE_T)) { \ - PyErr_SetString(PyExc_SystemError, \ - "PY_SSIZE_T_CLEAN macro must be defined for '#' formats"); \ - return NULL; \ + const char *msg = "PY_SSIZE_T_CLEAN macro must be defined for '#' formats"; \ + PyErr_SetString(PyExc_SystemError, msg); \ + return msg; \ } #define RETURN_ERR_OCCURRED return msgbuf From 3717f7109ea71417d0c87ea09d80f8ac8c12ff7f Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Fri, 26 Feb 2021 21:14:26 +0900 Subject: [PATCH 2/3] Use RETURN_ERR_OCCURRED --- Python/getargs.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Python/getargs.c b/Python/getargs.c index b1dafe7fb4b4509..7ca227c27749f2e 100644 --- a/Python/getargs.c +++ b/Python/getargs.c @@ -658,9 +658,9 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags, /* For # codes */ #define REQUIRE_PY_SSIZE_T_CLEAN \ if (!(flags & FLAG_SIZE_T)) { \ - const char *msg = "PY_SSIZE_T_CLEAN macro must be defined for '#' formats"; \ - PyErr_SetString(PyExc_SystemError, msg); \ - return msg; \ + PyErr_SetString(PyExc_SystemError, \ + "PY_SSIZE_T_CLEAN macro must be defined for '#' formats"); \ + RETURN_ERR_OCCURRED; \ } #define RETURN_ERR_OCCURRED return msgbuf From ff7e10464a42d1b20ea7b77571ca3d491b388c1e Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Sat, 27 Feb 2021 19:44:57 +0900 Subject: [PATCH 3/3] reorder macros --- Python/getargs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Python/getargs.c b/Python/getargs.c index 7ca227c27749f2e..b85b575a147fe6b 100644 --- a/Python/getargs.c +++ b/Python/getargs.c @@ -655,6 +655,7 @@ static const char * convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags, char *msgbuf, size_t bufsize, freelist_t *freelist) { +#define RETURN_ERR_OCCURRED return msgbuf /* For # codes */ #define REQUIRE_PY_SSIZE_T_CLEAN \ if (!(flags & FLAG_SIZE_T)) { \ @@ -662,7 +663,6 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags, "PY_SSIZE_T_CLEAN macro must be defined for '#' formats"); \ RETURN_ERR_OCCURRED; \ } -#define RETURN_ERR_OCCURRED return msgbuf const char *format = *p_format; char c = *format++;