Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34k
gh-116946: fully implement GC protocol for _curses_panel.panel#138333
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
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
8 commits Select commit Hold shift + click to select a range
93694c8 fully implement GC protocol for `_curses_panel.panel`
picnixz c05db69 address review comment
picnixz 23a9664 explicitly raise PyErr_FormatUnraisable in `tp_clear`
picnixz 13933a9 explicitly raise PyErr_FormatUnraisable in `tp_clear`
picnixz bfadf5b fixup
picnixz 49cf9ea address review
picnixz 3221127 use Py_DECREF when possible
picnixz 39de85b handle errors from `tp_clear` in `tp_dealloc`
picnixz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -410,8 +410,11 @@ static PyObject * | ||
| PyCursesPanel_New(_curses_panel_state *state, PANEL *pan, | ||
| PyCursesWindowObject *wo) | ||
| { | ||
| PyCursesPanelObject *po = PyObject_New(PyCursesPanelObject, | ||
| state->PyCursesPanel_Type); | ||
| assert(state != NULL); | ||
| PyTypeObject *type = state->PyCursesPanel_Type; | ||
| assert(type != NULL); | ||
| assert(type->tp_alloc != NULL); | ||
| PyCursesPanelObject *po = (PyCursesPanelObject *)type->tp_alloc(type, 0); | ||
| if (po == NULL){ | ||
| return NULL; | ||
| } | ||
| @@ -426,20 +429,31 @@ PyCursesPanel_New(_curses_panel_state *state, PANEL *pan, | ||
| return (PyObject *)po; | ||
| } | ||
| static int | ||
| PyCursesPanel_Clear(PyObject *op) | ||
| { | ||
| PyCursesPanelObject *self = _PyCursesPanelObject_CAST(op); | ||
| PyObject *extra = (PyObject *)panel_userptr(self->pan); | ||
| if (extra != NULL){ | ||
| Py_DECREF(extra); | ||
| if (set_panel_userptr(self->pan, NULL) == ERR){ | ||
| curses_panel_panel_set_error(self, "set_panel_userptr", NULL); | ||
| return -1; | ||
| } | ||
| } | ||
| // self->wo should not be cleared because an associated WINDOW may exist | ||
| return 0; | ||
| } | ||
| static void | ||
| PyCursesPanel_Dealloc(PyObject *self) | ||
| { | ||
| PyObject *tp, *obj; | ||
| PyCursesPanelObject *po = _PyCursesPanelObject_CAST(self); | ||
| PyTypeObject *tp = Py_TYPE(self); | ||
| PyObject_GC_UnTrack(self); | ||
| tp = (PyObject *) Py_TYPE(po); | ||
| obj = (PyObject *) panel_userptr(po->pan); | ||
| if (obj){ | ||
| Py_DECREF(obj); | ||
| if (set_panel_userptr(po->pan, NULL) == ERR){ | ||
| curses_panel_panel_set_error(po, "set_panel_userptr", "__del__"); | ||
| PyErr_FormatUnraisable("Exception ignored in PyCursesPanel_Dealloc()"); | ||
| } | ||
| PyCursesPanelObject *po = _PyCursesPanelObject_CAST(self); | ||
| if (PyCursesPanel_Clear(self) < 0){ | ||
| PyErr_FormatUnraisable("Exception ignored in PyCursesPanel_Dealloc()"); | ||
| } | ||
| if (del_panel(po->pan) == ERR && !PyErr_Occurred()){ | ||
| curses_panel_panel_set_error(po, "del_panel", "__del__"); | ||
| @@ -452,10 +466,20 @@ PyCursesPanel_Dealloc(PyObject *self) | ||
| PyErr_FormatUnraisable("Exception ignored in PyCursesPanel_Dealloc()"); | ||
| } | ||
| } | ||
| PyObject_Free(po); | ||
| tp->tp_free(po); | ||
| Py_DECREF(tp); | ||
| } | ||
| static int | ||
| PyCursesPanel_Traverse(PyObject *op, visitproc visit, void *arg) | ||
| { | ||
| PyCursesPanelObject *self = _PyCursesPanelObject_CAST(op); | ||
| Py_VISIT(Py_TYPE(op)); | ||
| Py_VISIT(panel_userptr(self->pan)); | ||
| Py_VISIT(self->wo); | ||
| return 0; | ||
| } | ||
| /* panel_above(NULL) returns the bottom panel in the stack. To get | ||
| this behaviour we use curses.panel.bottom_panel(). */ | ||
| /*[clinic input] | ||
| @@ -647,15 +671,21 @@ static PyMethodDef PyCursesPanel_Methods[] ={ | ||
| /* -------------------------------------------------------*/ | ||
| static PyType_Slot PyCursesPanel_Type_slots[] ={ | ||
| {Py_tp_clear, PyCursesPanel_Clear}, | ||
| {Py_tp_dealloc, PyCursesPanel_Dealloc}, | ||
| {Py_tp_traverse, PyCursesPanel_Traverse}, | ||
| {Py_tp_methods, PyCursesPanel_Methods}, | ||
| {0, 0}, | ||
| }; | ||
| static PyType_Spec PyCursesPanel_Type_spec ={ | ||
| .name = "_curses_panel.panel", | ||
| .basicsize = sizeof(PyCursesPanelObject), | ||
| .flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION, | ||
| .flags = ( | ||
| Py_TPFLAGS_DEFAULT | ||
| | Py_TPFLAGS_DISALLOW_INSTANTIATION | ||
picnixz marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading. Please reload this page. | ||
| | Py_TPFLAGS_HAVE_GC | ||
| ), | ||
| .slots = PyCursesPanel_Type_slots | ||
| }; | ||
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.