Skip to content

Commit

Permalink
Work around internal Python headers
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ludwigschwardt committed Oct 17, 2024
1 parent 550eabe commit 0059783
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
17 changes: 16 additions & 1 deletion Modules/3.x/clinic/readline.c.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 4 additions & 0 deletions Modules/3.x/readline.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.h> // errno
#include <signal.h> // SIGWINCH
Expand Down

0 comments on commit 0059783

Please sign in to comment.