doc: update outdated zstd.h comments for ZSTD_compressCCtx() and ZSTD_CCtx_loadDictionary()
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 78/100
- Tipo de issue
- Documentación
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- c
- Área
- documentation
Línea de trabajo
Lee los comentarios de ZSTD_compressCCtx() y ZSTD_CCtx_loadDictionary() en lib/zstd.h y luego consulta las secciones correspondientes en doc/zstd_manual.html. Actualiza ambos para describir cuándo se usan los parámetros y diccionarios existentes, y cuándo se crean y almacenan en caché las tablas del diccionario. El trabajo estará terminado cuando el encabezado y el manual generado coincidan con el comportamiento y los tiempos descritos en el issue.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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):
-
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()usescctx->simpleApiParams(lib/compress/zstd_compress.c:5468-5491) and deliberately does not resetcctx->requestedParamsor loaded dictionaries, nor does it overwriterequestedParams.compressionLevelwith@compressionLevel(tests/fuzzer.c:4110-4142relies onZSTD_c_formatremaining set across consecutive simple one-shot calls).
(Note: Open PR #4987 does not modifylib/zstd.h, and open PR #5041 appends aZSTD_reset_session_onlynote while leaving the false lines434-435unchanged — creating an internal contradiction within the same docstring.) -
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 buildinglocalDict.cdictuntilZSTD_initLocalDict()(lines 1280-1309) at the start of the first compression. CallingZSTD_CCtx_setParameter()afterZSTD_CCtx_loadDictionary()succeeds without error, and parameters modified before the first compression are used to build the dictionary tables (whereas after the first compression cacheslocalDict.cdict,superseded-by-cdictparameters 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:
- For
ZSTD_compressCCtx()(lib/zstd.h:434-435): clarify that advanced parameters and dictionaries set oncctxare ignored for this call (not reset), and remain intact for subsequent advanced API calls. - 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 afterZSTD_CCtx_loadDictionary()prior to the first compression (and once cached on the first frame,superseded-by-cdictparameters 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:
dev539a64c423(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).
- Lenguaje dominante
- C
- Estrellas
- 28.1k
- Forks
- 2.7k
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de facebook/zstd
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 92/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 83/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 83/100
-
windows-artifacts: the win-arm64 job uses a Visual Studio generator missing from windows-11-armPosiblemente ocupada @Ranjeet2063 la tomó hace 12 días. Abierto
Dificultad 1/5 Menos de una hora Aptitud para principiantes 86/100
Todos los issues de facebook/zstd
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
Los mantenedores suelen responder en 2 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
NVIDIA/open-gpu-kernel-modules#1635 ·
Los mantenedores suelen responder en 1 día
-
iOS: the "Edit controls" button never hides, even with a controller connected, and covers the gameAbiertogame: 010065A014024000 ios
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
seedds/nxnative#3714 · 1 comentario ·
Los mantenedores suelen responder en 2 días
-
HTTP/3
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día