version_sorter 2.2.3 → 2.2.4

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: 2cffc861c5e2a2c13dda17224f8ea4c5e151e158289acb450862dfab2290e349
4
- data.tar.gz: ac2db605551d166e433f07e7b47096532742d38ed6b1e46ba729a0db49a65fa3
3
+ metadata.gz: f4549572e0353ea5da5a91719cb77444249dbd5e30f199f4d50faa7a8c1b585d
4
+ data.tar.gz: c4744eb78ce03c4a654a56814d368c2d6f4fd0aa4345eca818cc659acd9991f3
5
5
  SHA512:
6
- metadata.gz: 71a8eb2720fa8f1080b15c672a1ae4180653475ae5b2bc769f6b412290b79c83870de869d0ef297d7597402b507b17ea058980514c866b652ceb2bcc0e6c581f
7
- data.tar.gz: 7898481b569023fd091a1e0d38dda1effdec20762043b71364cdc1c930bf4e061e1f3c23095481774317e2801e80826ada395c33eff41c06b0dd4a3ee71b0ab5
6
+ metadata.gz: 4309c00a5b4b5cb3eca9cfcec32a75fe918ca58954d80a10b489d834e1d8ea82f9348ae14ee92f4baba038ef0804f467fdf4fa7acd3e6e147c7762dcc89fa12c
7
+ data.tar.gz: a9cf4f8d1f3d57585ff4b22e5b91daa07d725927f56f7394bd70f7ecd57f891ef264ce245d50a0b286154c88c968b8ef628875a7bfcaa4abd5d51dabaea0269c
@@ -171,43 +171,75 @@ parse_version_number(const char *string)
171
171
  return version;
172
172
  }
173
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
+
174
181
  static VALUE
175
- rb_version_sort_1(VALUE rb_self, VALUE rb_version_array, compare_callback_t cmp)
182
+ rb_version_sort_1_cb(VALUE arg)
176
183
  {
177
- struct version_number **versions;
184
+ struct sort_context *context = (struct sort_context *)arg;
178
185
  long length, i;
179
186
  VALUE *rb_version_ptr;
180
187
 
181
- Check_Type(rb_version_array, T_ARRAY);
182
-
183
- length = RARRAY_LEN(rb_version_array);
184
- if (!length)
185
- return rb_ary_new();
186
-
187
- versions = xcalloc(length, sizeof(struct version_number *));
188
-
188
+ length = RARRAY_LEN(context->rb_version_array);
189
189
  for (i = 0; i < length; ++i) {
190
190
  VALUE rb_version, rb_version_string;
191
191
 
192
- rb_version = rb_ary_entry(rb_version_array, i);
192
+ rb_version = rb_ary_entry(context->rb_version_array, i);
193
193
  if (rb_block_given_p())
194
194
  rb_version_string = rb_yield(rb_version);
195
195
  else
196
196
  rb_version_string = rb_version;
197
197
 
198
- versions[i] = parse_version_number(StringValueCStr(rb_version_string));
199
- versions[i]->rb_version = rb_version;
198
+ context->versions[i] = parse_version_number(StringValueCStr(rb_version_string));
199
+ context->versions[i]->rb_version = rb_version;
200
+ }
201
+
202
+ qsort(context->versions, length, sizeof(struct version_number *), context->cmp);
203
+ rb_version_ptr = RARRAY_PTR(context->rb_version_array);
204
+
205
+ for (i = 0; i < length; ++i) {
206
+ rb_version_ptr[i] = context->versions[i]->rb_version;
200
207
  }
201
208
 
202
- qsort(versions, length, sizeof(struct version_number *), cmp);
203
- rb_version_ptr = RARRAY_PTR(rb_version_array);
209
+ return context->rb_version_array;
210
+ }
211
+
212
+ static VALUE
213
+ rb_version_sort_1(VALUE rb_self, VALUE rb_version_array, compare_callback_t cmp)
214
+ {
215
+ long length, i;
216
+ int exception;
217
+
218
+ Check_Type(rb_version_array, T_ARRAY);
219
+
220
+ length = RARRAY_LEN(rb_version_array);
221
+ if (!length)
222
+ return rb_ary_new();
223
+
224
+ struct sort_context context = {
225
+ rb_self,
226
+ rb_version_array,
227
+ cmp,
228
+ xcalloc(length, sizeof(struct version_number *)),
229
+ };
230
+
231
+ VALUE result = rb_protect(rb_version_sort_1_cb, (VALUE)&context, &exception);
204
232
 
205
233
  for (i = 0; i < length; ++i) {
206
- rb_version_ptr[i] = versions[i]->rb_version;
207
- xfree(versions[i]);
234
+ xfree(context.versions[i]);
208
235
  }
209
- xfree(versions);
210
- return rb_version_array;
236
+ xfree(context.versions);
237
+
238
+ if (exception) {
239
+ rb_jump_tag(exception);
240
+ }
241
+
242
+ return result;
211
243
  }
212
244
 
213
245
  static VALUE
@@ -234,16 +266,39 @@ rb_version_sort_r_bang(VALUE rb_self, VALUE rb_versions)
234
266
  return rb_version_sort_1(rb_self, rb_versions, version_compare_cb_r);
235
267
  }
236
268
 
269
+ struct compare_context {
270
+ VALUE rb_version_a, rb_version_b;
271
+ struct version_number *version_a, *version_b;
272
+ };
273
+
274
+ static VALUE
275
+ rb_version_compare_cb(VALUE arg)
276
+ {
277
+ struct compare_context *context = (struct compare_context *)arg;
278
+
279
+ context->version_a = parse_version_number(StringValueCStr(context->rb_version_a));
280
+ context->version_b = parse_version_number(StringValueCStr(context->rb_version_b));
281
+
282
+ return INT2NUM(version_compare_cb(&context->version_a, &context->version_b));
283
+ }
284
+
237
285
  static VALUE
238
286
  rb_version_compare(VALUE rb_self, VALUE rb_version_a, VALUE rb_version_b)
239
287
  {
240
- struct version_number *version_a = parse_version_number(StringValueCStr(rb_version_a));
241
- struct version_number *version_b = parse_version_number(StringValueCStr(rb_version_b));
288
+ int exception;
289
+ struct compare_context context = {
290
+ rb_version_a, rb_version_b,
291
+ NULL, NULL,
292
+ };
242
293
 
243
- VALUE result = INT2NUM(version_compare_cb(&version_a, &version_b));
294
+ VALUE result = rb_protect(rb_version_compare_cb, (VALUE)&context, &exception);
244
295
 
245
- xfree(version_a);
246
- xfree(version_b);
296
+ xfree(context.version_a);
297
+ xfree(context.version_b);
298
+
299
+ if (exception) {
300
+ rb_jump_tag(exception);
301
+ }
247
302
 
248
303
  return result;
249
304
  }
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.2.3
4
+ version: 2.2.4
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-02-07 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.