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: Set GC_DEBUG for debug builds of the interpreter
Type: Stage: resolved
Components: Versions: Python 3.9
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: pablogsal, tim.peters, vstinner
Priority: normal Keywords: patch

Created on 2019-10-10 19:39 by pablogsal, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 16707 merged pablogsal, 2019-10-10 19:40
Messages (6)
msg354401 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2019-10-10 19:39
While working on bpo-38379 I had to manually set the GC_DEBUG macro to 1 to activate the extra checks that 'validate_list' does. These checks are super useful to make sure all the gc lists used are consistent and in the expected state with the expected masks.

For this reason, I propose to always activate GC_DEBUG for debug builds of the interpreter. It will have a performance impact, but the debugging benefits are substantial.
msg354403 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-10-10 20:40
Under which condition can such list be corrupted?
msg354405 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2019-10-10 20:56
> Under which condition can such list be corrupted?

If someone is adding/modifiying the gc and calls any of the functions that set the gc flags like (PREV_MASK_COLLECTING).

One example is that after calling move_unreachable(), the unreachable set has NEXT_MASK_UNREACHABLE and therefore is an invalid list (until move_legacy_finalizers removes the flag and makes it valid again). If you mess the order or violate any of the contract, the lists will be invalid. It helps a lot to know that you are not leaving the lists in invalid state by mistake or on the other hand, to check that they are valid when they are supposed to be valid.
msg354406 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2019-10-10 21:24
+1.  This code got quite brittle when they decided to fit two pointers, a fat integer, and 3 flags into a struct with room for only the two pointers ;-)  It's a mine field now.  Enabling one of the few automated mine detectors is thoroughly sensible.
msg354408 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2019-10-10 21:45
New changeset 320dd504ddf65efe946e6d1e89053ed2d7ebe1e9 by Pablo Galindo in branch 'master':
bpo-38437: Activate GC_DEBUG when PY_DEBUG is set (GH-16707)
https://github.com/python/cpython/commit/320dd504ddf65efe946e6d1e89053ed2d7ebe1e9
msg354409 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2019-10-10 21:49
Thanks Victor and Tim!
History
Date User Action Args
2022-04-11 14:59:21adminsetgithub: 82618
2019-10-10 21:49:32pablogsalsetmessages: + msg354409
2019-10-10 21:49:20pablogsalsetstatus: open -> closed
resolution: fixed
stage: resolved
2019-10-10 21:45:20pablogsalsetmessages: + msg354408
2019-10-10 21:24:06tim.peterssetnosy: + tim.peters
messages: + msg354406
2019-10-10 20:56:23pablogsalsetmessages: + msg354405
2019-10-10 20:40:37vstinnersetmessages: + msg354403
2019-10-10 19:41:01pablogsalsetstage: patch review -> (no value)
versions: - Python 3.7, Python 3.8
2019-10-10 19:40:44pablogsalsetkeywords: + patch
stage: patch review
pull_requests: + pull_request16292
2019-10-10 19:39:02pablogsalcreate