python / python/cpython

Add support for defining variadic callbacks via ctypes

オープン
#135,620 コメント 0 件 リアクション 1 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

extension-modules topic-ctypes type-feature
主要言語
Python
スター
77.2k
フォーク
35.9k
PR マージ指標
PR 指標を取得中

説明

Feature or enhancement

Proposal:

When defining a callback with ctypes (CFUNCTYPE) it would be helpful to be able to replicate variadic functionality
for instance, take the following c code

void FormatPrintf(datap* format, char* fmt, ...) {

    va_list args;
    int length = 0;

    va_start(args, fmt);
    length = vsnprintf(NULL, 0, fmt, args);
    va_end(args);
    if (format->length + length > format->size) {
        return;
    }

    va_start(args, fmt);
    (void)vsnprintf(format->buffer, length, fmt, args);
    va_end(args);
    return;
}

Making something compatible with ctypes

@CFUNCTYPE(None, ctypes.POINTER(datap), ctypes.c_char_p, ctypes.c_variadic)
def FormatPrintf(format, fmt, variadic)
    args = variadic.va_list
    ...

Maybe even could be handled as a pyobject list of ctypes objects as the variadic on the python side. Not sure what all the options are explicitly.

Has this already been discussed elsewhere?

No response given

Links to previous discussion of this feature:

No response

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

issue にある ctypes CFUNCTYPE callback のエントリポイントと、C の variadic callback の例から始めます。variadic 引数でサポートされる表現と動作を明確にし、そのような callback の定義と呼び出しが機能することを示すために必要なテストを決定します。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
c, python
領域
api
issue の種類
機能追加
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
説明が足りない
初心者へのやさしさ
30/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。