Skip to content

Commit

Permalink
[2.7] bpo-31891: Fix building the curses module on NetBSD. (GH-4165). (
Browse files Browse the repository at this point in the history
…#4194)

(cherry picked from commit baac01e)
  • Loading branch information
serhiy-storchaka committed Oct 31, 2017
1 parent 1d48182 commit e0fc1af
Show file tree
Hide file tree
Showing 7 changed files with 334 additions and 50 deletions.
14 changes: 5 additions & 9 deletions Include/py_curses.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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
Expand All @@ -74,11 +70,11 @@ extern "C" {
/* Type declarations */

typedef struct {
PyObject_HEAD
WINDOW *win;
PyObject_HEAD
WINDOW *win;
} 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
32 changes: 24 additions & 8 deletions Lib/test/test_curses.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@

# 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),
Expand Down Expand Up @@ -137,7 +140,8 @@ def test_window_funcs(self):

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)
Expand Down Expand Up @@ -171,7 +175,8 @@ def test_window_funcs(self):
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)
Expand Down Expand Up @@ -201,14 +206,18 @@ def test_module_funcs(self):
"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]:
func()
if hasattr(curses, 'filter'):
curses.filter()
if hasattr(curses, 'getsyx'):
curses.getsyx()

# Functions that actually need arguments
if curses.tigetstr("cnorm"):
Expand All @@ -232,15 +241,18 @@ def test_module_funcs(self):
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):
Expand Down Expand Up @@ -274,6 +286,7 @@ def test_getmouse(self):
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)
Expand All @@ -282,6 +295,7 @@ def test_userptr_without_set(self):
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)
Expand All @@ -294,6 +308,7 @@ def test_userptr_memory_leak(self):
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:
Expand All @@ -302,6 +317,7 @@ def __del__(self):
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))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed building the curses module on NetBSD.
Loading

0 comments on commit e0fc1af

Please sign in to comment.