psych 5.1.2 → 5.2.3
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 +4 -4
- data/README.md +17 -10
- data/ext/psych/psych.c +1 -2
- data/ext/psych/psych_emitter.c +155 -121
- data/ext/psych/psych_parser.c +262 -263
- data/ext/psych/psych_to_ruby.c +0 -1
- data/ext/psych/psych_yaml_tree.c +0 -1
- data/lib/psych/nodes/node.rb +1 -1
- data/lib/psych/scalar_scanner.rb +8 -9
- data/lib/psych/versions.rb +2 -2
- data/lib/psych/visitors/to_ruby.rb +1 -2
- data/lib/psych/visitors/yaml_tree.rb +7 -10
- data/lib/psych.rb +23 -5
- metadata +18 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e8c48b70d7c4ff53b1d536997a6e63173cb7e123e3f6e70f82c5de8596d93c4c
|
4
|
+
data.tar.gz: c49d610314f1628a1e84267010dcfac5a076276eac2cad8dbbba9079ede9e08f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2d3d710995bfd6eb317994dd13024e5e3fd2967dbd379a1d510f86f7517177d2cc5e292a7d3b14c999071cc35ce625715ee3549fab90ce966567ba6e91f2475c
|
7
|
+
data.tar.gz: f1570e565d5dd8c9e5984155dfbc1418a594aaa871fab7b7fabe62f05bc0a3e72ab141dd9f39c09689f8f4949a5c6e58fa9b1ca99c26db3552b0c9866a6032ad
|
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# Psych
|
2
2
|
|
3
|
-
*
|
4
|
-
*
|
3
|
+
* https://github.com/ruby/psych
|
4
|
+
* https://docs.ruby-lang.org/en/master/Psych.html
|
5
5
|
|
6
6
|
## Description
|
7
7
|
|
@@ -22,31 +22,38 @@ Psych.dump("foo") # => "--- foo\n...\n"
|
|
22
22
|
|
23
23
|
## Dependencies
|
24
24
|
|
25
|
-
*
|
25
|
+
* libyaml
|
26
26
|
|
27
27
|
## Installation
|
28
28
|
|
29
29
|
Psych has been included with MRI since 1.9.2, and is the default YAML parser
|
30
30
|
in 1.9.3.
|
31
31
|
|
32
|
-
If you want a newer gem release of Psych, you can use
|
33
|
-
|
34
|
-
gem install psych
|
32
|
+
If you want a newer gem release of Psych, you can use RubyGems:
|
35
33
|
|
34
|
+
```bash
|
35
|
+
gem install psych
|
36
|
+
```
|
36
37
|
|
37
38
|
Psych supported the static build with specific version of libyaml sources. You can build psych with libyaml-0.2.5 like this.
|
38
39
|
|
39
|
-
|
40
|
+
```bash
|
41
|
+
gem install psych -- --with-libyaml-source-dir=/path/to/libyaml-0.2.5
|
42
|
+
```
|
40
43
|
|
41
44
|
In order to use the gem release in your app, and not the stdlib version,
|
42
45
|
you'll need the following:
|
43
46
|
|
44
|
-
|
45
|
-
|
47
|
+
```ruby
|
48
|
+
gem 'psych'
|
49
|
+
require 'psych'
|
50
|
+
```
|
46
51
|
|
47
52
|
Or if you use Bundler add this to your `Gemfile`:
|
48
53
|
|
49
|
-
|
54
|
+
```ruby
|
55
|
+
gem 'psych'
|
56
|
+
```
|
50
57
|
|
51
58
|
JRuby ships with a pure Java implementation of Psych.
|
52
59
|
|
data/ext/psych/psych.c
CHANGED
@@ -23,7 +23,7 @@ VALUE mPsych;
|
|
23
23
|
void Init_psych(void)
|
24
24
|
{
|
25
25
|
#ifdef HAVE_RB_EXT_RACTOR_SAFE
|
26
|
-
|
26
|
+
RB_EXT_RACTOR_SAFE(true);
|
27
27
|
#endif
|
28
28
|
mPsych = rb_define_module("Psych");
|
29
29
|
|
@@ -34,4 +34,3 @@ void Init_psych(void)
|
|
34
34
|
Init_psych_to_ruby();
|
35
35
|
Init_psych_yaml_tree();
|
36
36
|
}
|
37
|
-
/* vim: set noet sws=4 sw=4: */
|
data/ext/psych/psych_emitter.c
CHANGED
@@ -17,7 +17,7 @@ static ID id_canonical;
|
|
17
17
|
static void emit(yaml_emitter_t * emitter, yaml_event_t * event)
|
18
18
|
{
|
19
19
|
if(!yaml_emitter_emit(emitter, event))
|
20
|
-
|
20
|
+
rb_raise(rb_eRuntimeError, "%s", emitter->problem);
|
21
21
|
}
|
22
22
|
|
23
23
|
static int writer(void *ctx, unsigned char *buffer, size_t size)
|
@@ -82,13 +82,13 @@ static VALUE initialize(int argc, VALUE *argv, VALUE self)
|
|
82
82
|
TypedData_Get_Struct(self, yaml_emitter_t, &psych_emitter_type, emitter);
|
83
83
|
|
84
84
|
if (rb_scan_args(argc, argv, "11", &io, &options) == 2) {
|
85
|
-
|
86
|
-
|
87
|
-
|
85
|
+
line_width = rb_funcall(options, id_line_width, 0);
|
86
|
+
indent = rb_funcall(options, id_indentation, 0);
|
87
|
+
canonical = rb_funcall(options, id_canonical, 0);
|
88
88
|
|
89
|
-
|
90
|
-
|
91
|
-
|
89
|
+
yaml_emitter_set_width(emitter, NUM2INT(line_width));
|
90
|
+
yaml_emitter_set_indent(emitter, NUM2INT(indent));
|
91
|
+
yaml_emitter_set_canonical(emitter, Qtrue == canonical ? 1 : 0);
|
92
92
|
}
|
93
93
|
|
94
94
|
rb_ivar_set(self, id_io, io);
|
@@ -136,84 +136,118 @@ static VALUE end_stream(VALUE self)
|
|
136
136
|
return self;
|
137
137
|
}
|
138
138
|
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
139
|
+
struct start_document_data {
|
140
|
+
VALUE self;
|
141
|
+
VALUE version;
|
142
|
+
VALUE tags;
|
143
|
+
VALUE imp;
|
144
|
+
|
145
|
+
yaml_tag_directive_t * head;
|
146
|
+
};
|
147
|
+
|
148
|
+
static VALUE start_document_try(VALUE d)
|
147
149
|
{
|
150
|
+
struct start_document_data * data = (struct start_document_data *)d;
|
151
|
+
VALUE self = data->self;
|
152
|
+
VALUE version = data->version;
|
153
|
+
VALUE tags = data->tags;
|
154
|
+
VALUE imp = data->imp;
|
155
|
+
|
148
156
|
yaml_emitter_t * emitter;
|
149
|
-
yaml_tag_directive_t * head = NULL;
|
150
157
|
yaml_tag_directive_t * tail = NULL;
|
151
158
|
yaml_event_t event;
|
152
159
|
yaml_version_directive_t version_directive;
|
153
160
|
TypedData_Get_Struct(self, yaml_emitter_t, &psych_emitter_type, emitter);
|
154
161
|
|
155
|
-
|
156
162
|
Check_Type(version, T_ARRAY);
|
157
163
|
|
158
164
|
if(RARRAY_LEN(version) > 0) {
|
159
|
-
|
160
|
-
|
165
|
+
VALUE major = rb_ary_entry(version, (long)0);
|
166
|
+
VALUE minor = rb_ary_entry(version, (long)1);
|
161
167
|
|
162
|
-
|
163
|
-
|
168
|
+
version_directive.major = NUM2INT(major);
|
169
|
+
version_directive.minor = NUM2INT(minor);
|
164
170
|
}
|
165
171
|
|
166
172
|
if(RTEST(tags)) {
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
173
|
+
long i = 0;
|
174
|
+
long len;
|
175
|
+
rb_encoding * encoding = rb_utf8_encoding();
|
176
|
+
|
177
|
+
Check_Type(tags, T_ARRAY);
|
178
|
+
|
179
|
+
len = RARRAY_LEN(tags);
|
180
|
+
data->head = xcalloc((size_t)len, sizeof(yaml_tag_directive_t));
|
181
|
+
tail = data->head;
|
182
|
+
|
183
|
+
for(i = 0; i < len && i < RARRAY_LEN(tags); i++) {
|
184
|
+
VALUE tuple = RARRAY_AREF(tags, i);
|
185
|
+
VALUE name;
|
186
|
+
VALUE value;
|
187
|
+
|
188
|
+
Check_Type(tuple, T_ARRAY);
|
189
|
+
|
190
|
+
if(RARRAY_LEN(tuple) < 2) {
|
191
|
+
rb_raise(rb_eRuntimeError, "tag tuple must be of length 2");
|
192
|
+
}
|
193
|
+
|
194
|
+
name = RARRAY_AREF(tuple, 0);
|
195
|
+
value = RARRAY_AREF(tuple, 1);
|
196
|
+
StringValue(name);
|
197
|
+
StringValue(value);
|
198
|
+
name = rb_str_export_to_enc(name, encoding);
|
199
|
+
value = rb_str_export_to_enc(value, encoding);
|
200
|
+
|
201
|
+
tail->handle = (yaml_char_t *)StringValueCStr(name);
|
202
|
+
tail->prefix = (yaml_char_t *)StringValueCStr(value);
|
203
|
+
|
204
|
+
tail++;
|
205
|
+
}
|
200
206
|
}
|
201
207
|
|
202
208
|
yaml_document_start_event_initialize(
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
+
&event,
|
210
|
+
(RARRAY_LEN(version) > 0) ? &version_directive : NULL,
|
211
|
+
data->head,
|
212
|
+
tail,
|
213
|
+
imp ? 1 : 0
|
214
|
+
);
|
209
215
|
|
210
216
|
emit(emitter, &event);
|
211
217
|
|
212
|
-
if(head) xfree(head);
|
213
|
-
|
214
218
|
return self;
|
215
219
|
}
|
216
220
|
|
221
|
+
static VALUE start_document_ensure(VALUE d)
|
222
|
+
{
|
223
|
+
struct start_document_data * data = (struct start_document_data *)d;
|
224
|
+
|
225
|
+
xfree(data->head);
|
226
|
+
|
227
|
+
return Qnil;
|
228
|
+
}
|
229
|
+
|
230
|
+
/* call-seq: emitter.start_document(version, tags, implicit)
|
231
|
+
*
|
232
|
+
* Start a document emission with YAML +version+, +tags+, and an +implicit+
|
233
|
+
* start.
|
234
|
+
*
|
235
|
+
* See Psych::Handler#start_document
|
236
|
+
*/
|
237
|
+
static VALUE start_document(VALUE self, VALUE version, VALUE tags, VALUE imp)
|
238
|
+
{
|
239
|
+
struct start_document_data data = {
|
240
|
+
.self = self,
|
241
|
+
.version = version,
|
242
|
+
.tags = tags,
|
243
|
+
.imp = imp,
|
244
|
+
|
245
|
+
.head = NULL,
|
246
|
+
};
|
247
|
+
|
248
|
+
return rb_ensure(start_document_try, (VALUE)&data, start_document_ensure, (VALUE)&data);
|
249
|
+
}
|
250
|
+
|
217
251
|
/* call-seq: emitter.end_document(implicit)
|
218
252
|
*
|
219
253
|
* End a document emission with an +implicit+ ending.
|
@@ -241,14 +275,14 @@ static VALUE end_document(VALUE self, VALUE imp)
|
|
241
275
|
* See Psych::Handler#scalar
|
242
276
|
*/
|
243
277
|
static VALUE scalar(
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
278
|
+
VALUE self,
|
279
|
+
VALUE value,
|
280
|
+
VALUE anchor,
|
281
|
+
VALUE tag,
|
282
|
+
VALUE plain,
|
283
|
+
VALUE quoted,
|
284
|
+
VALUE style
|
285
|
+
) {
|
252
286
|
yaml_emitter_t * emitter;
|
253
287
|
yaml_event_t event;
|
254
288
|
rb_encoding *encoding;
|
@@ -261,25 +295,26 @@ static VALUE scalar(
|
|
261
295
|
value = rb_str_export_to_enc(value, encoding);
|
262
296
|
|
263
297
|
if(!NIL_P(anchor)) {
|
264
|
-
|
265
|
-
|
298
|
+
Check_Type(anchor, T_STRING);
|
299
|
+
anchor = rb_str_export_to_enc(anchor, encoding);
|
266
300
|
}
|
267
301
|
|
268
302
|
if(!NIL_P(tag)) {
|
269
|
-
|
270
|
-
|
303
|
+
Check_Type(tag, T_STRING);
|
304
|
+
tag = rb_str_export_to_enc(tag, encoding);
|
271
305
|
}
|
272
306
|
|
307
|
+
const char *value_ptr = StringValuePtr(value);
|
273
308
|
yaml_scalar_event_initialize(
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
309
|
+
&event,
|
310
|
+
(yaml_char_t *)(NIL_P(anchor) ? NULL : StringValueCStr(anchor)),
|
311
|
+
(yaml_char_t *)(NIL_P(tag) ? NULL : StringValueCStr(tag)),
|
312
|
+
(yaml_char_t*)value_ptr,
|
313
|
+
(int)RSTRING_LEN(value),
|
314
|
+
plain ? 1 : 0,
|
315
|
+
quoted ? 1 : 0,
|
316
|
+
(yaml_scalar_style_t)NUM2INT(style)
|
317
|
+
);
|
283
318
|
|
284
319
|
emit(emitter, &event);
|
285
320
|
|
@@ -294,36 +329,36 @@ static VALUE scalar(
|
|
294
329
|
* See Psych::Handler#start_sequence
|
295
330
|
*/
|
296
331
|
static VALUE start_sequence(
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
332
|
+
VALUE self,
|
333
|
+
VALUE anchor,
|
334
|
+
VALUE tag,
|
335
|
+
VALUE implicit,
|
336
|
+
VALUE style
|
337
|
+
) {
|
303
338
|
yaml_emitter_t * emitter;
|
304
339
|
yaml_event_t event;
|
305
340
|
|
306
341
|
rb_encoding * encoding = rb_utf8_encoding();
|
307
342
|
|
308
343
|
if(!NIL_P(anchor)) {
|
309
|
-
|
310
|
-
|
344
|
+
Check_Type(anchor, T_STRING);
|
345
|
+
anchor = rb_str_export_to_enc(anchor, encoding);
|
311
346
|
}
|
312
347
|
|
313
348
|
if(!NIL_P(tag)) {
|
314
|
-
|
315
|
-
|
349
|
+
Check_Type(tag, T_STRING);
|
350
|
+
tag = rb_str_export_to_enc(tag, encoding);
|
316
351
|
}
|
317
352
|
|
318
353
|
TypedData_Get_Struct(self, yaml_emitter_t, &psych_emitter_type, emitter);
|
319
354
|
|
320
355
|
yaml_sequence_start_event_initialize(
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
356
|
+
&event,
|
357
|
+
(yaml_char_t *)(NIL_P(anchor) ? NULL : StringValueCStr(anchor)),
|
358
|
+
(yaml_char_t *)(NIL_P(tag) ? NULL : StringValueCStr(tag)),
|
359
|
+
implicit ? 1 : 0,
|
360
|
+
(yaml_sequence_style_t)NUM2INT(style)
|
361
|
+
);
|
327
362
|
|
328
363
|
emit(emitter, &event);
|
329
364
|
|
@@ -357,12 +392,12 @@ static VALUE end_sequence(VALUE self)
|
|
357
392
|
* See Psych::Handler#start_mapping
|
358
393
|
*/
|
359
394
|
static VALUE start_mapping(
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
395
|
+
VALUE self,
|
396
|
+
VALUE anchor,
|
397
|
+
VALUE tag,
|
398
|
+
VALUE implicit,
|
399
|
+
VALUE style
|
400
|
+
) {
|
366
401
|
yaml_emitter_t * emitter;
|
367
402
|
yaml_event_t event;
|
368
403
|
rb_encoding *encoding;
|
@@ -372,22 +407,22 @@ static VALUE start_mapping(
|
|
372
407
|
encoding = rb_utf8_encoding();
|
373
408
|
|
374
409
|
if(!NIL_P(anchor)) {
|
375
|
-
|
376
|
-
|
410
|
+
Check_Type(anchor, T_STRING);
|
411
|
+
anchor = rb_str_export_to_enc(anchor, encoding);
|
377
412
|
}
|
378
413
|
|
379
414
|
if(!NIL_P(tag)) {
|
380
|
-
|
381
|
-
|
415
|
+
Check_Type(tag, T_STRING);
|
416
|
+
tag = rb_str_export_to_enc(tag, encoding);
|
382
417
|
}
|
383
418
|
|
384
419
|
yaml_mapping_start_event_initialize(
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
420
|
+
&event,
|
421
|
+
(yaml_char_t *)(NIL_P(anchor) ? NULL : StringValueCStr(anchor)),
|
422
|
+
(yaml_char_t *)(NIL_P(tag) ? NULL : StringValueCStr(tag)),
|
423
|
+
implicit ? 1 : 0,
|
424
|
+
(yaml_mapping_style_t)NUM2INT(style)
|
425
|
+
);
|
391
426
|
|
392
427
|
emit(emitter, &event);
|
393
428
|
|
@@ -426,14 +461,14 @@ static VALUE alias(VALUE self, VALUE anchor)
|
|
426
461
|
TypedData_Get_Struct(self, yaml_emitter_t, &psych_emitter_type, emitter);
|
427
462
|
|
428
463
|
if(!NIL_P(anchor)) {
|
429
|
-
|
430
|
-
|
464
|
+
Check_Type(anchor, T_STRING);
|
465
|
+
anchor = rb_str_export_to_enc(anchor, rb_utf8_encoding());
|
431
466
|
}
|
432
467
|
|
433
468
|
yaml_alias_event_initialize(
|
434
|
-
|
435
|
-
|
436
|
-
|
469
|
+
&event,
|
470
|
+
(yaml_char_t *)(NIL_P(anchor) ? NULL : StringValueCStr(anchor))
|
471
|
+
);
|
437
472
|
|
438
473
|
emit(emitter, &event);
|
439
474
|
|
@@ -552,4 +587,3 @@ void Init_psych_emitter(void)
|
|
552
587
|
id_indentation = rb_intern("indentation");
|
553
588
|
id_canonical = rb_intern("canonical");
|
554
589
|
}
|
555
|
-
/* vim: set noet sws=4 sw=4: */
|