From a34b6c23cdd03d89ad6288814832c5962e5e972d Mon Sep 17 00:00:00 2001 From: Bala Kumar Date: Tue, 1 Sep 2026 11:29:35 +0530 Subject: [PATCH] Remove dead decompress helpers and fix two copy-paste slips No behaviour change. - Remove the unused one-shot decompress path: zstd_decompress, its decompress_wrapper, and the decompress_params struct in common.h, plus decompress_buffered in zstdruby.c. Nothing calls them since decompress was rewritten around decode_one_frame/ZSTD_decompressStream; the streaming wrapper (stream_decompress_wrapper) is unaffected. - rb_ddict_alloc declared its pointer as ZSTD_CDict* though it wraps a DDict; correct it to ZSTD_DDict* (it is NULL here, so the wrong type name was cosmetic). - set_decompress_params raised "ZSTD_CCtx_loadDictionary failed" on a DDict load error; correct it to ZSTD_DCtx_loadDictionary. --- ext/zstdruby/common.h | 33 +-------------------------------- ext/zstdruby/zstdruby.c | 6 +----- 2 files changed, 2 insertions(+), 37 deletions(-) diff --git a/ext/zstdruby/common.h b/ext/zstdruby/common.h index 593e694..f051440 100644 --- a/ext/zstdruby/common.h +++ b/ext/zstdruby/common.h @@ -152,7 +152,7 @@ static VALUE set_decompress_params(ZSTD_DCtx* const dctx, VALUE kwargs) size_t load_dict_ret = ZSTD_DCtx_loadDictionary(dctx, dict_buffer, dict_size); if (ZSTD_isError(load_dict_ret)) { ZSTD_freeDCtx(dctx); - rb_raise(rb_eRuntimeError, "%s", "ZSTD_CCtx_loadDictionary failed"); + rb_raise(rb_eRuntimeError, "%s", "ZSTD_DCtx_loadDictionary failed"); } } else { ZSTD_freeDCtx(dctx); @@ -191,35 +191,4 @@ static size_t zstd_stream_decompress(ZSTD_DCtx* const dctx, ZSTD_outBuffer* outp #endif } -struct decompress_params { - ZSTD_DCtx* dctx; - char* output_data; - size_t output_size; - char* input_data; - size_t input_size; - size_t ret; -}; - -static void* decompress_wrapper(void* args) -{ - struct decompress_params* params = args; - params->ret = ZSTD_decompressDCtx(params->dctx, params->output_data, params->output_size, params->input_data, params->input_size); - return NULL; -} - -static size_t zstd_decompress(ZSTD_DCtx* const dctx, char* output_data, size_t output_size, char* input_data, size_t input_size, bool gvl) -{ -#ifdef HAVE_RUBY_THREAD_H - if (gvl) { - return ZSTD_decompressDCtx(dctx, output_data, output_size, input_data, input_size); - } else { - struct decompress_params params = { dctx, output_data, output_size, input_data, input_size }; - rb_thread_call_without_gvl(decompress_wrapper, ¶ms, NULL, NULL); - return params.ret; - } -#else - return ZSTD_decompressDCtx(dctx, output_data, output_size, input_data, input_size); -#endif -} - #endif /* ZSTD_RUBY_H */ diff --git a/ext/zstdruby/zstdruby.c b/ext/zstdruby/zstdruby.c index 924e9bb..5bc9e0e 100644 --- a/ext/zstdruby/zstdruby.c +++ b/ext/zstdruby/zstdruby.c @@ -78,10 +78,6 @@ static VALUE decode_one_frame(ZSTD_DCtx* dctx, const unsigned char* src, size_t return out; } -static VALUE decompress_buffered(ZSTD_DCtx* dctx, const char* data, size_t len) { - return decode_one_frame(dctx, (const unsigned char*)data, len, Qnil, NULL); -} - static VALUE rb_decompress(int argc, VALUE *argv, VALUE self) { VALUE input_value, kwargs; @@ -216,7 +212,7 @@ static VALUE rb_cdict_initialize(int argc, VALUE *argv, VALUE self) static VALUE rb_ddict_alloc(VALUE self) { - ZSTD_CDict* ddict = NULL; + ZSTD_DDict* ddict = NULL; return TypedData_Wrap_Struct(self, &ddict_type, ddict); }