version_sorter 2.0.2 → 2.0.3

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
- SHA1:
3
- metadata.gz: 9b7f83f240fe5c1f73869ea5d444c4353295ef09
4
- data.tar.gz: ce3be5fc421d9406a5176ea4b9d0b9739533d47d
2
+ SHA256:
3
+ metadata.gz: ca2c813ab2e3b07a3c6ba8c7cbac756613b61e7b514b0c06deac6d43b01d819e
4
+ data.tar.gz: caacf05c4444ed24ce2ec866af9bdc2b9455af2eba50afde6010a3d440088389
5
5
  SHA512:
6
- metadata.gz: bf063d33fbe28d170b5eec3bee5e5a1107fa8188d9524e0052b602a4f08ed6aae3d101286f9c9387dcc45489fc084ca15f066006d97034d8ceeb795c58d4088e
7
- data.tar.gz: b5d1c089b337f129a428515a2bc3066ab5d87f92c8e93895bfcd45c18b82625d7e152da0acfaa1215da54e9000d5a0fb58dd4721882945f67e52ee7304fb0be9
6
+ metadata.gz: 7cb7c84a4213cb66509f06809422892d9f14b0d95a955c5124764fa5fdb9881e8f0df86dec159d02fc585d3ee5b0816e39ac451135b675f1e3272ac512b8b93a
7
+ data.tar.gz: 493b92cb2e19a9e2d3b7cb2078c1965860fa299f35b3a07bc6342438903d2b379eb221ca6e32e074045f03ebb51bbc4740ec6beaa11d7f1678c8f325919dc027
@@ -15,6 +15,7 @@
15
15
  #include <ruby.h>
16
16
 
17
17
  #define min(a, b) ((a) < (b) ? (a) : (b))
18
+ #define max(a, b) ((a) > (b) ? (a) : (b))
18
19
  typedef int compare_callback_t(const void *, const void *);
19
20
 
20
21
  struct version_number {
@@ -56,7 +57,8 @@ compare_version_number(const struct version_number *a,
56
57
  int cmp = 0;
57
58
 
58
59
  if (num_a) {
59
- cmp = (int)ca->number - (int)cb->number;
60
+ int64_t cmp64 = (int64_t)ca->number - (int64_t)cb->number;
61
+ cmp = (int)max(-1, min(1, cmp64));
60
62
  } else {
61
63
  cmp = strchunk_cmp(
62
64
  a->original, &ca->string,
@@ -169,36 +171,68 @@ parse_version_number(const char *string)
169
171
  return version;
170
172
  }
171
173
 
174
+ struct sort_context {
175
+ VALUE rb_self;
176
+ VALUE rb_version_array;
177
+ compare_callback_t *cmp;
178
+ struct version_number **versions;
179
+ };
180
+
172
181
  static VALUE
173
- rb_version_sort_1(VALUE rb_self, VALUE rb_version_array, compare_callback_t cmp)
182
+ rb_version_sort_1_cb(VALUE arg)
174
183
  {
175
- struct version_number **versions;
184
+ struct sort_context *context = (struct sort_context *)arg;
176
185
  long length, i;
177
186
  VALUE *rb_version_ptr;
178
187
 
188
+ length = RARRAY_LEN(context->rb_version_array);
189
+ for (i = 0; i < length; ++i) {
190
+ VALUE rb_version = rb_ary_entry(context->rb_version_array, i);
191
+ context->versions[i] = parse_version_number(StringValueCStr(rb_version));
192
+ context->versions[i]->rb_version = rb_version;
193
+ }
194
+
195
+ qsort(context->versions, length, sizeof(struct version_number *), context->cmp);
196
+ rb_version_ptr = RARRAY_PTR(context->rb_version_array);
197
+
198
+ for (i = 0; i < length; ++i) {
199
+ rb_version_ptr[i] = context->versions[i]->rb_version;
200
+ }
201
+
202
+ return context->rb_version_array;
203
+ }
204
+
205
+ static VALUE
206
+ rb_version_sort_1(VALUE rb_self, VALUE rb_version_array, compare_callback_t cmp)
207
+ {
208
+ long length, i;
209
+ int exception;
210
+
179
211
  Check_Type(rb_version_array, T_ARRAY);
180
212
 
181
213
  length = RARRAY_LEN(rb_version_array);
182
214
  if (!length)
183
215
  return rb_ary_new();
184
216
 
185
- versions = xcalloc(length, sizeof(struct version_number *));
217
+ struct sort_context context = {
218
+ rb_self,
219
+ rb_version_array,
220
+ cmp,
221
+ xcalloc(length, sizeof(struct version_number *)),
222
+ };
223
+
224
+ VALUE result = rb_protect(rb_version_sort_1_cb, (VALUE)&context, &exception);
186
225
 
187
226
  for (i = 0; i < length; ++i) {
188
- VALUE rb_version = rb_ary_entry(rb_version_array, i);
189
- versions[i] = parse_version_number(StringValueCStr(rb_version));
190
- versions[i]->rb_version = rb_version;
227
+ xfree(context.versions[i]);
191
228
  }
229
+ xfree(context.versions);
192
230
 
193
- qsort(versions, length, sizeof(struct version_number *), cmp);
194
- rb_version_ptr = RARRAY_PTR(rb_version_array);
195
-
196
- for (i = 0; i < length; ++i) {
197
- rb_version_ptr[i] = versions[i]->rb_version;
198
- xfree(versions[i]);
231
+ if (exception) {
232
+ rb_jump_tag(exception);
199
233
  }
200
- xfree(versions);
201
- return rb_version_array;
234
+
235
+ return result;
202
236
  }
203
237
 
204
238
  static VALUE
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: version_sorter
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2
4
+ version: 2.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Wanstrath
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-01-29 00:00:00.000000000 Z
12
+ date: 2018-02-12 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: VersionSorter is a C extension that does fast sorting of large sets of
15
15
  version strings.
@@ -42,7 +42,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
42
42
  version: '0'
43
43
  requirements: []
44
44
  rubyforge_project:
45
- rubygems_version: 2.5.2
45
+ rubygems_version: 2.7.3
46
46
  signing_key:
47
47
  specification_version: 4
48
48
  summary: Fast sorting of version strings