8000 bpo-31891: Fix building the curses module on NetBSD. (GH-4165) (#4189) · python/cpython@5db3208 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5db3208

Browse files
miss-islingtonserhiy-storchaka
authored andcommitted
bpo-31891: Fix building the curses module on NetBSD. (GH-4165) (#4189)
(cherry picked from commit baac01e)
1 parent 41efc40 commit 5db3208

File tree

7 files changed

+335
-51
lines changed

7 files changed

+335
-51
lines changed

Include/py_curses.h

Lines changed: 6 additions & 10 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,12 +70,12 @@ extern "C" {
7470
/* Type declarations */
7571

7672
typedef struct {
77-
PyObject_HEAD
78-
WINDOW *win;
79-
char *encoding;
73+
PyObject_HEAD
74+
WINDOW *win;
75+
char *encoding;
8076
} PyCursesWindowObject;
8177

82-
#define PyCursesWindow_Check(v) (Py_TYPE(v) == &PyCursesWindow_Type)
78+
#define PyCursesWindow_Check(v) (Py_TYPE(v) == &PyCursesWindow_Type)
8379

8480
#define PyCurses_CAPSULE_NAME "_curses._C_API"
8581

Lib/test/test_curses.py

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

2626
# If either of these don't exist, skip the tests.
2727
curses = import_module('curses')
28-
import_module('curses.panel')
2928
import_module('curses.ascii')
3029
import_module('curses.textpad')
30+
try:
31+
import curses.panel
32+
except ImportError:
33+
pass
3134

3235
def requires_curses_func(name):
3336
return unittest.skipUnless(hasattr(curses, name),
@@ -138,7 +141,8 @@ def test_window_funcs(self):
138141

139142
stdscr.idcok(1)
140143
stdscr.idlok(1)
141-
stdscr.immedok(1)
144+
if hasattr(stdscr, 'immedok'):
145+
stdscr.immedok(1)
142146
stdscr.insch('c')
143147
stdscr.insdelln(1)
144148
stdscr.insnstr('abc', 3)
@@ -172,7 +176,8 @@ def test_window_funcs(self):
172176
stdscr.setscrreg(10,15)
173177
win3 = stdscr.subwin(10,10)
174178
win3 = stdscr.subwin(10,10, 5,5)
175-
stdscr.syncok(1)
179+
if hasattr(stdscr, 'syncok'):
180+
stdscr.syncok(1)
176181
stdscr.timeout(5)
177182
stdscr.touchline(5,5)
178183
stdscr.touchline(5,5,0)
@@ -211,15 +216,19 @@ def test_module_funcs(self):
211216
"Test module-level functions"
212217
for func in [curses.baudrate, curses.beep, curses.can_change_color,
213218
curses.cbreak, curses.def_prog_mode, curses.doupdate,
214-
curses.filter, curses.flash, curses.flushinp,
219+
curses.flash, curses.flushinp,
215220
curses.has_colors, curses.has_ic, curses.has_il,
216221
curses.isendwin, curses.killchar, curses.longname,
217222
curses.nocbreak, curses.noecho, curses.nonl,
218223
curses.noqiflush, curses.noraw,
219224
curses.reset_prog_mode, curses.termattrs,
220-
curses.termname, curses.erasechar, curses.getsyx]:
225+
curses.termname, curses.erasechar]:
221226
with self.subTest(func=func.__qualname__):
222227
func()
228+
if hasattr(curses, 'filter'):
229+
curses.filter()
230+
if hasattr(curses, 'getsyx'):
231+
curses.getsyx()
223232

224233
# Functions that actually need arguments
225234
if curses.tigetstr("cnorm"):
@@ -243,15 +252,18 @@ def test_module_funcs(self):
243252
curses.putp(b'abc')
244253
curses.qiflush()
245254
curses.raw() ; curses.raw(1)
246-
curses.setsyx(5,5)
255+
if hasattr(curses, 'setsyx'):
256+
curses.setsyx(5,5)
247257
curses.tigetflag('hc')
248258
curses.tigetnum('co')
249259
curses.tigetstr('cr')
250260
curses.tparm(b'cr')
251-
curses.typeahead(sys.__stdin__.fileno())
261+
if hasattr(curses, 'typeahead'):
262+
curses.typeahead(sys.__stdin__.fileno())
252263
curses.unctrl('a')
253264
curses.ungetch('a')
254-
curses.use_env(1)
265+
if hasattr(curses, 'use_env'):
266+
curses.use_env(1)
255267

256268
# Functions only available on a few platforms
257269
def test_colors_funcs(self):
@@ -285,6 +297,7 @@ def test_getmouse(self):
285297
curses.ungetmouse(0, 0, 0, 0, curses.BUTTON1_PRESSED)
286298
m = curses.getmouse()
287299

300+
@requires_curses_func('panel')
288301
def test_userptr_without_set(self):
289302
w = curses.newwin(10, 10)
290303
p = curses.panel.new_panel(w)
@@ -293,6 +306,7 @@ def test_userptr_without_set(self):
293306
msg='userptr should fail since not set'):
294307
p.userptr()
295308

309+
@requires_curses_func('panel')
296310
def test_userptr_memory_leak(self):
297311
w = curses.newwin(10, 10)
298312
p = curses.panel.new_panel(w)
@@ -305,6 +319,7 @@ def test_userptr_memory_leak(self):
305319
self.assertEqual(sys.getrefcount(obj), nrefs,
306320
"set_userptr leaked references")
307321

322+
@requires_curses_func('panel')
308323
def test_userptr_segfault(self):
309324
panel = curses.panel.new_panel(self.stdscr)
310325
class A:
@@ -313,6 +328,7 @@ def __del__(self):
313328
panel.set_userptr(A())
314329
panel.set_userptr(None)
315330

331+
@requires_curses_func('panel')
316332
def test_new_curses_panel(self):
317333
panel = curses.panel.new_panel(self.stdscr)
318334
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)
0