[C-API Docs] Clarify Constraints on the Arena Allocator
まだ誰も着手していません。
評価
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 初心者へのやさしさ
- 25/100
- issue の種類
- ドキュメント
- 明瞭さ
- 説明が足りない
- 活発さ
- 停滞
- 領域
- api, documentation
調査の方向性
まず、PyObject_GetArenaAllocator()、PyObject_SetArenaAllocator() および Python 初期化前に関するガイダンスの、リンク先の C-API ドキュメントを確認し、次に PyMem_SetAllocator の制限事項と比較してください。初期化、GIL、直接使用、スレッドセーフ性について許可される制約を判断して文書化し、非推奨化と PyConfig による置き換えを仕様として明記すべきかどうかを別途評価してください。
索引モデルが issue の本文から書いたものです。
説明
The "arena" allocator is used by obmalloc, as well as the code for allocating frames. It is exposed by the following public C-API:
PyObject_GetArenaAllocator()PyObject_SetArenaAllocator()
(It is also exposed/used internally as _PyObject_VirtualAlloc() and _PyObject_VirtualFree(). The implementation is exposed internally as _PyMem_ArenaAlloc() and _PyMem_ArenaFree().)
First of all, the docs for PyObject_GetArenaAllocator() are not clear at all about what the function should be used for. I expect it is only meant for use in combination with PyObject_SetArenaAllocator() (e.g. to wrap the old one; to check what's set). That should be clarified.
Second, the C-API docs make it clear that the two public functions may be called before the runtime is initialized. However, the following should be clarified, as there are no documented restrictions AFAICS:
- may
PyObject_SetArenaAllocator()be called after runtime init?- status quo: presumably not, since obmalloc would break (similar to the restrictions on
PyMem_SetAllocator()) - internally: we do not ever change the arena allocator
- recommendation: explicitly document that it must not be called after runtime init (a la
PyMem_SetAllocator())
- status quo: presumably not, since obmalloc would break (similar to the restrictions on
- may the allocator returned by
PyObject_GetArenaAllocator()be used directly?- status quo: possibly yes, since people may be doing so at this point (unlikely though)
- internally: we use it directly (but that's kind of the point)
- recommendation: explicitly state that it should not be used directly (point to object allocator API instead)
- ...before runtime init?
- (relevant only if direct use is okay)
- status quo: possibly yes, since people may be doing so at this point (unlikely though)
- internally: we do not use it before runtime init
- recommendation: at the least document that it shouldn't be used after runtime init
- better: state that it's only allowed when
PyObject_SetArenaAllocator()is allowed (i.e. only before init)
- must
PyObject_GetArenaAllocator()be called with the GIL held after runtime init?- (relevant only if post-init
PyObject_SetArenaAllocator()is okay) - status quo: possibly not, since people haven't needed to before (unlikely though)
- internally: we always hold the GIL
- recommendation: recommend (or require) that the GIL be held
- (relevant only if post-init
- must the allocator passed to
PyObject_SetArenaAllocator()be thread-safe (and reentrant)?- status quo: if the allocator may be used directly then possibly yes (since it seems it can be used before runtime init, as well as later without the GIL held); otherwise no (since the PyMem "object" allocator is documented as protected by the GIL)
- internally: the default arena allocator is thread-safe (and reentrant)
- recommendation: recommend that the arena allocator be thread-safe (just like the PyMem "raw" allocator)
- better: explicitly require it (so we can later drop the restriction on the PyMem "mem" and "object" allocators)
If we do specify tighter restrictions than were already documented then we'll need to consider who might be using the public functions in unexpected ways. However, I'd be surprised if there were more than a few (if any) using them at all.
Regardless, ISTM it would be better to deprecate the two public functions and replace them with a new PyConfig field. That would align a lot better with the intention. If there is a need to see if the currently set allocator matches some expected one, then it would be better to have an explicit function for that (e.g. PyObject_IsArenaAllocator()) rather than exposing PyObject_GetArenaAllocator() for that purpose.
The same goes for PyMem_SetAllocator(), where we'd have an additional PyMem_SetAllocatorWrapper() for the after-init case.
- 主要言語
- Python
- スター
- 77.2k
- フォーク
- 36k
- 平均マージ
- 1日 9時間
- マージ済み PR(30日)
- 558
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
python/cpython のほかの issue
-
docs pending
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
stdlib type-feature
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
stdlib type-feature
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
-
build type-bug
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
-
stdlib topic-email type-feature
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
似ている issue
-
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
zostera/django-bootstrap4#894 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
use-agent-os/agent-os#3276 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
zephyrproject-rtos/zephyr#119726 ·
-
area/auth bug comp/agent P3 platform/discord type/security
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
NousResearch/hermes-agent#117848 ·