python / python/cpython

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

未關閉
#116,828 2 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

type-bug
主要語言
Python
星號
77.2k
分支
35.9k
PR 合併指標
PR 指標待擷取

描述

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

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

從 Tools/c-analyzer/c_analyzer/datafiles.py、c_parser/info.py 和 cpython/_analyzer.py 開始,追蹤 check-c-globals.py 命令和 DeclID.from_row() 的 traceback。使用所示命令重現失敗;完成的標準是正常回報不受支援的 globals,且不出現無關的中間 traceback。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
c, python
領域
ci-cd, tooling
Issue 類型
缺陷
難度
3/5
預估耗時
1-2 天
活躍度
停滯
描述清晰度
描述清楚
新手友好度
45/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。