@@ -2699,21 +2699,21 @@ _curses_window_bkgdset_impl(PyCursesWindowObject *self, PyObject *ch,
26992699/*[clinic input]
27002700_curses.window.border
27012701
2702- ls: object(c_default="NULL") = _curses.ACS_VLINE
2702+ ls: object(c_default="NULL") = 0
27032703 Left side.
2704- rs: object(c_default="NULL") = _curses.ACS_VLINE
2704+ rs: object(c_default="NULL") = 0
27052705 Right side.
2706- ts: object(c_default="NULL") = _curses.ACS_HLINE
2706+ ts: object(c_default="NULL") = 0
27072707 Top side.
2708- bs: object(c_default="NULL") = _curses.ACS_HLINE
2708+ bs: object(c_default="NULL") = 0
27092709 Bottom side.
2710- tl: object(c_default="NULL") = _curses.ACS_ULCORNER
2710+ tl: object(c_default="NULL") = 0
27112711 Upper-left corner.
2712- tr: object(c_default="NULL") = _curses.ACS_URCORNER
2712+ tr: object(c_default="NULL") = 0
27132713 Upper-right corner.
2714- bl: object(c_default="NULL") = _curses.ACS_LLCORNER
2714+ bl: object(c_default="NULL") = 0
27152715 Bottom-left corner.
2716- br: object(c_default="NULL") = _curses.ACS_LRCORNER
2716+ br: object(c_default="NULL") = 0
27172717 Bottom-right corner.
27182718 /
27192719
@@ -2730,7 +2730,7 @@ _curses_window_border_impl(PyCursesWindowObject *self, PyObject *ls,
27302730 PyObject * rs , PyObject * ts , PyObject * bs ,
27312731 PyObject * tl , PyObject * tr , PyObject * bl ,
27322732 PyObject * br )
2733- /*[clinic end generated code: output=670ef38d3d7c2aa3 input=42568c1458221d24 ]*/
2733+ /*[clinic end generated code: output=670ef38d3d7c2aa3 input=d826ce9d6335479a ]*/
27342734{
27352735 chtype ch [8 ];
27362736 int i , rtn ;
@@ -2743,36 +2743,49 @@ _curses_window_border_impl(PyCursesWindowObject *self, PyObject *ls,
27432743#ifdef HAVE_NCURSESW
27442744 cchar_t wch [8 ];
27452745 const cchar_t * wch_p [8 ];
2746- int use_wide = 0 ;
2747- int types [8 ];
2746+ /* Only wborder_set() draws a complexchar and only wborder() an integer
2747+ or bytes character; a string character suits both, and so does the
2748+ integer 0, which asks for the default character. */
2749+ int has_narrow = 0 , has_str = 0 , has_cchar = 0 ;
27482750 for (i = 0 ; i < 8 ; i ++ ) {
2749- types [i ] = 0 ;
2751+ wch_p [i ] = NULL ; /* use the default character */
27502752 if (objs [i ] != NULL ) {
2751- types [ i ] = PyCurses_ConvertToCell (self , objs [i ], A_NORMAL , 0 ,
2753+ int type = PyCurses_ConvertToCell (self , objs [i ], A_NORMAL , 0 ,
27522754 "border" , & ch [i ], & wch [i ]);
2753- if (types [ i ] == 0 ) {
2755+ if (type == 0 ) {
27542756 return NULL ;
27552757 }
2756- if (types [i ] == 2 ) {
2757- use_wide = 1 ;
2758+ if (type == 2 ) {
2759+ wch_p [i ] = & wch [i ];
2760+ if (PyUnicode_Check (objs [i ])) {
2761+ has_str = 1 ;
2762+ }
2763+ else {
2764+ has_cchar = 1 ;
2765+ }
2766+ }
2767+ else if (!PyLong_CheckExact (objs [i ]) || ch [i ] != 0 ) {
2768+ has_narrow = 1 ; /* b'\0' is a byte character, not the 0 */
27582769 }
27592770 }
27602771 }
2761- if (use_wide ) {
2772+ if (has_narrow ) {
2773+ if (has_cchar ) {
2774+ PyErr_SetString (PyExc_TypeError ,
2775+ "border() cannot mix complexchar characters "
2776+ "with integer or bytes characters" );
2777+ return NULL ;
2778+ }
2779+ /* Narrow the string characters. */
27622780 for (i = 0 ; i < 8 ; i ++ ) {
2763- if (objs [i ] == NULL ) {
2764- wch_p [i ] = NULL ; /* use the default character */
2765- }
2766- else if (types [i ] == 2 ) {
2767- wch_p [i ] = & wch [i ];
2768- }
2769- else {
2770- PyErr_SetString (PyExc_TypeError ,
2771- "border() cannot mix integer or bytes "
2772- "characters with wide string characters" );
2781+ if (objs [i ] != NULL && PyUnicode_Check (objs [i ]) &&
2782+ !PyCurses_ConvertToChtype (self , objs [i ], & ch [i ]))
2783+ {
27732784 return NULL ;
27742785 }
27752786 }
2787+ }
2788+ else if (has_str || has_cchar ) {
27762789 rtn = wborder_set (self -> win ,
27772790 wch_p [0 ], wch_p [1 ], wch_p [2 ], wch_p [3 ],
27782791 wch_p [4 ], wch_p [5 ], wch_p [6 ], wch_p [7 ]);
@@ -2815,42 +2828,67 @@ _curses_window_box_impl(PyCursesWindowObject *self, int group_right_1,
28152828 PyObject * verch , PyObject * horch )
28162829/*[clinic end generated code: output=f3fcb038bb287192 input=e11acb7dbf6790b6]*/
28172830{
2818- chtype ch1 = 0 , ch2 = 0 ;
2831+ chtype ch [2 ] = {0 , 0 };
2832+ PyObject * objs [2 ] = {verch , horch };
2833+ int i ;
28192834#ifdef HAVE_NCURSESW
2820- cchar_t wch1 , wch2 ;
2821- int t1 = 0 , t2 = 0 ;
2835+ cchar_t wch [2 ];
2836+ const cchar_t * wch_p [2 ] = {NULL , NULL };
2837+ int has_narrow = 0 , has_str = 0 , has_cchar = 0 ;
28222838 if (group_right_1 ) {
2823- t1 = PyCurses_ConvertToCell (self , verch , A_NORMAL , 0 , "box" , & ch1 , & wch1 );
2824- if (t1 == 0 ) {
2825- return NULL ;
2826- }
2827- t2 = PyCurses_ConvertToCell (self , horch , A_NORMAL , 0 , "box" , & ch2 , & wch2 );
2828- if (t2 == 0 ) {
2829- return NULL ;
2839+ for (i = 0 ; i < 2 ; i ++ ) {
2840+ int type = PyCurses_ConvertToCell (self , objs [i ], A_NORMAL , 0 ,
2841+ "box" , & ch [i ], & wch [i ]);
2842+ if (type == 0 ) {
2843+ return NULL ;
2844+ }
2845+ if (type == 2 ) {
2846+ wch_p [i ] = & wch [i ];
2847+ if (PyUnicode_Check (objs [i ])) {
2848+ has_str = 1 ;
2849+ }
2850+ else {
2851+ has_cchar = 1 ;
2852+ }
2853+ }
2854+ else if (!PyLong_CheckExact (objs [i ]) || ch [i ] != 0 ) {
2855+ has_narrow = 1 ; /* b'\0' is a byte character, not the 0 */
2856+ }
28302857 }
28312858 }
2832- if (t1 == 2 || t2 == 2 ) {
2833- if (t1 != 2 || t2 != 2 ) {
2859+ if (has_narrow ) {
2860+ if (has_cchar ) {
28342861 PyErr_SetString (PyExc_TypeError ,
2835- "box() cannot mix integer or bytes characters "
2836- "with wide string characters" );
2862+ "box() cannot mix complexchar characters "
2863+ "with integer or bytes characters" );
28372864 return NULL ;
28382865 }
2839- int rtn = wborder_set (self -> win , & wch1 , & wch1 , & wch2 , & wch2 ,
2840- NULL , NULL , NULL , NULL );
2841- return curses_window_check_err (self , rtn , "wborder_set" , "box" );
2866+ /* Narrow the string characters. */
2867+ for (i = 0 ; i < 2 ; i ++ ) {
2868+ if (PyUnicode_Check (objs [i ]) &&
2869+ !PyCurses_ConvertToChtype (self , objs [i ], & ch [i ]))
2870+ {
2871+ return NULL ;
2872+ }
2873+ }
2874+ }
2875+ else if (has_str || has_cchar ) {
2876+ int rtn = box_set (self -> win , wch_p [0 ], wch_p [1 ]);
2877+ return curses_window_check_err (self , rtn , "box_set" , "box" );
28422878 }
28432879#else
28442880 if (group_right_1 ) {
2845- if (!PyCurses_ConvertToCell (self , verch , A_NORMAL , 0 , "box" , & ch1 )) {
2846- return NULL ;
2847- }
2848- if (!PyCurses_ConvertToCell (self , horch , A_NORMAL , 0 , "box" , & ch2 )) {
2849- return NULL ;
2881+ for (i = 0 ; i < 2 ; i ++ ) {
2882+ if (!PyCurses_ConvertToCell (self , objs [i ], A_NORMAL , 0 , "box" ,
2883+ & ch [i ]))
2884+ {
2885+ return NULL ;
2886+ }
28502887 }
28512888 }
28522889#endif
2853- return curses_window_check_err (self , box (self -> win , ch1 , ch2 ), "box" , NULL );
2890+ return curses_window_check_err (self , box (self -> win , ch [0 ], ch [1 ]),
2891+ "box" , NULL );
28542892}
28552893
28562894#if defined(HAVE_NCURSES_H ) || defined(MVWDELCH_IS_EXPRESSION )
0 commit comments