https://github.com/python/cpython/commit/cfe3e07f546d84b04ae2cab4dc464701d610dd02
commit: cfe3e07f546d84b04ae2cab4dc464701d610dd02
branch: main
author: Bénédikt Tran <[email protected]>
committer: picnixz <[email protected]>
date: 2026-07-04T12:21:16+02:00
summary:

gh-153009: Fix compilation of `curses` on platforms that define the `stdscr` 
macro (#153010)

files:
A Misc/NEWS.d/next/Library/2026-07-04-11-26-24.gh-issue-153009.KGl-nQ.rst
M Include/py_curses.h
M Modules/_cursesmodule.c

diff --git a/Include/py_curses.h b/Include/py_curses.h
index 23e67c4e6e634d..a5f5f3d7607582 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 00000000000000..a8a74caa41042a
--- /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 03e399b252fcfb..cc68a51f0bed93 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;

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to