This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: [easy C] GC: Use local variable 'op' when invoking 'traverse' in 'subtract_refs'
Type: enhancement Stage: resolved
Components: C API, Interpreter Core Versions: Python 3.11
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: WildCard65, vstinner
Priority: normal Keywords: patch

Created on 2020-06-25 16:35 by WildCard65, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
cpython.patch WildCard65, 2020-06-25 16:35 Proposed patch for the GC module.
Pull Requests
URL Status Linked Edit
PR 27593 merged vstinner, 2021-08-04 15:35
Messages (4)
msg372380 - (view) Author: William Pickard (WildCard65) * Date: 2020-06-25 16:35
When the GC module goes to collect objects (most notably, during Python shutdown), it makes a call to subtract_refs on the GC container.

During this invocation, it creates a local variable "op" who's value is the result of 'FROM_GC(gc)', but when it goes to use the obtained 'traverse' method, it calls FROM_GC(gc) instead of using 'op'.

This, unfortunately, makes it rather difficult to debug "Access Violations" for extension modules for when 'traverse' is 'NULL' as inspecting the variable 'op' in the chosen debugger (for my case: Visual Studio on Windows) is impossible.

This can potentially introduce a micro optimization in the overall runtime of the GC module as it no longer has to invoke the addition instruction (if it does) to construct the first parameter of the 'traverse' call.
msg398906 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-08-04 15:36
I created PR 27593.
msg398909 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-08-04 16:09
New changeset c34fa2bb06ea44045af8493dfa414addb2b7ce66 by Victor Stinner in branch 'main':
bpo-41117: Cleanup subtract_refs() (GH-27593)
https://github.com/python/cpython/commit/c34fa2bb06ea44045af8493dfa414addb2b7ce66
msg398910 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-08-04 16:09
Thanks William, I made the change that you suggested. Next time, please create a PR directly ;-)
History
Date User Action Args
2022-04-11 14:59:32adminsetgithub: 85289
2021-08-04 16:09:51vstinnersetstatus: open -> closed
versions: + Python 3.11, - Python 3.10
messages: + msg398910

resolution: fixed
stage: patch review -> resolved
2021-08-04 16:09:31vstinnersetmessages: + msg398909
2021-08-04 15:36:03vstinnersetmessages: + msg398906
2021-08-04 15:35:05vstinnersetnosy: + vstinner

pull_requests: + pull_request26094
stage: patch review
2020-06-25 16:35:27WildCard65create