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)
/* Allocation and deallocation of Window Objects */
static PyObject *
-PyCursesWindow_New(WINDOW *win, const char *encoding)
+PyCursesWindow_New(WINDOW *win, const char *encoding,
+ PyCursesWindowObject *orig)
{
PyCursesWindowObject *wo;
PyErr_NoMemory();
return NULL;
}
+ wo->orig = orig;
+ Py_XINCREF(orig);
return (PyObject *)wo;
}
if (wo->win != stdscr) delwin(wo->win);
if (wo->encoding != NULL)
PyMem_Free(wo->encoding);
+ Py_XDECREF(wo->orig);
PyObject_Free(wo);
}
return NULL;
}
- return (PyObject *)PyCursesWindow_New(win, NULL);
+ return (PyObject *)PyCursesWindow_New(win, NULL, self);
}
/*[clinic input]
return NULL;
}
- return (PyObject *)PyCursesWindow_New(win, self->encoding);
+ return (PyObject *)PyCursesWindow_New(win, self->encoding, self);
}
/*[clinic input]
PyErr_SetString(PyCursesError, catchall_NULL);
goto error;
}
- res = PyCursesWindow_New(win, NULL);
+ res = PyCursesWindow_New(win, NULL, NULL);
error:
fclose(fp);
if (initialised) {
wrefresh(stdscr);
- return (PyObject *)PyCursesWindow_New(stdscr, NULL);
+ return (PyObject *)PyCursesWindow_New(stdscr, NULL, NULL);
}
win = initscr();
SetDictInt("LINES", LINES);
SetDictInt("COLS", COLS);
- winobj = (PyCursesWindowObject *)PyCursesWindow_New(win, NULL);
+ winobj = (PyCursesWindowObject *)PyCursesWindow_New(win, NULL, NULL);
screen_encoding = winobj->encoding;
return (PyObject *)winobj;
}
return NULL;
}
- return (PyObject *)PyCursesWindow_New(win, NULL);
+ return (PyObject *)PyCursesWindow_New(win, NULL, NULL);
}
/*[clinic input]
return NULL;
}
- return (PyObject *)PyCursesWindow_New(win, NULL);
+ return (PyObject *)PyCursesWindow_New(win, NULL, NULL);
}
/*[clinic input]