Commit baac01e6 authored by Serhiy Storchaka's avatar Serhiy Storchaka Committed by GitHub

bpo-31891: Fix building the curses module on NetBSD. (#4165)

parent 19f68301
......@@ -7,7 +7,7 @@
** 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
......@@ -22,7 +22,7 @@
** 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
......@@ -48,10 +48,6 @@
#include <ncurses.h>
#else
#include <curses.h>
#ifdef HAVE_TERM_H
/* for tigetstr, which is not declared in SysV curses */
#include <term.h>
#endif
#endif
#ifdef HAVE_NCURSES_H
......@@ -74,12 +70,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"
......
......@@ -25,9 +25,12 @@ requires('curses')
# If either of these don't exist, skip the tests.
curses = import_module('curses')
import_module('curses.panel')
import_module('curses.ascii')
import_module('curses.textpad')
try:
import curses.panel
except ImportError:
pass
def requires_curses_func(name):
return unittest.skipUnless(hasattr(curses, name),
......@@ -138,7 +141,8 @@ class TestCurses(unittest.TestCase):
stdscr.idcok(1)
stdscr.idlok(1)
stdscr.immedok(1)
if hasattr(stdscr, 'immedok'):
stdscr.immedok(1)
stdscr.insch('c')
stdscr.insdelln(1)
stdscr.insnstr('abc', 3)
......@@ -172,7 +176,8 @@ class TestCurses(unittest.TestCase):
stdscr.setscrreg(10,15)
win3 = stdscr.subwin(10,10)
win3 = stdscr.subwin(10,10, 5,5)
stdscr.syncok(1)
if hasattr(stdscr, 'syncok'):
stdscr.syncok(1)
stdscr.timeout(5)
stdscr.touchline(5,5)
stdscr.touchline(5,5,0)
......@@ -211,15 +216,19 @@ class TestCurses(unittest.TestCase):
"Test module-level functions"
for func in [curses.baudrate, curses.beep, curses.can_change_color,
curses.cbreak, curses.def_prog_mode, curses.doupdate,
curses.filter, curses.flash, curses.flushinp,
curses.flash, curses.flushinp,
curses.has_colors, curses.has_ic, curses.has_il,
curses.isendwin, curses.killchar, curses.longname,
curses.nocbreak, curses.noecho, curses.nonl,
curses.noqiflush, curses.noraw,
curses.reset_prog_mode, curses.termattrs,
curses.termname, curses.erasechar, curses.getsyx]:
curses.termname, curses.erasechar]:
with self.subTest(func=func.__qualname__):
func()
if hasattr(curses, 'filter'):
curses.filter()
if hasattr(curses, 'getsyx'):
curses.getsyx()
# Functions that actually need arguments
if curses.tigetstr("cnorm"):
......@@ -243,15 +252,18 @@ class TestCurses(unittest.TestCase):
curses.putp(b'abc')
curses.qiflush()
curses.raw() ; curses.raw(1)
curses.setsyx(5,5)
if hasattr(curses, 'setsyx'):
curses.setsyx(5,5)
curses.tigetflag('hc')
curses.tigetnum('co')
curses.tigetstr('cr')
curses.tparm(b'cr')
curses.typeahead(sys.__stdin__.fileno())
if hasattr(curses, 'typeahead'):
curses.typeahead(sys.__stdin__.fileno())
curses.unctrl('a')
curses.ungetch('a')
curses.use_env(1)
if hasattr(curses, 'use_env'):
curses.use_env(1)
# Functions only available on a few platforms
def test_colors_funcs(self):
......@@ -285,6 +297,7 @@ class TestCurses(unittest.TestCase):
curses.ungetmouse(0, 0, 0, 0, curses.BUTTON1_PRESSED)
m = curses.getmouse()
@requires_curses_func('panel')
def test_userptr_without_set(self):
w = curses.newwin(10, 10)
p = curses.panel.new_panel(w)
......@@ -293,6 +306,7 @@ class TestCurses(unittest.TestCase):
msg='userptr should fail since not set'):
p.userptr()
@requires_curses_func('panel')
def test_userptr_memory_leak(self):
w = curses.newwin(10, 10)
p = curses.panel.new_panel(w)
......@@ -305,6 +319,7 @@ class TestCurses(unittest.TestCase):
self.assertEqual(sys.getrefcount(obj), nrefs,
"set_userptr leaked references")
@requires_curses_func('panel')
def test_userptr_segfault(self):
panel = curses.panel.new_panel(self.stdscr)
class A:
......@@ -313,6 +328,7 @@ class TestCurses(unittest.TestCase):
panel.set_userptr(A())
panel.set_userptr(None)
@requires_curses_func('panel')
def test_new_curses_panel(self):
panel = curses.panel.new_panel(self.stdscr)
self.assertRaises(TypeError, type(panel))
......
This diff is collapsed.
......@@ -15812,6 +15812,186 @@ 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 immedok" >&5
$as_echo_n "checking for immedok... " >&6; }
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
#include <curses.h>
int
main ()
{
#ifndef immedok
void *x=immedok
#endif
;
return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
$as_echo "#define HAVE_CURSES_IMMEDOK 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 syncok" >&5
$as_echo_n "checking for syncok... " >&6; }
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
#include <curses.h>
int
main ()
{
#ifndef syncok
void *x=syncok
#endif
;
return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
$as_echo "#define HAVE_CURSES_SYNCOK 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 filter" >&5
$as_echo_n "checking for filter... " >&6; }
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
#include <curses.h>
int
main ()
{
#ifndef filter
void *x=filter
#endif
;
return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
$as_echo "#define HAVE_CURSES_FILTER 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 has_key" >&5
$as_echo_n "checking for has_key... " >&6; }
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
#include <curses.h>
int
main ()
{
#ifndef has_key
void *x=has_key
#endif
;
return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
$as_echo "#define HAVE_CURSES_HAS_KEY 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 typeahead" >&5
$as_echo_n "checking for typeahead... " >&6; }
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
#include <curses.h>
int
main ()
{
#ifndef typeahead
void *x=typeahead
#endif
;
return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
$as_echo "#define HAVE_CURSES_TYPEAHEAD 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 use_env" >&5
$as_echo_n "checking for use_env... " >&6; }
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
#include <curses.h>
int
main ()
{
#ifndef use_env
void *x=use_env
#endif
;
return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
$as_echo "#define HAVE_CURSES_USE_ENV 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
# last curses configure check
......
......@@ -4992,6 +4992,72 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <curses.h>]], [[void *x=resizeterm
AC_MSG_RESULT(yes)],
[AC_MSG_RESULT(no)]
)
AC_MSG_CHECKING(for immedok)
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <curses.h>]], [[
#ifndef immedok
void *x=immedok
#endif
]])],
[AC_DEFINE(HAVE_CURSES_IMMEDOK, 1, Define if you have the 'immedok' function.)
AC_MSG_RESULT(yes)],
[AC_MSG_RESULT(no)]
)
AC_MSG_CHECKING(for syncok)
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <curses.h>]], [[
#ifndef syncok
void *x=syncok
#endif
]])],
[AC_DEFINE(HAVE_CURSES_SYNCOK, 1, Define if you have the 'syncok' function.)
AC_MSG_RESULT(yes)],
[AC_MSG_RESULT(no)]
)
AC_MSG_CHECKING(for filter)
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <curses.h>]], [[
#ifndef filter
void *x=filter
#endif
]])],
[AC_DEFINE(HAVE_CURSES_FILTER, 1, Define if you have the 'filter' function.)
AC_MSG_RESULT(yes)],
[AC_MSG_RESULT(no)]
)
AC_MSG_CHECKING(for has_key)
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <curses.h>]], [[
#ifndef has_key
void *x=has_key
#endif
]])],
[AC_DEFINE(HAVE_CURSES_HAS_KEY, 1, Define if you have the 'has_key' function.)
AC_MSG_RESULT(yes)],
[AC_MSG_RESULT(no)]
)
AC_MSG_CHECKING(for typeahead)
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <curses.h>]], [[
#ifndef typeahead
void *x=typeahead
#endif
]])],
[AC_DEFINE(HAVE_CURSES_TYPEAHEAD, 1, Define if you have the 'typeahead' function.)
AC_MSG_RESULT(yes)],
[AC_MSG_RESULT(no)]
)
AC_MSG_CHECKING(for use_env)
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <curses.h>]], [[
#ifndef use_env
void *x=use_env
#endif
]])],
[AC_DEFINE(HAVE_CURSES_USE_ENV, 1, Define if you have the 'use_env' function.)
AC_MSG_RESULT(yes)],
[AC_MSG_RESULT(no)]
)
# last curses configure check
CPPFLAGS=$ac_save_cppflags
......
......@@ -146,9 +146,18 @@
/* Define if you have the 'ctermid_r' function. */
#undef HAVE_CTERMID_R
/* Define if you have the 'filter' function. */
#undef HAVE_CURSES_FILTER
/* Define to 1 if you have the <curses.h> header file. */
#undef HAVE_CURSES_H
/* Define if you have the 'has_key' function. */
#undef HAVE_CURSES_HAS_KEY
/* Define if you have the 'immedok' function. */
#undef HAVE_CURSES_IMMEDOK
/* Define if you have the 'is_term_resized' function. */
#undef HAVE_CURSES_IS_TERM_RESIZED
......@@ -158,6 +167,15 @@
/* Define if you have the 'resize_term' function. */
#undef HAVE_CURSES_RESIZE_TERM
/* Define if you have the 'syncok' function. */
#undef HAVE_CURSES_SYNCOK
/* Define if you have the 'typeahead' function. */
#undef HAVE_CURSES_TYPEAHEAD
/* Define if you have the 'use_env' function. */
#undef HAVE_CURSES_USE_ENV
/* Define to 1 if you have the declaration of `isfinite', and to 0 if you
don't. */
#undef HAVE_DECL_ISFINITE
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment