8000 bpo-44172: Keep reference to original window in curses subwindow objects by michaelforney · Pull Request #26226 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-44172: Keep reference to original window in curses subwindow objects #26226

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 4, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge branch 'main' into curses-orig
  • Loading branch information
serhiy-storchaka committed Apr 12, 2025
commit 423bf28b4c25d22f172019c5d250b59c0d8cb871
43 changes: 32 additions & 11 deletions Modules/_cursesmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,8 @@ Window_TwoArgNoReturnFunction(wresize, int, "ii;lines,columns")
/* Allocation and deallocation of Window Objects */

static PyObject *
PyCursesWindow_New(WINDOW *win, const char *encoding,
PyCursesWindow_New(cursesmodule_state *state,
WINDOW *win, const char *encoding,
PyCursesWindowObject *orig)
{
if (encoding == NULL) {
Expand Down Expand Up @@ -823,6 +824,7 @@ PyCursesWindow_New(WINDOW *win, const char *encoding,
}
wo->orig = orig;
Py_XINCREF(orig);
PyObject_GC_Track((PyObject *)wo);
return (PyObject *)wo;
}

Expand All @@ -838,8 +840,17 @@ PyCursesWindow_dealloc(PyObject *self)
}
if (wo->encoding != NULL) {
PyMem_Free(wo->encoding);
}
Py_XDECREF(wo->orig);
PyObject_Free(wo);
window_type->tp_free(self);
Py_DECREF(window_type);
}

static int
PyCursesWindow_traverse(PyObject *self, visitproc visit, void *arg)
{
Py_VISIT(Py_TYPE(self));
return 0;
}

/* Addch, Addstr, Addnstr */
Expand Down Expand Up @@ -1445,7 +1456,8 @@ _curses_window_derwin_impl(PyCursesWindowObject *self, int group_left_1,
return NULL;
}

return (PyObject *)PyCursesWindow_New(win, NULL, self);
cursesmodule_state *state = get_cursesmodule_state_by_win(self);
return PyCursesWindow_New(state, win, NULL, self);
}

/*[clinic input]
Expand Down Expand Up @@ -2484,7 +2496,8 @@ _curses_window_subwin_impl(PyCursesWindowObject *self, int group_left_1,
return NULL;
}

return (PyObject *)PyCursesWindow_New(win, self->encoding, self);
cursesmodule_state *state = get_cursesmodule_state_by_win(self);
return PyCursesWindow_New(state, win, self->encoding, self);
}

/*[clinic input]
Expand Down Expand Up @@ -3227,7 +3240,8 @@ _curses_getwin(PyObject *module, PyObject *file)
PyErr_SetString(state->error, catchall_NULL);
goto error;
}
res = PyCursesWindow_New(win, NULL, NULL);
cursesmodule_state *state = get_cursesmodule_state(module);
res = PyCursesWindow_New(state, win, NULL, NULL);

error:
fclose(fp);
Expand Down Expand Up @@ -3399,7 +3413,8 @@ _curses_initscr_impl(PyObject *module)

if (curses_initscr_called) {
wrefresh(stdscr);
return (PyObject *)PyCursesWindow_New(stdscr, NULL, NULL);
cursesmodule_state *state = get_cursesmodule_state(module);
return PyCursesWindow_New(state, stdscr, NULL, NULL);
}

win = initscr();
Expand Down Expand Up @@ -3502,9 +3517,13 @@ _curses_initscr_impl(PyObject *module)
SetDictInt("COLS", COLS);
#undef SetDictInt

winobj = (PyCursesWindowObject *)PyCursesWindow_New(win, NULL, NULL);
screen_encoding = winobj->encoding;
return (PyObject *)winobj;
cursesmodule_state *state = get_cursesmodule_state(module);
PyObject *winobj = PyCursesWindow_New(state, win, NULL, NULL);
if (winobj == NULL) {
return NULL;
}
curses_screen_encoding = ((PyCursesWindowObject *)winobj)->encoding;
return winobj;
}

/*[clinic input]
Expand Down Expand Up @@ -3882,7 +3901,8 @@ _curses_newpad_impl(PyObject *module, int nlines, int ncols)
return NULL;
}

return (PyObject *)PyCursesWindow_New(win, NULL, NULL);
cursesmodule_state *state = get_cursesmodule_state(module);
return PyCursesWindow_New(state, win, NULL, NULL);
}

/*[clinic input]
Expand Down Expand Up @@ -3922,7 +3942,8 @@ _curses_newwin_impl(PyObject *module, int nlines, int ncols,
return NULL;
}

return (PyObject *)PyCursesWindow_New(win, NULL, NULL);
cursesmodule_state *state = get_cursesmodule_state(module);
return PyCursesWindow_New(state, win, NULL, NULL);
}

/*[clinic input]
Expand Down
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.
0