@@ -787,7 +787,8 @@ Window_TwoArgNoReturnFunction(wresize, int, "ii;lines,columns")
787787
788788static PyObject *
789789PyCursesWindow_New (cursesmodule_state * state ,
790- WINDOW * win , const char * encoding )
790+ WINDOW * win , const char * encoding ,
791+ PyCursesWindowObject * orig )
791792{
792793 if (encoding == NULL ) {
793794#if defined(MS_WINDOWS )
@@ -821,6 +822,8 @@ PyCursesWindow_New(cursesmodule_state *state,
821822 PyErr_NoMemory ();
822823 return NULL ;
823824 }
825+ wo -> orig = orig ;
826+ Py_XINCREF (orig );
824827 PyObject_GC_Track ((PyObject * )wo );
825828 return (PyObject * )wo ;
826829}
@@ -838,6 +841,7 @@ PyCursesWindow_dealloc(PyObject *self)
838841 if (wo -> encoding != NULL ) {
839842 PyMem_Free (wo -> encoding );
840843 }
844+ Py_XDECREF (wo -> orig );
841845 window_type -> tp_free (self );
842846 Py_DECREF (window_type );
843847}
@@ -846,6 +850,8 @@ static int
846850PyCursesWindow_traverse (PyObject * self , visitproc visit , void * arg )
847851{
848852 Py_VISIT (Py_TYPE (self ));
853+ PyCursesWindowObject * wo = (PyCursesWindowObject * )self ;
854+ Py_VISIT (wo -> orig );
849855 return 0 ;
850856}
851857
@@ -1453,7 +1459,7 @@ _curses_window_derwin_impl(PyCursesWindowObject *self, int group_left_1,
14531459 }
14541460
14551461 cursesmodule_state * state = get_cursesmodule_state_by_win (self );
1456- return PyCursesWindow_New (state , win , NULL );
1462+ return PyCursesWindow_New (state , win , NULL , self );
14571463}
14581464
14591465/*[clinic input]
@@ -2493,7 +2499,7 @@ _curses_window_subwin_impl(PyCursesWindowObject *self, int group_left_1,
24932499 }
24942500
24952501 cursesmodule_state * state = get_cursesmodule_state_by_win (self );
2496- return PyCursesWindow_New (state , win , self -> encoding );
2502+ return PyCursesWindow_New (state , win , self -> encoding , self );
24972503}
24982504
24992505/*[clinic input]
@@ -3237,7 +3243,7 @@ _curses_getwin(PyObject *module, PyObject *file)
32373243 goto error ;
32383244 }
32393245 cursesmodule_state * state = get_cursesmodule_state (module );
3240- res = PyCursesWindow_New (state , win , NULL );
3246+ res = PyCursesWindow_New (state , win , NULL , NULL );
32413247
32423248error :
32433249 fclose (fp );
@@ -3410,7 +3416,7 @@ _curses_initscr_impl(PyObject *module)
34103416 if (curses_initscr_called ) {
34113417 wrefresh (stdscr );
34123418 cursesmodule_state * state = get_cursesmodule_state (module );
3413- return PyCursesWindow_New (state , stdscr , NULL );
3419+ return PyCursesWindow_New (state , stdscr , NULL , NULL );
34143420 }
34153421
34163422 win = initscr ();
@@ -3514,7 +3520,7 @@ _curses_initscr_impl(PyObject *module)
35143520#undef SetDictInt
35153521
35163522 cursesmodule_state * state = get_cursesmodule_state (module );
3517- PyObject * winobj = PyCursesWindow_New (state , win , NULL );
3523+ PyObject * winobj = PyCursesWindow_New (state , win , NULL , NULL );
35183524 if (winobj == NULL ) {
35193525 return NULL ;
35203526 }
@@ -3898,7 +3904,7 @@ _curses_newpad_impl(PyObject *module, int nlines, int ncols)
38983904 }
38993905
39003906 cursesmodule_state * state = get_cursesmodule_state (module );
3901- return PyCursesWindow_New (state , win , NULL );
3907+ return PyCursesWindow_New (state , win , NULL , NULL );
39023908}
39033909
39043910/*[clinic input]
@@ -3939,7 +3945,7 @@ _curses_newwin_impl(PyObject *module, int nlines, int ncols,
39393945 }
39403946
39413947 cursesmodule_state * state = get_cursesmodule_state (module );
3942- return PyCursesWindow_New (state , win , NULL );
3948+ return PyCursesWindow_New (state , win , NULL , NULL );
39433949}
39443950
39453951/*[clinic input]
0 commit comments