edlib 0.0.2 → 0.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
2
  SHA256:
3
- metadata.gz: 1a7ecc7eca8aef827a022a66bcf9c540e24f0e3d070b8af5d37913f112f68b0d
4
- data.tar.gz: 6c25316af8bc413b4c014660e9bb7769a139ecd537983a67ab4a249fcaa31faf
3
+ metadata.gz: 6e6f83cf227f49681f1c3c1e50b0ca5a9816ff6b2ad42c8fc293963e4c82dd1a
4
+ data.tar.gz: d725b5937ea1c5c3c04cae03015682285d4481bde378f89bbc7336bc532c758e
5
5
  SHA512:
6
- metadata.gz: 0e63d0dbdb063833d7bea3e0ee53ca0ae0daa1e5828d0c022e9d7da8c5c3f3a3ce8dc16418fd7b925894767bdc053cebc7e85c214f5541d2d4c2d40434ef4dd9
7
- data.tar.gz: c666e503c1af8de0d91cc8acce4d253f5e73f84137cc2b2436b936a145c552997db518c8193ba917c6ccd6f14134f80e464bb6e6f1e6b23f751413529d00c454
6
+ metadata.gz: 4a5aba207f2e51a0091b36dd1666a68daf68f93cba48ffa86f6daf0c18a28967f8b393f58ff3377191096bd0e8994e8d99afd64322cf5d53fa42a69499d1b4fe
7
+ data.tar.gz: ddd9bc252e46eb4bd53d3a435321242b42829f94aeaa6d115597ad9ec27d05424a53523cc0d5688af49368e59bb1023b5766adb45cba58e309823a3ce82c5317
data/ext/edlib/edlibext.c CHANGED
@@ -3,13 +3,15 @@
3
3
 
4
4
  VALUE mEdlib;
5
5
  VALUE cAligner;
6
+ EdlibEqualityPair *eqpairs;
6
7
 
7
8
  static size_t config_memsize(const void *ptr);
9
+ static void config_free(void *ptr);
8
10
 
9
11
  static const rb_data_type_t config_type = {
10
12
  .wrap_struct_name = "EdlibAlignConfig",
11
13
  .function = {
12
- .dfree = RUBY_DEFAULT_FREE,
14
+ .dfree = config_free,
13
15
  .dsize = config_memsize,
14
16
  },
15
17
  .flags = RUBY_TYPED_FREE_IMMEDIATELY,
@@ -24,6 +26,17 @@ config_allocate(VALUE klass)
24
26
  return obj;
25
27
  }
26
28
 
29
+ static void
30
+ config_free(void *ptr)
31
+ {
32
+ if (eqpairs != NULL)
33
+ {
34
+ free(eqpairs);
35
+ eqpairs = NULL;
36
+ }
37
+ xfree(ptr);
38
+ }
39
+
27
40
  static size_t
28
41
  config_memsize(const void *ptr)
29
42
  {
@@ -31,7 +44,8 @@ config_memsize(const void *ptr)
31
44
  return sizeof(ptr) + 2 * sizeof(char) * (config->additionalEqualitiesLength);
32
45
  }
33
46
 
34
- static EdlibAlignConfig *get_config(VALUE self)
47
+ static EdlibAlignConfig *
48
+ get_config(VALUE self)
35
49
  {
36
50
  EdlibAlignConfig *ptr = NULL;
37
51
  TypedData_Get_Struct(self, EdlibAlignConfig, &config_type, ptr);
@@ -94,7 +108,7 @@ set_mode(EdlibAlignConfig *config, VALUE mode)
94
108
  {
95
109
  if (TYPE(mode) == T_SYMBOL)
96
110
  {
97
- mode = rb_String(mode);
111
+ mode = rb_String(mode);
98
112
  }
99
113
  switch (TYPE(mode))
100
114
  {
@@ -238,9 +252,20 @@ static VALUE
238
252
  set_additional_equalities(EdlibAlignConfig *config, VALUE equalities)
239
253
  {
240
254
  Check_Type(equalities, T_ARRAY);
241
- EdlibEqualityPair *pairs = (EdlibEqualityPair *)malloc(sizeof(EdlibEqualityPair) * RARRAY_LEN(equalities));
242
-
243
- for (int i = 0; i < RARRAY_LEN(equalities); i++)
255
+ int len = RARRAY_LEN(equalities);
256
+ if (len == 0)
257
+ {
258
+ if(eqpairs != NULL) {
259
+ free(eqpairs);
260
+ eqpairs = NULL;
261
+ }
262
+ config->additionalEqualities = NULL;
263
+ config->additionalEqualitiesLength = 0;
264
+ return equalities;
265
+ }
266
+ char *first_arr = malloc(len * sizeof(char));
267
+ char *second_arr = malloc(len * sizeof(char));
268
+ for (int i = 0; i < len; i++)
244
269
  {
245
270
  VALUE pair = rb_ary_entry(equalities, i);
246
271
  Check_Type(pair, T_ARRAY);
@@ -258,15 +283,28 @@ set_additional_equalities(EdlibAlignConfig *config, VALUE equalities)
258
283
  }
259
284
  char c1 = RSTRING_PTR(s1)[0];
260
285
  char c2 = RSTRING_PTR(s2)[0];
286
+ first_arr[i] = c1;
287
+ second_arr[i] = c2;
288
+ }
289
+
290
+ if (eqpairs != NULL)
291
+ {
292
+ free(eqpairs);
293
+ }
261
294
 
262
- pairs[i].first = c1;
263
- pairs[i].second = c2;
295
+ eqpairs = (EdlibEqualityPair *)malloc(sizeof(EdlibEqualityPair) * len);
296
+
297
+ for (int i = 0; i < len; i++)
298
+ {
299
+ eqpairs[i].first = first_arr[i];
300
+ eqpairs[i].second = second_arr[i];
264
301
  }
265
302
 
266
- config->additionalEqualities = pairs;
267
- free(pairs);
303
+ config->additionalEqualities = eqpairs;
304
+ config->additionalEqualitiesLength = len;
268
305
 
269
- config->additionalEqualitiesLength = RARRAY_LEN(equalities);
306
+ free(first_arr);
307
+ free(second_arr);
270
308
 
271
309
  return equalities;
272
310
  }
data/lib/edlib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Edlib
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
metadata CHANGED
@@ -1,11 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: edlib
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - kojix2
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
  date: 2022-10-31 00:00:00.000000000 Z
@@ -29,7 +29,7 @@ homepage: https://github.com/kojix2/ruby-edlib
29
29
  licenses:
30
30
  - MIT
31
31
  metadata: {}
32
- post_install_message:
32
+ post_install_message:
33
33
  rdoc_options: []
34
34
  require_paths:
35
35
  - lib
@@ -45,7 +45,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
45
45
  version: '0'
46
46
  requirements: []
47
47
  rubygems_version: 3.3.7
48
- signing_key:
48
+ signing_key:
49
49
  specification_version: 4
50
50
  summary: ruby-edlib is a wrapper for edlib.
51
51
  test_files: []