msgpack 1.2.0-x86-mingw32 → 1.2.2-x86-mingw32

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: 7c14dafc60f8a2d68c22006e7891636397a3c93c
4
- data.tar.gz: e67291dc047e8b406b3792bda09be8517152393c
3
+ metadata.gz: ff565d69a17eb604c162b7bfbda56a6438180286
4
+ data.tar.gz: c6f4e68cbfaeadde530e6be0a4f88256f40b9c81
5
5
  SHA512:
6
- metadata.gz: f9153cbc455911a43e90a833bc7923246a91a493acb0c996f901ea73660924a4fd605f17166ebf6005674345bc2feb4bc7449d1986d90612a01cf5dd2796a3b8
7
- data.tar.gz: 0b3580e1e142564498353a02f86dba9e3e52da0364d5c79d9771fbe6cc7ce85f033af86964404698b3b36ac8efbf16953d4ef7c16cd8421675a157fb2d2254da
6
+ metadata.gz: 7a5b1b049fa6ec1c26104ea9f4e134d66adf46d4dfcef59ad74c185cb86f7d88eadbbfdf84fad292582a8dcf1d44098ea153199ca8ad920a3bf20cc912d77713
7
+ data.tar.gz: 89b66dbdd97210ba64a621e8dc2984af963789cd3a08e85d45c32a9604786e7c35f54c2966fd3aa4520b4791d90713b6d68455736aa834b4d43e6983fac646fa
@@ -1,20 +1,5 @@
1
1
  language: ruby
2
2
 
3
- rvm:
4
- - 2.0.0
5
- - 2.1.6
6
- - 2.2.2
7
- - 2.3.0
8
- - 2.4.0
9
- - ruby-head
10
- - jruby-19mode
11
- - jruby-9.1.5.0
12
- - jruby-head
13
-
14
- os:
15
- - linux
16
- - osx
17
-
18
3
  sudo: false
19
4
 
20
5
  branches:
@@ -24,18 +9,30 @@ branches:
24
9
  gemfile:
25
10
  - Gemfile
26
11
 
12
+ # http://rubies.travis-ci.org/
27
13
  matrix:
28
- exclude:
29
- - rvm: 2.0.0
30
- os: osx
31
- - rvm: jruby-19mode
14
+ include:
15
+ - rvm: 2.1.10
16
+ os: linux
17
+ - rvm: 2.2.8
18
+ os: linux
19
+ - rvm: 2.3.5
20
+ os: linux
21
+ - rvm: 2.3.5
32
22
  os: osx
33
- - rvm: jruby-9.1.5.0
23
+ - rvm: 2.4.2
24
+ os: linux
25
+ - rvm: 2.4.2
34
26
  os: osx
27
+ - rvm: ruby-head
28
+ os: linux
29
+ - rvm: jruby-9.1.9.0
30
+ os: linux
35
31
  - rvm: jruby-head
36
- os: osx
32
+ os: linux
33
+ - rvm: jruby-19mode
34
+ os: linux
37
35
  allow_failures:
38
36
  - rvm: ruby-head
39
37
  - rvm: jruby-head
40
38
  - rvm: jruby-19mode
41
- os: osx
data/ChangeLog CHANGED
@@ -1,3 +1,12 @@
1
+ 2018-01-11 version 1.2.2:
2
+
3
+ * Fix bug to occur SEGV occasionally (depends on GC timing) when exttype is used
4
+ * Fix bug to encode an ext type with wrong type id if superclass is also registered as ext type
5
+
6
+ 2017-12-08 version 1.2.1:
7
+
8
+ * Hotfix release only for JRuby: 1.2.0-java was built in incorrect way
9
+
1
10
  2017-12-07 version 1.2.0:
2
11
 
3
12
  * Add MessagePack::Factory#dump and MessagePack::Factory#load as convenient methods
@@ -384,7 +384,7 @@ public class Encoder {
384
384
  lookupClass = object.getSingletonClass();
385
385
  }
386
386
 
387
- IRubyObject[] pair = registry.lookupPackerByModule(lookupClass);
387
+ IRubyObject[] pair = registry.lookupPackerForObject(object);
388
388
  if (pair != null) {
389
389
  RubyString bytes = pair[0].callMethod(runtime.getCurrentContext(), "call", object).asString();
390
390
  int type = (int) ((RubyFixnum) pair[1]).getLongValue();
@@ -5,6 +5,7 @@ import org.jruby.RubyHash;
5
5
  import org.jruby.RubyArray;
6
6
  import org.jruby.RubyModule;
7
7
  import org.jruby.RubyFixnum;
8
+ import org.jruby.RubySymbol;
8
9
  import org.jruby.runtime.ThreadContext;
9
10
  import org.jruby.runtime.builtin.IRubyObject;
10
11
 
@@ -74,22 +75,50 @@ public class ExtensionRegistry {
74
75
  }
75
76
  }
76
77
 
77
- public IRubyObject[] lookupPackerByModule(RubyModule mod) {
78
+ public IRubyObject[] lookupPackerForObject(IRubyObject object) {
79
+ RubyModule lookupClass = null;
80
+ IRubyObject[] pair;
81
+ /*
82
+ * Objects of type Integer (Fixnum, Bignum), Float, Symbol and frozen
83
+ * String have no singleton class and raise a TypeError when trying to get
84
+ * it.
85
+ *
86
+ * Since all but symbols are already filtered out when reaching this code
87
+ * only symbols are checked here.
88
+ */
89
+ if (!(object instanceof RubySymbol)) {
90
+ lookupClass = object.getSingletonClass();
91
+ pair = fetchEntryByModule(lookupClass);
92
+ if (pair != null) {
93
+ return pair;
94
+ }
95
+ }
96
+
97
+ pair = fetchEntryByModule(object.getType());
98
+ if (pair != null) {
99
+ return pair;
100
+ }
101
+
102
+ if (lookupClass == null) {
103
+ lookupClass = object.getType(); // only for Symbol
104
+ }
105
+ ExtensionEntry e = findEntryByModuleOrAncestor(lookupClass);
106
+ if (e != null && e.hasPacker()) {
107
+ extensionsByAncestor.put(e.getExtensionModule(), e);
108
+ return e.toPackerProcTypeIdPair(lookupClass.getRuntime().getCurrentContext());
109
+ }
110
+ return null;
111
+ }
112
+
113
+ private IRubyObject[] fetchEntryByModule(final RubyModule mod) {
78
114
  ExtensionEntry e = extensionsByModule.get(mod);
79
115
  if (e == null) {
80
116
  e = extensionsByAncestor.get(mod);
81
117
  }
82
- if (e == null) {
83
- e = findEntryByModuleOrAncestor(mod);
84
- if (e != null) {
85
- extensionsByAncestor.put(e.getExtensionModule(), e);
86
- }
87
- }
88
118
  if (e != null && e.hasPacker()) {
89
119
  return e.toPackerProcTypeIdPair(mod.getRuntime().getCurrentContext());
90
- } else {
91
- return null;
92
120
  }
121
+ return null;
93
122
  }
94
123
 
95
124
  private ExtensionEntry findEntryByModuleOrAncestor(final RubyModule mod) {
@@ -54,7 +54,7 @@ static void Buffer_free(void* data)
54
54
 
55
55
  static VALUE Buffer_alloc(VALUE klass)
56
56
  {
57
- msgpack_buffer_t* b = ALLOC_N(msgpack_buffer_t, 1);
57
+ msgpack_buffer_t* b = ZALLOC_N(msgpack_buffer_t, 1);
58
58
  msgpack_buffer_init(b);
59
59
 
60
60
  return Data_Wrap_Struct(klass, msgpack_buffer_mark, Buffer_free, b);
@@ -28,6 +28,16 @@
28
28
  #endif
29
29
 
30
30
 
31
+ /*
32
+ * ZALLOC_N (ruby 2.2 or later)
33
+ */
34
+ #ifndef RB_ZALLOC_N
35
+ # define RB_ZALLOC_N(type,n) ((type*)ruby_xcalloc((size_t)(n),sizeof(type)))
36
+ #endif
37
+ #ifndef ZALLOC_N
38
+ # define ZALLOC_N(type,n) RB_ZALLOC_N(type,n)
39
+ #endif
40
+
31
41
  /*
32
42
  * COMPAT_HAVE_ENCODING
33
43
  */
@@ -59,10 +59,7 @@ void Factory_mark(msgpack_factory_t* fc)
59
59
 
60
60
  static VALUE Factory_alloc(VALUE klass)
61
61
  {
62
- msgpack_factory_t* fc = ALLOC_N(msgpack_factory_t, 1);
63
-
64
- msgpack_packer_ext_registry_init(&fc->pkrg);
65
- msgpack_unpacker_ext_registry_init(&fc->ukrg);
62
+ msgpack_factory_t* fc = ZALLOC_N(msgpack_factory_t, 1);
66
63
 
67
64
  VALUE self = Data_Wrap_Struct(klass, Factory_mark, Factory_free, fc);
68
65
  return self;
@@ -72,6 +69,9 @@ static VALUE Factory_initialize(int argc, VALUE* argv, VALUE self)
72
69
  {
73
70
  FACTORY(self, fc);
74
71
 
72
+ msgpack_packer_ext_registry_init(&fc->pkrg);
73
+ msgpack_unpacker_ext_registry_init(&fc->ukrg);
74
+
75
75
  fc->has_symbol_ext_type = false;
76
76
 
77
77
  switch (argc) {
@@ -125,25 +125,7 @@ void msgpack_packer_write_other_value(msgpack_packer_t* pk, VALUE v)
125
125
  {
126
126
  int ext_type;
127
127
 
128
- VALUE lookup_class;
129
-
130
- /*
131
- * Objects of type Integer (Fixnum, Bignum), Float, Symbol and frozen
132
- * String have no singleton class and raise a TypeError when trying to get
133
- * it. See implementation of #singleton_class in ruby's source code:
134
- * VALUE rb_singleton_class(VALUE obj);
135
- *
136
- * Since all but symbols are already filtered out when reaching this code
137
- * only symbols are checked here.
138
- */
139
- if (SYMBOL_P(v)) {
140
- lookup_class = rb_obj_class(v);
141
- } else {
142
- lookup_class = rb_singleton_class(v);
143
- }
144
-
145
- VALUE proc = msgpack_packer_ext_registry_lookup(&pk->ext_registry, lookup_class,
146
- &ext_type);
128
+ VALUE proc = msgpack_packer_ext_registry_lookup(&pk->ext_registry, v, &ext_type);
147
129
 
148
130
  if(proc != Qnil) {
149
131
  VALUE payload = rb_funcall(proc, s_call, 1, v);
@@ -56,14 +56,12 @@ static void Packer_mark(msgpack_packer_t* pk)
56
56
 
57
57
  VALUE MessagePack_Packer_alloc(VALUE klass)
58
58
  {
59
- msgpack_packer_t* pk = ALLOC_N(msgpack_packer_t, 1);
59
+ msgpack_packer_t* pk = ZALLOC_N(msgpack_packer_t, 1);
60
60
  msgpack_packer_init(pk);
61
61
 
62
62
  VALUE self = Data_Wrap_Struct(klass, Packer_mark, Packer_free, pk);
63
63
 
64
64
  msgpack_packer_set_to_msgpack_method(pk, s_to_msgpack, self);
65
- msgpack_packer_ext_registry_init(&pk->ext_registry);
66
- pk->buffer_ref = MessagePack_Buffer_wrap(PACKER_BUFFER_(pk), self);
67
65
 
68
66
  return self;
69
67
  }
@@ -97,6 +95,9 @@ VALUE MessagePack_Packer_initialize(int argc, VALUE* argv, VALUE self)
97
95
 
98
96
  PACKER(self, pk);
99
97
 
98
+ msgpack_packer_ext_registry_init(&pk->ext_registry);
99
+ pk->buffer_ref = MessagePack_Buffer_wrap(PACKER_BUFFER_(pk), self);
100
+
100
101
  MessagePack_Buffer_set_options(PACKER_BUFFER_(pk), io, options);
101
102
 
102
103
  if(options != Qnil) {
@@ -59,24 +59,64 @@ static int msgpack_packer_ext_find_superclass(VALUE key, VALUE value, VALUE arg)
59
59
  return ST_CONTINUE;
60
60
  }
61
61
 
62
-
63
- static inline VALUE msgpack_packer_ext_registry_lookup(msgpack_packer_ext_registry_t* pkrg,
62
+ static inline VALUE msgpack_packer_ext_registry_fetch(msgpack_packer_ext_registry_t* pkrg,
64
63
  VALUE lookup_class, int* ext_type_result)
65
64
  {
65
+ // fetch lookup_class from hash, which is a hash to register classes
66
66
  VALUE type = rb_hash_lookup(pkrg->hash, lookup_class);
67
67
  if(type != Qnil) {
68
68
  *ext_type_result = FIX2INT(rb_ary_entry(type, 0));
69
69
  return rb_ary_entry(type, 1);
70
70
  }
71
71
 
72
+ // fetch lookup_class from cache, which stores results of searching ancestors from pkrg->hash
72
73
  VALUE type_inht = rb_hash_lookup(pkrg->cache, lookup_class);
73
74
  if(type_inht != Qnil) {
74
75
  *ext_type_result = FIX2INT(rb_ary_entry(type_inht, 0));
75
76
  return rb_ary_entry(type_inht, 1);
76
77
  }
77
78
 
79
+ return Qnil;
80
+ }
81
+
82
+ static inline VALUE msgpack_packer_ext_registry_lookup(msgpack_packer_ext_registry_t* pkrg,
83
+ VALUE instance, int* ext_type_result)
84
+ {
85
+ VALUE lookup_class;
86
+ VALUE type;
87
+
88
+ /*
89
+ * 1. check whether singleton_class of this instance is registered (or resolved in past) or not.
90
+ *
91
+ * Objects of type Integer (Fixnum, Bignum), Float, Symbol and frozen
92
+ * String have no singleton class and raise a TypeError when trying to get
93
+ * it. See implementation of #singleton_class in ruby's source code:
94
+ * VALUE rb_singleton_class(VALUE obj);
95
+ *
96
+ * Since all but symbols are already filtered out when reaching this code
97
+ * only symbols are checked here.
98
+ */
99
+ if (!SYMBOL_P(instance)) {
100
+ lookup_class = rb_singleton_class(instance);
101
+
102
+ type = msgpack_packer_ext_registry_fetch(pkrg, lookup_class, ext_type_result);
103
+
104
+ if(type != Qnil) {
105
+ return type;
106
+ }
107
+ }
108
+
109
+ /*
110
+ * 2. check the class of instance is registered (or resolved in past) or not.
111
+ */
112
+ type = msgpack_packer_ext_registry_fetch(pkrg, rb_obj_class(instance), ext_type_result);
113
+
114
+ if(type != Qnil) {
115
+ return type;
116
+ }
117
+
78
118
  /*
79
- * check all keys whether it is an ancestor of lookup_class, or not
119
+ * 3. check all keys whether it is an ancestor of lookup_class, or not
80
120
  */
81
121
  VALUE args[2];
82
122
  args[0] = lookup_class;
@@ -58,14 +58,10 @@ static void Unpacker_mark(msgpack_unpacker_t* uk)
58
58
 
59
59
  VALUE MessagePack_Unpacker_alloc(VALUE klass)
60
60
  {
61
- msgpack_unpacker_t* uk = ALLOC_N(msgpack_unpacker_t, 1);
61
+ msgpack_unpacker_t* uk = ZALLOC_N(msgpack_unpacker_t, 1);
62
62
  _msgpack_unpacker_init(uk);
63
63
 
64
64
  VALUE self = Data_Wrap_Struct(klass, Unpacker_mark, Unpacker_free, uk);
65
-
66
- msgpack_unpacker_ext_registry_init(&uk->ext_registry);
67
- uk->buffer_ref = MessagePack_Buffer_wrap(UNPACKER_BUFFER_(uk), self);
68
-
69
65
  return self;
70
66
  }
71
67
 
@@ -101,6 +97,9 @@ VALUE MessagePack_Unpacker_initialize(int argc, VALUE* argv, VALUE self)
101
97
 
102
98
  UNPACKER(self, uk);
103
99
 
100
+ msgpack_unpacker_ext_registry_init(&uk->ext_registry);
101
+ uk->buffer_ref = MessagePack_Buffer_wrap(UNPACKER_BUFFER_(uk), self);
102
+
104
103
  MessagePack_Buffer_set_options(UNPACKER_BUFFER_(uk), io, options);
105
104
 
106
105
  if(options != Qnil) {
@@ -1,3 +1,3 @@
1
1
  module MessagePack
2
- VERSION = "1.2.0"
2
+ VERSION = "1.2.2"
3
3
  end
@@ -331,6 +331,19 @@ describe MessagePack::Factory do
331
331
  end
332
332
  end
333
333
 
334
+ describe 'under stressful GC' do
335
+ it 'works well' do
336
+ begin
337
+ GC.stress = true
338
+
339
+ f = MessagePack::Factory.new
340
+ f.register_type(0x0a, Symbol)
341
+ ensure
342
+ GC.stress = false
343
+ end
344
+ end
345
+ end
346
+
334
347
  describe 'DefaultFactory' do
335
348
  it 'is a factory' do
336
349
  MessagePack::DefaultFactory.should be_kind_of(MessagePack::Factory)
@@ -372,6 +372,50 @@ describe MessagePack::Packer do
372
372
  end
373
373
  end
374
374
 
375
+ context 'when it and its super class has an ext type' do
376
+ before { stub_const('Value', Class.new) }
377
+ before do
378
+ Value.class_eval do
379
+ def to_msgpack_ext
380
+ 'value_msgpacked'
381
+ end
382
+ end
383
+ end
384
+ before { packer.register_type(0x01, Value, :to_msgpack_ext) }
385
+
386
+ context "when it is a child class" do
387
+ before { stub_const('InheritedValue', Class.new(Value)) }
388
+ before do
389
+ InheritedValue.class_eval do
390
+ def to_msgpack_ext
391
+ 'inherited_value_msgpacked'
392
+ end
393
+ end
394
+ end
395
+
396
+ before { packer.register_type(0x02, InheritedValue, :to_msgpack_ext) }
397
+ subject { packer.pack(InheritedValue.new).to_s }
398
+
399
+ it { is_expected.to eq "\xC7\x19\x02inherited_value_msgpacked" }
400
+ end
401
+
402
+ context "even when it is a child class" do
403
+ before { stub_const('InheritedValue', Class.new(Value)) }
404
+ before do
405
+ InheritedValue.class_eval do
406
+ def to_msgpack_ext
407
+ 'inherited_value_msgpacked'
408
+ end
409
+ end
410
+ end
411
+
412
+ before { packer.register_type(0x02, InheritedValue, :to_msgpack_ext) }
413
+ subject { packer.pack(Value.new).to_s }
414
+
415
+ it { is_expected.to eq "\xC7\x0F\x01value_msgpacked" }
416
+ end
417
+ end
418
+
375
419
  context 'when it has no ext type but an included module has' do
376
420
  subject { packer.pack(Value.new).to_s }
377
421
 
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.2.0
4
+ version: 1.2.2
5
5
  platform: x86-mingw32
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: 2017-12-07 00:00:00.000000000 Z
13
+ date: 2018-01-11 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
@@ -246,7 +246,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
246
246
  version: '0'
247
247
  requirements: []
248
248
  rubyforge_project: msgpack
249
- rubygems_version: 2.6.12
249
+ rubygems_version: 2.6.14
250
250
  signing_key:
251
251
  specification_version: 4
252
252
  summary: MessagePack, a binary-based efficient data interchange format.