msgpack 0.5.4 → 0.5.5

Sign up to get free protection for your applications and to get access to all the features.
data/ChangeLog CHANGED
@@ -1,16 +1,23 @@
1
1
 
2
- 2012-03-15 version 0.5.4:
2
+ 2013-05-12 version 0.5.5:
3
+
4
+ * Fixed SEGV problem in to_msgpack
5
+ * Fixed a possible race condition in MessagePack.load when it loads data from IO
6
+ * mingw32 package includes binary for ruby-2.0.0
7
+
8
+
9
+ 2013-03-15 version 0.5.4:
3
10
 
4
11
  * Added missing MessagePack::Unpacker#reset method
5
12
 
6
13
 
7
- 2012-02-14 version 0.5.3:
14
+ 2013-02-14 version 0.5.3:
8
15
 
9
16
  * Fixed segfault problem on Buffer#clear (reuse rmem internal fragment optimization)
10
17
  * Fixed segfault problem on Buffer (rmem free code)
11
18
 
12
19
 
13
- 2012-02-07 version 0.5.2:
20
+ 2013-02-07 version 0.5.2:
14
21
 
15
22
  * Fixed invalid pack/unpack on 32bit architecture such as Win32
16
23
  * Disable rmem on Rubinius because rmem is not thread safe
data/Rakefile CHANGED
@@ -70,6 +70,11 @@ task :default => :build
70
70
  # echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
71
71
  # exec $SHELL -l
72
72
  #
73
+ ### install cross-compiled ruby 2.0.0
74
+ # rbenv install 2.0.0-p0
75
+ # gem install rake-compiler
76
+ # rake-compiler cross-ruby VERSION=2.0.0-p0
77
+ #
73
78
  ### install cross-compiled ruby 1.9.3
74
79
  # rbenv install 1.9.3-p327
75
80
  # gem install rake-compiler
@@ -83,6 +88,6 @@ task :default => :build
83
88
  ### build gem
84
89
  # rbenv shell 1.8.7-p371
85
90
  # gem install bundler && bundle
86
- # rake cross native gem RUBY_CC_VERSION=1.8.7:1.9.3
91
+ # rake cross native gem RUBY_CC_VERSION=1.8.7:1.9.3:2.0.0
87
92
  #
88
93
 
@@ -24,7 +24,7 @@ module MessagePack
24
24
  #
25
25
  # Internal buffer
26
26
  #
27
- # @return MessagePack::Unpacker
27
+ # @return MessagePack::Buffer
28
28
  #
29
29
  attr_reader :buffer
30
30
 
@@ -54,7 +54,7 @@ module MessagePack
54
54
  #
55
55
  # @return [Packer] self
56
56
  #
57
- def write_array_header(size)
57
+ def write_array_header(n)
58
58
  end
59
59
 
60
60
  #
@@ -63,12 +63,12 @@ module MessagePack
63
63
  #
64
64
  # @return [Packer] self
65
65
  #
66
- def write_map_header(size)
66
+ def write_map_header(n)
67
67
  end
68
68
 
69
69
  #
70
70
  # Flushes data in the internal buffer to the internal IO. Same as _buffer.flush.
71
- # If internal IO is not set, it doesn nothing.
71
+ # If internal IO is not set, it does nothing.
72
72
  #
73
73
  # @return [Packer] self
74
74
  #
@@ -108,6 +108,8 @@ module MessagePack
108
108
  def to_str
109
109
  end
110
110
 
111
+ alias to_s to_str
112
+
111
113
  #
112
114
  # Returns content of the internal buffer as an array of strings. Same as buffer.to_a.
113
115
  # This method is faster than _to_str_.
@@ -25,7 +25,7 @@ module MessagePack
25
25
  #
26
26
  # Internal buffer
27
27
  #
28
- # @return [MessagePack::Unpacker]
28
+ # @return [MessagePack::Buffer]
29
29
  #
30
30
  attr_reader :buffer
31
31
 
@@ -230,6 +230,13 @@ VALUE MessagePack_pack(int argc, VALUE* argv)
230
230
  }
231
231
 
232
232
  msgpack_buffer_clear(PACKER_BUFFER_(pk)); /* to free rmem before GC */
233
+
234
+ #ifdef RB_GC_GUARD
235
+ /* This prevents compilers from optimizing out the `self` variable
236
+ * from stack. Otherwise GC free()s it. */
237
+ RB_GC_GUARD(self);
238
+ #endif
239
+
233
240
  return retval;
234
241
  }
235
242
 
@@ -17,6 +17,16 @@
17
17
  */
18
18
 
19
19
  #include "unpacker.h"
20
+ #include "rmem.h"
21
+
22
+ #if !defined(DISABLE_RMEM) && !defined(DISABLE_UNPACKER_STACK_RMEM) && \
23
+ MSGPACK_UNPACKER_STACK_CAPACITY * MSGPACK_UNPACKER_STACK_SIZE <= MSGPACK_RMEM_PAGE_SIZE
24
+ #define UNPACKER_STACK_RMEM
25
+ #endif
26
+
27
+ #ifdef UNPACKER_STACK_RMEM
28
+ static msgpack_rmem_t s_stack_rmem;
29
+ #endif
20
30
 
21
31
  #ifdef COMPAT_HAVE_ENCODING /* see compat.h*/
22
32
  static int s_enc_utf8;
@@ -24,13 +34,21 @@ static int s_enc_utf8;
24
34
 
25
35
  void msgpack_unpacker_static_init()
26
36
  {
37
+ #ifdef UNPACKER_STACK_RMEM
38
+ msgpack_rmem_init(&s_stack_rmem);
39
+ #endif
40
+
27
41
  #ifdef COMPAT_HAVE_ENCODING
28
42
  s_enc_utf8 = rb_utf8_encindex();
29
43
  #endif
30
44
  }
31
45
 
32
46
  void msgpack_unpacker_static_destroy()
33
- { }
47
+ {
48
+ #ifdef UNPACKER_STACK_RMEM
49
+ msgpack_rmem_destroy(&s_stack_rmem);
50
+ #endif
51
+ }
34
52
 
35
53
  #define HEAD_BYTE_REQUIRED 0xc6
36
54
 
@@ -45,13 +63,24 @@ void msgpack_unpacker_init(msgpack_unpacker_t* uk)
45
63
  uk->last_object = Qnil;
46
64
  uk->reading_raw = Qnil;
47
65
 
48
- uk->stack = calloc(MSGPACK_UNPACKER_STACK_CAPACITY, sizeof(msgpack_unpacker_stack_t));
66
+ #ifdef UNPACKER_STACK_RMEM
67
+ uk->stack = msgpack_rmem_alloc(&s_stack_rmem);
68
+ /*memset(uk->stack, 0, MSGPACK_UNPACKER_STACK_CAPACITY);*/
69
+ #else
70
+ /*uk->stack = calloc(MSGPACK_UNPACKER_STACK_CAPACITY, sizeof(msgpack_unpacker_stack_t));*/
71
+ uk->stack = malloc(MSGPACK_UNPACKER_STACK_CAPACITY * sizeof(msgpack_unpacker_stack_t));
72
+ #endif
49
73
  uk->stack_capacity = MSGPACK_UNPACKER_STACK_CAPACITY;
50
74
  }
51
75
 
52
76
  void msgpack_unpacker_destroy(msgpack_unpacker_t* uk)
53
77
  {
78
+ #ifdef UNPACKER_STACK_RMEM
79
+ msgpack_rmem_free(&s_stack_rmem, uk->stack);
80
+ #else
54
81
  free(uk->stack);
82
+ #endif
83
+
55
84
  msgpack_buffer_destroy(UNPACKER_BUFFER_(uk));
56
85
  }
57
86
 
@@ -78,7 +107,7 @@ void msgpack_unpacker_reset(msgpack_unpacker_t* uk)
78
107
 
79
108
  uk->head_byte = HEAD_BYTE_REQUIRED;
80
109
 
81
- memset(uk->stack, 0, sizeof(msgpack_unpacker_t) * uk->stack_depth);
110
+ /*memset(uk->stack, 0, sizeof(msgpack_unpacker_t) * uk->stack_depth);*/
82
111
  uk->stack_depth = 0;
83
112
 
84
113
  uk->last_object = Qnil;
@@ -40,6 +40,8 @@ typedef struct {
40
40
  VALUE key;
41
41
  } msgpack_unpacker_stack_t;
42
42
 
43
+ #define MSGPACK_UNPACKER_STACK_SIZE (8+4+8+8) /* assumes size_t <= 64bit, enum <= 32bit, VALUE <= 64bit */
44
+
43
45
  struct msgpack_unpacker_t {
44
46
  msgpack_buffer_t buffer;
45
47
 
@@ -22,8 +22,8 @@
22
22
 
23
23
  VALUE cMessagePack_Unpacker;
24
24
 
25
- static VALUE s_unpacker_value;
26
- static msgpack_unpacker_t* s_unpacker;
25
+ //static VALUE s_unpacker_value;
26
+ //static msgpack_unpacker_t* s_unpacker;
27
27
 
28
28
  static VALUE eUnpackError;
29
29
  static VALUE eMalformedFormatError;
@@ -303,32 +303,40 @@ VALUE MessagePack_unpack(int argc, VALUE* argv)
303
303
  src = Qnil;
304
304
  }
305
305
 
306
- // TODO create an instance if io is set for thread safety?
307
- //VALUE self = Unpacker_alloc(cMessagePack_Unpacker);
308
- //UNPACKER(self, uk);
309
- msgpack_unpacker_reset(s_unpacker);
310
- msgpack_buffer_reset_io(UNPACKER_BUFFER_(s_unpacker));
306
+ VALUE self = Unpacker_alloc(cMessagePack_Unpacker);
307
+ UNPACKER(self, uk);
308
+ //msgpack_unpacker_reset(s_unpacker);
309
+ //msgpack_buffer_reset_io(UNPACKER_BUFFER_(s_unpacker));
310
+
311
+ /* prefer reference than copying */
312
+ msgpack_buffer_set_write_reference_threshold(UNPACKER_BUFFER_(uk), 0);
311
313
 
312
314
  if(io != Qnil) {
313
- MessagePack_Buffer_initialize(UNPACKER_BUFFER_(s_unpacker), io, Qnil);
315
+ MessagePack_Buffer_initialize(UNPACKER_BUFFER_(uk), io, Qnil);
314
316
  }
315
317
 
316
318
  if(src != Qnil) {
317
319
  /* prefer reference than copying; see MessagePack_Unpacker_module_init */
318
- msgpack_buffer_append_string(UNPACKER_BUFFER_(s_unpacker), src);
320
+ msgpack_buffer_append_string(UNPACKER_BUFFER_(uk), src);
319
321
  }
320
322
 
321
- int r = msgpack_unpacker_read(s_unpacker, 0);
323
+ int r = msgpack_unpacker_read(uk, 0);
322
324
  if(r < 0) {
323
325
  raise_unpacker_error(r);
324
326
  }
325
327
 
326
328
  /* raise if extra bytes follow */
327
- if(msgpack_buffer_top_readable_size(UNPACKER_BUFFER_(s_unpacker)) > 0) {
329
+ if(msgpack_buffer_top_readable_size(UNPACKER_BUFFER_(uk)) > 0) {
328
330
  rb_raise(eMalformedFormatError, "extra bytes follow after a deserialized object");
329
331
  }
330
332
 
331
- return msgpack_unpacker_get_last_object(s_unpacker);
333
+ #ifdef RB_GC_GUARD
334
+ /* This prevents compilers from optimizing out the `self` variable
335
+ * from stack. Otherwise GC free()s it. */
336
+ RB_GC_GUARD(self);
337
+ #endif
338
+
339
+ return msgpack_unpacker_get_last_object(uk);
332
340
  }
333
341
 
334
342
  static VALUE MessagePack_load_module_method(int argc, VALUE* argv, VALUE mod)
@@ -373,11 +381,11 @@ void MessagePack_Unpacker_module_init(VALUE mMessagePack)
373
381
  rb_define_method(cMessagePack_Unpacker, "feed_each", Unpacker_feed_each, 1);
374
382
  rb_define_method(cMessagePack_Unpacker, "reset", Unpacker_reset, 0);
375
383
 
376
- s_unpacker_value = Unpacker_alloc(cMessagePack_Unpacker);
377
- rb_gc_register_address(&s_unpacker_value);
378
- Data_Get_Struct(s_unpacker_value, msgpack_unpacker_t, s_unpacker);
384
+ //s_unpacker_value = Unpacker_alloc(cMessagePack_Unpacker);
385
+ //rb_gc_register_address(&s_unpacker_value);
386
+ //Data_Get_Struct(s_unpacker_value, msgpack_unpacker_t, s_unpacker);
379
387
  /* prefer reference than copying */
380
- msgpack_buffer_set_write_reference_threshold(UNPACKER_BUFFER_(s_unpacker), 0);
388
+ //msgpack_buffer_set_write_reference_threshold(UNPACKER_BUFFER_(s_unpacker), 0);
381
389
 
382
390
  /* MessagePack.unpack(x) */
383
391
  rb_define_module_function(mMessagePack, "load", MessagePack_load_module_method, -1);
@@ -1,3 +1,3 @@
1
1
  module MessagePack
2
- VERSION = "0.5.4"
2
+ VERSION = "0.5.5"
3
3
  end
@@ -18,7 +18,7 @@ Gem::Specification.new do |s|
18
18
 
19
19
  s.add_development_dependency 'bundler', ['~> 1.0']
20
20
  s.add_development_dependency 'rake', ['~> 0.9.2']
21
- s.add_development_dependency 'rake-compiler', ['~> 0.8.1']
21
+ s.add_development_dependency 'rake-compiler', ['~> 0.8.3']
22
22
  s.add_development_dependency 'rspec', ['~> 2.11']
23
23
  s.add_development_dependency 'json', ['~> 1.7']
24
24
  s.add_development_dependency 'yard', ['~> 0.8.2']
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: 0.5.4
4
+ version: 0.5.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-15 00:00:00.000000000 Z
12
+ date: 2013-05-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -50,7 +50,7 @@ dependencies:
50
50
  requirements:
51
51
  - - ~>
52
52
  - !ruby/object:Gem::Version
53
- version: 0.8.1
53
+ version: 0.8.3
54
54
  type: :development
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
@@ -58,7 +58,7 @@ dependencies:
58
58
  requirements:
59
59
  - - ~>
60
60
  - !ruby/object:Gem::Version
61
- version: 0.8.1
61
+ version: 0.8.3
62
62
  - !ruby/object:Gem::Dependency
63
63
  name: rspec
64
64
  requirement: !ruby/object:Gem::Requirement