gh-109617: fix ncurses incompatibility on macOS with Xcode 15 (#111258) · python/cpython@08d169f · GitHub
Skip to content

Commit 08d169f

Browse files
sorciohugovkambv
authored
gh-109617: fix ncurses incompatibility on macOS with Xcode 15 (#111258)
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Co-authored-by: Łukasz Langa <lukasz@langa.pl>
1 parent 291cfa4 commit 08d169f

5 files changed

Lines changed: 77 additions & 21 deletions

File tree

Include/py_curses.h

Lines changed: 14 additions & 5 deletions
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
:mod:`ncurses`: fixed a crash that could occur on macOS 13 or earlier when
2+
Python was built with Apple Xcode 15's SDK.

Modules/_cursesmodule.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,8 +1156,10 @@ int py_mvwdelch(WINDOW *w, int y, int x)
11561156
#endif
11571157

11581158
#if defined(HAVE_CURSES_IS_PAD)
1159+
// is_pad() is defined, either as a macro or as a function
11591160
#define py_is_pad(win) is_pad(win)
11601161
#elif defined(WINDOW_HAS_FLAGS)
1162+
// is_pad() is not defined, but we can inspect WINDOW structure members
11611163
#define py_is_pad(win) ((win) ? ((win)->_flags & _ISPAD) != 0 : FALSE)
11621164
#endif
11631165

@@ -4586,17 +4588,24 @@ make_ncurses_version(PyTypeObject *type)
45864588
if (ncurses_version == NULL) {
45874589
return NULL;
45884590
}
4589-
4591+
const char *str = curses_version();
4592+
unsigned long major = 0, minor = 0, patch = 0;
4593+
if (!str || sscanf(str, "%*[^0-9]%lu.%lu.%lu", &major, &minor, &patch) < 3) {
4594+
// Fallback to header version, which cannot be that wrong
4595+
major = NCURSES_VERSION_MAJOR;
4596+
minor = NCURSES_VERSION_MINOR;
4597+
patch = NCURSES_VERSION_PATCH;
4598+
}
45904599
#define SetIntItem(flag) \
45914600
PyStructSequence_SET_ITEM(ncurses_version, pos++, PyLong_FromLong(flag)); \
45924601
if (PyErr_Occurred()) { \
45934602
Py_CLEAR(ncurses_version); \
45944603
return NULL; \
45954604
}
45964605

4597-
SetIntItem(NCURSES_VERSION_MAJOR)
4598-
SetIntItem(NCURSES_VERSION_MINOR)
4599-
SetIntItem(NCURSES_VERSION_PATCH)
4606+
SetIntItem(major)
4607+
SetIntItem(minor)
4608+
SetIntItem(patch)
46004609
#undef SetIntItem
46014610

46024611
return ncurses_version;

configure

Lines changed: 44 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

configure.ac

Lines changed: 4 additions & 1 deletion

0 commit comments

Comments
 (0)