[3.13] bpo-44172: Keep reference to original window in curses subwindow objects (GH-26226) by serhiy-storchaka · Pull Request #133370 · python/cpython · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion Include/py_curses.h
11 changes: 10 additions & 1 deletion Lib/test/test_curses.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
from unittest.mock import MagicMock

from test.support import (requires, verbose, SaveSignals, cpython_only,
check_disallow_instantiation, MISSING_C_DOCSTRINGS)
check_disallow_instantiation, MISSING_C_DOCSTRINGS,
gc_collect)
from test.support.import_helper import import_module

# Optionally test curses module. This currently requires that the
Expand Down Expand Up @@ -187,6 +188,14 @@ def test_create_windows(self):
self.assertEqual(win3.getparyx(), (2, 1))
self.assertEqual(win3.getmaxyx(), (6, 11))

def test_subwindows_references(self):
win = curses.newwin(5, 10)
win2 = win.subwin(3, 7)
del win
gc_collect()
del win2
gc_collect()

def test_move_cursor(self):
stdscr = self.stdscr
win = stdscr.subwin(10, 15, 2, 5)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Keep a reference to original :mod:`curses` windows in subwindows so
that the original window does not get deleted before subwindows.
20 changes: 12 additions & 8 deletions Modules/_cursesmodule.c