cpython/Tools/c-analyzer
2021-09-15 17:08:48 +03:00
..
c_analyzer bpo-36876: [c-analyzer tool] Add a "capi" subcommand to the c-analyzer tool. (gh-23918) 2020-12-24 11:04:19 -07:00
c_common bpo-44786: Fix a warning in RE in c-analyzer (GH-28351) 2021-09-15 17:08:48 +03:00
c_parser bpo-44854: Remove trailing whitespaces (GH-27689) 2021-08-09 21:32:54 +03:00
cpython bpo-42064: Move sqlite3 exceptions to global state, part 2 of 2 (GH-26884) 2021-07-14 04:26:44 -07:00
c-analyzer.py bpo-36876: Fix the C analyzer tool. (GH-22841) 2020-10-22 18:42:51 -06:00
check-c-globals.py bpo-36876: [c-analyzer tool] Add a "capi" subcommand to the c-analyzer tool. (gh-23918) 2020-12-24 11:04:19 -07:00
must-resolve.sh bpo-36876: [c-analyzer tool] Additional CLI updates for "capi" command. (gh-23929) 2020-12-25 15:57:30 -07:00
README bpo-36876: Fix the C analyzer tool. (GH-22841) 2020-10-22 18:42:51 -06:00
TODO bpo-42161: Remove private _PyLong_Zero and _PyLong_One (GH-23003) 2020-10-27 21:34:33 +01:00

#######################################
# 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

You can also use the more generic tool:

  python3 Tools/c-analyzer/c-analyzer.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.