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
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)
static PyObject *
PyCursesWindow_New(cursesmodule_state *state,
- WINDOW *win, const char *encoding)
+ WINDOW *win, const char *encoding,
+ PyCursesWindowObject *orig)
{
if (encoding == NULL) {
#if defined(MS_WINDOWS)
PyErr_NoMemory();
return NULL;
}
+ wo->orig = orig;
+ Py_XINCREF(orig);
PyObject_GC_Track((PyObject *)wo);
return (PyObject *)wo;
}
if (wo->encoding != NULL) {
PyMem_Free(wo->encoding);
}
+ Py_XDECREF(wo->orig);
window_type->tp_free(self);
Py_DECREF(window_type);
}
PyCursesWindow_traverse(PyObject *self, visitproc visit, void *arg)
{
Py_VISIT(Py_TYPE(self));
+ PyCursesWindowObject *wo = (PyCursesWindowObject *)self;
+ Py_VISIT(wo->orig);
return 0;
}
}
cursesmodule_state *state = get_cursesmodule_state_by_win(self);
- return PyCursesWindow_New(state, win, NULL);
+ return PyCursesWindow_New(state, win, NULL, self);
}
/*[clinic input]
}
cursesmodule_state *state = get_cursesmodule_state_by_win(self);
- return PyCursesWindow_New(state, win, self->encoding);
+ return PyCursesWindow_New(state, win, self->encoding, self);
}
/*[clinic input]
goto error;
}
cursesmodule_state *state = get_cursesmodule_state(module);
- res = PyCursesWindow_New(state, win, NULL);
+ res = PyCursesWindow_New(state, win, NULL, NULL);
error:
fclose(fp);
if (curses_initscr_called) {
wrefresh(stdscr);
cursesmodule_state *state = get_cursesmodule_state(module);
- return PyCursesWindow_New(state, stdscr, NULL);
+ return PyCursesWindow_New(state, stdscr, NULL, NULL);
}
win = initscr();
#undef SetDictInt
cursesmodule_state *state = get_cursesmodule_state(module);
- PyObject *winobj = PyCursesWindow_New(state, win, NULL);
+ PyObject *winobj = PyCursesWindow_New(state, win, NULL, NULL);
if (winobj == NULL) {
return NULL;
}
}
cursesmodule_state *state = get_cursesmodule_state(module);
- return PyCursesWindow_New(state, win, NULL);
+ return PyCursesWindow_New(state, win, NULL, NULL);
}
/*[clinic input]
}
cursesmodule_state *state = get_cursesmodule_state(module);
- return PyCursesWindow_New(state, win, NULL);
+ return PyCursesWindow_New(state, win, NULL, NULL);
}
/*[clinic input]