ucl 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/ext/ucl.c +34 -24
  3. data/ucl.gemspec +1 -1
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 425cfe9bbc447dd450e023ce22cf7d87ff55999c44e9c662c478bfb04f27afdc
4
- data.tar.gz: c71501063aa394c0f32f8a9e6ad66f4ca54a61309af6ee1f9e78d960d26711da
3
+ metadata.gz: 3fb8e8b518ea32adfa5365bf32e260487f3aa4ec9e546738911e6cf37a16e300
4
+ data.tar.gz: e9067e8747899c187f9ae400cd4bfe58e4343c41ff04b70cdbe161a500062bfc
5
5
  SHA512:
6
- metadata.gz: dd42a5c178ca47bf3287b72bf7fa150ca21242c457cb8421590fa12f41a8d721079c3fe582335d85e7339c5cd5fd0b866dad2fa3a9569dba1eebf0460f4e2089
7
- data.tar.gz: ca19582a1d3ef8882e46dae1da77c614d59cfe953b86fb05bc82e8dae491af6388acdf2085075c90b2f324870dc8ec26e6aebc8c8f6cd9d7f7513c334897b90a
6
+ metadata.gz: 962eea2f25228aec1ee903315074ceabd9cc424b2afab0963e68179fd39f1666abe6954404594ae6d4c658704b89200d4bfad21174bc9cd298b8ce66ea9252b7
7
+ data.tar.gz: b5c9bbe4b92be69734f5bd0df81a043dba97158489da7f67d7fce6e33f976a6eb209c45b7a72690bd441aa2fd8aed203f47389753328efd875fe05175e875afa
data/ext/ucl.c CHANGED
@@ -25,6 +25,11 @@
25
25
  static VALUE mUCL = Qundef;
26
26
  static VALUE eUCLError = Qundef;
27
27
 
28
+ static int ucl_allowed_flags = UCL_PARSER_KEY_LOWERCASE |
29
+ UCL_PARSER_NO_TIME |
30
+ UCL_PARSER_DISABLE_MACRO |
31
+ UCL_PARSER_NO_FILEVARS ;
32
+
28
33
 
29
34
  VALUE
30
35
  _iterate_valid_ucl(ucl_object_t const *root, int flags)
@@ -130,11 +135,6 @@ ucl_s_set_flags(VALUE klass, VALUE val)
130
135
  static VALUE
131
136
  ucl_s_parse(int argc, VALUE *argv, VALUE klass)
132
137
  {
133
- static int allowed_flags = UCL_PARSER_KEY_LOWERCASE |
134
- UCL_PARSER_NO_TIME |
135
- UCL_PARSER_DISABLE_MACRO |
136
- UCL_PARSER_NO_FILEVARS ;
137
-
138
138
  VALUE data, flags;
139
139
  rb_scan_args(argc, argv, "11", &data, &flags);
140
140
  if (NIL_P(flags)) flags = ucl_s_get_flags(mUCL);
@@ -142,7 +142,7 @@ ucl_s_parse(int argc, VALUE *argv, VALUE klass)
142
142
  rb_check_type(data, T_STRING);
143
143
  rb_check_type(flags, T_FIXNUM);
144
144
 
145
- int c_flags = FIX2INT(flags) & allowed_flags;
145
+ int c_flags = FIX2INT(flags) & ucl_allowed_flags;
146
146
 
147
147
  struct ucl_parser *parser =
148
148
  ucl_parser_new(c_flags | UCL_PARSER_NO_IMPLICIT_ARRAYS);
@@ -152,20 +152,16 @@ ucl_s_parse(int argc, VALUE *argv, VALUE klass)
152
152
  RSTRING_LEN(data));
153
153
 
154
154
  if (ucl_parser_get_error(parser)) {
155
- rb_raise(eUCLError, "%s", ucl_parser_get_error(parser));
155
+ const char *errormsg = ucl_parser_get_error(parser);
156
+ if (parser != NULL) { ucl_parser_free(parser); }
157
+ rb_raise(eUCLError, "%s", errormsg);
156
158
  }
157
159
 
158
160
  ucl_object_t *root = ucl_parser_get_object(parser);
161
+ VALUE res = _iterate_valid_ucl(root, FIX2INT(flags));
159
162
 
160
- VALUE res = _iterate_valid_ucl(root, FIX2INT(flags));
161
-
162
- if (parser != NULL) {
163
- ucl_parser_free(parser);
164
- }
165
-
166
- if (root != NULL) {
167
- ucl_object_unref(root);
168
- }
163
+ if (parser != NULL) { ucl_parser_free(parser); }
164
+ if (root != NULL) { ucl_object_unref(root); }
169
165
 
170
166
  return res;
171
167
  }
@@ -187,17 +183,31 @@ ucl_s_load_file(int argc, VALUE *argv, VALUE klass)
187
183
  {
188
184
  VALUE file, flags;
189
185
  rb_scan_args(argc, argv, "11", &file, &flags);
186
+ if (NIL_P(flags)) flags = ucl_s_get_flags(mUCL);
190
187
 
191
- VALUE read_kwargs = rb_hash_new();
192
- rb_hash_aset(read_kwargs, rb_id2sym(rb_intern("encoding")),
193
- rb_str_new_cstr("BINARY"));
188
+ rb_check_type(file, T_STRING);
189
+ rb_check_type(flags, T_FIXNUM);
190
+
191
+ int c_flags = FIX2INT(flags) & ucl_allowed_flags;
192
+ char *c_file = StringValueCStr(file);
193
+
194
+ struct ucl_parser *parser =
195
+ ucl_parser_new(c_flags | UCL_PARSER_NO_IMPLICIT_ARRAYS);
196
+ ucl_parser_add_file(parser, c_file);
197
+
198
+ if (ucl_parser_get_error(parser)) {
199
+ const char *errormsg = ucl_parser_get_error(parser);
200
+ if (parser != NULL) { ucl_parser_free(parser); }
201
+ rb_raise(eUCLError, "%s", errormsg);
202
+ }
194
203
 
195
- VALUE read_args[] = { file, read_kwargs };
196
- VALUE data = rb_funcallv_kw(rb_cFile, rb_intern("read"),
197
- 2, read_args, RB_PASS_KEYWORDS);
204
+ ucl_object_t *root = ucl_parser_get_object(parser);
205
+ VALUE res = _iterate_valid_ucl(root, FIX2INT(flags));
198
206
 
199
- VALUE parse_args[] = { data, flags };
200
- return ucl_s_parse(2, parse_args, klass);
207
+ if (parser != NULL) { ucl_parser_free(parser); }
208
+ if (root != NULL) { ucl_object_unref(root); }
209
+
210
+ return res;
201
211
  }
202
212
 
203
213
 
data/ucl.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'ucl'
3
- s.version = '0.1.1'
3
+ s.version = '0.1.2'
4
4
  s.summary = " Universal configuration library parser"
5
5
  s.description = <<~EOF
6
6
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ucl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stéphane D'Alu