cpython/Tools/c-analyzer
Miss Skeleton (bot) 4af6729219
bpo-41971: Fix test failure in test.test_tools.test_c_analyzer when mutating global state (GH-22652) (GH-22653)
(cherry picked from commit 47ecfd8030)

Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>

Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
2020-10-11 21:54:35 +01:00
..
c_analyzer bpo-41971: Fix test failure in test.test_tools.test_c_analyzer when mutating global state (GH-22652) (GH-22653) 2020-10-11 21:54:35 +01:00
cpython bpo-36876: Re-organize the c-analyzer tool code. (gh-16841) 2019-10-18 19:00:04 -07:00
README bpo-38419: fix "check-c-globals" path (GH-16680) 2019-10-22 21:05:54 -03:00
TODO Move Eric's TODO file into his directory. (GH-16072) 2019-09-12 18:19:46 +01:00
c-globals.py bpo-36876: Re-organize the c-analyzer tool code. (gh-16841) 2019-10-18 19:00:04 -07:00
check-c-globals.py [3.9] bpo-41043: Escape literal part of the path for glob(). (GH-20994). (GH-21275) 2020-07-02 10:05:16 +03:00
ignored-globals.txt bpo-36876: Add a tool that identifies unsupported global C variables. (#15877) 2019-09-11 19:49:45 +01:00
ignored.tsv bpo-36876: Add a tool that identifies unsupported global C variables. (#15877) 2019-09-11 19:49:45 +01:00
known.tsv bpo-36876: Fix the globals checker tool. (gh-16058) 2019-09-12 16:59:38 +01:00

README

#######################################
# C Globals and CPython Runtime State.

CPython's C code makes extensive use of global variables.  Each global
falls into one of several categories:

* (effectively) constants (incl. static types)
* globals used exclusively in main or in the REPL
* freelists, caches, and counters
* process-global state
* module state
* Python runtime state

The ignored-globals.txt file is organized similarly.  Of the different
categories, the last two are problematic and generally should not exist
in the codebase.

Globals that hold module state (i.e. in Modules/*.c) cause problems
when multiple interpreters are in use.  For more info, see PEP 3121,
which addresses the situation for extension modules in general.

Globals in the last category should be avoided as well.  The problem
isn't with the Python runtime having state.  Rather, the problem is with
that state being spread throughout the codebase in dozens of individual
globals.  Unlike the other globals, the runtime state represents a set
of values that are constantly shifting in a complex way.  When they are
spread out it's harder to get a clear picture of what the runtime
involves.  Furthermore, when they are spread out it complicates efforts
that change the runtime.

Consequently, the globals for Python's runtime state have been
consolidated under a single top-level _PyRuntime global. No new globals
should be added for runtime state.  Instead, they should be added to
_PyRuntimeState or one of its sub-structs.  The check-c-globals script
should be run to ensure that no new globals have been added:

  python3 Tools/c-analyzer/check-c-globals.py

If it reports any globals then they should be resolved.  If the globals
are runtime state then they should be folded into _PyRuntimeState.
Otherwise they should be added to ignored-globals.txt.