-
-
Notifications
You must be signed in to change notification settings - Fork 30.3k
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
gh-123290: fix reference leaks in curses
#123630
Conversation
This is achieved by introducing a module's state and changing the memory management of `PyCursesWindow_Type`.
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 resolved
Hide resolved
@erlend-aasland @encukou @ericsnowcurrently: This PR converts the |
By the way, with this PR and #123285, no modules from the standard library (except those in tests, but that's because the |
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? |
Mmh I don't think so actually (or at least I didn't manage to) [so yes, they are one-time] |
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 |
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 :) |
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.
winobj = (PyCursesWindowObject *)PyCursesWindow_New(win, NULL); | ||
_cursesmodule_state *state = get_cursesmodule_state(module); | ||
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.
Sorry for that :( Do you want me to split it into multiple PRs or multiple commits? |
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 #define PyCursesSetupTermCalled \
if (initialised_setupterm != TRUE) { \
PyErr_SetString(PyCursesError, \
"must call (at least) setupterm() first"); \
return 0; } So maybe we need to live with those refleaks? |
Multiple PRs. Start by just creating one, others will follow once the first is merged. |
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 🥳
curses
error-branches #123290