Deprecate accepting out of range values for unsigned integers in PyArg_Parse
未關閉
還沒有人認領這個 Issue。
interpreter-core
pending
topic-C-API
type-feature
- 主要語言
- Python
- 星號
- 77.2k
- 分支
- 35.9k
- PR 合併指標
- PR 指標待擷取
描述
Feature or enhancement
For unsigned integer formats (B, H, I, k, K) in PyArg_Parse, there is no overflow check. If the Python integer value is out of range of the corresponding C type, only the lowest bits are stored, and the higher bits are silently dropped. There are two reasons for this:
- The signess of the C type accepted by the C API (like uid_t, etc) is not always known. We need to accept values that fit in corresponding both signed and unsigned C types.
- Even if the type is unsigned, some small negative integers (casted to the unsigned tyep) can have special meaning. It is convenient if we can pass -1 instead of 0xffff_ffff or 0xffff_ffff_ffff_ffff, depending on platform.
But values that cannot be represented neither in unsigned not in signed C type, are obviously invalid. Silently accepting them can provoke bugs.
At first, I propose to emit a deprecation warning for such values. Later they will became errors.
Linked PRs
- gh-132630
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
先閱讀 PyArg_Parse 對無號整數格式 B、H、I、k 和 K 的處理,然後檢視相關的 PR gh-132630,了解已在進行的工作。當既不適合有號 C 型別也不適合無號 C 型別的超出範圍值發出所提議的棄用警告,同時受支援的負值保留其預期行為時,即表示完成。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- c, python
- 領域
- api, backend
- Issue 類型
- 功能
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 25/100