summaryrefslogtreecommitdiff
path: root/Modules/_cursesmodule.c
diff options
context:
space:
mode:
authorMasayuki Yamamoto <ma3yuki.8mamo10@gmail.com>2017-11-01 21:05:26 +0900
committerSerhiy Storchaka <storchaka@gmail.com>2017-11-01 14:05:26 +0200
commit8bc7d63560024681dce9f40445f2877b2987e92c (patch)
treeb1e05ed1a68b1d8b0f3d7a5268c11922084dc29f /Modules/_cursesmodule.c
parent280c22a82a6756e9caffef031c564fd98f1b50e7 (diff)
downloadcpython-git-8bc7d63560024681dce9f40445f2877b2987e92c.tar.gz
bpo-25720: Fix the method for checking pad state of curses WINDOW (#4164)
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().
Diffstat (limited to 'Modules/_cursesmodule.c')
-rw-r--r--Modules/_cursesmodule.c24
1 files changed, 16 insertions, 8 deletions
diff --git a/Modules/_cursesmodule.c b/Modules/_cursesmodule.c
index d30bd1ab20..2a2eed2c48 100644
--- a/Modules/_cursesmodule.c
+++ b/Modules/_cursesmodule.c
@@ -934,6 +934,12 @@ int py_mvwdelch(WINDOW *w, int y, int x)
}
#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 *
@@ -1073,10 +1079,11 @@ PyCursesWindow_EchoChar(PyCursesWindowObject *self, PyObject *args)
if (!PyCurses_ConvertToChtype(self, temp, &ch))
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),
@@ -1603,10 +1610,10 @@ PyCursesWindow_NoOutRefresh(PyCursesWindowObject *self, PyObject *args)
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)) {
@@ -1766,10 +1773,10 @@ PyCursesWindow_Refresh(PyCursesWindowObject *self, PyObject *args)
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)) {
@@ -1835,9 +1842,10 @@ PyCursesWindow_SubWin(PyCursesWindowObject *self, PyObject *args)
}
/* 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);