diff --git a/Include/py_curses.h b/Include/py_curses.h index 23e67c4e6e634d0..a5f5f3d76075827 100644 --- a/Include/py_curses.h +++ b/Include/py_curses.h @@ -96,7 +96,7 @@ typedef struct { SCREEN *screen; /* NULL after the screen has been deleted */ FILE *outfp; /* owned output stream, or NULL */ FILE *infp; /* owned input stream, or NULL */ - PyObject *stdscr; /* the screen's standard window, or NULL */ + PyObject *stdscr_win; /* the screen's standard window, or NULL */ } PyCursesScreenObject; #define PyCurses_CAPSULE_NAME "_curses._C_API" diff --git a/Misc/NEWS.d/next/Library/2026-07-04-11-26-24.gh-issue-153009.KGl-nQ.rst b/Misc/NEWS.d/next/Library/2026-07-04-11-26-24.gh-issue-153009.KGl-nQ.rst new file mode 100644 index 000000000000000..a8a74caa41042ac --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-07-04-11-26-24.gh-issue-153009.KGl-nQ.rst @@ -0,0 +1,2 @@ +Fix compilation of :mod:`curses` on platforms that define the ``stdscr`` +macro. Patch by Bénédikt Tran. diff --git a/Modules/_cursesmodule.c b/Modules/_cursesmodule.c index 03e399b252fcfb2..cc68a51f0bed935 100644 --- a/Modules/_cursesmodule.c +++ b/Modules/_cursesmodule.c @@ -5125,7 +5125,7 @@ static PyType_Spec PyCursesWindow_Type_spec = { static PyObject * PyCursesScreen_New(cursesmodule_state *state, SCREEN *screen, - FILE *outfp, FILE *infp, PyObject *stdscr) + FILE *outfp, FILE *infp, PyObject *stdscr_win) { PyCursesScreenObject *so = PyObject_GC_New(PyCursesScreenObject, state->screen_type); @@ -5135,7 +5135,7 @@ PyCursesScreen_New(cursesmodule_state *state, SCREEN *screen, so->screen = screen; so->outfp = outfp; so->infp = infp; - so->stdscr = Py_XNewRef(stdscr); + so->stdscr_win = Py_XNewRef(stdscr_win); PyObject_GC_Track((PyObject *)so); return (PyObject *)so; } @@ -5169,17 +5169,17 @@ static PyObject * PyCursesScreen_get_stdscr(PyObject *self, void *Py_UNUSED(closure)) { PyCursesScreenObject *so = _PyCursesScreenObject_CAST(self); - if (so->stdscr == NULL) { + if (so->stdscr_win == NULL) { Py_RETURN_NONE; } - return Py_NewRef(so->stdscr); + return Py_NewRef(so->stdscr_win); } static int PyCursesScreen_traverse(PyObject *self, visitproc visit, void *arg) { Py_VISIT(Py_TYPE(self)); - Py_VISIT(_PyCursesScreenObject_CAST(self)->stdscr); + Py_VISIT(_PyCursesScreenObject_CAST(self)->stdscr_win); return 0; } @@ -5194,10 +5194,10 @@ PyCursesScreen_clear(PyObject *self) detach it from its wrapper first: the wrapper must not delwin() a window that delscreen() frees. Any further use of the wrapper operates on a NULL window and fails cleanly. */ - if (so->stdscr != NULL) { - ((PyCursesWindowObject *)so->stdscr)->win = NULL; + if (so->stdscr_win != NULL) { + ((PyCursesWindowObject *)so->stdscr_win)->win = NULL; } - Py_CLEAR(so->stdscr); + Py_CLEAR(so->stdscr_win); return 0; } @@ -6724,7 +6724,7 @@ _curses_newterm_impl(PyObject *module, const char *type, PyObject *fd, Py_DECREF(screenobj); return NULL; } - ((PyCursesScreenObject *)screenobj)->stdscr = Py_NewRef(win); + ((PyCursesScreenObject *)screenobj)->stdscr_win = Py_NewRef(win); Py_DECREF(win); Py_XSETREF(state->topscreen, Py_NewRef(screenobj)); return screenobj;