8000 [3.6] bpo-25720: Fix the method for checking pad state of curses WINDOW (GH-4164) by miss-islington · Pull Request #4212 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

[3.6] bpo-25720: Fix the method for checking pad state of curses WINDOW (GH-4164) #4212

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions Include/py_curses.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@
#ifdef _BSD_WCHAR_T_DEFINED_
#define _WCHAR_T
#endif

/* the following define is necessary for OS X 10.6; without it, the
Apple-supplied ncurses.h sets NCURSES_OPAQUE to 1, and then Python
can't get at the WINDOW flags field. */
#define NCURSES_OPAQUE 0
#endif /* __APPLE__ */

#ifdef __FreeBSD__
Expand Down Expand Up @@ -44,6 +39,13 @@
#endif
#endif

#if !defined(HAVE_CURSES_IS_PAD) && defined(WINDOW_HAS_FLAGS)
/* The following definition is necessary for ncurses 5.7; without it,
some of [n]curses.h set NCURSES_OPAQUE to 1, and then Python
can't get at the WINDOW flags field. */
#define NCURSES_OPAQUE 0
#endif

#ifdef HAVE_NCURSES_H
#include <ncurses.h>
#else
Expand All @@ -52,10 +54,13 @@

#ifdef HAVE_NCURSES_H
/* configure was checking <curses.h>, but we will
use <ncurses.h>, which has all these features. */
#ifndef WINDOW_HAS_FLAGS
use <ncurses.h>, which has some or all these features. */
#if !defined(WINDOW_HAS_FLAGS) && !(NCURSES_OPAQUE+0)
#define WINDOW_HAS_FLAGS 1
#endif
#if !defined(HAVE_CURSES_IS_PAD) && NCURSES_VERSION_PATCH+0 >= 20090906
#define HAVE_CURSES_IS_PAD 1
#endif
#ifndef MVWDELCH_IS_EXPRESSION
#define MVWDELCH_IS_EXPRESSION 1
#endif
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix the method for checking pad state of curses WINDOW. Patch by Masayuki
Yamamoto.
24 changes: 16 additions & 8 deletions Modules/_cursesmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -936,6 +936,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 *
Expand Down Expand Up @@ -1075,10 +1081,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),
Expand Down Expand Up @@ -1607,10 +1614,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)) {
Expand Down Expand Up @@ -1782,10 +1789,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)) {
Expand Down Expand Up @@ -1851,9 +1858,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);
Expand Down
39 changes: 38 additions & 1 deletion configure
Original file line number Diff line number Diff line change
Expand Up @@ -15897,14 +15897,21 @@ $as_echo "#define MVWDELCH_IS_EXPRESSION 1" >>confdefs.h

fi

# Issue #25720: ncurses has introduced the NCURSES_OPAQUE symbol making opaque
# structs since version 5.7. If the macro is defined as zero before including
# [n]curses.h, ncurses will expose fields of the structs regardless of the
# configuration.
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether WINDOW has _flags" >&5
$as_echo_n "checking whether WINDOW has _flags... " >&6; }
if ${ac_cv_window_has_flags+:} false; then :
$as_echo_n "(cached) " >&6
else
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
#include <curses.h>

#define NCURSES_OPAQUE 0
#include <curses.h>

int
main ()
{
Expand Down Expand Up @@ -15935,6 +15942,36 @@ $as_echo "#define WINDOW_HAS_FLAGS 1" >>confdefs.h

fi

{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for is_pad" >&5
$as_echo_n "checking for is_pad... " >&6; }
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
#include <curses.h>
int
main ()
{

#ifndef is_pad
void *x=is_pad
#endif

;
return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :

$as_echo "#define HAVE_CURSES_IS_PAD 1" >>confdefs.h

{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; }
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }

fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext

{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for is_term_resized" >&5
$as_echo_n "checking for is_term_resized... " >&6; }
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
Expand Down
20 changes: 19 additions & 1 deletion configure.ac
< 2364 /tr>
Original file line number Diff line number Diff line change
Expand Up @@ -4993,9 +4993,16 @@ then
[Define if mvwdelch in curses.h is an expression.])
fi

# Issue #25720: ncurses has introduced the NCURSES_OPAQUE symbol making opaque
# structs since version 5.7. If the macro is defined as zero before including
# [n]curses.h, ncurses will expose fields of the structs regardless of the
# configuration.
AC_MSG_CHECKING(whether WINDOW has _flags)
AC_CACHE_VAL(ac_cv_window_has_flags,
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <curses.h>]], [[
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#define NCURSES_OPAQUE 0
#include <curses.h>
]], [[
WINDOW *w;
w->_flags = 0;
]])],
Expand All @@ -5010,6 +5017,17 @@ then
[Define if WINDOW in curses.h offers a field _flags.])
fi

AC_MSG_CHECKING(for is_pad)
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <curses.h>]], [[
#ifndef is_pad
void *x=is_pad
#endif
]])],
[AC_DEFINE(HAVE_CURSES_IS_PAD, 1, Define if you have the 'is_pad' function or macro.)
AC_MSG_RESULT(yes)],
[AC_MSG_RESULT(no)]
)

AC_MSG_CHECKING(for is_term_resized)
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <curses.h>]], [[void *x=is_term_resized]])],
[AC_DEFINE(HAVE_CURSES_IS_TERM_RESIZED, 1, Define if you have the 'is_term_resized' function.)
Expand Down
3 changes: 3 additions & 0 deletions pyconfig.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@
/* Define if you have the 'immedok' function. */
#undef HAVE_CURSES_IMMEDOK

/* Define if you have the 'is_pad' function or macro. */
#undef HAVE_CURSES_IS_PAD

/* Define if you have the 'is_term_resized' function. */
#undef HAVE_CURSES_IS_TERM_RESIZED

Expand Down
0