Avoid double checking `tp_as_number`, `tp_as_sequence` and `tp_as_mapping`
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 77.2k
- フォーク
- 35.9k
- PR マージ指標
- PR 指標を取得中
説明
Feature or enhancement
The PyTypeObject fields tp_as_number, tp_as_sequence and tp_as_mapping can be set to NULL
which means that any code that wants to access a field in those structs needs to first check for NULL.
e.g. checking if an object is a sequence:
if (Py_TYPE(s)->tp_as_mapping && Py_TYPE(s)->tp_as_mapping->mp_length) {
this is ugly, a bit error prone and slower than necessary.
Instead, during PyType_Ready, any of these fields that are NULL should be made to pointer to a struct full of NULLs.
This would remove the need for the extra check:
if (Py_TYPE(s)->tp_as_mapping->mp_length) {
since we would be guaranteed that Py_TYPE(s)->tp_as_mapping is never NULL.
Immutable types can all share common constant structs, so this should use very little extra memory.
Linked PRs
- gh-149317
- gh-149476
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
PyType_Ready から始めて tp_as_number、tp_as_sequence、tp_as_mapping の処理を追跡し、その後、issue で説明されているアクセスパターンを調べます。NULL スロットが、追加のチェックなしで、すべての要素が NULL の共有構造体によって安全に表現され、関連する CPython テストが通れば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- backend
- issue の種類
- 機能追加
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 30/100