Skip to content

Commit e0fc1af

Browse files
[2.7] bpo-31891: Fix building the curses module on NetBSD. (GH-4165). (#4194)
(cherry picked from commit baac01e)
1 parent 1d48182 commit e0fc1af

7 files changed

Lines changed: 334 additions & 50 deletions

File tree

Include/py_curses.h

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
** On Mac OS X 10.2 [n]curses.h and stdlib.h use different guards
88
** against multiple definition of wchar_t.
99
*/
10-
#ifdef _BSD_WCHAR_T_DEFINED_
10+
#ifdef _BSD_WCHAR_T_DEFINED_
1111
#define _WCHAR_T
1212
#endif
1313

@@ -22,7 +22,7 @@
2222
** On FreeBSD, [n]curses.h and stdlib.h/wchar.h use different guards
2323
** against multiple definition of wchar_t and wint_t.
2424
*/
25-
#ifdef _XOPEN_SOURCE_EXTENDED
25+
#ifdef _XOPEN_SOURCE_EXTENDED
2626
#ifndef __FreeBSD_version
2727
#include <osreldate.h>
2828
#endif
@@ -48,10 +48,6 @@
4848
#include <ncurses.h>
4949
#else
5050
#include <curses.h>
51-
#ifdef HAVE_TERM_H
52-
/* for tigetstr, which is not declared in SysV curses */
53-
#include <term.h>
54-
#endif
5551
#endif
5652

5753
#ifdef HAVE_NCURSES_H
@@ -74,11 +70,11 @@ extern "C" {
7470
/* Type declarations */
7571

7672
typedef struct {
77-
PyObject_HEAD
78-
WINDOW *win;
73+
PyObject_HEAD
74+
WINDOW *win;
7975
} PyCursesWindowObject;
8076

81-
#define PyCursesWindow_Check(v) (Py_TYPE(v) == &PyCursesWindow_Type)
77+
#define PyCursesWindow_Check(v) (Py_TYPE(v) == &PyCursesWindow_Type)
8278

8379
#define PyCurses_CAPSULE_NAME "_curses._C_API"
8480

Lib/test/test_curses.py

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,12 @@
2626

2727
# If either of these don't exist, skip the tests.
2828
curses = import_module('curses')
29-
import_module('curses.panel')
3029
import_module('curses.ascii')
3130
import_module('curses.textpad')
31+
try:
32+
import curses.panel
33+
except ImportError:
34+
pass
3235

3336
def requires_curses_func(name):
3437
return unittest.skipUnless(hasattr(curses, name),
@@ -137,7 +140,8 @@ def test_window_funcs(self):
137140

138141
stdscr.idcok(1)
139142
stdscr.idlok(1)
140-
stdscr.immedok(1)
143+
if hasattr(stdscr, 'immedok'):
144+
stdscr.immedok(1)
141145
stdscr.insch('c')
142146
stdscr.insdelln(1)
143147
stdscr.insnstr('abc', 3)
@@ -171,7 +175,8 @@ def test_window_funcs(self):
171175
stdscr.setscrreg(10,15)
172176
win3 = stdscr.subwin(10,10)
173177
win3 = stdscr.subwin(10,10, 5,5)
174-
stdscr.syncok(1)
178+
if hasattr(stdscr, 'syncok'):
179+
stdscr.syncok(1)
175180
stdscr.timeout(5)
176181
stdscr.touchline(5,5)
177182
stdscr.touchline(5,5,0)
@@ -201,14 +206,18 @@ def test_module_funcs(self):
201206
"Test module-level functions"
202207
for func in [curses.baudrate, curses.beep, curses.can_change_color,
203208
curses.cbreak, curses.def_prog_mode, curses.doupdate,
204-
curses.filter, curses.flash, curses.flushinp,
209+
curses.flash, curses.flushinp,
205210
curses.has_colors, curses.has_ic, curses.has_il,
206211
curses.isendwin, curses.killchar, curses.longname,
207212
curses.nocbreak, curses.noecho, curses.nonl,
208213
curses.noqiflush, curses.noraw,
209214
curses.reset_prog_mode, curses.termattrs,
210-
curses.termname, curses.erasechar, curses.getsyx]:
215+
curses.termname, curses.erasechar]:
211216
func()
217+
if hasattr(curses, 'filter'):
218+
curses.filter()
219+
if hasattr(curses, 'getsyx'):
220+
curses.getsyx()
212221

213222
# Functions that actually need arguments
214223
if curses.tigetstr("cnorm"):
@@ -232,15 +241,18 @@ def test_module_funcs(self):
232241
curses.putp(b'abc')
233242
curses.qiflush()
234243
curses.raw() ; curses.raw(1)
235-
curses.setsyx(5,5)
244+
if hasattr(curses, 'setsyx'):
245+
curses.setsyx(5,5)
236246
curses.tigetflag('hc')
237247
curses.tigetnum('co')
238248
curses.tigetstr('cr')
239249
curses.tparm(b'cr')
240-
curses.typeahead(sys.__stdin__.fileno())
250+
if hasattr(curses, 'typeahead'):
251+
curses.typeahead(sys.__stdin__.fileno())
241252
curses.unctrl('a')
242253
curses.ungetch('a')
243-
curses.use_env(1)
254+
if hasattr(curses, 'use_env'):
255+
curses.use_env(1)
244256

245257
# Functions only available on a few platforms
246258
def test_colors_funcs(self):
@@ -274,6 +286,7 @@ def test_getmouse(self):
274286
curses.ungetmouse(0, 0, 0, 0, curses.BUTTON1_PRESSED)
275287
m = curses.getmouse()
276288

289+
@requires_curses_func('panel')
277290
def test_userptr_without_set(self):
278291
w = curses.newwin(10, 10)
279292
p = curses.panel.new_panel(w)
@@ -282,6 +295,7 @@ def test_userptr_without_set(self):
282295
msg='userptr should fail since not set'):
283296
p.userptr()
284297

298+
@requires_curses_func('panel')
285299
def test_userptr_memory_leak(self):
286300
w = curses.newwin(10, 10)
287301
p = curses.panel.new_panel(w)
@@ -294,6 +308,7 @@ def test_userptr_memory_leak(self):
294308
self.assertEqual(sys.getrefcount(obj), nrefs,
295309
"set_userptr leaked references")
296310

311+
@requires_curses_func('panel')
297312
def test_userptr_segfault(self):
298313
panel = curses.panel.new_panel(self.stdscr)
299314
class A:
@@ -302,6 +317,7 @@ def __del__(self):
302317
panel.set_userptr(A())
303318
panel.set_userptr(None)
304319

320+
@requires_curses_func('panel')
305321
def test_new_curses_panel(self):
306322
panel = curses.panel.new_panel(self.stdscr)
307323
self.assertRaises(TypeError, type(panel))
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed building the curses module on NetBSD.

0 commit comments

Comments
 (0)