Re: [PATCH v2 3/5] zstd: move ZSTD_MAX_CLEVEL to zstd_lib.h
From: Sergey Senozhatsky
Date: Wed Jul 29 2026 - 00:27:38 EST
On (26/07/29 12:16), haoqin huang wrote:
> > On (26/07/28 17:29), Haoqin Huang wrote:
> > [..]
> > > #define ZSTD_MINMATCH_MAX 7 /* only for ZSTD_fast, other strategies are limited to 6 */
> > > #define ZSTD_MINMATCH_MIN 3 /* only for ZSTD_btopt+, faster strategies are limited to 4 */
> > > +#define ZSTD_MAX_CLEVEL 22
> > > #define ZSTD_TARGETLENGTH_MAX ZSTD_BLOCKSIZE_MAX
> > > #define ZSTD_TARGETLENGTH_MIN 0 /* note : comparing this constant to an unsigned results in a tautological test */
> > > #define ZSTD_STRATEGY_MIN ZSTD_fast
> > > diff --git a/lib/zstd/compress/clevels.h b/lib/zstd/compress/clevels.h
> > > index 6ab8be6532ef..06565e064456 100644
> > > --- a/lib/zstd/compress/clevels.h
> > > +++ b/lib/zstd/compress/clevels.h
> > > @@ -17,8 +17,6 @@
> > >
> > > /*-===== Pre-defined compression levels =====-*/
> > >
> > > -#define ZSTD_MAX_CLEVEL 22
> > > -
> > > __attribute__((__unused__))
> >
> > Sashiko made a good point. Can we use zstd_max_clevel() instead?
>
> Good point, I'll drop this patch and use zstd_max_clevel() instead
> in v3.
>
> Since it's a runtime function and can't be used for static struct
> initialization, I plan to set backend_zstd's level_max to -1 as a
> sentinel value, and query the actual maximum in
> zcomp_validate_params():
>
> s32 max = backend->level_max;
> if (max < 0)
> max = zstd_max_clevel();
>
> Do you think this approach is feasible?
Hmm, no, that doesn't look good. zcomp should not include
zstd.h or any other libs directly. Should params validation
be a per-backend callback then?