Skip to content

Commit 0059783

Browse files
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.
1 parent 550eabe commit 0059783

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

Modules/3.x/clinic/readline.c.h

+16-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,22 @@
22
preserve
33
[clinic start generated code]*/
44

5-
#include "pycore_modsupport.h" // _PyArg_CheckPositional()
5+
/* Don't include internal Python header file - see workaround below
6+
#include "pycore_modsupport.h" // _PyArg_CheckPositional(), _PyArg_BadArgument()
7+
*/
8+
/* Include only necessary bits of internal pycore_modsupport.h header */
9+
PyAPI_FUNC(int) _PyArg_CheckPositional(const char *, Py_ssize_t,
10+
Py_ssize_t, Py_ssize_t);
11+
#define _Py_ANY_VARARGS(n) ((n) == PY_SSIZE_T_MAX)
12+
#define _PyArg_CheckPositional(funcname, nargs, min, max) \
13+
((!_Py_ANY_VARARGS(max) && (min) <= (nargs) && (nargs) <= (max)) \
14+
|| _PyArg_CheckPositional((funcname), (nargs), (min), (max)))
15+
PyAPI_FUNC(void) _PyArg_BadArgument(
16+
const char *fname,
17+
const char *displayname,
18+
const char *expected,
19+
PyObject *arg);
20+
/* end of includes from pycore_modsupport.h */
621

722
PyDoc_STRVAR(readline_parse_and_bind__doc__,
823
"parse_and_bind($module, string, /)\n"

Modules/3.x/readline.c

+4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010

1111
/* Standard definitions */
1212
#include "Python.h"
13+
/* Don't include internal Python header file - see workaround below
1314
#include "pycore_pylifecycle.h" // _Py_SetLocaleFromEnv()
15+
*/
16+
/* Include the only bit needed from internal pycore_pylifecycle.h header */
17+
PyAPI_FUNC(char*) _Py_SetLocaleFromEnv(int category);
1418

1519
#include <errno.h> // errno
1620
#include <signal.h> // SIGWINCH

0 commit comments

Comments
 (0)