Skip to content

Commit 97695e5

Browse files
committed
add helper for parsing (x, y) coordinates and optional length
1 parent 8e818e1 commit 97695e5

File tree

1 file changed

+39
-2
lines changed

1 file changed

+39
-2
lines changed

Modules/_cursesmodule.c

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1803,8 +1803,45 @@ _curses_window_get_wch_impl(PyCursesWindowObject *self, int group_right_1,
18031803
}
18041804
#endif
18051805

1806-
/*[-clinic input]
1807-
_curses.window.getstr
1806+
/*
1807+
* Helper function for parsing parameters from getstr() and instr().
1808+
* This function is necessary because Argument Clinic does not know
1809+
* how to handle nested optional groups with default values inside.
1810+
*
1811+
* Return 1 on success and 0 on failure, similar to PyArg_ParseTuple().
1812+
*/
1813+
static int
1814+
curses_clinic_parse_optional_xy_n(PyObject *args,
1815+
int *y, int *x, unsigned int *n, int *use_xy,
1816+
const char *qualname)
1817+
{
1818+
switch (PyTuple_GET_SIZE(args)) {
1819+
case 0: {
1820+
*use_xy = 0;
1821+
return 1;
1822+
}
1823+
case 1: {
1824+
*use_xy = 0;
1825+
return PyArg_ParseTuple(args, "O&;n",
1826+
_PyLong_UnsignedInt_Converter, n);
1827+
}
1828+
case 2: {
1829+
*use_xy = 1;
1830+
return PyArg_ParseTuple(args, "ii;y,x", y, x);
1831+
}
1832+
case 3: {
1833+
*use_xy = 1;
1834+
return PyArg_ParseTuple(args, "iiO&;y,x,n", y, x,
1835+
_PyLong_UnsignedInt_Converter, n);
1836+
}
1837+
default: {
1838+
*use_xy = 0;
1839+
PyErr_Format(PyExc_TypeError, "%s requires 0 to 3 arguments",
1840+
qualname);
1841+
return 0;
1842+
}
1843+
}
1844+
}
18081845

18091846
[
18101847
y: int

0 commit comments

Comments
 (0)