Skip to content
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

Merged
merged 8 commits into from
Feb 10, 2024

Conversation

sobolevn
Copy link
Member

@sobolevn sobolevn commented Jan 28, 2024

@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.

Copy link
Member

@serhiy-storchaka serhiy-storchaka left a 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.

@sobolevn
Copy link
Member Author

sobolevn commented Feb 7, 2024

simple_format = PyUnicode_FromString(simple_fmt); was also leaking.

Copy link
Member

@serhiy-storchaka serhiy-storchaka left a 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.

@sobolevn
Copy link
Member Author

sobolevn commented Feb 7, 2024

@serhiy-storchaka when this PR will be ready, can you please let me merge it? :)

@serhiy-storchaka
Copy link
Member

Of course, it is now your work.

@serhiy-storchaka
Copy link
Member

Just don't forget to clean up the commit message before merging.

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) {
Copy link
Member

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().

Copy link
Member Author

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 👍

Copy link
Member

@serhiy-storchaka serhiy-storchaka left a 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.

Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Copy link
Member

@vstinner vstinner left a 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 😇

@sobolevn sobolevn merged commit 3a5b38e into python:main Feb 10, 2024
@sobolevn
Copy link
Member Author

Thanks a lot, everyone! 👍
Especially @vstinner for guiding me through the merge process :)

@sobolevn sobolevn deleted the issue-114670 branch February 10, 2024 21:48
@bedevere-bot
Copy link

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot AMD64 Windows11 Bigmem 3.x has failed when building commit 3a5b38e.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/all/#builders/1079/builds/3360) and take a look at the build logs.
  4. Check if the failure is related to this commit (3a5b38e) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/all/#builders/1079/builds/3360

Failed tests:

  • test_queue

Summary of the results of the build (if available):

==

Click to see traceback logs
remote: Enumerating objects: 9, done.        
remote: Counting objects:  11% (1/9)        
remote: Counting objects:  22% (2/9)        
remote: Counting objects:  33% (3/9)        
remote: Counting objects:  44% (4/9)        
remote: Counting objects:  55% (5/9)        
remote: Counting objects:  66% (6/9)        
remote: Counting objects:  77% (7/9)        
remote: Counting objects:  88% (8/9)        
remote: Counting objects: 100% (9/9)        
remote: Counting objects: 100% (9/9), done.        
remote: Compressing objects:  14% (1/7)        
remote: Compressing objects:  28% (2/7)        
remote: Compressing objects:  42% (3/7)        
remote: Compressing objects:  57% (4/7)        
remote: Compressing objects:  71% (5/7)        
remote: Compressing objects:  85% (6/7)        
remote: Compressing objects: 100% (7/7)        
remote: Compressing objects: 100% (7/7), done.        
remote: Total 9 (delta 2), reused 3 (delta 2), pack-reused 0        
From https://github.com/python/cpython
 * branch                  main       -> FETCH_HEAD
Note: switching to '3a5b38e3b465e00f133ff8074a2d4afb1392dfb5'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:

  git switch -c <new-branch-name>

Or undo this operation with:

  git switch -

Turn off this advice by setting config variable advice.detachedHead to false

HEAD is now at 3a5b38e3b4 gh-114670: Fix `_testbuffer` module initialization (#114672)
Switched to and reset branch 'main'

Could Not Find R:\buildarea\3.x.ambv-bb-win11.bigmem\build\Lib\*.pyc
The system cannot find the file specified.
Could Not Find R:\buildarea\3.x.ambv-bb-win11.bigmem\build\PCbuild\python*.zip

Could Not Find R:\buildarea\3.x.ambv-bb-win11.bigmem\build\PCbuild\python*.zip

@sobolevn
Copy link
Member Author

The failure is unrelated and kwown, it happened before: https://github.com/python/cpython/actions/runs/7855933464/job/21438170525
Reported here: #115258

@sobolevn
Copy link
Member Author

Since https://github.com/python/cpython/blob/3.11/Modules/_testbuffer.c exists, I will make backports.

@sobolevn sobolevn added needs backport to 3.11 only security fixes needs backport to 3.12 bug and security fixes labels Feb 11, 2024
@miss-islington-app
Copy link

Thanks @sobolevn for the PR 🌮🎉.. I'm working now to backport this PR to: 3.11.
🐍🍒⛏🤖

@miss-islington-app
Copy link

Thanks @sobolevn for the PR 🌮🎉.. I'm working now to backport this PR to: 3.12.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Feb 11, 2024
…4672)

(cherry picked from commit 3a5b38e)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
@bedevere-app
Copy link

bedevere-app bot commented Feb 11, 2024

GH-115271 is a backport of this pull request to the 3.11 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Feb 11, 2024
…4672)

(cherry picked from commit 3a5b38e)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
@bedevere-app bedevere-app bot removed the needs backport to 3.11 only security fixes label Feb 11, 2024
@bedevere-app
Copy link

bedevere-app bot commented Feb 11, 2024

GH-115272 is a backport of this pull request to the 3.12 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.12 bug and security fixes label Feb 11, 2024
sobolevn added a commit that referenced this pull request Feb 11, 2024
…#115272)

(cherry picked from commit 3a5b38e)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
sobolevn added a commit that referenced this pull request Feb 11, 2024
…#115271)

(cherry picked from commit 3a5b38e)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
fsc-eriker pushed a commit to fsc-eriker/cpython that referenced this pull request Feb 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
skip news tests Tests in the Lib/test dir
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants