-
-
Notifications
You must be signed in to change notification settings - Fork 31.5k
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-114670: Fix _testbuffer
module initialization
#114672
Conversation
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.
PyImport_ImportModule()
returns a new reference. structmodule
is a leaked reference.
|
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.
Ah, wait. structmodule
and simple_format
are global variables. They should hold a reference.
Previous version was more correct, I am sorry.
This reverts commit c36c054.
@serhiy-storchaka when this PR will be ready, can you please let me merge it? :) |
Of course, it is now your work. |
Just don't forget to clean up the commit message before merging. |
Misc/NEWS.d/next/Core and Builtins/2024-01-28-22-32-07.gh-issue-114672.9iEHAg.rst
Outdated
Show resolved
Hide resolved
Modules/_testbuffer.c
Outdated
Py_SET_TYPE(&NDArray_Type, &PyType_Type); | ||
Py_INCREF(&NDArray_Type); | ||
PyModule_AddObject(m, "ndarray", (PyObject *)&NDArray_Type); | ||
if (PyModule_AddObjectRef(m, "ndarray", (PyObject *)&NDArray_Type) < 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 might use PyModule_AddType().
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.
Looks like it the best one here 👍
Misc/NEWS.d/next/Core and Builtins/2024-01-28-22-32-07.gh-issue-114672.9iEHAg.rst
Outdated
Show resolved
Hide resolved
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 would remove the NEWS entry at all.
- There are no leaks during
_testbuffer
initialization in normal case. They are only occurred if the initialization fails. - But the module still leaks references when it is reloaded. It is not normal case, and it does not support reloading.
- It is an internal module only used in internal tests. Common Python users never use it. The NEWS entry is purposed for Python users.
So it is rather an internal refactoring and an intermediate step to make _testbuffer
reloadable, but it is not practical to make the next step.
…e-114672.9iEHAg.rst
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.
LGTM.
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.
LGTM.
@sobolevn: Maybe it's a first good PR to merge for your new role 😇
Thanks a lot, everyone! 👍 |
|
The failure is unrelated and kwown, it happened before: https://github.com/python/cpython/actions/runs/7855933464/job/21438170525 |
Since https://github.com/python/cpython/blob/3.11/Modules/_testbuffer.c exists, I will make backports. |
Thanks @sobolevn for the PR 🌮🎉.. I'm working now to backport this PR to: 3.11. |
Thanks @sobolevn for the PR 🌮🎉.. I'm working now to backport this PR to: 3.12. |
GH-115271 is a backport of this pull request to the 3.11 branch. |
GH-115272 is a backport of this pull request to the 3.12 branch. |
@erlend-aasland would you please take a look? :)
I think you've already reviewed several similar PRs from me.
The change is straight-forward: check for errors, clean things up.
_testbuffer.c
's initialization does not handle errors #114670