python / python/cpython

Fix forced arg format in AC-processed modules with custom converters

未關閉
#94,512 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

topic-argument-clinic type-feature
主要語言
Python
星號
77.2k
分支
36k
PR 合併指標
PR 指標待擷取

描述

There are custom Argument Clinic converters that define format_unit but omit parse_arg. As a result, generation of positional argument parsers is forced to back up from the fastest possible _PyArg_CheckPositional to slower _PyArg_ParseStack-based format strings.

Here is a list of such classes (and fixing PRs except complex cases):

  • Modules\_multiprocessing\multiprocessing.c (gh-94517)

    • HANDLE_converter
  • Modules\_multiprocessing\semaphore.c

    • SEM_HANDLE_converter
  • Modules\overlapped.c (gh-94516)

    • OVERLAPPED_converter
    • HANDLE_converter
    • ULONG_PTR_converter
    • DWORD_converter
    • BOOL_converter
  • Modules\posixmodule.c (gh-122516)

    • pid_t_converter
    • idtype_t_converter
    • id_t_converter
    • intptr_t_converter
    • Py_off_t_converter
  • Modules\resource.c (gh-94515)

    • pid_t_converter
  • PC\msvcrtmodule.c (gh-94514)

    • HANDLE_converter
  • PC\winreg.c (gh-94513)

    • REGSAM_converter
    • DWORD_converter
    • HKEY_converter

An example of such a converter:

class BOOL_converter(CConverter):
    type = 'BOOL'
    format_unit = 'i'

class pid_t_converter(CConverter):
    type = 'pid_t'
    format_unit = '" _Py_PARSE_PID "'

I'm going to teach all of them about low-level generation by replacing manual format_unit definitions with:

  • inheritance from a corresponding builtin converter where possible
  • and custom parse_args in other places.

For the example it gives:

class BOOL_converter(int_converter):
    type = 'BOOL'

class pid_t_converter(CConverter):
    type = 'pid_t'
    # Left as a backup for potential complex cases
    format_unit = '" _Py_PARSE_PID "'

    def parse_arg(self, argname, displayname):
        return """
            {paramname} = PyLong_AsPid({argname});
            if ({paramname} == -1 && PyErr_Occurred()) {{{{
                goto exit;
            }}}}
            """.format(argname=argname, paramname=self.parser_name)

貢獻指南

開啟貢獻指南

從這裡開始

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

研究方向

從 Modules/_multiprocessing/semaphore.c 及其 SEM_HANDLE_converter 開始,接著閱讀列出的 converter 範例和相應的已完成模組以進行比較。檢視 Argument Clinic 在產生 positional parser 時如何使用 format_unit 和 parse_arg。完成的標準是 converter 不再強制使用較慢的 format-string parser,同時仍能正確解析引數。

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

評估

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

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

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