Skip to content

Commit f80376b

Browse files
gh-113565: Improve and harden detection of curses dependencies (#119816)
1. Use pkg-config to check for ncursesw/panelw. If that fails, use pkg-config to check for ncurses/panel. 2. Regardless of pkg-config output, search for curses/panel headers, so we're sure we have all defines in pyconfig.h. 3. Regardless of pkg-config output, check if libncurses or libncursesw contains the 'initscr' symbol; if it does _and_ pkg-config failed earlier, add the resulting -llib linker option to CURSES_LIBS. Ditto for 'update_panels' and PANEL_LIBS. 4. Wrap the rest of the checks with WITH_SAVE_ENV and make sure we're using updated LIBS and CPPFLAGS for those. Add the PY_CHECK_CURSES convenience macro.
1 parent bd473aa commit f80376b

File tree

7 files changed

+580
-746
lines changed

7 files changed

+580
-746
lines changed

Include/py_curses.h

+13-5
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,21 @@
3636
#define NCURSES_OPAQUE 0
3737
#endif
3838

39-
#ifdef HAVE_NCURSES_H
40-
#include <ncurses.h>
41-
#else
42-
#include <curses.h>
39+
#if defined(HAVE_NCURSESW_NCURSES_H)
40+
# include <ncursesw/ncurses.h>
41+
#elif defined(HAVE_NCURSESW_CURSES_H)
42+
# include <ncursesw/curses.h>
43+
#elif defined(HAVE_NCURSES_NCURSES_H)
44+
# include <ncurses/ncurses.h>
45+
#elif defined(HAVE_NCURSES_CURSES_H)
46+
# include <ncurses/curses.h>
47+
#elif defined(HAVE_NCURSES_H)
48+
# include <ncurses.h>
49+
#elif defined(HAVE_CURSES_H)
50+
# include <curses.h>
4351
#endif
4452

45-
#ifdef HAVE_NCURSES_H
53+
#ifdef NCURSES_VERSION
4654
/* configure was checking <curses.h>, but we will
4755
use <ncurses.h>, which has some or all these features. */
4856
#if !defined(WINDOW_HAS_FLAGS) && \
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Improve :mod:`curses` and :mod:`curses.panel` dependency checks in
2+
:program:`configure`.

Modules/_curses_panel.c

+7-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,13 @@ static const char PyCursesVersion[] = "2.1";
1919

2020
#include "py_curses.h"
2121

22-
#include <panel.h>
22+
#if defined(HAVE_NCURSESW_PANEL_H)
23+
# include <ncursesw/panel.h>
24+
#elif defined(HAVE_NCURSES_PANEL_H)
25+
# include <ncurses/panel.h>
26+
#elif defined(HAVE_PANEL_H)
27+
# include <panel.h>
28+
#endif
2329

2430
typedef struct {
2531
PyObject *PyCursesError;

Modules/_cursesmodule.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ static const char PyCursesVersion[] = "2.2";
128128
#include <langinfo.h>
129129
#endif
130130

131-
#if !defined(HAVE_NCURSES_H) && (defined(sgi) || defined(__sun) || defined(SCO5))
131+
#if !defined(NCURSES_VERSION) && (defined(sgi) || defined(__sun) || defined(SCO5))
132132
#define STRICT_SYSV_CURSES /* Don't use ncurses extensions */
133133
typedef chtype attr_t; /* No attr_t type is available */
134134
#endif

0 commit comments

Comments
 (0)