msgpack 1.0.0 → 1.0.1

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: 5b0022850815574e6a143c08513a2b9cb2b9e77b
4
- data.tar.gz: d5b2885ea44ef93b59c653dc3955ab65d58378aa
3
+ metadata.gz: fda451694c92442e4a2779a81b999d2ecaacbb41
4
+ data.tar.gz: 0f4cb5f219f9ea079ab76423caadecd704c9848c
5
5
  SHA512:
6
- metadata.gz: 4908bfa50709cf9e0c642d402b23be97f891e1991ed4dbe530577a2f8d8051b00aaa8dc1b37e83705c961ebe996c648de9c87a03bc2276c2315a31c944cc09e9
7
- data.tar.gz: c77c6d4525fb762b353aaa09c3c15d505b2b6b1783d578001976f9c3e8ebdd7111fe129e4b7b4f5bb5e5c58fc98b2f084077652b303b98f075ac6e918ffc3ed8
6
+ metadata.gz: 3e1088230c4029a9812292b499f65cd9e96674f03a45ffad650a1936378fcd3f69d62eb999969c29470a6b01c49702442916492b08036cd34e75417452e5d3fe
7
+ data.tar.gz: dec45f52de01bfac41ca348f953b2f82a22e19a3a4cfd95b70406be5db98e2bf4aafe6fe9299b6ada0bf1af2532af34b2d63eacf7330b207fe245a5feac4e6d1
data/ChangeLog CHANGED
@@ -1,3 +1,8 @@
1
+ 2016-10-17 version 1.0.1:
2
+
3
+ * Fix a bug to crash at packer when ext type is registered for superclass of packed object
4
+ * Fix JRuby implementation about inconsistent API of Unpacker constructor
5
+
1
6
  2016-07-08 version 1.0.0:
2
7
 
3
8
  * Fix to be able to pack Symbol with ext types
@@ -51,7 +51,7 @@ public class Unpacker extends RubyObject {
51
51
  }
52
52
  }
53
53
 
54
- @JRubyMethod(name = "initialize", optional = 1, visibility = PRIVATE)
54
+ @JRubyMethod(name = "initialize", optional = 2, visibility = PRIVATE)
55
55
  public IRubyObject initialize(ThreadContext ctx, IRubyObject[] args) {
56
56
  symbolizeKeys = false;
57
57
  allowUnknownExt = false;
@@ -66,7 +66,8 @@ public class Unpacker extends RubyObject {
66
66
  if (au != null) {
67
67
  allowUnknownExt = au.isTrue();
68
68
  }
69
- } else if (!(args[0] instanceof RubyHash)) {
69
+ }
70
+ if (!(args[0] instanceof RubyHash)) {
70
71
  setStream(ctx, args[0]);
71
72
  }
72
73
  }
@@ -26,10 +26,7 @@ typedef struct msgpack_packer_ext_registry_t msgpack_packer_ext_registry_t;
26
26
 
27
27
  struct msgpack_packer_ext_registry_t {
28
28
  VALUE hash;
29
- /*
30
- * lookup cache for subclasses of registered classes
31
- */
32
- VALUE cache;
29
+ VALUE cache; // lookup cache for ext types inherited from a super class
33
30
  };
34
31
 
35
32
  void msgpack_packer_ext_registry_static_init();
@@ -49,7 +46,7 @@ void msgpack_packer_ext_registry_dup(msgpack_packer_ext_registry_t* src,
49
46
  VALUE msgpack_packer_ext_registry_put(msgpack_packer_ext_registry_t* pkrg,
50
47
  VALUE ext_class, int ext_type, VALUE proc, VALUE arg);
51
48
 
52
- static int msgpack_packer_ext_find_inherited(VALUE key, VALUE value, VALUE arg)
49
+ static int msgpack_packer_ext_find_superclass(VALUE key, VALUE value, VALUE arg)
53
50
  {
54
51
  VALUE *args = (VALUE *) arg;
55
52
  if(key == Qundef) {
@@ -66,16 +63,16 @@ static int msgpack_packer_ext_find_inherited(VALUE key, VALUE value, VALUE arg)
66
63
  static inline VALUE msgpack_packer_ext_registry_lookup(msgpack_packer_ext_registry_t* pkrg,
67
64
  VALUE ext_class, int* ext_type_result)
68
65
  {
69
- VALUE e = rb_hash_lookup(pkrg->hash, ext_class);
70
- if(e != Qnil) {
71
- *ext_type_result = FIX2INT(rb_ary_entry(e, 0));
72
- return rb_ary_entry(e, 1);
66
+ VALUE type = rb_hash_lookup(pkrg->hash, ext_class);
67
+ if(type != Qnil) {
68
+ *ext_type_result = FIX2INT(rb_ary_entry(type, 0));
69
+ return rb_ary_entry(type, 1);
73
70
  }
74
71
 
75
- VALUE c = rb_hash_lookup(pkrg->cache, ext_class);
76
- if(c != Qnil) {
77
- *ext_type_result = FIX2INT(rb_ary_entry(c, 0));
78
- return rb_ary_entry(c, 1);
72
+ VALUE type_inht = rb_hash_lookup(pkrg->cache, ext_class);
73
+ if(type_inht != Qnil) {
74
+ *ext_type_result = FIX2INT(rb_ary_entry(type_inht, 0));
75
+ return rb_ary_entry(type_inht, 1);
79
76
  }
80
77
 
81
78
  /*
@@ -84,12 +81,14 @@ static inline VALUE msgpack_packer_ext_registry_lookup(msgpack_packer_ext_regist
84
81
  VALUE args[2];
85
82
  args[0] = ext_class;
86
83
  args[1] = Qnil;
87
- rb_hash_foreach(pkrg->hash, msgpack_packer_ext_find_inherited, (VALUE) args);
88
-
89
- VALUE hit = args[1];
90
- if(hit != Qnil) {
91
- rb_hash_aset(pkrg->cache, ext_class, hit);
92
- return hit;
84
+ rb_hash_foreach(pkrg->hash, msgpack_packer_ext_find_superclass, (VALUE) args);
85
+
86
+ VALUE superclass = args[1];
87
+ if(superclass != Qnil) {
88
+ VALUE superclass_type = rb_hash_lookup(pkrg->hash, superclass);
89
+ rb_hash_aset(pkrg->cache, ext_class, superclass_type);
90
+ *ext_type_result = FIX2INT(rb_ary_entry(superclass_type, 0));
91
+ return rb_ary_entry(superclass_type, 1);
93
92
  }
94
93
 
95
94
  return Qnil;
@@ -1,3 +1,3 @@
1
1
  module MessagePack
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
@@ -324,6 +324,32 @@ describe MessagePack::Packer do
324
324
  expect(two[:packer]).to eq(:to_msgpack_ext)
325
325
  end
326
326
 
327
+ context 'when it has no ext type but a super class has' do
328
+ before { stub_const('Value', Class.new) }
329
+ before do
330
+ Value.class_eval do
331
+ def to_msgpack_ext
332
+ 'value_msgpacked'
333
+ end
334
+ end
335
+ end
336
+ before { packer.register_type(0x01, Value, :to_msgpack_ext) }
337
+
338
+ context "when it is a child class" do
339
+ before { stub_const('InheritedValue', Class.new(Value)) }
340
+ subject { packer.pack(InheritedValue.new).to_s }
341
+
342
+ it { is_expected.to eq "\xC7\x0F\x01value_msgpacked" }
343
+
344
+ context "when it is a grandchild class" do
345
+ before { stub_const('InheritedTwiceValue', Class.new(InheritedValue)) }
346
+ subject { packer.pack(InheritedTwiceValue.new).to_s }
347
+
348
+ it { is_expected.to eq "\xC7\x0F\x01value_msgpacked" }
349
+ end
350
+ end
351
+ end
352
+
327
353
  context 'when registering a type for symbols' do
328
354
  before { packer.register_type(0x00, ::Symbol, :to_msgpack_ext) }
329
355
 
@@ -564,6 +564,17 @@ describe MessagePack::Unpacker do
564
564
  objects.should == [{'foo' => 'bar'}, {'hello' => {'world' => [1, 2, 3]}}, {'x' => 'y'}]
565
565
  end
566
566
  end
567
+
568
+ context 'with a stream and symbolize_keys passed to the constructor' do
569
+ it 'yields each object in the stream, with symbolized keys' do
570
+ objects = []
571
+ unpacker = described_class.new(StringIO.new(buffer1 + buffer2 + buffer3), symbolize_keys: true)
572
+ unpacker.each do |obj|
573
+ objects << obj
574
+ end
575
+ objects.should == [{:foo => 'bar'}, {:hello => {:world => [1, 2, 3]}}, {:x => 'y'}]
576
+ end
577
+ end
567
578
  end
568
579
 
569
580
  describe '#feed_each' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: msgpack
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sadayuki Furuhashi
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2016-07-08 00:00:00.000000000 Z
13
+ date: 2016-10-17 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler