python / python/cpython

[Tool: c-analyzer] Unexpected Intermediate Error When the Tool Fails

Aperta
#116,828 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

type-bug
Lingua principale
Python
Stelle
77.2k
Fork
35.9k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

Bug report

When the c-analyzer tool (Tools/c-analyzer) fails due to an unsupported C global variable, it is also printing a traceback that indicates a bug somewhere in the tool.

(expand for an example)

From the CI check in gh-116413:

python3.12 ./Tools/c-analyzer/check-c-globals.py \
	--format summary \
	--traceback
analyzing files...
..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....

..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....

..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....

..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....

..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....

..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....

..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....

..... ....
checking analysis results...
Traceback (most recent call last):

-------------------------
  File "/home/runner/work/cpython/cpython/./Tools/c-analyzer/check-c-globals.py", line 39, in <module>
    main(cmd, cmd_kwargs)
  File "/home/runner/work/cpython/cpython/Tools/c-analyzer/cpython/__main__.py", line 498, in main

Non-constant global variables are generally not supported
in the CPython repo.  We use a tool to analyze the C code
and report if any unsupported globals are found.  The tool
may be run manually with:

  ./python Tools/c-analyzer/check-c-globals.py --format summary [FILE]

Occasionally the tool is unable to parse updated code.
If this happens then add the file to the "EXCLUDED" list
in Tools/c-analyzer/cpython/_parser.py and create a new
issue for fixing the tool (and CC ericsnowcurrently
on the issue).

If the tool reports an unsupported global variable and
it is actually const (and thus supported) then first try
fixing the declaration appropriately in the code.  If that
doesn't work then add the variable to the "should be const"
section of Tools/c-analyzer/cpython/ignored.tsv.

If the tool otherwise reports an unsupported global variable
then first try to make it non-global, possibly adding to
PyInterpreterState (for core code) or module state (for
extension modules).  In an emergency, you can add the
variable to Tools/c-analyzer/cpython/globals-to-fix.tsv
to get CI passing, but doing so should be avoided.  If
this course it taken, be sure to create an issue for
eliminating the global (and CC ericsnowcurrently).

    run_cmd(**cmd_kwargs)
  File "/home/runner/work/cpython/cpython/Tools/c-analyzer/cpython/__main__.py", line 1[59](https://github.com/python/cpython/actions/runs/8281492333/job/22660094475#step:16:60), in cmd_check
    c_analyzer.cmd_check(
  File "/home/runner/work/cpython/cpython/Tools/c-analyzer/c_analyzer/__main__.py", line 331, in cmd_check
    for data, failure in _check_all(decls, checks, failfast=failfast):
  File "/home/runner/work/cpython/cpython/Tools/c-analyzer/c_analyzer/__init__.py", line 94, in check_all
    for data, failure in check(analysis):
  File "/home/runner/work/cpython/cpython/Tools/c-analyzer/cpython/_analyzer.py", line 411, in check_globals
    ignored = read_ignored()
              ^^^^^^^^^^^^^^
  File "/home/runner/work/cpython/cpython/Tools/c-analyzer/cpython/_analyzer.py", line 124, in read_ignored
    _IGNORED.update(_datafiles.read_ignored(NEED_FIX_FILE, relroot=REPO_ROOT))
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/work/cpython/cpython/Tools/c-analyzer/c_analyzer/datafiles.py", line [93](https://github.com/python/cpython/actions/runs/8281492333/job/22660094475#step:16:94), in read_ignored
    return dict(_iter_ignored(infile, relroot))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/work/cpython/cpython/Tools/c-analyzer/c_analyzer/datafiles.py", line [107](https://github.com/python/cpython/actions/runs/8281492333/job/22660094475#step:16:108), in _iter_ignored
    varid = _info.DeclID.from_row(varidinfo)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/work/cpython/cpython/Tools/c-analyzer/c_parser/info.py", line 207, in from_row
    return cls(*row)
           ^^^^^^^^^
TypeError: DeclID.__new__() missing 3 required positional arguments: 'filename', 'funcname', and 'name'
make: *** [Makefile:3[16](https://github.com/python/cpython/actions/runs/8281492333/job/22660094475#step:16:17)1: check-c-globals] Error 1
Error: Process completed with exit code 2.
(expand for another example)

From the CI check in gh-116413:

python3.12 ./Tools/c-analyzer/check-c-globals.py \
	--format summary \
	--traceback
analyzing files...
..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....

..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....

..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....

..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....

..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....

..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....

..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....

..... ....
checking analysis results...
Traceback (most recent call last):
  File "/home/runner/work/cpython/cpython/./Tools/c-analyzer/check-c-globals.py", line 39, in <module>

    main(cmd, cmd_kwargs)
  File "/home/runner/work/cpython/cpython/Tools/c-analyzer/cpython/__main__.py", line 498, in main
-------------------------
    run_cmd(**cmd_kwargs)
  File "/home/runner/work/cpython/cpython/Tools/c-analyzer/cpython/__main__.py", line 1[59](https://github.com/python/cpython/actions/runs/8280034808/job/22655683079#step:16:60), in cmd_check
    c_analyzer.cmd_check(
  File "/home/runner/work/cpython/cpython/Tools/c-analyzer/c_analyzer/__main__.py", line 331, in cmd_check
    for data, failure in _check_all(decls, checks, failfast=failfast):
  File "/home/runner/work/cpython/cpython/Tools/c-analyzer/c_analyzer/__init__.py", line 94, in check_all
    for data, failure in check(analysis):
  File "/home/runner/work/cpython/cpython/Tools/c-analyzer/cpython/_analyzer.py", line 411, in check_globals
    ignored = read_ignored()
              ^^^^^^^^^^^^^^
  File "/home/runner/work/cpython/cpython/Tools/c-analyzer/cpython/_analyzer.py", line 124, in read_ignored
    _IGNORED.update(_datafiles.read_ignored(NEED_FIX_FILE, relroot=REPO_ROOT))
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/work/cpython/cpython/Tools/c-analyzer/c_analyzer/datafiles.py", line 93, in read_ignored
    return dict(_iter_ignored(infile, relroot))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/work/cpython/cpython/Tools/c-analyzer/c_analyzer/datafiles.py", line 107, in _iter_ignored
    varid = _info.DeclID.from_row(varidinfo)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/work/cpython/cpython/Tools/c-analyzer/c_parser/info.py", line 207, in from_row
    return cls(*row)
           ^^^^^^^^^
TypeError: DeclID.__new__() missing 3 required positional arguments: 'filename', 'funcname', and 'name'

Non-constant global variables are generally not supported
in the CPython repo.  We use a tool to analyze the C code
and report if any unsupported globals are found.  The tool
may be run manually with:

  ./python Tools/c-analyzer/check-c-globals.py --format summary [FILE]

Occasionally the tool is unable to parse updated code.
If this happens then add the file to the "EXCLUDED" list
in Tools/c-analyzer/cpython/_parser.py and create a new
issue for fixing the tool (and CC ericsnowcurrently
on the issue).

If the tool reports an unsupported global variable and
it is actually const (and thus supported) then first try
fixing the declaration appropriately in the code.  If that
doesn't work then add the variable to the "should be const"
section of Tools/c-analyzer/cpython/ignored.tsv.

If the tool otherwise reports an unsupported global variable
then first try to make it non-global, possibly adding to
PyInterpreterState (for core code) or module state (for
extension modules).  In an emergency, you can add the
variable to Tools/c-analyzer/cpython/globals-to-fix.tsv
to get CI passing, but doing so should be avoided.  If
this course it taken, be sure to create an issue for
eliminating the global (and CC ericsnowcurrently).

make: *** [Makefile:3[16](https://github.com/python/cpython/actions/runs/8280034808/job/22655683079#step:16:17)1: check-c-globals] Error 1
Error: Process completed with exit code 2.

The examples demonstrate that the traceback is coming from a different thread than the expected error message.

Note that, in the examples, the tool doesn't report the unsupported globals it found, like it normally would.

Related: gh-116826

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia da Tools/c-analyzer/c_analyzer/datafiles.py, c_parser/info.py e cpython/_analyzer.py, seguendo il comando check-c-globals.py e il traceback di DeclID.from_row(). Riproduci il problema con il comando mostrato; il lavoro è completato quando i globals non supportati vengono segnalati normalmente, senza il traceback intermedio non correlato.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
c, python
Ambito
ci-cd, tooling
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Specificata chiaramente
Idoneità per principianti
45/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.