Skip to content
Closed
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
29 changes: 15 additions & 14 deletions Include/py_curses.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,17 @@
** On Mac OS X 10.2 [n]curses.h and stdlib.h use different guards
** against multiple definition of wchar_t.
*/
#ifdef _BSD_WCHAR_T_DEFINED_
#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__
/*
** On FreeBSD, [n]curses.h and stdlib.h/wchar.h use different guards
** against multiple definition of wchar_t and wint_t.
*/
#ifdef _XOPEN_SOURCE_EXTENDED
#ifdef _XOPEN_SOURCE_EXTENDED
#ifndef __FreeBSD_version
#include <osreldate.h>
#endif
Expand All @@ -44,6 +39,15 @@
#endif
#endif

#if !defined(HAVE_CURSES_IS_PAD) && !defined(WINDOW_HAS_FLAGS)
/* If ncurses doesn't have both is_pad function and _flags field of WINDOW,
there is no method to check whether WINDOW is a pad. Therefore, add the
definitions to make WINDOW to non-opaque type before including [n]curses.h.
*/
#define NCURSES_OPAQUE 0
#define WINDOW_HAS_FLAGS 1
#endif

#ifdef HAVE_NCURSES_H
#include <ncurses.h>
#else
Expand All @@ -57,9 +61,6 @@
#ifdef HAVE_NCURSES_H
/* configure was checking <curses.h>, but we will
use <ncurses.h>, which has all these features. */
#ifndef WINDOW_HAS_FLAGS
#define WINDOW_HAS_FLAGS 1
#endif
#ifndef MVWDELCH_IS_EXPRESSION
#define MVWDELCH_IS_EXPRESSION 1
#endif
Expand All @@ -74,12 +75,12 @@ extern "C" {
/* Type declarations */

typedef struct {
PyObject_HEAD
WINDOW *win;
char *encoding;
PyObject_HEAD
WINDOW *win;
char *encoding;
} PyCursesWindowObject;

#define PyCursesWindow_Check(v) (Py_TYPE(v) == &PyCursesWindow_Type)
#define PyCursesWindow_Check(v) (Py_TYPE(v) == &PyCursesWindow_Type)

#define PyCurses_CAPSULE_NAME "_curses._C_API"

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
curses: Fix check for whether WINDOW is a pad.
126 changes: 67 additions & 59 deletions Modules/_cursesmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -928,6 +928,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 @@ -1067,8 +1073,8 @@ 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
Expand Down Expand Up @@ -1602,41 +1608,42 @@ 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)
#endif
{
switch(PyTuple_Size(args)) {
case 6:
if (!PyArg_ParseTuple(args,
"iiiiii;" \
"pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol",
&pminrow, &pmincol, &sminrow,
&smincol, &smaxrow, &smaxcol))
return NULL;
Py_BEGIN_ALLOW_THREADS
rtn = pnoutrefresh(self->win,
pminrow, pmincol, sminrow,
smincol, smaxrow, smaxcol);
Py_END_ALLOW_THREADS
return PyCursesCheckERR(rtn, "pnoutrefresh");
default:
PyErr_SetString(PyCursesError,
"noutrefresh() called for a pad "
"requires 6 arguments");
return NULL;
}
} else {
if (!PyArg_ParseTuple(args, ":noutrefresh"))
if (py_is_pad(self->win))
#endif
{
switch(PyTuple_Size(args)) {
case 6:
if (!PyArg_ParseTuple(args,
"iiiiii;" \
"pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol",
&pminrow, &pmincol, &sminrow,
&smincol, &smaxrow, &smaxcol))
return NULL;

Py_BEGIN_ALLOW_THREADS
rtn = wnoutrefresh(self->win);
rtn = pnoutrefresh(self->win,
pminrow, pmincol, sminrow,
smincol, smaxrow, smaxcol);
Py_END_ALLOW_THREADS
return PyCursesCheckERR(rtn, "wnoutrefresh");
return PyCursesCheckERR(rtn, "pnoutrefresh");
default:
PyErr_SetString(PyCursesError,
"noutrefresh() called for a pad "
"requires 6 arguments");
return NULL;
}
} else {
if (!PyArg_ParseTuple(args, ":noutrefresh"))
return NULL;

Py_BEGIN_ALLOW_THREADS
rtn = wnoutrefresh(self->win);
Py_END_ALLOW_THREADS
return PyCursesCheckERR(rtn, "wnoutrefresh");
}
}

static PyObject *
Expand Down Expand Up @@ -1765,40 +1772,41 @@ 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)
#endif
{
switch(PyTuple_Size(args)) {
case 6:
if (!PyArg_ParseTuple(args,
"iiiiii;" \
"pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol",
&pminrow, &pmincol, &sminrow,
&smincol, &smaxrow, &smaxcol))
return NULL;

Py_BEGIN_ALLOW_THREADS
rtn = prefresh(self->win,
pminrow, pmincol, sminrow,
smincol, smaxrow, smaxcol);
Py_END_ALLOW_THREADS
return PyCursesCheckERR(rtn, "prefresh");
default:
PyErr_SetString(PyCursesError,
"refresh() for a pad requires 6 arguments");
return NULL;
}
} else {
if (!PyArg_ParseTuple(args, ":refresh"))
if (py_is_pad(self->win))
#endif
{
switch(PyTuple_Size(args)) {
case 6:
if (!PyArg_ParseTuple(args,
"iiiiii;" \
"pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol",
&pminrow, &pmincol, &sminrow,
&smincol, &smaxrow, &smaxcol))
return NULL;

Py_BEGIN_ALLOW_THREADS
rtn = wrefresh(self->win);
rtn = prefresh(self->win,
pminrow, pmincol, sminrow,
smincol, smaxrow, smaxcol);
Py_END_ALLOW_THREADS
return PyCursesCheckERR(rtn, "prefresh");
default:
PyErr_SetString(PyCursesError,
"refresh() for a pad requires 6 arguments");
return NULL;
}
} else {
if (!PyArg_ParseTuple(args, ":refresh"))
return NULL;

Py_BEGIN_ALLOW_THREADS
rtn = wrefresh(self->win);
Py_END_ALLOW_THREADS
return PyCursesCheckERR(rtn, "prefresh");
}
}

static PyObject *
Expand Down Expand Up @@ -1834,8 +1842,8 @@ 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
Expand Down
30 changes: 30 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -15957,6 +15957,36 @@ $as_echo "#define MVWDELCH_IS_EXPRESSION 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 ()
{

bool b;
WINDOW *w;
b = is_pad(w);

;
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 whether WINDOW has _flags" >&5
$as_echo_n "checking whether WINDOW has _flags... " >&6; }
if ${ac_cv_window_has_flags+:} false; then :
Expand Down
12 changes: 12 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -5044,6 +5044,18 @@ then
[Define if mvwdelch in curses.h is an expression.])
fi

AC_MSG_CHECKING(for is_pad)
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <curses.h>]], [[
bool b;
WINDOW *w;
b = is_pad(w);
]])],
[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(whether WINDOW has _flags)
AC_CACHE_VAL(ac_cv_window_has_flags,
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <curses.h>]], [[
Expand Down
3 changes: 3 additions & 0 deletions pyconfig.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@
/* Define to 1 if you have the <curses.h> header file. */
#undef HAVE_CURSES_H

/* 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