From 2b67fc57f6e97c8389fe970ed232c1ad484113e1 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Mon, 11 Mar 2024 23:42:18 +0100 Subject: [PATCH] gh-108494: Fix Argument Clinic LIMITED_CAPI_REGEX (#116610) Accept spaces in "# define Py_LIMITED_API 0x030d0000". --- Modules/_ctypes/_ctypes_test.c | 7 +++---- Modules/_multiprocessing/posixshmem.c | 7 +++---- Modules/_scproxy.c | 7 +++---- Modules/_stat.c | 7 +++---- Modules/_testclinic_limited.c | 5 ++--- Modules/_testimportmultiple.c | 3 +-- Modules/_uuidmodule.c | 7 +++---- Modules/errnomodule.c | 7 +++---- Modules/resource.c | 7 +++---- Modules/xxlimited.c | 7 +++---- Modules/xxlimited_35.c | 4 ++-- PC/winsound.c | 7 +++---- Tools/clinic/clinic.py | 5 +++-- 13 files changed, 35 insertions(+), 45 deletions(-) diff --git a/Modules/_ctypes/_ctypes_test.c b/Modules/_ctypes/_ctypes_test.c index ecc60417790..1dd3ef19052 100644 --- a/Modules/_ctypes/_ctypes_test.c +++ b/Modules/_ctypes/_ctypes_test.c @@ -1,8 +1,7 @@ -#include "pyconfig.h" // Py_GIL_DISABLED - -#ifndef Py_GIL_DISABLED // Need limited C API version 3.12 for Py_MOD_PER_INTERPRETER_GIL_SUPPORTED -#define Py_LIMITED_API 0x030c0000 +#include "pyconfig.h" // Py_GIL_DISABLED +#ifndef Py_GIL_DISABLED +# define Py_LIMITED_API 0x030c0000 #endif // gh-85283: On Windows, Py_LIMITED_API requires Py_BUILD_CORE to not attempt diff --git a/Modules/_multiprocessing/posixshmem.c b/Modules/_multiprocessing/posixshmem.c index 4ab15fa6573..d332a4e9d9e 100644 --- a/Modules/_multiprocessing/posixshmem.c +++ b/Modules/_multiprocessing/posixshmem.c @@ -2,11 +2,10 @@ posixshmem - A Python extension that provides shm_open() and shm_unlink() */ -#include "pyconfig.h" // Py_GIL_DISABLED - -#ifndef Py_GIL_DISABLED // Need limited C API version 3.12 for Py_MOD_PER_INTERPRETER_GIL_SUPPORTED -#define Py_LIMITED_API 0x030c0000 +#include "pyconfig.h" // Py_GIL_DISABLED +#ifndef Py_GIL_DISABLED +# define Py_LIMITED_API 0x030c0000 #endif #include diff --git a/Modules/_scproxy.c b/Modules/_scproxy.c index fe82e918677..042738b4ab8 100644 --- a/Modules/_scproxy.c +++ b/Modules/_scproxy.c @@ -3,11 +3,10 @@ * using the SystemConfiguration framework. */ -#include "pyconfig.h" // Py_GIL_DISABLED - -#ifndef Py_GIL_DISABLED // Need limited C API version 3.12 for Py_MOD_PER_INTERPRETER_GIL_SUPPORTED -#define Py_LIMITED_API 0x030c0000 +#include "pyconfig.h" // Py_GIL_DISABLED +#ifndef Py_GIL_DISABLED +# define Py_LIMITED_API 0x030c0000 #endif #include diff --git a/Modules/_stat.c b/Modules/_stat.c index b43e79453f5..8059ec2f1f0 100644 --- a/Modules/_stat.c +++ b/Modules/_stat.c @@ -11,11 +11,10 @@ * */ -#include "pyconfig.h" // Py_GIL_DISABLED - -#ifndef Py_GIL_DISABLED // Need limited C API version 3.13 for PyModule_Add() on Windows -#define Py_LIMITED_API 0x030d0000 +#include "pyconfig.h" // Py_GIL_DISABLED +#ifndef Py_GIL_DISABLED +# define Py_LIMITED_API 0x030d0000 #endif #include "Python.h" diff --git a/Modules/_testclinic_limited.c b/Modules/_testclinic_limited.c index df08ff9a369..1a73c04aecb 100644 --- a/Modules/_testclinic_limited.c +++ b/Modules/_testclinic_limited.c @@ -4,11 +4,10 @@ #undef Py_BUILD_CORE_MODULE #undef Py_BUILD_CORE_BUILTIN +// For now, AC only supports the limited C API version 3.13 #include "pyconfig.h" // Py_GIL_DISABLED - #ifndef Py_GIL_DISABLED -// For now, only limited C API 3.13 is supported -#define Py_LIMITED_API 0x030d0000 +# define Py_LIMITED_API 0x030d0000 #endif /* Always enable assertions */ diff --git a/Modules/_testimportmultiple.c b/Modules/_testimportmultiple.c index 7e6556ad400..a65ca513a12 100644 --- a/Modules/_testimportmultiple.c +++ b/Modules/_testimportmultiple.c @@ -5,9 +5,8 @@ */ #include "pyconfig.h" // Py_GIL_DISABLED - #ifndef Py_GIL_DISABLED -#define Py_LIMITED_API 0x03020000 +# define Py_LIMITED_API 0x03020000 #endif #include diff --git a/Modules/_uuidmodule.c b/Modules/_uuidmodule.c index 4b6852c0d0e..052cb9fef3b 100644 --- a/Modules/_uuidmodule.c +++ b/Modules/_uuidmodule.c @@ -3,11 +3,10 @@ * DCE compatible Universally Unique Identifier library. */ -#include "pyconfig.h" // Py_GIL_DISABLED - -#ifndef Py_GIL_DISABLED // Need limited C API version 3.12 for Py_MOD_PER_INTERPRETER_GIL_SUPPORTED -#define Py_LIMITED_API 0x030c0000 +#include "pyconfig.h" // Py_GIL_DISABLED +#ifndef Py_GIL_DISABLED +# define Py_LIMITED_API 0x030c0000 #endif #include "Python.h" diff --git a/Modules/errnomodule.c b/Modules/errnomodule.c index 1100e9f6094..97e5f0180d7 100644 --- a/Modules/errnomodule.c +++ b/Modules/errnomodule.c @@ -1,10 +1,9 @@ /* Errno module */ -#include "pyconfig.h" // Py_GIL_DISABLED - -#ifndef Py_GIL_DISABLED // Need limited C API version 3.12 for Py_MOD_PER_INTERPRETER_GIL_SUPPORTED -#define Py_LIMITED_API 0x030c0000 +#include "pyconfig.h" // Py_GIL_DISABLED +#ifndef Py_GIL_DISABLED +# define Py_LIMITED_API 0x030c0000 #endif #include "Python.h" diff --git a/Modules/resource.c b/Modules/resource.c index 19020b8cc1b..8ee07bd0c80 100644 --- a/Modules/resource.c +++ b/Modules/resource.c @@ -1,8 +1,7 @@ -#include "pyconfig.h" // Py_GIL_DISABLED - -#ifndef Py_GIL_DISABLED // Need limited C API version 3.13 for PySys_Audit() -#define Py_LIMITED_API 0x030d0000 +#include "pyconfig.h" // Py_GIL_DISABLED +#ifndef Py_GIL_DISABLED +# define Py_LIMITED_API 0x030d0000 #endif #include "Python.h" diff --git a/Modules/xxlimited.c b/Modules/xxlimited.c index 0bb5e12d7c3..3357b8076b6 100644 --- a/Modules/xxlimited.c +++ b/Modules/xxlimited.c @@ -62,11 +62,10 @@ pass */ -#include "pyconfig.h" // Py_GIL_DISABLED - -#ifndef Py_GIL_DISABLED // Need limited C API version 3.12 for Py_MOD_PER_INTERPRETER_GIL_SUPPORTED -#define Py_LIMITED_API 0x030c0000 +#include "pyconfig.h" // Py_GIL_DISABLED +#ifndef Py_GIL_DISABLED +# define Py_LIMITED_API 0x030c0000 #endif #include "Python.h" diff --git a/Modules/xxlimited_35.c b/Modules/xxlimited_35.c index 754a368f77e..52690d9d10a 100644 --- a/Modules/xxlimited_35.c +++ b/Modules/xxlimited_35.c @@ -5,10 +5,10 @@ * See the xxlimited module for an extension module template. */ +// Test the limited C API version 3.5 #include "pyconfig.h" // Py_GIL_DISABLED - #ifndef Py_GIL_DISABLED -#define Py_LIMITED_API 0x03050000 +# define Py_LIMITED_API 0x03050000 #endif #include "Python.h" diff --git a/PC/winsound.c b/PC/winsound.c index 7e4ebd90f50..a6b2dac6ac1 100644 --- a/PC/winsound.c +++ b/PC/winsound.c @@ -35,11 +35,10 @@ winsound.PlaySound(None, 0) */ -#include "pyconfig.h" // Py_GIL_DISABLED - -#ifndef Py_GIL_DISABLED // Need limited C API version 3.12 for Py_MOD_PER_INTERPRETER_GIL_SUPPORTED -#define Py_LIMITED_API 0x030c0000 +#include "pyconfig.h" // Py_GIL_DISABLED +#ifndef Py_GIL_DISABLED +# define Py_LIMITED_API 0x030c0000 #endif #include diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py index 8353941f929..893f4cc12ed 100755 --- a/Tools/clinic/clinic.py +++ b/Tools/clinic/clinic.py @@ -66,8 +66,9 @@ # -# match '#define Py_LIMITED_API' -LIMITED_CAPI_REGEX = re.compile(r'#define +Py_LIMITED_API') +# Match '#define Py_LIMITED_API'. +# Match '# define Py_LIMITED_API 0x030d0000' (without the version). +LIMITED_CAPI_REGEX = re.compile(r'# *define +Py_LIMITED_API') class Sentinels(enum.Enum):