ruby-zstds 1.2.0 → 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fd4f85616a45bb4ea60d08e4f6e4dfa0091d5a098458e3f5c5ac81d6c9113aa3
4
- data.tar.gz: a7b1afaa038f4339b0de26e91ae86c16a942620f8f450cbc791a7330cec372cb
3
+ metadata.gz: 1a3bf1ddf3028d59dbfadc868b7dd0049f95213ccede92b223cab2f1af2a847b
4
+ data.tar.gz: d8dce89cd592e7815aea864900afd336e67a0bc65def9f6b21b30a67b184a7fc
5
5
  SHA512:
6
- metadata.gz: 0e76817922415c3fa1381aca25636aef90cc1a4bb98c8c8adc998667fc5eb10e24e27f66127f6c93d341af222bbf44229ef37996ea24fa89888b5381f0e8f1fb
7
- data.tar.gz: c4aaa1527b723e6c2eec1f185b10657d50fd2e55fb0a9debf4cf993d561931b8cb60216023b0971d4739389eadcdccec011db668b943bfdc49f323e5852f409c
6
+ metadata.gz: b956bba7a80f4456b736748e2355d9e862f230af855d5b539cb0d7034c183238d8e8b68a65c629fb5baae2ec94757d0e8f822572d0bcc694a2740bb173ab6e7d
7
+ data.tar.gz: 6222867bf832bf0d8b08e8cc94d25be1eec376e87b6f24e1bc2d8c75f36d06bb12a7a601f8737eccafa02bdd1c1c0a3eee65c7d7f2c77fcb9e0b4068d9afaef1
data/AUTHORS CHANGED
@@ -1 +1,3 @@
1
1
  Andrew Aladjev
2
+ Ivan Takarlikov
3
+ Jenner La Fave
data/README.md CHANGED
@@ -1,14 +1,23 @@
1
1
  # Ruby bindings for zstd library
2
2
 
3
- | AppVeyor | Circle | Github actions | Codecov | Gem |
4
- | :------: | :----: | :------------: | :-----: | :--: |
5
- | [![AppVeyor test status](https://ci.appveyor.com/api/projects/status/github/andrew-aladev/ruby-zstds?branch=master&svg=true)](https://ci.appveyor.com/project/andrew-aladev/ruby-zstds/branch/master) | [![Circle test status](https://circleci.com/gh/andrew-aladev/ruby-zstds/tree/master.svg?style=shield)](https://circleci.com/gh/andrew-aladev/ruby-zstds/tree/master) | [![Github Actions test status](https://github.com/andrew-aladev/ruby-zstds/workflows/test/badge.svg?branch=master)](https://github.com/andrew-aladev/ruby-zstds/actions) | [![Codecov](https://codecov.io/gh/andrew-aladev/ruby-zstds/branch/master/graph/badge.svg)](https://codecov.io/gh/andrew-aladev/ruby-zstds) | [![Gem](https://img.shields.io/gem/v/ruby-zstds.svg)](https://rubygems.org/gems/ruby-zstds) |
3
+ | AppVeyor | Jenkins | Github actions | Codecov | Gem |
4
+ | :------: | :-----: | :------------: | :-----: | :--: |
5
+ | [![AppVeyor test status](https://ci.appveyor.com/api/projects/status/github/andrew-aladev/ruby-zstds?branch=master&svg=true)](https://ci.appveyor.com/project/andrew-aladev/ruby-zstds/branch/master) | [![Jenkins test status](http://37.187.122.190:58182/buildStatus/icon?job=ruby-zstds)](http://37.187.122.190:58182/job/ruby-zstds) | [![Github Actions test status](https://github.com/andrew-aladev/ruby-zstds/workflows/test/badge.svg?branch=master)](https://github.com/andrew-aladev/ruby-zstds/actions) | [![Codecov](https://codecov.io/gh/andrew-aladev/ruby-zstds/branch/master/graph/badge.svg)](https://codecov.io/gh/andrew-aladev/ruby-zstds) | [![Gem](https://img.shields.io/gem/v/ruby-zstds.svg)](https://rubygems.org/gems/ruby-zstds) |
6
6
 
7
7
  See [zstd library](https://github.com/facebook/zstd).
8
8
 
9
9
  ## Installation
10
10
 
11
- Please install zstd library first, use latest 1.4.0+ version.
11
+ Operating systems: GNU/Linux, FreeBSD, OSX.
12
+
13
+ Dependencies: [zstd](https://github.com/facebook/zstd) 1.4.0+ version.
14
+
15
+ | Popular OS | Dependencies |
16
+ |------------|---------------------------|
17
+ | Ubuntu | `libzstd-dev` |
18
+ | CentOS | `libzstd-devel` |
19
+ | ArchLinux | `zstd` |
20
+ | OSX | `zstd` |
12
21
 
13
22
  ```sh
14
23
  gem install ruby-zstds
@@ -23,6 +32,22 @@ gem install pkg/ruby-zstds-*.gem
23
32
 
24
33
  You can also use [overlay](https://github.com/andrew-aladev/overlay) for gentoo.
25
34
 
35
+ ### Installation in macOS on Apple Silicon
36
+
37
+ On M1 Macs, Homebrew installs to /opt/homebrew, so you'll need to specify its
38
+ include and lib paths when building the native extension for zstd.
39
+
40
+ ```sh
41
+ brew install zstd
42
+ gem install ruby-zstds -- --with-opt-include=/opt/homebrew/include --with-opt-lib=/opt/homebrew/lib
43
+ ```
44
+
45
+ You can also configure Bundler to use those options when installing:
46
+
47
+ ```sh
48
+ bundle config set build.ruby-zstds "--with-opt-include=/opt/homebrew/include --with-opt-lib=/opt/homebrew/lib"
49
+ ```
50
+
26
51
  ## Usage
27
52
 
28
53
  There are simple APIs: `String` and `File`. Also you can use generic streaming API: `Stream::Writer` and `Stream::Reader`.
@@ -125,6 +150,10 @@ Parallel.each large_datas do |large_data|
125
150
  end
126
151
  ```
127
152
 
153
+ # Docs
154
+
155
+ Please review [rdoc generated docs](https://andrew-aladev.github.io/ruby-zstds).
156
+
128
157
  ## Options
129
158
 
130
159
  | Option | Values | Default | Description |
@@ -318,14 +347,11 @@ Special asynchronous methods missing in `Zlib::GzipWriter`.
318
347
  So it is possible to have asynchronous variants for these synchronous methods.
319
348
  Behaviour is the same as `IO#write_nonblock` method.
320
349
 
321
- All nonblock operations for file will raise `EBADF` error on Windows.
322
- Setting file into nonblocking mode is [not available on Windows](https://github.com/ruby/ruby/blob/master/win32/win32.c#L4388).
323
-
324
350
  ```
325
351
  #<<(object)
326
352
  #print(*objects)
327
353
  #printf(*args)
328
- #putc(object, encoding: ::Encoding::BINARY)
354
+ #putc(object, :encoding => 'ASCII-8BIT')
329
355
  #puts(*objects)
330
356
  ```
331
357
 
@@ -449,10 +475,6 @@ You should lock all shared data between threads.
449
475
  For example: you should not use same compressor/decompressor inside multiple threads.
450
476
  Please verify that you are using each processor inside single thread at the same time.
451
477
 
452
- ## Operating systems
453
-
454
- GNU/Linux, FreeBSD, OSX, Windows (MinGW).
455
-
456
478
  ## CI
457
479
 
458
480
  Please visit [scripts/test-images](scripts/test-images).
data/ext/extconf.rb CHANGED
@@ -72,6 +72,7 @@ require_header(
72
72
  "ZSTD_strategy"
73
73
  ]
74
74
  )
75
+
75
76
  require_header(
76
77
  "zstd_errors.h",
77
78
  :constants => %w[
@@ -106,11 +107,23 @@ def require_library(name, functions)
106
107
  end
107
108
  end
108
109
 
110
+ # rubocop:disable Style/GlobalVars
111
+ if find_library "zstd", "ZDICT_getDictHeaderSize"
112
+ $defs.push "-DHAVE_ZDICT_HEADER_SIZE"
113
+ end
114
+
115
+ zdict_has_params = find_type "ZDICT_params_t", nil, "zdict.h"
116
+ zdict_has_finalize = find_library "zstd", "ZDICT_finalizeDictionary"
117
+
118
+ if zdict_has_params && zdict_has_finalize
119
+ $defs.push "-DHAVE_ZDICT_FINALIZE"
120
+ end
121
+ # rubocop:enable Style/GlobalVars
122
+
109
123
  require_library(
110
124
  "zstd",
111
125
  %w[
112
126
  ZDICT_getDictID
113
- ZDICT_getDictHeaderSize
114
127
  ZDICT_isError
115
128
  ZDICT_trainFromBuffer
116
129
  ZSTD_CCtx_loadDictionary
@@ -9,10 +9,9 @@
9
9
  #include "zstds_ext/buffer.h"
10
10
  #include "zstds_ext/error.h"
11
11
  #include "zstds_ext/gvl.h"
12
- #include "zstds_ext/macro.h"
13
12
  #include "zstds_ext/option.h"
14
13
 
15
- // -- initialization --
14
+ // -- common --
16
15
 
17
16
  typedef struct
18
17
  {
@@ -20,43 +19,64 @@ typedef struct
20
19
  size_t size;
21
20
  } sample_t;
22
21
 
23
- typedef struct
22
+ static inline void check_raw_samples(VALUE raw_samples)
24
23
  {
25
- const sample_t* samples;
26
- size_t length;
27
- char* buffer;
28
- size_t capacity;
29
- zstds_result_t result;
30
- zstds_ext_result_t ext_result;
31
- } train_args_t;
24
+ Check_Type(raw_samples, T_ARRAY);
32
25
 
33
- static inline void* train_wrapper(void* data)
26
+ size_t samples_length = RARRAY_LEN(raw_samples);
27
+
28
+ for (size_t index = 0; index < samples_length; index++) {
29
+ Check_Type(rb_ary_entry(raw_samples, index), T_STRING);
30
+ }
31
+ }
32
+
33
+ static inline sample_t* prepare_samples(VALUE raw_samples, size_t* samples_length_ptr)
34
+ {
35
+ size_t samples_length = RARRAY_LEN(raw_samples);
36
+ sample_t* samples = malloc(sizeof(sample_t) * samples_length);
37
+ if (samples == NULL) {
38
+ zstds_ext_raise_error(ZSTDS_EXT_ERROR_ALLOCATE_FAILED);
39
+ }
40
+
41
+ for (size_t index = 0; index < samples_length; index++) {
42
+ VALUE raw_sample = rb_ary_entry(raw_samples, index);
43
+ sample_t* sample = &samples[index];
44
+
45
+ sample->data = RSTRING_PTR(raw_sample);
46
+ sample->size = RSTRING_LEN(raw_sample);
47
+ }
48
+
49
+ *samples_length_ptr = samples_length;
50
+
51
+ return samples;
52
+ }
53
+
54
+ static inline zstds_ext_result_t prepare_samples_group(
55
+ const sample_t* samples,
56
+ size_t samples_length,
57
+ zstds_ext_byte_t** group_ptr,
58
+ size_t** sizes_ptr)
34
59
  {
35
- train_args_t* args = data;
36
- const sample_t* samples = args->samples;
37
- size_t length = args->length;
38
- size_t size = 0;
60
+ size_t size = 0;
39
61
 
40
- for (size_t index = 0; index < length; index++) {
62
+ for (size_t index = 0; index < samples_length; index++) {
41
63
  size += samples[index].size;
42
64
  }
43
65
 
44
66
  zstds_ext_byte_t* group = malloc(size);
45
67
  if (group == NULL) {
46
- args->ext_result = ZSTDS_EXT_ERROR_ALLOCATE_FAILED;
47
- return NULL;
68
+ return ZSTDS_EXT_ERROR_ALLOCATE_FAILED;
48
69
  }
49
70
 
50
- size_t* sizes = malloc(length * sizeof(size_t));
71
+ size_t* sizes = malloc(samples_length * sizeof(size_t));
51
72
  if (sizes == NULL) {
52
73
  free(group);
53
- args->ext_result = ZSTDS_EXT_ERROR_ALLOCATE_FAILED;
54
- return NULL;
74
+ return ZSTDS_EXT_ERROR_ALLOCATE_FAILED;
55
75
  }
56
76
 
57
77
  size_t offset = 0;
58
78
 
59
- for (size_t index = 0; index < length; index++) {
79
+ for (size_t index = 0; index < samples_length; index++) {
60
80
  const sample_t* sample_ptr = &samples[index];
61
81
  size_t sample_size = sample_ptr->size;
62
82
 
@@ -66,7 +86,38 @@ static inline void* train_wrapper(void* data)
66
86
  sizes[index] = sample_size;
67
87
  }
68
88
 
69
- args->result = ZDICT_trainFromBuffer((void*) args->buffer, args->capacity, group, sizes, (unsigned int) length);
89
+ *group_ptr = group;
90
+ *sizes_ptr = sizes;
91
+
92
+ return 0;
93
+ }
94
+
95
+ // -- training --
96
+
97
+ typedef struct
98
+ {
99
+ const sample_t* samples;
100
+ size_t samples_length;
101
+ char* buffer;
102
+ size_t capacity;
103
+ zstds_result_t result;
104
+ zstds_ext_result_t ext_result;
105
+ } train_args_t;
106
+
107
+ static inline void* train_wrapper(void* data)
108
+ {
109
+ train_args_t* args = data;
110
+
111
+ zstds_ext_byte_t* group;
112
+ size_t* sizes;
113
+ zstds_ext_result_t result = prepare_samples_group(args->samples, args->samples_length, &group, &sizes);
114
+ if (result != 0) {
115
+ args->ext_result = result;
116
+ return NULL;
117
+ }
118
+
119
+ args->result =
120
+ ZDICT_trainFromBuffer((void*) args->buffer, args->capacity, group, sizes, (unsigned int) args->samples_length);
70
121
 
71
122
  free(group);
72
123
  free(sizes);
@@ -83,17 +134,13 @@ static inline void* train_wrapper(void* data)
83
134
 
84
135
  VALUE zstds_ext_train_dictionary_buffer(VALUE ZSTDS_EXT_UNUSED(self), VALUE raw_samples, VALUE options)
85
136
  {
86
- Check_Type(raw_samples, T_ARRAY);
87
-
88
- size_t length = RARRAY_LEN(raw_samples);
89
-
90
- for (size_t index = 0; index < length; index++) {
91
- Check_Type(rb_ary_entry(raw_samples, index), T_STRING);
92
- }
93
-
137
+ check_raw_samples(raw_samples);
94
138
  Check_Type(options, T_HASH);
95
- ZSTDS_EXT_GET_BOOL_OPTION(options, gvl);
96
139
  ZSTDS_EXT_GET_SIZE_OPTION(options, capacity);
140
+ ZSTDS_EXT_GET_BOOL_OPTION(options, gvl);
141
+
142
+ size_t samples_length;
143
+ sample_t* samples = prepare_samples(raw_samples, &samples_length);
97
144
 
98
145
  if (capacity == 0) {
99
146
  capacity = ZSTDS_EXT_DEFAULT_DICTIONARY_CAPACITY;
@@ -106,27 +153,147 @@ VALUE zstds_ext_train_dictionary_buffer(VALUE ZSTDS_EXT_UNUSED(self), VALUE raw_
106
153
  zstds_ext_raise_error(ZSTDS_EXT_ERROR_ALLOCATE_FAILED);
107
154
  }
108
155
 
109
- sample_t* samples = malloc(sizeof(sample_t) * length);
110
- if (samples == NULL) {
156
+ train_args_t args = {
157
+ .samples = samples,
158
+ .samples_length = samples_length,
159
+ .buffer = RSTRING_PTR(buffer),
160
+ .capacity = capacity,
161
+ };
162
+
163
+ ZSTDS_EXT_GVL_WRAP(gvl, train_wrapper, &args);
164
+ free(samples);
165
+
166
+ if (args.ext_result != 0) {
167
+ zstds_ext_raise_error(args.ext_result);
168
+ }
169
+
170
+ ZSTDS_EXT_RESIZE_STRING_BUFFER(buffer, args.result, exception);
171
+ if (exception != 0) {
111
172
  zstds_ext_raise_error(ZSTDS_EXT_ERROR_ALLOCATE_FAILED);
112
173
  }
113
174
 
114
- for (size_t index = 0; index < length; index++) {
115
- VALUE raw_sample = rb_ary_entry(raw_samples, index);
116
- sample_t* sample = &samples[index];
175
+ return buffer;
176
+ }
117
177
 
118
- sample->data = RSTRING_PTR(raw_sample);
119
- sample->size = RSTRING_LEN(raw_sample);
178
+ // -- finalizing --
179
+
180
+ #if defined(HAVE_ZDICT_FINALIZE)
181
+ typedef struct
182
+ {
183
+ const sample_t* samples;
184
+ size_t samples_length;
185
+ char* buffer;
186
+ size_t max_size;
187
+ char* content;
188
+ size_t content_length;
189
+ zstds_ext_dictionary_options_t dictionary_options;
190
+ zstds_result_t result;
191
+ zstds_ext_result_t ext_result;
192
+ } finalize_args_t;
193
+
194
+ static inline void* finalize_wrapper(void* data)
195
+ {
196
+ finalize_args_t* args = data;
197
+
198
+ zstds_ext_byte_t* group;
199
+ size_t* sizes;
200
+ zstds_ext_result_t result = prepare_samples_group(args->samples, args->samples_length, &group, &sizes);
201
+ if (result != 0) {
202
+ args->ext_result = result;
203
+ return NULL;
120
204
  }
121
205
 
122
- train_args_t args = {
123
- .samples = samples,
124
- .length = length,
125
- .buffer = RSTRING_PTR(buffer),
126
- .capacity = capacity,
206
+ zstds_ext_option_t compression_level = args->dictionary_options.compression_level;
207
+ int compression_level_value;
208
+ if (compression_level.has_value) {
209
+ compression_level_value = compression_level.value;
210
+ } else {
211
+ compression_level_value = 0;
212
+ }
213
+
214
+ zstds_ext_option_t notification_level = args->dictionary_options.notification_level;
215
+ unsigned int notification_level_value;
216
+ if (notification_level.has_value) {
217
+ notification_level_value = notification_level.value;
218
+ } else {
219
+ notification_level_value = 0;
220
+ }
221
+
222
+ zstds_ext_option_t dictionary_id = args->dictionary_options.dictionary_id;
223
+ unsigned int dictionary_id_value;
224
+ if (dictionary_id.has_value) {
225
+ dictionary_id_value = dictionary_id.value;
226
+ } else {
227
+ dictionary_id_value = 0;
228
+ }
229
+
230
+ ZDICT_params_t dictionary_params = {
231
+ .compressionLevel = compression_level_value,
232
+ .notificationLevel = notification_level_value,
233
+ .dictID = dictionary_id_value,
127
234
  };
128
235
 
129
- ZSTDS_EXT_GVL_WRAP(gvl, train_wrapper, &args);
236
+ args->result = ZDICT_finalizeDictionary(
237
+ (void*) args->buffer,
238
+ args->max_size,
239
+ (void*) args->content,
240
+ args->content_length,
241
+ group,
242
+ sizes,
243
+ (unsigned int) args->samples_length,
244
+ dictionary_params);
245
+
246
+ free(group);
247
+ free(sizes);
248
+
249
+ if (ZDICT_isError(args->result)) {
250
+ args->ext_result = zstds_ext_get_error(ZSTD_getErrorCode(args->result));
251
+ return NULL;
252
+ }
253
+
254
+ args->ext_result = 0;
255
+
256
+ return NULL;
257
+ }
258
+
259
+ VALUE zstds_ext_finalize_dictionary_buffer(
260
+ VALUE ZSTDS_EXT_UNUSED(self),
261
+ VALUE content,
262
+ VALUE raw_samples,
263
+ VALUE options)
264
+ {
265
+ Check_Type(content, T_STRING);
266
+ check_raw_samples(raw_samples);
267
+ Check_Type(options, T_HASH);
268
+ ZSTDS_EXT_GET_SIZE_OPTION(options, max_size);
269
+ ZSTDS_EXT_GET_BOOL_OPTION(options, gvl);
270
+ ZSTDS_EXT_GET_DICTIONARY_OPTIONS(options);
271
+
272
+ size_t samples_length;
273
+ sample_t* samples = prepare_samples(raw_samples, &samples_length);
274
+
275
+ if (max_size == 0) {
276
+ max_size = ZSTDS_EXT_DEFAULT_DICTIONARY_MAX_SIZE;
277
+ }
278
+
279
+ int exception;
280
+
281
+ ZSTDS_EXT_CREATE_STRING_BUFFER(buffer, max_size, exception);
282
+ if (exception != 0) {
283
+ zstds_ext_raise_error(ZSTDS_EXT_ERROR_ALLOCATE_FAILED);
284
+ }
285
+
286
+ finalize_args_t args = {
287
+ .samples = samples,
288
+ .samples_length = samples_length,
289
+ .buffer = RSTRING_PTR(buffer),
290
+ .max_size = max_size,
291
+ .content = RSTRING_PTR(content),
292
+ .content_length = RSTRING_LEN(content),
293
+ .dictionary_options = dictionary_options,
294
+ };
295
+
296
+ ZSTDS_EXT_GVL_WRAP(gvl, finalize_wrapper, &args);
130
297
  free(samples);
131
298
 
132
299
  if (args.ext_result != 0) {
@@ -141,6 +308,17 @@ VALUE zstds_ext_train_dictionary_buffer(VALUE ZSTDS_EXT_UNUSED(self), VALUE raw_
141
308
  return buffer;
142
309
  }
143
310
 
311
+ #else
312
+ ZSTDS_EXT_NORETURN VALUE zstds_ext_finalize_dictionary_buffer(
313
+ VALUE ZSTDS_EXT_UNUSED(self),
314
+ VALUE ZSTDS_EXT_UNUSED(content),
315
+ VALUE ZSTDS_EXT_UNUSED(raw_samples),
316
+ VALUE ZSTDS_EXT_UNUSED(options))
317
+ {
318
+ zstds_ext_raise_error(ZSTDS_EXT_ERROR_NOT_IMPLEMENTED);
319
+ }
320
+ #endif // HAVE_ZDICT_FINALIZE
321
+
144
322
  // -- other --
145
323
 
146
324
  VALUE zstds_ext_get_dictionary_buffer_id(VALUE ZSTDS_EXT_UNUSED(self), VALUE buffer)
@@ -153,6 +331,7 @@ VALUE zstds_ext_get_dictionary_buffer_id(VALUE ZSTDS_EXT_UNUSED(self), VALUE buf
153
331
  return UINT2NUM(id);
154
332
  }
155
333
 
334
+ #if defined(HAVE_ZDICT_HEADER_SIZE)
156
335
  VALUE zstds_ext_get_dictionary_header_size(VALUE ZSTDS_EXT_UNUSED(self), VALUE buffer)
157
336
  {
158
337
  zstds_result_t result = ZDICT_getDictHeaderSize(RSTRING_PTR(buffer), RSTRING_LEN(buffer));
@@ -163,12 +342,21 @@ VALUE zstds_ext_get_dictionary_header_size(VALUE ZSTDS_EXT_UNUSED(self), VALUE b
163
342
  return SIZET2NUM(result);
164
343
  }
165
344
 
345
+ #else
346
+ ZSTDS_EXT_NORETURN VALUE
347
+ zstds_ext_get_dictionary_header_size(VALUE ZSTDS_EXT_UNUSED(self), VALUE ZSTDS_EXT_UNUSED(buffer))
348
+ {
349
+ zstds_ext_raise_error(ZSTDS_EXT_ERROR_NOT_IMPLEMENTED);
350
+ };
351
+ #endif // HAVE_ZDICT_HEADER_SIZE
352
+
166
353
  // -- exports --
167
354
 
168
355
  void zstds_ext_dictionary_exports(VALUE root_module)
169
356
  {
170
357
  VALUE dictionary = rb_define_class_under(root_module, "Dictionary", rb_cObject);
171
358
 
359
+ rb_define_singleton_method(dictionary, "finalize_buffer", zstds_ext_finalize_dictionary_buffer, 3);
172
360
  rb_define_singleton_method(dictionary, "get_buffer_id", zstds_ext_get_dictionary_buffer_id, 1);
173
361
  rb_define_singleton_method(dictionary, "get_header_size", zstds_ext_get_dictionary_header_size, 1);
174
362
  rb_define_singleton_method(dictionary, "train_buffer", zstds_ext_train_dictionary_buffer, 2);
@@ -6,11 +6,33 @@
6
6
 
7
7
  #include "ruby.h"
8
8
 
9
+ #include "zstds_ext/macro.h"
10
+
9
11
  #define ZSTDS_EXT_DEFAULT_DICTIONARY_CAPACITY (1 << 17); // 128 KB
12
+ #define ZSTDS_EXT_DEFAULT_DICTIONARY_MAX_SIZE ZSTDS_EXT_DEFAULT_DICTIONARY_CAPACITY
13
+
14
+ // -- training --
10
15
 
11
16
  VALUE zstds_ext_train_dictionary_buffer(VALUE self, VALUE samples, VALUE options);
17
+
18
+ // -- finalizing --
19
+
20
+ #if defined(HAVE_ZDICT_FINALIZE)
21
+ VALUE zstds_ext_finalize_dictionary_buffer(VALUE self, VALUE content, VALUE samples, VALUE options);
22
+ #else
23
+ ZSTDS_EXT_NORETURN VALUE zstds_ext_finalize_dictionary_buffer(VALUE self, VALUE content, VALUE samples, VALUE options);
24
+ #endif // HAVE_ZDICT_FINALIZE
25
+
26
+ // -- other --
27
+
12
28
  VALUE zstds_ext_get_dictionary_buffer_id(VALUE self, VALUE buffer);
13
29
 
30
+ #if defined(HAVE_ZDICT_HEADER_SIZE)
31
+ VALUE zstds_ext_get_dictionary_header_size(VALUE self, VALUE buffer);
32
+ #else
33
+ ZSTDS_EXT_NORETURN VALUE zstds_ext_get_dictionary_header_size(VALUE self, VALUE buffer);
34
+ #endif // HAVE_ZDICT_HEADER_SIZE
35
+
14
36
  void zstds_ext_dictionary_exports(VALUE root_module);
15
37
 
16
38
  #endif // ZSTDS_EXT_DICTIONARY_H
@@ -69,6 +69,9 @@ void zstds_ext_raise_error(zstds_ext_result_t ext_result)
69
69
  case ZSTDS_EXT_ERROR_WRITE_IO:
70
70
  raise_error("WriteIOError", "failed to write IO");
71
71
 
72
+ case ZSTDS_EXT_ERROR_NOT_IMPLEMENTED:
73
+ raise_error("NotImplementedError", "not implemented error");
74
+
72
75
  default:
73
76
  // ZSTDS_EXT_ERROR_UNEXPECTED
74
77
  raise_error("UnexpectedError", "unexpected error");
@@ -26,6 +26,7 @@ enum
26
26
  ZSTDS_EXT_ERROR_READ_IO,
27
27
  ZSTDS_EXT_ERROR_WRITE_IO,
28
28
 
29
+ ZSTDS_EXT_ERROR_NOT_IMPLEMENTED,
29
30
  ZSTDS_EXT_ERROR_UNEXPECTED
30
31
  };
31
32
 
data/ext/zstds_ext/gvl.h CHANGED
@@ -4,7 +4,7 @@
4
4
  #if !defined(ZSTDS_EXT_GVL_H)
5
5
  #define ZSTDS_EXT_GVL_H
6
6
 
7
- #ifdef HAVE_RB_THREAD_CALL_WITHOUT_GVL
7
+ #if defined(HAVE_RB_THREAD_CALL_WITHOUT_GVL)
8
8
 
9
9
  #include "ruby/thread.h"
10
10
 
@@ -19,6 +19,6 @@
19
19
 
20
20
  #define ZSTDS_EXT_GVL_WRAP(_gvl, function, data) function((void*) data);
21
21
 
22
- #endif
22
+ #endif // HAVE_RB_THREAD_CALL_WITHOUT_GVL
23
23
 
24
24
  #endif // ZSTDS_EXT_GVL_H
@@ -8,6 +8,12 @@
8
8
  #define ZSTDS_EXT_UNUSED(x) x __attribute__((__unused__))
9
9
  #else
10
10
  #define ZSTDS_EXT_UNUSED(x) x
11
- #endif
11
+ #endif // __GNUC__
12
+
13
+ #if defined(__GNUC__)
14
+ #define ZSTDS_EXT_NORETURN __attribute__((__noreturn__))
15
+ #else
16
+ #define ZSTDS_EXT_NORETURN
17
+ #endif // __GNUC__
12
18
 
13
19
  #endif // ZSTDS_EXT_MACRO_H
@@ -68,6 +68,13 @@ typedef struct
68
68
  VALUE dictionary;
69
69
  } zstds_ext_decompressor_options_t;
70
70
 
71
+ typedef struct
72
+ {
73
+ zstds_ext_option_t compression_level;
74
+ zstds_ext_option_t notification_level;
75
+ zstds_ext_option_t dictionary_id;
76
+ } zstds_ext_dictionary_options_t;
77
+
71
78
  void zstds_ext_resolve_option(
72
79
  VALUE options,
73
80
  zstds_ext_option_t* option,
@@ -117,6 +124,13 @@ void zstds_ext_resolve_dictionary_option(VALUE options, VALUE* option, const cha
117
124
  ZSTDS_EXT_RESOLVE_OPTION(options, decompressor_options, ZSTDS_EXT_OPTION_TYPE_UINT, window_log_max); \
118
125
  ZSTDS_EXT_RESOLVE_DICTIONARY_OPTION(options, decompressor_options, dictionary);
119
126
 
127
+ #define ZSTDS_EXT_GET_DICTIONARY_OPTIONS(options) \
128
+ zstds_ext_dictionary_options_t dictionary_options; \
129
+ \
130
+ ZSTDS_EXT_RESOLVE_OPTION(options, dictionary_options, ZSTDS_EXT_OPTION_TYPE_INT, compression_level); \
131
+ ZSTDS_EXT_RESOLVE_OPTION(options, dictionary_options, ZSTDS_EXT_OPTION_TYPE_UINT, notification_level); \
132
+ ZSTDS_EXT_RESOLVE_OPTION(options, dictionary_options, ZSTDS_EXT_OPTION_TYPE_UINT, dictionary_id);
133
+
120
134
  bool zstds_ext_get_bool_option_value(VALUE options, const char* name);
121
135
  size_t zstds_ext_get_size_option_value(VALUE options, const char* name);
122
136