From 0059783edcede63d3e629826158fe70f03238bdb Mon Sep 17 00:00:00 2001 From: Ludwig Schwardt Date: Thu, 17 Oct 2024 18:11:17 +0200 Subject: [PATCH] Work around internal Python headers Python 3.13 moved some private C API functions to internal header files. See python/cpython#106320 for a general discussion on this (glad to see that gnureadline was at least listed as an affected PyPI package :-) ). These private functions affect us: - _Py_SetLocaleFromEnv -> pycore_pylifecycle.h (see python/cpython#106400) - _PyArg_CheckPositional, _PyArg_BadArgument -> pycore_modsupport.h (see python/cpython#110964) Since we can't include these anymore, patch the relevant declarations into the module code. The alternative (add the internal headers to this package) is much messier, as we would have to pull in most of those headers. --- Modules/3.x/clinic/readline.c.h | 17 ++++++++++++++++- Modules/3.x/readline.c | 4 ++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/Modules/3.x/clinic/readline.c.h b/Modules/3.x/clinic/readline.c.h index 1c616d6..cdcbdee 100644 --- a/Modules/3.x/clinic/readline.c.h +++ b/Modules/3.x/clinic/readline.c.h @@ -2,7 +2,22 @@ preserve [clinic start generated code]*/ -#include "pycore_modsupport.h" // _PyArg_CheckPositional() +/* Don't include internal Python header file - see workaround below +#include "pycore_modsupport.h" // _PyArg_CheckPositional(), _PyArg_BadArgument() +*/ +/* Include only necessary bits of internal pycore_modsupport.h header */ +PyAPI_FUNC(int) _PyArg_CheckPositional(const char *, Py_ssize_t, + Py_ssize_t, Py_ssize_t); +#define _Py_ANY_VARARGS(n) ((n) == PY_SSIZE_T_MAX) +#define _PyArg_CheckPositional(funcname, nargs, min, max) \ + ((!_Py_ANY_VARARGS(max) && (min) <= (nargs) && (nargs) <= (max)) \ + || _PyArg_CheckPositional((funcname), (nargs), (min), (max))) +PyAPI_FUNC(void) _PyArg_BadArgument( + const char *fname, + const char *displayname, + const char *expected, + PyObject *arg); +/* end of includes from pycore_modsupport.h */ PyDoc_STRVAR(readline_parse_and_bind__doc__, "parse_and_bind($module, string, /)\n" diff --git a/Modules/3.x/readline.c b/Modules/3.x/readline.c index c2e949e..dd6b230 100644 --- a/Modules/3.x/readline.c +++ b/Modules/3.x/readline.c @@ -10,7 +10,11 @@ /* Standard definitions */ #include "Python.h" +/* Don't include internal Python header file - see workaround below #include "pycore_pylifecycle.h" // _Py_SetLocaleFromEnv() +*/ +/* Include the only bit needed from internal pycore_pylifecycle.h header */ +PyAPI_FUNC(char*) _Py_SetLocaleFromEnv(int category); #include // errno #include // SIGWINCH