bpo-25720: Fix the method for checking pad state of curses WINDOW (GH-4164) (#4213)
Modify the code to use ncurses is_pad() instead of checking WINDOW
_flags field. If your platform does not provide the is_pad(), the
existing way that checks the field will be enabled.
Note: This change does not drop support for platforms where do not
have both WINDOW _flags field and is_pad().
(cherry picked from commit 8bc7d63560024681dce9f40445f2877b2987e92c)
diff --git a/Modules/_cursesmodule.c b/Modules/_cursesmodule.c
index fb51c43..9149d76 100644
--- a/Modules/_cursesmodule.c
+++ b/Modules/_cursesmodule.c
@@ -663,6 +663,12 @@
}
#endif
+#if defined(HAVE_CURSES_IS_PAD)
+#define py_is_pad(win) is_pad(win)
+#elif defined(WINDOW_HAS_FLAGS)
+#define py_is_pad(win) ((win) ? ((win)->_flags & _ISPAD) != 0 : FALSE)
+#endif
+
/* chgat, added by Fabian Kreutz <fabian.kreutz at gmx.net> */
static PyObject *
@@ -804,10 +810,11 @@
return NULL;
}
-#ifdef WINDOW_HAS_FLAGS
- if (self->win->_flags & _ISPAD)
+#ifdef py_is_pad
+ if (py_is_pad(self->win)) {
return PyCursesCheckERR(pechochar(self->win, ch | attr),
"echochar");
+ }
else
#endif
return PyCursesCheckERR(wechochar(self->win, ch | attr),
@@ -1243,10 +1250,10 @@
int pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol;
int rtn;
-#ifndef WINDOW_HAS_FLAGS
+#ifndef py_is_pad
if (0)
#else
- if (self->win->_flags & _ISPAD)
+ if (py_is_pad(self->win))
#endif
{
switch(PyTuple_Size(args)) {
@@ -1386,10 +1393,10 @@
int pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol;
int rtn;
-#ifndef WINDOW_HAS_FLAGS
+#ifndef py_is_pad
if (0)
#else
- if (self->win->_flags & _ISPAD)
+ if (py_is_pad(self->win))
#endif
{
switch(PyTuple_Size(args)) {
@@ -1455,9 +1462,10 @@
}
/* printf("Subwin: %i %i %i %i \n", nlines, ncols, begin_y, begin_x); */
-#ifdef WINDOW_HAS_FLAGS
- if (self->win->_flags & _ISPAD)
+#ifdef py_is_pad
+ if (py_is_pad(self->win)) {
win = subpad(self->win, nlines, ncols, begin_y, begin_x);
+ }
else
#endif
win = subwin(self->win, nlines, ncols, begin_y, begin_x);