cpython/Tools/c-analyzer
Nikita Sobolev 762eb58220
Remove `imp_dummy_def` from `Tools/c-analyzer/cpython/ignored.tsv` (gh-112122)
It was removed in 3.12, no need to keep the ignore.
2023-11-16 12:21:23 -07:00
..
c_analyzer gh-102033: Fix syntax error in `Tools/c-analyzer` (GH-102066) 2023-03-22 07:59:32 -07:00
c_common gh-105407: Remove unused imports in Tools/c-analyzer/ (#105410) 2023-06-06 21:08:48 +00:00
c_parser gh-106212: Raise when using c-analyzer with clang on darwin (#110757) 2023-10-13 10:52:30 +02:00
cpython Remove `imp_dummy_def` from `Tools/c-analyzer/cpython/ignored.tsv` (gh-112122) 2023-11-16 12:21:23 -07:00
distutils gh-105407: Remove unused imports in Tools/c-analyzer/ (#105410) 2023-06-06 21:08:48 +00:00
README
TODO gh-104169: Fix test_peg_generator after tokenizer refactoring (#110727) 2023-10-12 09:34:35 +02:00
c-analyzer.py
check-c-globals.py gh-90110: Get the C Analyzer Tool Working Again (gh-95545) 2022-08-01 17:13:23 -06:00
must-resolve.sh
table-file.py gh-90110: Clean Up the C-analyzer Globals Lists (gh-100091) 2022-12-07 15:02:47 -07: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

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.