From ca6a73277b7f48ce4cf9d30d7bff7813f3685684 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Mon, 9 May 2022 19:53:20 +0200 Subject: [PATCH 1/2] Python: define PY_SSIZE_T_CLEAN It is recommended to always define PY_SSIZE_T_CLEAN before including Python.h. Cf. https://docs.python.org/3/c-api/intro.html This avoids errors like: SystemError: PY_SSIZE_T_CLEAN macro must be defined for '#' formats Signed-off-by: Heinrich Schuchardt --- Lib/python/embed.i | 4 +++- Lib/python/pyruntime.swg | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Lib/python/embed.i b/Lib/python/embed.i index efd048789..95225e2de 100644 --- a/Lib/python/embed.i +++ b/Lib/python/embed.i @@ -29,7 +29,9 @@ As far as I know, this module is C++ safe. #endif %wrapper %{ - +#ifndef PY_SSIZE_T_CLEAN +#define PY_SSIZE_T_CLEAN +#endif #include #ifdef __cplusplus diff --git a/Lib/python/pyruntime.swg b/Lib/python/pyruntime.swg index 843fa6ce1..9b516ebaa 100644 --- a/Lib/python/pyruntime.swg +++ b/Lib/python/pyruntime.swg @@ -11,6 +11,9 @@ # include #endif +#ifndef PY_SSIZE_T_CLEAN +#define PY_SSIZE_T_CLEAN +#endif #if defined(_DEBUG) && defined(SWIG_PYTHON_INTERPRETER_NO_DEBUG) /* Use debug wrappers with the Python release dll */ # undef _DEBUG From abc8e0bb277f7a54ff4ee209845dde910d267819 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 27 May 2022 18:58:04 +0100 Subject: [PATCH 2/2] Define PY_SSIZE_T_CLEAN macro before #include "Python.h" as recommended in Python 3.7 and later. Issue #2277 --- CHANGES.current | 11 +++++++++++ Lib/python/embed.i | 2 +- Lib/python/pyruntime.swg | 2 +- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index a8975a03f..a950b930f 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -7,6 +7,17 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/ Version 4.1.0 (in progress) =========================== +2022-05-27: xypron + [Python] #2277 Define PY_SSIZE_T_CLEAN macro before #include "Python.h" as + recommended in Python 3.7 and later. + + To avoid this macro definition, add the following to your interface file so + that SWIG_NO_PY_SSIZE_T_CLEAN is defined at the beginning of the C++ wrappers: + + %begin %{ + #define SWIG_NO_PY_SSIZE_T_CLEAN + %} + 2022-05-07: KrisThielemans [Python] Fix "too many initializers for 'PyHeapTypeObject'" errors using PyPy 3.8 and later. diff --git a/Lib/python/embed.i b/Lib/python/embed.i index 95225e2de..34cb9b92a 100644 --- a/Lib/python/embed.i +++ b/Lib/python/embed.i @@ -29,7 +29,7 @@ As far as I know, this module is C++ safe. #endif %wrapper %{ -#ifndef PY_SSIZE_T_CLEAN +#ifndef SWIG_NO_PY_SSIZE_T_CLEAN #define PY_SSIZE_T_CLEAN #endif #include diff --git a/Lib/python/pyruntime.swg b/Lib/python/pyruntime.swg index 9b516ebaa..b1033dfbc 100644 --- a/Lib/python/pyruntime.swg +++ b/Lib/python/pyruntime.swg @@ -11,7 +11,7 @@ # include #endif -#ifndef PY_SSIZE_T_CLEAN +#ifndef SWIG_NO_PY_SSIZE_T_CLEAN #define PY_SSIZE_T_CLEAN #endif #if defined(_DEBUG) && defined(SWIG_PYTHON_INTERPRETER_NO_DEBUG)