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-123290: fix reference leaks in curses#123630
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
Uh oh!
There was an error while loading. Please reload this page.
Conversation
picnixz commented Sep 3, 2024 • edited by bedevere-app bot
Loading Uh oh!
There was an error while loading. Please reload this page.
edited by bedevere-app bot
Uh oh!
There was an error while loading. Please reload this page.
This is achieved by introducing a module's state and changing the memory management of `PyCursesWindow_Type`.
bedevere-bot commented Sep 3, 2024
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as resolved.
This comment was marked as resolved.
Misc/NEWS.d/next/Library/2024-09-03-13-51-15.gh-issue-123290.IDR-iN.rst Outdated Show resolvedHide resolved
Uh oh!
There was an error while loading. Please reload this page.
vstinner commented Sep 4, 2024
@erlend-aasland@encukou@ericsnowcurrently: This PR converts the |
picnixz commented Sep 4, 2024 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
By the way, with this PR and #123285, no modules from the standard library (except those in tests, but that's because the |
encukou commented Sep 9, 2024 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
I guess it's not very useful outside the main interpreter, so it was left behind. I haven't looked at the code in detail, but,
But neither had priority, so it's left with old behaviour that's somewhat broken with multiple interpreters. The refleaks are one-time, right? Or can you leak an unlimited amount of memory by re-loading the module? |
picnixz commented Sep 9, 2024 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
Mmh I don't think so actually (or at least I didn't manage to) [so yes, they are one-time] |
picnixz commented Sep 9, 2024
I have a module's state but I'm not sure this is what you have in mind.
Would
I'm not sure if this could matter, but for extensions that could be using stdlib modules, wouldn't it be better if they could detect whether they have refleaks by running |
encukou commented Sep 10, 2024
Sorry for the truncated message! I meant global state is not stored in module-level state. (edited above)
Yes.
Yes. I'm not talking about whether this is a valid issue, but about priorities :) |
vstinner left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR does "everything" at once, so it's hard to review. I would prefer to split the PR into sub-steps:
- Cleanup the code, prepare PyInit__curses()
- Add a module state
- Convert static types to heap types
| do{\ | ||
| int rc = PyModule_AddIntConstant(MODULE, STRING, VALUE); \ | ||
| CHECK_RET_CODE_OR_ABORT(rc); \ | ||
| } while (0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should move these macros just before their first use, I don't think that it's useful to have them at the top.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I put them in the "/* Utility Macros */" section where the other macros are being declared.
| PyCursesWindowObject *winobj = (PyCursesWindowObject *)PyCursesWindow_New(state, win, NULL); | ||
| CHECK_NOT_NULL_OR_ABORT(winobj); | ||
| screen_encoding = winobj->encoding; | ||
| return (PyObject *)winobj; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest adding an empty line (after return, before the label) for readability.
picnixz commented Sep 10, 2024
Sorry for that :( Do you want me to split it into multiple PRs or multiple commits? |
picnixz commented Sep 10, 2024
What would the the global state consists of? Currently, what's being stored is the type of curses window ( Those functions are exported in the #definePyCursesSetupTermCalled \ if (initialised_setupterm != TRUE){\ PyErr_SetString(PyCursesError, \ "must call (at least) setupterm() first"); \ return 0}So maybe we need to live with those refleaks? |
vstinner commented Sep 10, 2024
Multiple PRs. Start by just creating one, others will follow once the first is merged. |
picnixz commented Sep 10, 2024
Closing this one since I'll split it in different PRs (and to reduce the number of opened PRs) |
This will superseed #123291. With this PR, the curses module does not leak anymore 🥳
curseserror-branches #123290