@@ -24,7 +24,11 @@ static int convert_compression_level(ZSTD_CCtx* ctx, VALUE compression_level_val
2424 return NUM2INT (compression_level_value);
2525}
2626
27- static void set_compress_params (ZSTD_CCtx* const ctx, VALUE kwargs)
27+ /* Returns the Zstd::CDict given as `dict:`, or Qnil. ZSTD_CCtx_refCDict only
28+ borrows the pointer, so a caller that keeps the ZSTD_CCtx alive beyond this
29+ call has to keep the returned object reachable for just as long. A String
30+ dictionary needs no such handling: ZSTD_CCtx_loadDictionary copies it. */
31+ static VALUE set_compress_params (ZSTD_CCtx* const ctx, VALUE kwargs)
2832{
2933 ID kwargs_keys[2 ];
3034 kwargs_keys[0 ] = rb_intern (" level" );
@@ -46,6 +50,7 @@ static void set_compress_params(ZSTD_CCtx* const ctx, VALUE kwargs)
4650 ZSTD_freeCCtx (ctx);
4751 rb_raise (rb_eRuntimeError, " %s" , " ZSTD_CCtx_refCDict failed" );
4852 }
53+ return kwargs_values[1 ];
4954 } else if (TYPE (kwargs_values[1 ]) == T_STRING ) {
5055 char * dict_buffer = RSTRING_PTR (kwargs_values[1 ]);
5156 size_t dict_size = RSTRING_LEN (kwargs_values[1 ]);
@@ -59,6 +64,7 @@ static void set_compress_params(ZSTD_CCtx* const ctx, VALUE kwargs)
5964 rb_raise (rb_eArgError, " `dict:` must be a Zstd::CDict or a String" );
6065 }
6166 }
67+ return Qnil;
6268}
6369
6470struct stream_compress_params {
@@ -122,7 +128,9 @@ static size_t zstd_compress(ZSTD_CCtx* const ctx, char* output_data, size_t outp
122128#endif
123129}
124130
125- static void set_decompress_params (ZSTD_DCtx* const dctx, VALUE kwargs)
131+ /* Returns the Zstd::DDict given as `dict:`, or Qnil. See set_compress_params:
132+ ZSTD_DCtx_refDDict borrows, ZSTD_DCtx_loadDictionary copies. */
133+ static VALUE set_decompress_params (ZSTD_DCtx* const dctx, VALUE kwargs)
126134{
127135 ID kwargs_keys[1 ];
128136 kwargs_keys[0 ] = rb_intern (" dict" );
@@ -137,6 +145,7 @@ static void set_decompress_params(ZSTD_DCtx* const dctx, VALUE kwargs)
137145 ZSTD_freeDCtx (dctx);
138146 rb_raise (rb_eRuntimeError, " %s" , " ZSTD_DCtx_refDDict failed" );
139147 }
148+ return kwargs_values[0 ];
140149 } else if (TYPE (kwargs_values[0 ]) == T_STRING ) {
141150 char * dict_buffer = RSTRING_PTR (kwargs_values[0 ]);
142151 size_t dict_size = RSTRING_LEN (kwargs_values[0 ]);
@@ -150,6 +159,7 @@ static void set_decompress_params(ZSTD_DCtx* const dctx, VALUE kwargs)
150159 rb_raise (rb_eArgError, " `dict:` must be a Zstd::DDict or a String" );
151160 }
152161 }
162+ return Qnil;
153163}
154164
155165struct stream_decompress_params {
0 commit comments