Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9f16e44

Browse files
committed
Close #14223: Fix window.addch(curses.ACS_HLINE)
Fix window.addch() of the curses module for special characters like curses.ACS_HLINE: the Python function addch(int) and addch(bytes) is now calling the C function waddch()/mvwaddch() (as it was done in Python 3.2), instead of wadd_wch()/mvwadd_wch(). The Python function addch(str) is still calling the C function wadd_wch()/mvwadd_wch() if the Python curses is linked to libncursesw.
1 parent dbf56c2 commit 9f16e44

2 files changed

Lines changed: 14 additions & 27 deletions

File tree

Misc/NEWS

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,13 @@ Library
7373
always returning an integer. So it is now possible to distinguish special
7474
keys like keypad keys.
7575

76+
- Issue #14223: Fix window.addch() of the curses module for special characters
77+
like curses.ACS_HLINE: the Python function addch(int) and addch(bytes) is now
78+
calling the C function waddch()/mvwaddch() (as it was done in Python 3.2),
79+
instead of wadd_wch()/mvwadd_wch(). The Python function addch(str) is still
80+
calling the C function wadd_wch()/mvwadd_wch() if the Python curses is linked
81+
to libncursesw.
82+
7683

7784
What's New in Python 3.3.0 Release Candidate 1?
7885
===============================================

Modules/_cursesmodule.c

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,6 @@ PyCurses_ConvertToCchar_t(PyCursesWindowObject *win, PyObject *obj,
280280
#endif
281281
)
282282
{
283-
int ret = 0;
284283
long value;
285284
#ifdef HAVE_NCURSESW
286285
wchar_t buffer[2];
@@ -304,7 +303,6 @@ PyCurses_ConvertToCchar_t(PyCursesWindowObject *win, PyObject *obj,
304303
}
305304
else if(PyBytes_Check(obj) && PyBytes_Size(obj) == 1) {
306305
value = (unsigned char)PyBytes_AsString(obj)[0];
307-
ret = 1;
308306
}
309307
else if (PyLong_CheckExact(obj)) {
310308
int overflow;
@@ -314,39 +312,21 @@ PyCurses_ConvertToCchar_t(PyCursesWindowObject *win, PyObject *obj,
314312
"int doesn't fit in long");
315313
return 0;
316314
}
317-
#ifdef HAVE_NCURSESW
318-
ret = 2;
319-
#else
320-
ret = 1;
321-
#endif
322315
}
323316
else {
324317
PyErr_Format(PyExc_TypeError,
325318
"expect bytes or str of length 1, or int, got %s",
326319
Py_TYPE(obj)->tp_name);
327320
return 0;
328321
}
329-
#ifdef HAVE_NCURSESW
330-
if (ret == 2) {
331-
memset(wch->chars, 0, sizeof(wch->chars));
332-
wch->chars[0] = (wchar_t)value;
333-
if ((long)wch->chars[0] != value) {
334-
PyErr_Format(PyExc_OverflowError,
335-
"character doesn't fit in wchar_t");
336-
return 0;
337-
}
338-
}
339-
else
340-
#endif
341-
{
342-
*ch = (chtype)value;
343-
if ((long)*ch != value) {
344-
PyErr_Format(PyExc_OverflowError,
345-
"byte doesn't fit in chtype");
346-
return 0;
347-
}
322+
323+
*ch = (chtype)value;
324+
if ((long)*ch != value) {
325+
PyErr_Format(PyExc_OverflowError,
326+
"byte doesn't fit in chtype");
327+
return 0;
348328
}
349-
return ret;
329+
return 1;
350330
}
351331

352332
/* Convert an object to a byte string (char*) or a wide character string

0 commit comments

Comments
 (0)