Skip to content

Commit 187785e

Browse files
[3.8] bpo-36589: Fix the error handling in curses.update_lines_cols(). (GH-12766) (GH-24023)
Return None instead of 1. (cherry picked from commit 2bc3434) Co-authored-by: Zackery Spytz <zspytz@gmail.com>
1 parent 1a544e1 commit 187785e

3 files changed

Lines changed: 26 additions & 21 deletions

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
The :func:`curses.update_lines_cols` function now returns ``None`` instead
2+
of ``1`` on success.

Modules/_cursesmodule.c

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3757,15 +3757,18 @@ update_lines_cols(void)
37573757
}
37583758

37593759
/*[clinic input]
3760-
_curses.update_lines_cols -> int
3760+
_curses.update_lines_cols
37613761
37623762
[clinic start generated code]*/
37633763

3764-
static int
3764+
static PyObject *
37653765
_curses_update_lines_cols_impl(PyObject *module)
3766-
/*[clinic end generated code: output=0345e7f072ea711a input=3a87760f7d5197f0]*/
3766+
/*[clinic end generated code: output=423f2b1e63ed0f75 input=5f065ab7a28a5d90]*/
37673767
{
3768-
return update_lines_cols();
3768+
if (!update_lines_cols()) {
3769+
return NULL;
3770+
}
3771+
Py_RETURN_NONE;
37693772
}
37703773

37713774
#endif
@@ -3849,8 +3852,10 @@ _curses_resizeterm_impl(PyObject *module, int nlines, int ncols)
38493852
result = PyCursesCheckERR(resizeterm(nlines, ncols), "resizeterm");
38503853
if (!result)
38513854
return NULL;
3852-
if (!update_lines_cols())
3855+
if (!update_lines_cols()) {
3856+
Py_DECREF(result);
38533857
return NULL;
3858+
}
38543859
return result;
38553860
}
38563861

@@ -3886,8 +3891,10 @@ _curses_resize_term_impl(PyObject *module, int nlines, int ncols)
38863891
result = PyCursesCheckERR(resize_term(nlines, ncols), "resize_term");
38873892
if (!result)
38883893
return NULL;
3889-
if (!update_lines_cols())
3894+
if (!update_lines_cols()) {
3895+
Py_DECREF(result);
38903896
return NULL;
3897+
}
38913898
return result;
38923899
}
38933900
#endif /* HAVE_CURSES_RESIZE_TERM */
@@ -3958,12 +3965,18 @@ _curses_start_color_impl(PyObject *module)
39583965
c = PyLong_FromLong((long) COLORS);
39593966
if (c == NULL)
39603967
return NULL;
3961-
PyDict_SetItemString(ModDict, "COLORS", c);
3968+
if (PyDict_SetItemString(ModDict, "COLORS", c) < 0) {
3969+
Py_DECREF(c);
3970+
return NULL;
3971+
}
39623972
Py_DECREF(c);
39633973
cp = PyLong_FromLong((long) COLOR_PAIRS);
39643974
if (cp == NULL)
39653975
return NULL;
3966-
PyDict_SetItemString(ModDict, "COLOR_PAIRS", cp);
3976+
if (PyDict_SetItemString(ModDict, "COLOR_PAIRS", cp) < 0) {
3977+
Py_DECREF(cp);
3978+
return NULL;
3979+
}
39673980
Py_DECREF(cp);
39683981
Py_RETURN_NONE;
39693982
} else {

Modules/clinic/_cursesmodule.c.h

Lines changed: 3 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)