@@ -1695,6 +1695,14 @@ _curses_window_getch_impl(PyCursesWindowObject *self, int group_right_1,
16951695 }
16961696 Py_END_ALLOW_THREADS
16971697
1698+ /* getch() returns ERR in nodelay mode */
1699+ if (PyErr_CheckSignals ()) {
1700+ cursesmodule_state * state = get_cursesmodule_state_by_win (self );
1701+ const char * funcname = group_right_1 ? "mvwgetch" : "wgetch" ;
1702+ PyErr_Format (state -> error , "getch(): %s(): no input" , funcname );
1703+ return ERR ;
1704+ }
1705+
16981706 return rtn ;
16991707}
17001708
@@ -2042,12 +2050,16 @@ PyCursesWindow_InStr(PyObject *op, PyObject *args)
20422050 PyCursesWindowObject * self = _PyCursesWindowObject_CAST (op );
20432051
20442052 int x , y , n ;
2045- char rtn [1024 ]; /* This should be big enough.. I hope */
2046- int rtn2 ;
2053+ int err_code ;
2054+
2055+ /* could make the buffer size larger/dynamic */
2056+ const int max_buf_size = 2048 ;
2057+ PyObject * result = PyBytes_FromStringAndSize (NULL , max_buf_size );
2058+ char * buf = PyBytes_AS_STRING (result );
20472059
20482060 switch (PyTuple_Size (args )) {
20492061 case 0 :
2050- rtn2 = winnstr (self -> win ,rtn , 1023 );
2062+ err_code = winnstr (self -> win , buf , max_buf_size - 1 );
20512063 break ;
20522064 case 1 :
20532065 if (!PyArg_ParseTuple (args ,"i;n" , & n ))
@@ -2056,12 +2068,12 @@ PyCursesWindow_InStr(PyObject *op, PyObject *args)
20562068 PyErr_SetString (PyExc_ValueError , "'n' must be nonnegative" );
20572069 return NULL ;
20582070 }
2059- rtn2 = winnstr (self -> win , rtn , Py_MIN (n , 1023 ));
2071+ err_code = winnstr (self -> win , buf , Py_MIN (n , max_buf_size - 1 ));
20602072 break ;
20612073 case 2 :
20622074 if (!PyArg_ParseTuple (args ,"ii;y,x" ,& y ,& x ))
20632075 return NULL ;
2064- rtn2 = mvwinnstr (self -> win ,y , x , rtn , 1023 );
2076+ err_code = mvwinnstr (self -> win , y , x , buf , max_buf_size - 1 );
20652077 break ;
20662078 case 3 :
20672079 if (!PyArg_ParseTuple (args , "iii;y,x,n" , & y , & x , & n ))
@@ -2070,15 +2082,19 @@ PyCursesWindow_InStr(PyObject *op, PyObject *args)
20702082 PyErr_SetString (PyExc_ValueError , "'n' must be nonnegative" );
20712083 return NULL ;
20722084 }
2073- rtn2 = mvwinnstr (self -> win , y , x , rtn , Py_MIN (n ,1023 ));
2085+ err_code = mvwinnstr (self -> win , y , x , buf , Py_MIN (n , max_buf_size - 1 ));
20742086 break ;
20752087 default :
20762088 PyErr_SetString (PyExc_TypeError , "instr requires 0 or 3 arguments" );
20772089 return NULL ;
20782090 }
2079- if (rtn2 == ERR )
2080- rtn [0 ] = 0 ;
2081- return PyBytes_FromString (rtn );
2091+ if (err_code == ERR )
2092+ buf [0 ] = '\0' ;
2093+
2094+ size_t size = strlen (buf );
2095+ _PyBytes_Resize (& result , size );
2096+
2097+ return result ;
20822098}
20832099
20842100/*[clinic input]
0 commit comments