Skip to content

Commit f55a435

Browse files
[3.15] gh-152502: Detect optional curses functions with configure probes (GH-152504)
Some curses functions were called unconditionally or gated only by the ncurses-specific NCURSES_EXT_FUNCS macro, which broke building the module against other curses implementations (narrow ncurses, NetBSD curses) even when they provided the function. Detect each with a configure capability probe and gate on HAVE_CURSES_*. (cherry picked from commit 0635e55) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com> Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent bbc7e9b commit f55a435

6 files changed

Lines changed: 300 additions & 14 deletions

File tree

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
The :mod:`curses` module now detects its optional functions with
2+
:program:`configure` capability probes instead of assuming ncurses, so it
3+
builds against narrow (non-wide) ncurses and other curses implementations such
4+
as NetBSD curses, exposing exactly the functions they provide.

Modules/_cursesmodule.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4027,9 +4027,7 @@ _curses_setupterm_impl(PyObject *module, const char *term, int fd)
40274027
Py_RETURN_NONE;
40284028
}
40294029

4030-
#if defined(NCURSES_EXT_FUNCS) && NCURSES_EXT_FUNCS >= 20081102
4031-
// https://invisible-island.net/ncurses/NEWS.html#index-t20080119
4032-
4030+
#ifdef HAVE_CURSES_ESCDELAY
40334031
/*[clinic input]
40344032
_curses.get_escdelay
40354033
@@ -4046,6 +4044,9 @@ _curses_get_escdelay_impl(PyObject *module)
40464044
{
40474045
return PyLong_FromLong(ESCDELAY);
40484046
}
4047+
#endif /* HAVE_CURSES_ESCDELAY */
4048+
4049+
#ifdef HAVE_CURSES_SET_ESCDELAY
40494050
/*[clinic input]
40504051
_curses.set_escdelay
40514052
ms: int
@@ -4070,7 +4071,9 @@ _curses_set_escdelay_impl(PyObject *module, int ms)
40704071

40714072
return curses_check_err(module, set_escdelay(ms), "set_escdelay", NULL);
40724073
}
4074+
#endif /* HAVE_CURSES_SET_ESCDELAY */
40734075

4076+
#ifdef HAVE_CURSES_TABSIZE
40744077
/*[clinic input]
40754078
_curses.get_tabsize
40764079
@@ -4086,6 +4089,9 @@ _curses_get_tabsize_impl(PyObject *module)
40864089
{
40874090
return PyLong_FromLong(TABSIZE);
40884091
}
4092+
#endif /* HAVE_CURSES_TABSIZE */
4093+
4094+
#ifdef HAVE_CURSES_SET_TABSIZE
40894095
/*[clinic input]
40904096
_curses.set_tabsize
40914097
size: int
@@ -4109,7 +4115,7 @@ _curses_set_tabsize_impl(PyObject *module, int size)
41094115

41104116
return curses_check_err(module, set_tabsize(size), "set_tabsize", NULL);
41114117
}
4112-
#endif
4118+
#endif /* HAVE_CURSES_SET_TABSIZE */
41134119

41144120
/*[clinic input]
41154121
_curses.intrflush
@@ -5372,10 +5378,8 @@ static PyMethodDef cursesmodule_methods[] = {
53725378
_CURSES_RESIZETERM_METHODDEF
53735379
_CURSES_RESIZE_TERM_METHODDEF
53745380
_CURSES_SAVETTY_METHODDEF
5375-
#if defined(NCURSES_EXT_FUNCS) && NCURSES_EXT_FUNCS >= 20081102
53765381
_CURSES_GET_ESCDELAY_METHODDEF
53775382
_CURSES_SET_ESCDELAY_METHODDEF
5378-
#endif
53795383
_CURSES_GET_TABSIZE_METHODDEF
53805384
_CURSES_SET_TABSIZE_METHODDEF
53815385
_CURSES_SETSYX_METHODDEF

Modules/clinic/_cursesmodule.c.h

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

configure

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

0 commit comments

Comments
 (0)