dartsclone 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5f885b4746eda49bbcdf7dd447acf1f5249f41fd3f259b9b5a0c4aefdb166a53
4
- data.tar.gz: 1526d141d3e0671be8b7bf80ea192477a6f2795fbfc627050a1a7edb9e37f7f7
3
+ metadata.gz: 97644d2ac4c4641a5ece8c2a6f75286843955f3a6c8c777c54984a33d7f40ffa
4
+ data.tar.gz: 11d1bc54058b6e13a13ed115df887cdfc80488466815d873bc7219739ba40f92
5
5
  SHA512:
6
- metadata.gz: a3edde3163b959f31f61bed40d031bbeb6f86ca4774d9b110af4dd3d5e787210cef5fab01d87ba342def771ee52d28c133c643bd7179df8c42c6e2cc8e53c731
7
- data.tar.gz: e292bcd0444398425b931a6bf92217b06cf1f45eedc85af841aeb82cbbcb4bd1caaab5f57f43e54aa8e59a5e8b833570c269d699c71a2bd0d7f4e15482197a62
6
+ metadata.gz: '0309acb6f96c43590c39cd1c2e11a47fe7ca35dbb8f9e8dbf71b5a5465607d561624837ea901ac60964c85453c50c8b6333c7a62cd477f48644056eabab60783'
7
+ data.tar.gz: cd63a1951b7f7bdd376ade80a3f978c45fc4c82e41c3418c3310182da5035b735c67189c932bdf6e1557d657d1415d3ee7df0dff39ab57e744d0d7d20c3d114a
@@ -1,6 +1,6 @@
1
1
  name: build
2
2
 
3
- on: [push]
3
+ on: [push, pull_request]
4
4
 
5
5
  jobs:
6
6
  build:
@@ -1,3 +1,6 @@
1
+ ## 0.2.2
2
+ - Refactor native extension codes considering garbage collection.
3
+
1
4
  ## 0.2.1
2
5
  - Replace Data_ functions to TypedData_ functions.
3
6
  - Fix some config files.
@@ -1,4 +1,4 @@
1
- Copyright (c) 2020 Atsushi Tatsuma
1
+ Copyright (c) 2020-2021 Atsushi Tatsuma
2
2
  All rights reserved.
3
3
 
4
4
  Redistribution and use in source and binary forms, with or without
@@ -1,6 +1,8 @@
1
1
  #ifndef DARTSCLONEEXT_HPP
2
2
  #define DARTSCLONEEXT_HPP 1
3
3
 
4
+ #include <cstring>
5
+
4
6
  #include <ruby.h>
5
7
  #include <darts.h>
6
8
 
@@ -68,22 +70,26 @@ class RbDoubleArray
68
70
  const int n_keys = RARRAY_LEN(_keys);
69
71
  char** keys = (char**)ruby_xmalloc(n_keys * sizeof(char*));
70
72
  int* values = _values == Qundef ? NULL : (int*)ruby_xmalloc(n_keys * sizeof(int));
73
+ VALUE key_str;
71
74
  for (int i = 0; i < n_keys; i++) {
72
- VALUE key_str = rb_ary_entry(_keys, i);
73
- keys[i] = StringValueCStr(key_str);
75
+ key_str = rb_ary_entry(_keys, i);
76
+ keys[i] = strcpy((char*)ruby_xmalloc((RSTRING_LEN(key_str) + 1) * sizeof(char)), StringValueCStr(key_str));
74
77
  if (_values != Qundef) values[i] = NUM2INT(rb_ary_entry(_values, i));
75
78
  }
76
79
 
77
80
  try {
78
81
  get_double_array(self)->build(n_keys, keys, NULL, values);
79
82
  } catch (Darts::Details::Exception e) {
83
+ for (int i = 0; i < n_keys; i++) ruby_xfree(keys[i]);
80
84
  ruby_xfree(keys);
81
85
  if (_values != Qundef) ruby_xfree(values);
82
86
  rb_raise(rb_eRuntimeError, "%s", e.what());
83
87
  return Qfalse;
84
88
  }
89
+ for (int i = 0; i < n_keys; i++) ruby_xfree(keys[i]);
85
90
  ruby_xfree(keys);
86
91
  if (_values != Qundef) ruby_xfree(values);
92
+ RB_GC_GUARD(key_str);
87
93
  return Qtrue;
88
94
  }
89
95
 
@@ -97,13 +103,16 @@ class RbDoubleArray
97
103
  rb_get_kwargs(kwargs, kwtable, 0, 3, kwvalues);
98
104
 
99
105
  const char* filename = StringValueCStr(_filename);
100
- const char* mode = kwvalues[0] == Qundef ? "rb" : StringValueCStr(kwvalues[0]);
106
+ VALUE _mode = kwvalues[0];
107
+ const char* mode = kwvalues[0] == Qundef ? "rb" : StringValueCStr(_mode);
101
108
  const size_t offset = kwvalues[1] == Qundef ? 0 : NUM2SIZET(kwvalues[1]);
102
109
  const size_t size = kwvalues[2] == Qundef ? 0 : NUM2SIZET(kwvalues[2]);
103
110
 
104
111
  if (get_double_array(self)->open(filename, mode, offset, size) != 0) {
105
112
  return Qfalse;
106
113
  }
114
+ RB_GC_GUARD(_filename);
115
+ RB_GC_GUARD(_mode);
107
116
  return Qtrue;
108
117
  };
109
118
 
@@ -117,12 +126,15 @@ class RbDoubleArray
117
126
  rb_get_kwargs(kwargs, kwtable, 0, 2, kwvalues);
118
127
 
119
128
  const char* filename = StringValueCStr(_filename);
120
- const char* mode = kwvalues[0] == Qundef ? "wb" : StringValueCStr(kwvalues[0]);
129
+ VALUE _mode = kwvalues[0];
130
+ const char* mode = kwvalues[0] == Qundef ? "wb" : StringValueCStr(_mode);
121
131
  const size_t offset = kwvalues[1] == Qundef ? 0 : NUM2SIZET(kwvalues[1]);
122
132
 
123
133
  if (get_double_array(self)->save(filename, mode, offset) != 0) {
124
134
  return Qfalse;
125
135
  }
136
+ RB_GC_GUARD(_filename);
137
+ RB_GC_GUARD(_mode);
126
138
  return Qtrue;
127
139
  };
128
140
 
@@ -137,6 +149,7 @@ class RbDoubleArray
137
149
  const size_t total_sz = sz / get_double_array(self)->unit_size();
138
150
  char* arr = StringValuePtr(bytes);
139
151
  get_double_array(self)->set_array(arr, total_sz);
152
+ RB_GC_GUARD(bytes);
140
153
  return Qnil;
141
154
  };
142
155
 
@@ -160,6 +173,7 @@ class RbDoubleArray
160
173
 
161
174
  Darts::DoubleArray::value_type value;
162
175
  get_double_array(self)->exactMatchSearch(key, value, length, node_pos);
176
+ RB_GC_GUARD(_key);
163
177
  return INT2NUM(value);
164
178
  };
165
179
 
@@ -200,6 +214,7 @@ class RbDoubleArray
200
214
  rb_ary_push(ret, values);
201
215
  }
202
216
  ruby_xfree(results);
217
+ RB_GC_GUARD(_key);
203
218
  return ret;
204
219
  };
205
220
 
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DartsClone
4
- VERSION = '0.2.1'
4
+ VERSION = '0.2.2'
5
5
  DARTS_CLONE_VERSION = '0.32'
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dartsclone
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - yoshoku
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-11-29 00:00:00.000000000 Z
11
+ date: 2021-01-17 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Darts-clone.rb is a Ruby binding for the Darts-clone.
14
14
  email: