psych 2.0.6 → 2.0.7

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
  SHA1:
3
- metadata.gz: e91f848f788c5da3599afe0e778bc171cc12bc04
4
- data.tar.gz: c134efc70bfb872c283ae9feba311993eaa0ce33
3
+ metadata.gz: 163fb9a33cd5288edcf15b1fab6557d2a850e317
4
+ data.tar.gz: 1b5b162695a85cd2eb4e1908628fb8de47a1c4a2
5
5
  SHA512:
6
- metadata.gz: 42d1532a925bb1dc75cb64f67671b69c444ef67ccabbd649176b82d3da09c6c791bc65ddbd75dc3c8a9a23e075458f11c883d8c3902c5189ac32e404c0ce03b8
7
- data.tar.gz: a8fc0522e9ffb4cb98065efd400129a32a8990d90c7c957acf0811285c5ef7fa3e36c540756e4ea399dcef6f6088a8f8f6d6e8c26efdf2f1a6cf5612d7f71b9c
6
+ metadata.gz: 978a354b0030d9454d1f24e7c4fa2a5224960777a5fa488cf8197d01d5362ce45aa48ef7c734a50c1d0bb4beb3b9740aeaa85dd3a248d9c6b2078f9674f90013
7
+ data.tar.gz: 4d246b34357ab91db5fad9333b08d842cf2f18a9e893efdf446b3db1eaa24d4dd78a7d4f0762b82bada7fcbc971667b357e1d449bb7b140cb1aaceaddf94145e
@@ -1,3 +1,10 @@
1
+ Sun Nov 23 13:11:24 2014 Sean Griffin <sean@thoughtbot.com>
2
+
3
+ * lib/psych/visitors/to_ruby.rb: Allow loading any BasicObject that
4
+ defines #marshal_load, fixes #100
5
+ * lib/psych/visitors/yaml_tree.rb: Allow dumping any BasicObject that
6
+ defines #marshal_dump
7
+
1
8
  Sat Aug 30 06:39:48 2014 Aaron Patterson <aaron@tenderlovemaking.com>
2
9
 
3
10
  * ext/psych/lib/psych/visitors/yaml_tree.rb: fix NameError dumping and
@@ -20,7 +20,7 @@ static VALUE libyaml_version(VALUE module)
20
20
 
21
21
  VALUE mPsych;
22
22
 
23
- void Init_psych()
23
+ void Init_psych(void)
24
24
  {
25
25
  mPsych = rb_define_module("Psych");
26
26
 
@@ -29,6 +29,22 @@ static void dealloc(void * ptr)
29
29
  xfree(emitter);
30
30
  }
31
31
 
32
+ #if 0
33
+ static size_t memsize(const void *ptr)
34
+ {
35
+ const yaml_emitter_t *emitter = ptr;
36
+ /* TODO: calculate emitter's size */
37
+ return 0;
38
+ }
39
+ #endif
40
+
41
+ static const rb_data_type_t psych_emitter_type = {
42
+ "Psych/emitter",
43
+ {0, dealloc, 0,},
44
+ 0, 0,
45
+ RUBY_TYPED_FREE_IMMEDIATELY,
46
+ };
47
+
32
48
  static VALUE allocate(VALUE klass)
33
49
  {
34
50
  yaml_emitter_t * emitter;
@@ -39,7 +55,7 @@ static VALUE allocate(VALUE klass)
39
55
  yaml_emitter_set_unicode(emitter, 1);
40
56
  yaml_emitter_set_indent(emitter, 2);
41
57
 
42
- return Data_Wrap_Struct(klass, 0, dealloc, emitter);
58
+ return TypedData_Wrap_Struct(klass, &psych_emitter_type, emitter);
43
59
  }
44
60
 
45
61
  /* call-seq: Psych::Emitter.new(io, options = Psych::Emitter::OPTIONS)
@@ -54,7 +70,7 @@ static VALUE initialize(int argc, VALUE *argv, VALUE self)
54
70
  VALUE indent;
55
71
  VALUE canonical;
56
72
 
57
- Data_Get_Struct(self, yaml_emitter_t, emitter);
73
+ TypedData_Get_Struct(self, yaml_emitter_t, &psych_emitter_type, emitter);
58
74
 
59
75
  if (rb_scan_args(argc, argv, "11", &io, &options) == 2) {
60
76
  line_width = rb_funcall(options, id_line_width, 0);
@@ -81,7 +97,7 @@ static VALUE start_stream(VALUE self, VALUE encoding)
81
97
  {
82
98
  yaml_emitter_t * emitter;
83
99
  yaml_event_t event;
84
- Data_Get_Struct(self, yaml_emitter_t, emitter);
100
+ TypedData_Get_Struct(self, yaml_emitter_t, &psych_emitter_type, emitter);
85
101
  Check_Type(encoding, T_FIXNUM);
86
102
 
87
103
  yaml_stream_start_event_initialize(&event, (yaml_encoding_t)NUM2INT(encoding));
@@ -101,7 +117,7 @@ static VALUE end_stream(VALUE self)
101
117
  {
102
118
  yaml_emitter_t * emitter;
103
119
  yaml_event_t event;
104
- Data_Get_Struct(self, yaml_emitter_t, emitter);
120
+ TypedData_Get_Struct(self, yaml_emitter_t, &psych_emitter_type, emitter);
105
121
 
106
122
  yaml_stream_end_event_initialize(&event);
107
123
 
@@ -124,7 +140,7 @@ static VALUE start_document(VALUE self, VALUE version, VALUE tags, VALUE imp)
124
140
  yaml_tag_directive_t * tail = NULL;
125
141
  yaml_event_t event;
126
142
  yaml_version_directive_t version_directive;
127
- Data_Get_Struct(self, yaml_emitter_t, emitter);
143
+ TypedData_Get_Struct(self, yaml_emitter_t, &psych_emitter_type, emitter);
128
144
 
129
145
 
130
146
  Check_Type(version, T_ARRAY);
@@ -198,7 +214,7 @@ static VALUE end_document(VALUE self, VALUE imp)
198
214
  {
199
215
  yaml_emitter_t * emitter;
200
216
  yaml_event_t event;
201
- Data_Get_Struct(self, yaml_emitter_t, emitter);
217
+ TypedData_Get_Struct(self, yaml_emitter_t, &psych_emitter_type, emitter);
202
218
 
203
219
  yaml_document_end_event_initialize(&event, imp ? 1 : 0);
204
220
 
@@ -228,7 +244,7 @@ static VALUE scalar(
228
244
  #ifdef HAVE_RUBY_ENCODING_H
229
245
  rb_encoding *encoding;
230
246
  #endif
231
- Data_Get_Struct(self, yaml_emitter_t, emitter);
247
+ TypedData_Get_Struct(self, yaml_emitter_t, &psych_emitter_type, emitter);
232
248
 
233
249
  Check_Type(value, T_STRING);
234
250
 
@@ -295,7 +311,7 @@ static VALUE start_sequence(
295
311
  }
296
312
  #endif
297
313
 
298
- Data_Get_Struct(self, yaml_emitter_t, emitter);
314
+ TypedData_Get_Struct(self, yaml_emitter_t, &psych_emitter_type, emitter);
299
315
 
300
316
  yaml_sequence_start_event_initialize(
301
317
  &event,
@@ -320,7 +336,7 @@ static VALUE end_sequence(VALUE self)
320
336
  {
321
337
  yaml_emitter_t * emitter;
322
338
  yaml_event_t event;
323
- Data_Get_Struct(self, yaml_emitter_t, emitter);
339
+ TypedData_Get_Struct(self, yaml_emitter_t, &psych_emitter_type, emitter);
324
340
 
325
341
  yaml_sequence_end_event_initialize(&event);
326
342
 
@@ -348,7 +364,7 @@ static VALUE start_mapping(
348
364
  #ifdef HAVE_RUBY_ENCODING_H
349
365
  rb_encoding *encoding;
350
366
  #endif
351
- Data_Get_Struct(self, yaml_emitter_t, emitter);
367
+ TypedData_Get_Struct(self, yaml_emitter_t, &psych_emitter_type, emitter);
352
368
 
353
369
  #ifdef HAVE_RUBY_ENCODING_H
354
370
  encoding = rb_utf8_encoding();
@@ -387,7 +403,7 @@ static VALUE end_mapping(VALUE self)
387
403
  {
388
404
  yaml_emitter_t * emitter;
389
405
  yaml_event_t event;
390
- Data_Get_Struct(self, yaml_emitter_t, emitter);
406
+ TypedData_Get_Struct(self, yaml_emitter_t, &psych_emitter_type, emitter);
391
407
 
392
408
  yaml_mapping_end_event_initialize(&event);
393
409
 
@@ -406,7 +422,7 @@ static VALUE alias(VALUE self, VALUE anchor)
406
422
  {
407
423
  yaml_emitter_t * emitter;
408
424
  yaml_event_t event;
409
- Data_Get_Struct(self, yaml_emitter_t, emitter);
425
+ TypedData_Get_Struct(self, yaml_emitter_t, &psych_emitter_type, emitter);
410
426
 
411
427
  #ifdef HAVE_RUBY_ENCODING_H
412
428
  if(!NIL_P(anchor)) {
@@ -432,7 +448,7 @@ static VALUE alias(VALUE self, VALUE anchor)
432
448
  static VALUE set_canonical(VALUE self, VALUE style)
433
449
  {
434
450
  yaml_emitter_t * emitter;
435
- Data_Get_Struct(self, yaml_emitter_t, emitter);
451
+ TypedData_Get_Struct(self, yaml_emitter_t, &psych_emitter_type, emitter);
436
452
 
437
453
  yaml_emitter_set_canonical(emitter, Qtrue == style ? 1 : 0);
438
454
 
@@ -446,7 +462,7 @@ static VALUE set_canonical(VALUE self, VALUE style)
446
462
  static VALUE canonical(VALUE self)
447
463
  {
448
464
  yaml_emitter_t * emitter;
449
- Data_Get_Struct(self, yaml_emitter_t, emitter);
465
+ TypedData_Get_Struct(self, yaml_emitter_t, &psych_emitter_type, emitter);
450
466
 
451
467
  return (emitter->canonical == 0) ? Qfalse : Qtrue;
452
468
  }
@@ -459,7 +475,7 @@ static VALUE canonical(VALUE self)
459
475
  static VALUE set_indentation(VALUE self, VALUE level)
460
476
  {
461
477
  yaml_emitter_t * emitter;
462
- Data_Get_Struct(self, yaml_emitter_t, emitter);
478
+ TypedData_Get_Struct(self, yaml_emitter_t, &psych_emitter_type, emitter);
463
479
 
464
480
  yaml_emitter_set_indent(emitter, NUM2INT(level));
465
481
 
@@ -473,7 +489,7 @@ static VALUE set_indentation(VALUE self, VALUE level)
473
489
  static VALUE indentation(VALUE self)
474
490
  {
475
491
  yaml_emitter_t * emitter;
476
- Data_Get_Struct(self, yaml_emitter_t, emitter);
492
+ TypedData_Get_Struct(self, yaml_emitter_t, &psych_emitter_type, emitter);
477
493
 
478
494
  return INT2NUM(emitter->best_indent);
479
495
  }
@@ -485,7 +501,7 @@ static VALUE indentation(VALUE self)
485
501
  static VALUE line_width(VALUE self)
486
502
  {
487
503
  yaml_emitter_t * emitter;
488
- Data_Get_Struct(self, yaml_emitter_t, emitter);
504
+ TypedData_Get_Struct(self, yaml_emitter_t, &psych_emitter_type, emitter);
489
505
 
490
506
  return INT2NUM(emitter->best_width);
491
507
  }
@@ -497,14 +513,14 @@ static VALUE line_width(VALUE self)
497
513
  static VALUE set_line_width(VALUE self, VALUE width)
498
514
  {
499
515
  yaml_emitter_t * emitter;
500
- Data_Get_Struct(self, yaml_emitter_t, emitter);
516
+ TypedData_Get_Struct(self, yaml_emitter_t, &psych_emitter_type, emitter);
501
517
 
502
518
  yaml_emitter_set_width(emitter, NUM2INT(width));
503
519
 
504
520
  return width;
505
521
  }
506
522
 
507
- void Init_psych_emitter()
523
+ void Init_psych_emitter(void)
508
524
  {
509
525
  VALUE psych = rb_define_module("Psych");
510
526
  VALUE handler = rb_define_class_under(psych, "Handler", rb_cObject);
@@ -3,6 +3,6 @@
3
3
 
4
4
  #include <psych.h>
5
5
 
6
- void Init_psych_emitter();
6
+ void Init_psych_emitter(void);
7
7
 
8
8
  #endif
@@ -49,6 +49,22 @@ static void dealloc(void * ptr)
49
49
  xfree(parser);
50
50
  }
51
51
 
52
+ #if 0
53
+ static size_t memsize(const void *ptr)
54
+ {
55
+ const yaml_parser_t *parser = ptr;
56
+ /* TODO: calculate parser's size */
57
+ return 0;
58
+ }
59
+ #endif
60
+
61
+ static const rb_data_type_t psych_parser_type = {
62
+ "Psych/parser",
63
+ {0, dealloc, 0,},
64
+ 0, 0,
65
+ RUBY_TYPED_FREE_IMMEDIATELY,
66
+ };
67
+
52
68
  static VALUE allocate(VALUE klass)
53
69
  {
54
70
  yaml_parser_t * parser;
@@ -56,7 +72,7 @@ static VALUE allocate(VALUE klass)
56
72
  parser = xmalloc(sizeof(yaml_parser_t));
57
73
  yaml_parser_initialize(parser);
58
74
 
59
- return Data_Wrap_Struct(klass, 0, dealloc, parser);
75
+ return TypedData_Wrap_Struct(klass, &psych_parser_type, parser);
60
76
  }
61
77
 
62
78
  static VALUE make_exception(yaml_parser_t * parser, VALUE path)
@@ -248,7 +264,7 @@ static VALUE parse(int argc, VALUE *argv, VALUE self)
248
264
  path = rb_str_new2("<unknown>");
249
265
  }
250
266
 
251
- Data_Get_Struct(self, yaml_parser_t, parser);
267
+ TypedData_Get_Struct(self, yaml_parser_t, &psych_parser_type, parser);
252
268
 
253
269
  yaml_parser_delete(parser);
254
270
  yaml_parser_initialize(parser);
@@ -526,7 +542,7 @@ static VALUE mark(VALUE self)
526
542
  VALUE args[3];
527
543
  yaml_parser_t * parser;
528
544
 
529
- Data_Get_Struct(self, yaml_parser_t, parser);
545
+ TypedData_Get_Struct(self, yaml_parser_t, &psych_parser_type, parser);
530
546
  mark_klass = rb_const_get_at(cPsychParser, rb_intern("Mark"));
531
547
  args[0] = INT2NUM(parser->mark.index);
532
548
  args[1] = INT2NUM(parser->mark.line);
@@ -535,7 +551,7 @@ static VALUE mark(VALUE self)
535
551
  return rb_class_new_instance(3, args, mark_klass);
536
552
  }
537
553
 
538
- void Init_psych_parser()
554
+ void Init_psych_parser(void)
539
555
  {
540
556
  #if 0
541
557
  mPsych = rb_define_module("Psych");
@@ -1,6 +1,6 @@
1
1
  #ifndef PSYCH_PARSER_H
2
2
  #define PSYCH_PARSER_H
3
3
 
4
- void Init_psych_parser();
4
+ void Init_psych_parser(void);
5
5
 
6
6
  #endif
@@ -217,7 +217,7 @@ require 'psych/class_loader'
217
217
 
218
218
  module Psych
219
219
  # The version is Psych you're using
220
- VERSION = '2.0.6'
220
+ VERSION = '2.0.7'
221
221
 
222
222
  # The version of libyaml Psych is using
223
223
  LIBYAML_VERSION = Psych.libyaml_version.join '.'
@@ -271,6 +271,21 @@ module Psych
271
271
  end
272
272
  map
273
273
 
274
+ when /^!ruby\/marshalable:(.*)$/
275
+ name = $1
276
+ klass = resolve_class(name)
277
+ obj = register(o, klass.allocate)
278
+
279
+ if obj.respond_to?(:init_with)
280
+ init_with(obj, revive_hash({}, o), o)
281
+ elsif obj.respond_to?(:marshal_load)
282
+ marshal_data = o.children.map(&method(:accept))
283
+ obj.marshal_load(marshal_data)
284
+ obj
285
+ else
286
+ raise ArgumentError, "Cannot deserialize #{name}"
287
+ end
288
+
274
289
  else
275
290
  revive_hash(register(o, {}), o)
276
291
  end
@@ -27,6 +27,8 @@ module Psych
27
27
 
28
28
  def key? target
29
29
  @obj_to_node.key? target.object_id
30
+ rescue NoMethodError
31
+ false
30
32
  end
31
33
 
32
34
  def id_for target
@@ -411,6 +413,18 @@ module Psych
411
413
  end
412
414
  end
413
415
 
416
+ def visit_BasicObject o
417
+ tag = Psych.dump_tags[o.class]
418
+ tag ||= "!ruby/marshalable:#{o.class.name}"
419
+
420
+ map = @emitter.start_mapping(nil, tag, false, Nodes::Mapping::BLOCK)
421
+ register(o, map)
422
+
423
+ o.marshal_dump.each(&method(:accept))
424
+
425
+ @emitter.end_mapping
426
+ end
427
+
414
428
  private
415
429
  # FIXME: Remove the index and count checks in Psych 3.0
416
430
  NULL = "\x00"
@@ -65,7 +65,7 @@ module Psych
65
65
  @stream.push list
66
66
 
67
67
  json = @io.string
68
- assert_match(/]$/, json)
68
+ assert_match(/\]$/, json)
69
69
  assert_match(/^--- \[/, json)
70
70
  assert_match(/["]one["]/, json)
71
71
  assert_match(/["]two["]/, json)
@@ -11,8 +11,7 @@ module Psych
11
11
  end
12
12
 
13
13
  def test_line_width
14
- assert_equal 0, @emitter.line_width
15
- assert_equal 10, @emitter.line_width = 10
14
+ @emitter.line_width = 10
16
15
  assert_equal 10, @emitter.line_width
17
16
  end
18
17
 
@@ -45,7 +45,7 @@ module Psych
45
45
  def test_list_to_json
46
46
  list = %w{ one two }
47
47
  json = Psych.to_json(list)
48
- assert_match(/]$/, json)
48
+ assert_match(/\]$/, json)
49
49
  assert_match(/^\[/, json)
50
50
  assert_match(/"one"/, json)
51
51
  assert_match(/"two"/, json)
@@ -0,0 +1,54 @@
1
+ require_relative 'helper'
2
+ require 'delegate'
3
+
4
+ module Psych
5
+ class TestMarshalable < TestCase
6
+ def test_objects_defining_marshal_dump_and_marshal_load_can_be_dumped
7
+ sd = SimpleDelegator.new(1)
8
+ loaded = Psych.load(Psych.dump(sd))
9
+
10
+ assert_instance_of(SimpleDelegator, loaded)
11
+ assert_equal(sd, loaded)
12
+ end
13
+
14
+ class PsychCustomMarshalable < BasicObject
15
+ attr_reader :foo
16
+
17
+ def initialize(foo)
18
+ @foo = foo
19
+ end
20
+
21
+ def marshal_dump
22
+ [foo]
23
+ end
24
+
25
+ def mashal_load(data)
26
+ @foo = data[0]
27
+ end
28
+
29
+ def init_with(coder)
30
+ @foo = coder['foo']
31
+ end
32
+
33
+ def encode_with(coder)
34
+ coder['foo'] = 2
35
+ end
36
+
37
+ def respond_to?(method)
38
+ [:marshal_dump, :marshal_load, :init_with, :encode_with].include?(method)
39
+ end
40
+
41
+ def class
42
+ PsychCustomMarshalable
43
+ end
44
+ end
45
+
46
+ def test_init_with_takes_priority_over_marshal_methods
47
+ obj = PsychCustomMarshalable.new(1)
48
+ loaded = Psych.load(Psych.dump(obj))
49
+
50
+ assert(PsychCustomMarshalable === loaded)
51
+ assert_equal(2, loaded.foo)
52
+ end
53
+ end
54
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: psych
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.6
4
+ version: 2.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Patterson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-14 00:00:00.000000000 Z
11
+ date: 2014-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rdoc
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '3.12'
47
+ version: '3.13'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '3.12'
54
+ version: '3.13'
55
55
  description: |-
56
56
  Psych is a YAML parser and emitter. Psych leverages libyaml[http://pyyaml.org/wiki/LibYAML]
57
57
  for its YAML parsing and emitting capabilities. In addition to wrapping
@@ -152,6 +152,7 @@ files:
152
152
  - test/psych/test_exception.rb
153
153
  - test/psych/test_hash.rb
154
154
  - test/psych/test_json_tree.rb
155
+ - test/psych/test_marshalable.rb
155
156
  - test/psych/test_merge_keys.rb
156
157
  - test/psych/test_nil.rb
157
158
  - test/psych/test_null.rb
@@ -202,7 +203,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
202
203
  version: '0'
203
204
  requirements: []
204
205
  rubyforge_project:
205
- rubygems_version: 2.2.2
206
+ rubygems_version: 2.4.4
206
207
  signing_key:
207
208
  specification_version: 4
208
209
  summary: Psych is a YAML parser and emitter
@@ -223,6 +224,7 @@ test_files:
223
224
  - test/psych/test_exception.rb
224
225
  - test/psych/test_hash.rb
225
226
  - test/psych/test_json_tree.rb
227
+ - test/psych/test_marshalable.rb
226
228
  - test/psych/test_merge_keys.rb
227
229
  - test/psych/test_nil.rb
228
230
  - test/psych/test_null.rb