doc: update outdated zstd.h comments for ZSTD_compressCCtx() and ZSTD_CCtx_loadDictionary()

オープン 初心者向け
#5,129 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

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

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
78/100
issue の種類
ドキュメント
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
c
領域
documentation

調査の方向性

lib/zstd.hにあるZSTD_compressCCtx()とZSTD_CCtx_loadDictionary()のコメントを読み、続いてdoc/zstd_manual.htmlの対応するセクションを確認してください。既存のパラメーターと辞書がいつ使われるのか、辞書テーブルがいつ構築されてキャッシュされるのかを説明するように、両方を更新してください。ヘッダーと生成されたマニュアルの内容が、issueに記載された動作とタイミングに一致すれば完了です。

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

説明

Describe the bug
Two stable API doc comments in lib/zstd.h (and doc/zstd_manual.html) directly contradict the current intentional implementation and test suite on dev (539a64c423):

  1. ZSTD_compressCCtx() (lib/zstd.h:429-436):

    /*! ZSTD_compressCCtx() :
     *  Same as ZSTD_compress(), using an explicit ZSTD_CCtx.
     *  Important : in order to mirror `ZSTD_compress()` behavior,
     *  this function compresses at the requested compression level,
     *  __ignoring any other advanced parameter__ .
     *  If any advanced parameter was set using the advanced API,
     *  they will all be reset. Only @compressionLevel remains.
     */
    

    Since PR #2498 (and PR #2615), ZSTD_compressCCtx() -> ZSTD_compress_usingDict() uses cctx->simpleApiParams (lib/compress/zstd_compress.c:5468-5491) and deliberately does not reset cctx->requestedParams or loaded dictionaries, nor does it overwrite requestedParams.compressionLevel with @compressionLevel (tests/fuzzer.c:4110-4142 relies on ZSTD_c_format remaining set across consecutive simple one-shot calls).
    (Note: Open PR #4987 does not modify lib/zstd.h, and open PR #5041 appends a ZSTD_reset_session_only note while leaving the false lines 434-435 unchanged — creating an internal contradiction within the same docstring.)

  2. ZSTD_CCtx_loadDictionary() (lib/zstd.h:1267-1270):

     *  Note 2 : Loading a dictionary involves building tables.
     *           It's also a CPU consuming operation, with non-negligible impact on latency.
     *           Tables are dependent on compression parameters, and for this reason,
     *           compression parameters can no longer be changed after loading a dictionary.
    

    Since PR #1555 ([lib] Allow ZSTD_CCtx_loadDictionary() to be called before parameters are set), ZSTD_CCtx_loadDictionary() stores the dictionary lazily (lib/compress/zstd_compress.c:1311-1353) and defers building localDict.cdict until ZSTD_initLocalDict() (lines 1280-1309) at the start of the first compression. Calling ZSTD_CCtx_setParameter() after ZSTD_CCtx_loadDictionary() succeeds without error, and parameters modified before the first compression are used to build the dictionary tables (whereas after the first compression caches localDict.cdict, superseded-by-cdict parameters are ignored until the dictionary is reloaded or parameters are reset).

To Reproduce
C reproducer (built and run against dev 539a64c423):

#include <stdio.h>
#include <string.h>
#include "zstd.h"

int main(void) {
    const char* data = "hello world repeated hello world repeated";
    char c1[256];
    ZSTD_CCtx* cctx = ZSTD_createCCtx();

    /* 1. ZSTD_compressCCtx() ignores for this call, but does NOT reset requestedParams */
    ZSTD_CCtx_setParameter(cctx, ZSTD_c_checksumFlag, 1);
    ZSTD_CCtx_setParameter(cctx, ZSTD_c_contentSizeFlag, 0);
    ZSTD_CCtx_setParameter(cctx, ZSTD_c_compressionLevel, 10);
    ZSTD_compressCCtx(cctx, c1, sizeof(c1), data, strlen(data), 1);

    int level = -1, cksum = -1, fcs = -1;
    ZSTD_CCtx_getParameter(cctx, ZSTD_c_compressionLevel, &level);
    ZSTD_CCtx_getParameter(cctx, ZSTD_c_checksumFlag, &cksum);
    ZSTD_CCtx_getParameter(cctx, ZSTD_c_contentSizeFlag, &fcs);
    printf("After ZSTD_compressCCtx(level=1): level=%d, checksum=%d, contentSize=%d\n",
           level, cksum, fcs);

    /* 2. ZSTD_CCtx_setParameter() succeeds after ZSTD_CCtx_loadDictionary() */
    ZSTD_CCtx_reset(cctx, ZSTD_reset_session_and_parameters);
    ZSTD_CCtx_loadDictionary(cctx, data, strlen(data));
    size_t r = ZSTD_CCtx_setParameter(cctx, ZSTD_c_windowLog, 14);
    printf("After ZSTD_CCtx_loadDictionary(): setParameter(windowLog=14) -> %zu (isError=%d)\n",
           r, ZSTD_isError(r));

    ZSTD_freeCCtx(cctx);
    return 0;
}

Actual output on dev 539a64c423:

After ZSTD_compressCCtx(level=1): level=10, checksum=1, contentSize=0
After ZSTD_CCtx_loadDictionary(): setParameter(windowLog=14) -> 14 (isError=0)

Expected behavior
Update lib/zstd.h (and regenerated doc/zstd_manual.html) to match the implemented behavior:

  1. For ZSTD_compressCCtx() (lib/zstd.h:434-435): clarify that advanced parameters and dictionaries set on cctx are ignored for this call (not reset), and remain intact for subsequent advanced API calls.
  2. For ZSTD_CCtx_loadDictionary() (lib/zstd.h:1267-1270): clarify that dictionary tables are built lazily on the first compression, so compression parameters can still be modified after ZSTD_CCtx_loadDictionary() prior to the first compression (and once cached on the first frame, superseded-by-cdict parameters are ignored until the dictionary is reloaded or parameters are reset).

Desktop (please complete the following information):

  • OS: Linux x86_64 (Ubuntu 22.04)
  • Version: dev 539a64c423 (v1.6.0+)
  • Compiler: gcc 11.4.0
  • Flags: -O2
  • Build system: Makefile

Additional context
Related PRs: #2498, #2615, #4987, #5041 (ZSTD_compressCCtx), and #1555 (ZSTD_CCtx_loadDictionary).

主要言語
C
スター
28.1k
フォーク
2.7k
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

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

facebook/zstd のほかの issue

facebook/zstd の issue をすべて見る

似ている issue

C の issue をもっと見る

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

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