gh-134208: remove dead AC directives for _curses.window.{chgat,getstr,instr} (#134325)

This commit is contained in:
Bénédikt Tran 2025-05-26 10:52:19 +02:00 committed by GitHub
parent fb09db1b93
commit 29e8115964
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1429,32 +1429,27 @@ int py_mvwdelch(WINDOW *w, int y, int x)
/* chgat, added by Fabian Kreutz <fabian.kreutz at gmx.net> */ /* chgat, added by Fabian Kreutz <fabian.kreutz at gmx.net> */
#ifdef HAVE_CURSES_WCHGAT #ifdef HAVE_CURSES_WCHGAT
/*[-clinic input]
_curses.window.chgat
[ PyDoc_STRVAR(_curses_window_chgat__doc__,
y: int "chgat([y, x,] [n=-1,] attr)\n"
Y-coordinate. "Set the attributes of characters.\n"
x: int "\n"
X-coordinate. " y\n"
] " Y-coordinate.\n"
" x\n"
" X-coordinate.\n"
" n\n"
" Number of characters.\n"
" attr\n"
" Attributes for characters.\n"
"\n"
"Set the attributes of num characters at the current cursor position, or at\n"
"position (y, x) if supplied. If no value of num is given or num = -1, the\n"
"attribute will be set on all the characters to the end of the line. This\n"
"function does not move the cursor. The changed line will be touched using\n"
"the touchline() method so that the contents will be redisplayed by the next\n"
"window refresh.");
n: int = -1
Number of characters.
attr: long
Attributes for characters.
/
Set the attributes of characters.
Set the attributes of num characters at the current cursor position, or at
position (y, x) if supplied. If no value of num is given or num = -1, the
attribute will be set on all the characters to the end of the line. This
function does not move the cursor. The changed line will be touched using
the touchline() method so that the contents will be redisplayed by the next
window refresh.
[-clinic start generated code]*/
static PyObject * static PyObject *
PyCursesWindow_ChgAt(PyObject *op, PyObject *args) PyCursesWindow_ChgAt(PyObject *op, PyObject *args)
{ {
@ -1481,19 +1476,20 @@ PyCursesWindow_ChgAt(PyObject *op, PyObject *args)
attr = lattr; attr = lattr;
break; break;
case 3: case 3:
if (!PyArg_ParseTuple(args,"iil;int,int,attr", &y, &x, &lattr)) if (!PyArg_ParseTuple(args,"iil;y,x,attr", &y, &x, &lattr))
return NULL; return NULL;
attr = lattr; attr = lattr;
use_xy = TRUE; use_xy = TRUE;
break; break;
case 4: case 4:
if (!PyArg_ParseTuple(args,"iiil;int,int,n,attr", &y, &x, &num, &lattr)) if (!PyArg_ParseTuple(args,"iiil;y,x,n,attr", &y, &x, &num, &lattr))
return NULL; return NULL;
attr = lattr; attr = lattr;
use_xy = TRUE; use_xy = TRUE;
break; break;
default: default:
PyErr_SetString(PyExc_TypeError, "chgat requires 1 to 4 arguments"); PyErr_SetString(PyExc_TypeError,
"_curses.window.chgat requires 1 to 4 arguments");
return NULL; return NULL;
} }
@ -1807,102 +1803,102 @@ _curses_window_get_wch_impl(PyCursesWindowObject *self, int group_right_1,
} }
#endif #endif
/*[-clinic input] /*
_curses.window.getstr * Helper function for parsing parameters from getstr() and instr().
* This function is necessary because Argument Clinic does not know
* how to handle nested optional groups with default values inside.
*
* Return 1 on success and 0 on failure, similar to PyArg_ParseTuple().
*/
static int
curses_clinic_parse_optional_xy_n(PyObject *args,
int *y, int *x, unsigned int *n, int *use_xy,
const char *qualname)
{
switch (PyTuple_GET_SIZE(args)) {
case 0: {
*use_xy = 0;
return 1;
}
case 1: {
*use_xy = 0;
return PyArg_ParseTuple(args, "O&;n",
_PyLong_UnsignedInt_Converter, n);
}
case 2: {
*use_xy = 1;
return PyArg_ParseTuple(args, "ii;y,x", y, x);
}
case 3: {
*use_xy = 1;
return PyArg_ParseTuple(args, "iiO&;y,x,n", y, x,
_PyLong_UnsignedInt_Converter, n);
}
default: {
*use_xy = 0;
PyErr_Format(PyExc_TypeError, "%s requires 0 to 3 arguments",
qualname);
return 0;
}
}
}
[ PyDoc_STRVAR(_curses_window_getstr__doc__,
y: int "getstr([[y, x,] n=2047])\n"
Y-coordinate. "Read a string from the user, with primitive line editing capacity.\n"
x: int "\n"
X-coordinate. " y\n"
] " Y-coordinate.\n"
n: int = 2047 " x\n"
Maximal number of characters. " X-coordinate.\n"
/ " n\n"
" Maximal number of characters.");
Read a string from the user, with primitive line editing capacity.
[-clinic start generated code]*/
static PyObject * static PyObject *
PyCursesWindow_GetStr(PyObject *op, PyObject *args) PyCursesWindow_getstr(PyObject *op, PyObject *args)
{ {
PyCursesWindowObject *self = _PyCursesWindowObject_CAST(op); PyCursesWindowObject *self = _PyCursesWindowObject_CAST(op);
int rtn, use_xy = 0, y = 0, x = 0;
unsigned int max_buf_size = 2048;
unsigned int n = max_buf_size - 1;
PyObject *res;
int x, y, n; if (!curses_clinic_parse_optional_xy_n(args, &y, &x, &n, &use_xy,
int rtn; "_curses.window.instr"))
{
/* could make the buffer size larger/dynamic */
Py_ssize_t max_buf_size = 2048;
PyObject *result = PyBytes_FromStringAndSize(NULL, max_buf_size);
if (result == NULL)
return NULL; return NULL;
char *buf = PyBytes_AS_STRING(result); }
switch (PyTuple_Size(args)) { n = Py_MIN(n, max_buf_size - 1);
case 0: res = PyBytes_FromStringAndSize(NULL, n + 1);
Py_BEGIN_ALLOW_THREADS if (res == NULL) {
rtn = wgetnstr(self->win, buf, max_buf_size - 1); return NULL;
Py_END_ALLOW_THREADS }
break; char *buf = PyBytes_AS_STRING(res);
case 1:
if (!PyArg_ParseTuple(args,"i;n", &n)) if (use_xy) {
goto error;
if (n < 0) {
PyErr_SetString(PyExc_ValueError, "'n' must be nonnegative");
goto error;
}
Py_BEGIN_ALLOW_THREADS
rtn = wgetnstr(self->win, buf, Py_MIN(n, max_buf_size - 1));
Py_END_ALLOW_THREADS
break;
case 2:
if (!PyArg_ParseTuple(args,"ii;y,x",&y,&x))
goto error;
Py_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
#ifdef STRICT_SYSV_CURSES #ifdef STRICT_SYSV_CURSES
rtn = wmove(self->win,y,x)==ERR ? ERR : wgetnstr(self->win, rtn, max_buf_size - 1); rtn = wmove(self->win, y, x) == ERR
? ERR
: wgetnstr(self->win, buf, n);
#else #else
rtn = mvwgetnstr(self->win,y,x,buf, max_buf_size - 1); rtn = mvwgetnstr(self->win, y, x, buf, n);
#endif #endif
Py_END_ALLOW_THREADS Py_END_ALLOW_THREADS
break; }
case 3: else {
if (!PyArg_ParseTuple(args,"iii;y,x,n", &y, &x, &n))
goto error;
if (n < 0) {
PyErr_SetString(PyExc_ValueError, "'n' must be nonnegative");
goto error;
}
#ifdef STRICT_SYSV_CURSES
Py_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
rtn = wmove(self->win,y,x)==ERR ? ERR : rtn = wgetnstr(self->win, buf, n);
wgetnstr(self->win, rtn, Py_MIN(n, max_buf_size - 1));
Py_END_ALLOW_THREADS Py_END_ALLOW_THREADS
#else
Py_BEGIN_ALLOW_THREADS
rtn = mvwgetnstr(self->win, y, x, buf, Py_MIN(n, max_buf_size - 1));
Py_END_ALLOW_THREADS
#endif
break;
default:
PyErr_SetString(PyExc_TypeError, "getstr requires 0 to 3 arguments");
goto error;
} }
if (rtn == ERR) { if (rtn == ERR) {
Py_DECREF(result); Py_DECREF(res);
return Py_GetConstant(Py_CONSTANT_EMPTY_BYTES); return Py_GetConstant(Py_CONSTANT_EMPTY_BYTES);
} }
_PyBytes_Resize(&res, strlen(buf)); // 'res' is set to NULL on failure
if (_PyBytes_Resize(&result, strlen(buf)) < 0) { return res;
return NULL;
}
return result;
error:
Py_DECREF(result);
return NULL;
} }
/*[clinic input] /*[clinic input]
@ -2032,87 +2028,57 @@ _curses_window_inch_impl(PyCursesWindowObject *self, int group_right_1,
return rtn; return rtn;
} }
/*[-clinic input] PyDoc_STRVAR(_curses_window_instr__doc__,
_curses.window.instr "instr([y, x,] n=2047)\n"
"Return a string of characters, extracted from the window.\n"
"\n"
" y\n"
" Y-coordinate.\n"
" x\n"
" X-coordinate.\n"
" n\n"
" Maximal number of characters.\n"
"\n"
"Return a string of characters, extracted from the window starting at the\n"
"current cursor position, or at y, x if specified. Attributes are stripped\n"
"from the characters. If n is specified, instr() returns a string at most\n"
"n characters long (exclusive of the trailing NUL).");
[
y: int
Y-coordinate.
x: int
X-coordinate.
]
n: int = 2047
Maximal number of characters.
/
Return a string of characters, extracted from the window.
Return a string of characters, extracted from the window starting at the
current cursor position, or at y, x if specified. Attributes are stripped
from the characters. If n is specified, instr() returns a string at most
n characters long (exclusive of the trailing NUL).
[-clinic start generated code]*/
static PyObject * static PyObject *
PyCursesWindow_InStr(PyObject *op, PyObject *args) PyCursesWindow_instr(PyObject *op, PyObject *args)
{ {
PyCursesWindowObject *self = _PyCursesWindowObject_CAST(op); PyCursesWindowObject *self = _PyCursesWindowObject_CAST(op);
int rtn, use_xy = 0, y = 0, x = 0;
unsigned int max_buf_size = 2048;
unsigned int n = max_buf_size - 1;
PyObject *res;
int x, y, n; if (!curses_clinic_parse_optional_xy_n(args, &y, &x, &n, &use_xy,
int rtn; "_curses.window.instr"))
{
/* could make the buffer size larger/dynamic */
Py_ssize_t max_buf_size = 2048;
PyObject *result = PyBytes_FromStringAndSize(NULL, max_buf_size);
if (result == NULL)
return NULL; return NULL;
char *buf = PyBytes_AS_STRING(result); }
switch (PyTuple_Size(args)) { n = Py_MIN(n, max_buf_size - 1);
case 0: res = PyBytes_FromStringAndSize(NULL, n + 1);
rtn = winnstr(self->win, buf, max_buf_size - 1); if (res == NULL) {
break; return NULL;
case 1: }
if (!PyArg_ParseTuple(args,"i;n", &n)) char *buf = PyBytes_AS_STRING(res);
goto error;
if (n < 0) { if (use_xy) {
PyErr_SetString(PyExc_ValueError, "'n' must be nonnegative"); rtn = mvwinnstr(self->win, y, x, buf, n);
goto error; }
} else {
rtn = winnstr(self->win, buf, Py_MIN(n, max_buf_size - 1)); rtn = winnstr(self->win, buf, n);
break;
case 2:
if (!PyArg_ParseTuple(args,"ii;y,x",&y,&x))
goto error;
rtn = mvwinnstr(self->win, y, x, buf, max_buf_size - 1);
break;
case 3:
if (!PyArg_ParseTuple(args, "iii;y,x,n", &y, &x, &n))
goto error;
if (n < 0) {
PyErr_SetString(PyExc_ValueError, "'n' must be nonnegative");
goto error;
}
rtn = mvwinnstr(self->win, y, x, buf, Py_MIN(n, max_buf_size - 1));
break;
default:
PyErr_SetString(PyExc_TypeError, "instr requires 0 or 3 arguments");
goto error;
} }
if (rtn == ERR) { if (rtn == ERR) {
Py_DECREF(result); Py_DECREF(res);
return Py_GetConstant(Py_CONSTANT_EMPTY_BYTES); return Py_GetConstant(Py_CONSTANT_EMPTY_BYTES);
} }
_PyBytes_Resize(&res, strlen(buf)); // 'res' is set to NULL on failure
if (_PyBytes_Resize(&result, strlen(buf)) < 0) { return res;
return NULL;
}
return result;
error:
Py_DECREF(result);
return NULL;
} }
/*[clinic input] /*[clinic input]
@ -2854,7 +2820,10 @@ static PyMethodDef PyCursesWindow_methods[] = {
_CURSES_WINDOW_ATTRSET_METHODDEF _CURSES_WINDOW_ATTRSET_METHODDEF
_CURSES_WINDOW_BKGD_METHODDEF _CURSES_WINDOW_BKGD_METHODDEF
#ifdef HAVE_CURSES_WCHGAT #ifdef HAVE_CURSES_WCHGAT
{"chgat", PyCursesWindow_ChgAt, METH_VARARGS}, {
"chgat", PyCursesWindow_ChgAt, METH_VARARGS,
_curses_window_chgat__doc__
},
#endif #endif
_CURSES_WINDOW_BKGDSET_METHODDEF _CURSES_WINDOW_BKGDSET_METHODDEF
_CURSES_WINDOW_BORDER_METHODDEF _CURSES_WINDOW_BORDER_METHODDEF
@ -2877,7 +2846,10 @@ static PyMethodDef PyCursesWindow_methods[] = {
_CURSES_WINDOW_GET_WCH_METHODDEF _CURSES_WINDOW_GET_WCH_METHODDEF
{"getmaxyx", PyCursesWindow_getmaxyx, METH_NOARGS}, {"getmaxyx", PyCursesWindow_getmaxyx, METH_NOARGS},
{"getparyx", PyCursesWindow_getparyx, METH_NOARGS}, {"getparyx", PyCursesWindow_getparyx, METH_NOARGS},
{"getstr", PyCursesWindow_GetStr, METH_VARARGS}, {
"getstr", PyCursesWindow_getstr, METH_VARARGS,
_curses_window_getstr__doc__
},
{"getyx", PyCursesWindow_getyx, METH_NOARGS}, {"getyx", PyCursesWindow_getyx, METH_NOARGS},
_CURSES_WINDOW_HLINE_METHODDEF _CURSES_WINDOW_HLINE_METHODDEF
{"idcok", PyCursesWindow_idcok, METH_VARARGS}, {"idcok", PyCursesWindow_idcok, METH_VARARGS},
@ -2891,7 +2863,10 @@ static PyMethodDef PyCursesWindow_methods[] = {
{"insertln", PyCursesWindow_winsertln, METH_NOARGS}, {"insertln", PyCursesWindow_winsertln, METH_NOARGS},
_CURSES_WINDOW_INSNSTR_METHODDEF _CURSES_WINDOW_INSNSTR_METHODDEF
_CURSES_WINDOW_INSSTR_METHODDEF _CURSES_WINDOW_INSSTR_METHODDEF
{"instr", PyCursesWindow_InStr, METH_VARARGS}, {
"instr", PyCursesWindow_instr, METH_VARARGS,
_curses_window_instr__doc__
},
_CURSES_WINDOW_IS_LINETOUCHED_METHODDEF _CURSES_WINDOW_IS_LINETOUCHED_METHODDEF
{"is_wintouched", PyCursesWindow_is_wintouched, METH_NOARGS}, {"is_wintouched", PyCursesWindow_is_wintouched, METH_NOARGS},
{"keypad", PyCursesWindow_keypad, METH_VARARGS}, {"keypad", PyCursesWindow_keypad, METH_VARARGS},