1From 6dc83db69b5e29d25ba6d73646ea2e9a1097848a Mon Sep 17 00:00:00 2001
2From: Roumen Petrov <local@example.net>
3Date: Sun, 19 Feb 2012 16:13:24 +0200
4Subject: [PATCH] CROSS-properly detect WINDOW _flags for different ncurses versions
5
6---
7 Include/py_curses.h | 5 +++++
8 configure.ac | 40 ++++++++++++++++++++++++++++++++++++++--
9 pyconfig.h.in | 6 ++++++
10 3 files changed, 49 insertions(+), 2 deletions(-)
11
12diff --git a/Include/py_curses.h b/Include/py_curses.h
13index f2c08f6..a9b5260 100644
14--- a/Include/py_curses.h
15+++ b/Include/py_curses.h
16@@ -14,7 +14,9 @@
17 /* the following define is necessary for OS X 10.6; without it, the
18 Apple-supplied ncurses.h sets NCURSES_OPAQUE to 1, and then Python
19 can't get at the WINDOW flags field. */
20+/* NOTE configure check if ncurses require such definition
21 #define NCURSES_OPAQUE 0
22+*/
23 #endif /* __APPLE__ */
24
25 #ifdef __FreeBSD__
26@@ -57,9 +59,12 @@
27 #ifdef HAVE_NCURSES_H
28 /* configure was checking <curses.h>, but we will
29 use <ncurses.h>, which has all these features. */
30+/* NOTE configure check for existence of flags
31+ * Also flags are visible only if WINDOW structure is not opaque
32 #ifndef WINDOW_HAS_FLAGS
33 #define WINDOW_HAS_FLAGS 1
34 #endif
35+*/
36 #ifndef MVWDELCH_IS_EXPRESSION
37 #define MVWDELCH_IS_EXPRESSION 1
38 #endif
39diff --git a/configure.ac b/configure.ac
40index 0a3a186..75f5142 100644
41--- a/configure.ac
42+++ b/configure.ac
43@@ -4150,15 +4150,51 @@ then
44 fi
45
46 AC_MSG_CHECKING(whether WINDOW has _flags)
47-AC_CACHE_VAL(ac_cv_window_has_flags,
48 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <curses.h>]], [[
49 WINDOW *w;
50 w->_flags = 0;
51 ]])],
52 [ac_cv_window_has_flags=yes],
53-[ac_cv_window_has_flags=no]))
54+[ac_cv_window_has_flags=no])
55 AC_MSG_RESULT($ac_cv_window_has_flags)
56
57+py_curses_window_is_opaque=no
58+if test no = $ac_cv_window_has_flags; then
59+ AC_MSG_CHECKING([whether WINDOW has _flags in non-opaque structure])
60+ AC_COMPILE_IFELSE([
61+ AC_LANG_PROGRAM([[
62+ #define NCURSES_OPAQUE 0
63+ #include <curses.h>
64+ ]],[[
65+ WINDOW *w;
66+ w->_flags = 0;
67+ ]])],
68+ [py_curses_window_is_opaque=yes])
69+ AC_MSG_RESULT([$py_curses_window_is_opaque])
70+fi
71+if test yes = $py_curses_window_is_opaque; then
72+ ac_cv_window_has_flags=yes
73+ AC_DEFINE([NCURSES_OPAQUE], [0], [Define to 0 if you have WINDOW _flags in non-opaque structure.])
74+fi
75+
76+py_curses_window_is_internal=no
77+if test no = $ac_cv_window_has_flags; then
78+ AC_MSG_CHECKING([whether WINDOW has _flags as internal structure])
79+ AC_COMPILE_IFELSE([
80+ AC_LANG_PROGRAM([[
81+ #define NCURSES_INTERNALS 1
82+ #include <curses.h>
83+ ]],[[
84+ WINDOW *w;
85+ w->_flags = 0;
86+ ]])],
87+ [py_curses_window_is_internal=yes])
88+ AC_MSG_RESULT([$py_curses_window_is_internal])
89+fi
90+if test yes = $py_curses_window_is_internal; then
91+ ac_cv_window_has_flags=yes
92+ AC_DEFINE([NCURSES_INTERNALS], [1], [Define to 1 if you have WINDOW _flags as internal structure.])
93+fi
94
95 if test "$ac_cv_window_has_flags" = yes
96 then
97diff --git a/pyconfig.h.in b/pyconfig.h.in
98index 3ca3a4f..484c817 100644
99--- a/pyconfig.h.in
100+++ b/pyconfig.h.in
101@@ -1130,6 +1130,12 @@
102 /* Define if mvwdelch in curses.h is an expression. */
103 #undef MVWDELCH_IS_EXPRESSION
104
105+/* Define to 1 if you have WINDOW _flags as internal structure. */
106+#undef NCURSES_INTERNALS
107+
108+/* Define to 0 if you have WINDOW _flags in non-opaque structure. */
109+#undef NCURSES_OPAQUE
110+
111 /* Define to the address where bug reports for this package should be sent. */
112 #undef PACKAGE_BUGREPORT
113
114--
1151.6.4
116