Make `xml.etree.ElementTree.Element` usable on free-threaded builds
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 77.2k
- フォーク
- 35.9k
- PR マージ指標
- PR 指標を取得中
説明
Crash report
What happened?
Descriptino
_elementtree.c declares Py_MOD_GIL_NOT_USED but has zero @critical_section annotations. element_getitem() checks self->extra != NULL then dereferences self->extra->children[index], but with no lock between the check and the use. Concurrent elem.clear() sets self->extra = NULL and frees the children array between those two operations, causing a NULL dereference.
Repro Code
import sys
import threading
from xml.etree.ElementTree import Element
if sys._is_gil_enabled():
sys.exit("SKIP: requires --disable-gil build")
NUM_THREADS = 4
ITERS = 5_000_000
elem = Element('root')
for i in range(10):
elem.append(Element(f'child{i}'))
def reader():
for _ in range(ITERS):
try:
_ = elem[0]
except IndexError:
pass
def writer():
for _ in range(ITERS):
elem.clear()
for i in range(10):
elem.append(Element(f'child{i}'))
readers = [threading.Thread(target=reader) for _ in range(NUM_THREADS)]
writers = [threading.Thread(target=writer) for _ in range(NUM_THREADS)]
for t in writers + readers:
t.start()
for t in writers + readers:
t.join()
print("Completed without crash.")
Output
[1] 40136 segmentation fault ./python3 /tmp/test_elementtree_race.py
CPython versions tested on:
3.15, CPython main branch
Operating systems tested on:
macOS
Output from running 'python -VV' on the command line:
Python 3.15.0a7+ free-threading build (heads/main:e167e06f8c6, Mar 15 2026, 09:14:39) [Clang 17.0.0 (clang-1700.6.4.2)]
Linked PRs
- gh-157000
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
Modules/_elementtree.c、特に element_getitem() から始め、提供されたスクリプトを使って free-threaded ビルドで race を再現してください。リンク先の PR gh-157000 を確認し、関連する ElementTree テストを実行してください。並行アクセスでクラッシュが発生しなくなり、リグレッションがカバーされれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- c, python
- 領域
- backend
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 20/100