msgpack 0.7.0 → 0.7.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: 08b929d16e3f5eb48b0de6a10041092be2510361
4
- data.tar.gz: 34c606ea1c703c22f94d1295b5648f4430fd69ae
3
+ metadata.gz: 0ca0c3abd8883f5ba34b519986e789b6e029505a
4
+ data.tar.gz: 2d8db1bcaeccbccebe206b99cdd361e7c32621a9
5
5
  SHA512:
6
- metadata.gz: 4ec69a5b4e904359b7c1d1a15f37ee2e57fa5e340fbab0e658cf2d476d736d41100cd350ce580f52afbbb88721640be3bd120583adfd6f179aa1b3afa4395142
7
- data.tar.gz: 63bf4dd13deaa7c767bbc1f6c50170548cb6819ebb2ca87282939f6cd88da078820af2453634dcb0e4c3d056073807f34ac86623c5b75ec89ea416ed8fa6f7c1
6
+ metadata.gz: f1adc454c670e6cb401bf103f389b0d3cff36f644bb1eeb57a2795c6757718a9124cb09c71a56a38e4a22345aec4a1f18178e45407fa5528566e762abaf3dc48
7
+ data.tar.gz: 820785bf3360304db2d1011d108fbc167a827c07b43b3a17f0f9c6359a734aa6572f01c72946af6f6be923266c3d0e47e148009f557875cf66ecf8ce57f47a3c
@@ -13,6 +13,8 @@ os:
13
13
  - linux
14
14
  - osx
15
15
 
16
+ sudo: false
17
+
16
18
  branches:
17
19
  only:
18
20
  - master
data/ChangeLog CHANGED
@@ -1,3 +1,7 @@
1
+ 2015-11-20 version 0.7.1:
2
+
3
+ * Fixed bug to pack/unpack ext type objects larger than 256bytes incorrectly.
4
+
1
5
  2015-10-24 version 0.7.0:
2
6
 
3
7
  * Add extention types support.
@@ -73,5 +73,15 @@ module MessagePack
73
73
  #
74
74
  def self.unpack(src, options={})
75
75
  end
76
+
77
+ #
78
+ # An instance of Factory class. DefaultFactory is also used
79
+ # by global pack/unpack methods such as MessagePack.dump/load,
80
+ # Hash#to_msgpack, and other to_msgpack methods.
81
+ #
82
+ # Calling DefaultFactory.register_type lets you add an extension
83
+ # type globally.
84
+ #
85
+ DefaultFactory = Factory.new
76
86
  end
77
87
 
@@ -236,8 +236,8 @@ public class Decoder implements Iterator<IRubyObject> {
236
236
  case BIN8: return consumeString(buffer.get() & 0xff, binaryEncoding);
237
237
  case BIN16: return consumeString(buffer.getShort() & 0xffff, binaryEncoding);
238
238
  case BIN32: return consumeString(buffer.getInt(), binaryEncoding);
239
- case VAREXT8: return consumeExtension(buffer.get());
240
- case VAREXT16: return consumeExtension(buffer.getShort());
239
+ case VAREXT8: return consumeExtension(buffer.get() & 0xff);
240
+ case VAREXT16: return consumeExtension(buffer.getShort() & 0xffff);
241
241
  case VAREXT32: return consumeExtension(buffer.getInt());
242
242
  case FLOAT32: return runtime.newFloat(buffer.getFloat());
243
243
  case FLOAT64: return runtime.newFloat(buffer.getDouble());
@@ -74,13 +74,13 @@ static void _msgpack_buffer_chunk_destroy(msgpack_buffer_chunk_t* c)
74
74
  if(c->mem != NULL) {
75
75
  #ifndef DISABLE_RMEM
76
76
  if(!msgpack_rmem_free(&s_rmem, c->mem)) {
77
- free(c->mem);
77
+ xfree(c->mem);
78
78
  }
79
79
  /* no needs to update rmem_owner because chunks will not be
80
80
  * free()ed (left in free_list) and thus *rmem_owner is
81
81
  * always valid. */
82
82
  #else
83
- free(c->mem);
83
+ xfree(c->mem);
84
84
  #endif
85
85
  }
86
86
  c->first = NULL;
@@ -95,7 +95,7 @@ void msgpack_buffer_destroy(msgpack_buffer_t* b)
95
95
  while(c != &b->tail) {
96
96
  msgpack_buffer_chunk_t* n = c->next;
97
97
  _msgpack_buffer_chunk_destroy(c);
98
- free(c);
98
+ xfree(c);
99
99
  c = n;
100
100
  }
101
101
  _msgpack_buffer_chunk_destroy(c);
@@ -103,7 +103,7 @@ void msgpack_buffer_destroy(msgpack_buffer_t* b)
103
103
  c = b->free_list;
104
104
  while(c != NULL) {
105
105
  msgpack_buffer_chunk_t* n = c->next;
106
- free(c);
106
+ xfree(c);
107
107
  c = n;
108
108
  }
109
109
  }
@@ -259,7 +259,7 @@ static inline msgpack_buffer_chunk_t* _msgpack_buffer_alloc_new_chunk(msgpack_bu
259
259
  {
260
260
  msgpack_buffer_chunk_t* reuse = b->free_list;
261
261
  if(reuse == NULL) {
262
- return malloc(sizeof(msgpack_buffer_chunk_t));
262
+ return xmalloc(sizeof(msgpack_buffer_chunk_t));
263
263
  }
264
264
  b->free_list = b->free_list->next;
265
265
  return reuse;
@@ -403,7 +403,7 @@ static inline void* _msgpack_buffer_chunk_malloc(
403
403
 
404
404
  // TODO alignment?
405
405
  *allocated_size = required_size;
406
- void* mem = malloc(required_size);
406
+ void* mem = xmalloc(required_size);
407
407
  c->mem = mem;
408
408
  return mem;
409
409
  }
@@ -421,7 +421,7 @@ static inline void* _msgpack_buffer_chunk_realloc(
421
421
  next_size *= 2;
422
422
  }
423
423
  *current_size = next_size;
424
- mem = realloc(mem, next_size);
424
+ mem = xrealloc(mem, next_size);
425
425
 
426
426
  c->mem = mem;
427
427
  return mem;
@@ -49,7 +49,7 @@ static void Buffer_free(void* data)
49
49
  }
50
50
  msgpack_buffer_t* b = (msgpack_buffer_t*) data;
51
51
  msgpack_buffer_destroy(b);
52
- free(b);
52
+ xfree(b);
53
53
  }
54
54
 
55
55
  static VALUE Buffer_alloc(VALUE klass)
@@ -48,7 +48,7 @@ static void Factory_free(msgpack_factory_t* fc)
48
48
  }
49
49
  msgpack_packer_ext_registry_destroy(&fc->pkrg);
50
50
  msgpack_unpacker_ext_registry_destroy(&fc->ukrg);
51
- free(fc);
51
+ xfree(fc);
52
52
  }
53
53
 
54
54
  void Factory_mark(msgpack_factory_t* fc)
@@ -364,7 +364,7 @@ static inline void msgpack_packer_write_ext(msgpack_packer_t* pk, int ext_type,
364
364
  msgpack_buffer_write_2(PACKER_BUFFER_(pk), 0xd8, ext_type);
365
365
  break;
366
366
  default:
367
- if(len < 255) {
367
+ if(len < 256) {
368
368
  msgpack_buffer_ensure_writable(PACKER_BUFFER_(pk), 3);
369
369
  msgpack_buffer_write_2(PACKER_BUFFER_(pk), 0xc7, len);
370
370
  msgpack_buffer_write_1(PACKER_BUFFER_(pk), ext_type);
@@ -45,7 +45,7 @@ static void Packer_free(msgpack_packer_t* pk)
45
45
  }
46
46
  msgpack_packer_ext_registry_destroy(&pk->ext_registry);
47
47
  msgpack_packer_destroy(pk);
48
- free(pk);
48
+ xfree(pk);
49
49
  }
50
50
 
51
51
  static void Packer_mark(msgpack_packer_t* pk)
@@ -21,7 +21,7 @@
21
21
  void msgpack_rmem_init(msgpack_rmem_t* pm)
22
22
  {
23
23
  memset(pm, 0, sizeof(msgpack_rmem_t));
24
- pm->head.pages = malloc(MSGPACK_RMEM_PAGE_SIZE * 32);
24
+ pm->head.pages = xmalloc(MSGPACK_RMEM_PAGE_SIZE * 32);
25
25
  pm->head.mask = 0xffffffff; /* all bit is 1 = available */
26
26
  }
27
27
 
@@ -30,10 +30,10 @@ void msgpack_rmem_destroy(msgpack_rmem_t* pm)
30
30
  msgpack_rmem_chunk_t* c = pm->array_first;
31
31
  msgpack_rmem_chunk_t* cend = pm->array_last;
32
32
  for(; c != cend; c++) {
33
- free(c->pages);
33
+ xfree(c->pages);
34
34
  }
35
- free(pm->head.pages);
36
- free(pm->array_first);
35
+ xfree(pm->head.pages);
36
+ xfree(pm->array_first);
37
37
  }
38
38
 
39
39
  void* _msgpack_rmem_alloc2(msgpack_rmem_t* pm)
@@ -56,7 +56,7 @@ void* _msgpack_rmem_alloc2(msgpack_rmem_t* pm)
56
56
  size_t capacity = c - pm->array_first;
57
57
  size_t length = last - pm->array_first;
58
58
  capacity = (capacity == 0) ? 8 : capacity * 2;
59
- msgpack_rmem_chunk_t* array = realloc(pm->array_first, capacity * sizeof(msgpack_rmem_chunk_t));
59
+ msgpack_rmem_chunk_t* array = xrealloc(pm->array_first, capacity * sizeof(msgpack_rmem_chunk_t));
60
60
  pm->array_first = array;
61
61
  pm->array_last = array + length;
62
62
  pm->array_end = array + capacity;
@@ -71,7 +71,7 @@ void* _msgpack_rmem_alloc2(msgpack_rmem_t* pm)
71
71
  *c = tmp;
72
72
 
73
73
  pm->head.mask = 0xffffffff & (~1); /* "& (~1)" means first chunk is already allocated */
74
- pm->head.pages = malloc(MSGPACK_RMEM_PAGE_SIZE * 32);
74
+ pm->head.pages = xmalloc(MSGPACK_RMEM_PAGE_SIZE * 32);
75
75
 
76
76
  return pm->head.pages;
77
77
  }
@@ -81,7 +81,7 @@ void _msgpack_rmem_chunk_free(msgpack_rmem_t* pm, msgpack_rmem_chunk_t* c)
81
81
  if(pm->array_first->mask == 0xffffffff) {
82
82
  /* free and move to last */
83
83
  pm->array_last--;
84
- free(c->pages);
84
+ xfree(c->pages);
85
85
  *c = *pm->array_last;
86
86
  return;
87
87
  }
@@ -68,7 +68,7 @@ void _msgpack_unpacker_init(msgpack_unpacker_t* uk)
68
68
  /*memset(uk->stack, 0, MSGPACK_UNPACKER_STACK_CAPACITY);*/
69
69
  #else
70
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));
71
+ uk->stack = xmalloc(MSGPACK_UNPACKER_STACK_CAPACITY * sizeof(msgpack_unpacker_stack_t));
72
72
  #endif
73
73
  uk->stack_capacity = MSGPACK_UNPACKER_STACK_CAPACITY;
74
74
  }
@@ -78,7 +78,7 @@ void _msgpack_unpacker_destroy(msgpack_unpacker_t* uk)
78
78
  #ifdef UNPACKER_STACK_RMEM
79
79
  msgpack_rmem_free(&s_stack_rmem, uk->stack);
80
80
  #else
81
- free(uk->stack);
81
+ xfree(uk->stack);
82
82
  #endif
83
83
 
84
84
  msgpack_buffer_destroy(UNPACKER_BUFFER_(uk));
@@ -380,7 +380,7 @@ static int read_primitive(msgpack_unpacker_t* uk)
380
380
  case 0xc8: // ext 16
381
381
  {
382
382
  READ_CAST_BLOCK_OR_RETURN_EOF(cb, uk, 3);
383
- uint16_t length = cb->u16;
383
+ uint16_t length = _msgpack_be16(cb->u16);
384
384
  int ext_type = cb->buffer[2];
385
385
  if(length == 0) {
386
386
  return object_complete_ext(uk, ext_type, rb_str_buf_new(0));
@@ -392,7 +392,7 @@ static int read_primitive(msgpack_unpacker_t* uk)
392
392
  case 0xc9: // ext 32
393
393
  {
394
394
  READ_CAST_BLOCK_OR_RETURN_EOF(cb, uk, 5);
395
- uint32_t length = cb->u32;
395
+ uint32_t length = _msgpack_be32(cb->u32);
396
396
  int ext_type = cb->buffer[4];
397
397
  if(length == 0) {
398
398
  return object_complete_ext(uk, ext_type, rb_str_buf_new(0));
@@ -47,7 +47,7 @@ static void Unpacker_free(msgpack_unpacker_t* uk)
47
47
  }
48
48
  msgpack_unpacker_ext_registry_destroy(&uk->ext_registry);
49
49
  _msgpack_unpacker_destroy(uk);
50
- free(uk);
50
+ xfree(uk);
51
51
  }
52
52
 
53
53
  static void Unpacker_mark(msgpack_unpacker_t* uk)
@@ -1,3 +1,3 @@
1
1
  module MessagePack
2
- VERSION = "0.7.0"
2
+ VERSION = "0.7.1"
3
3
  end
@@ -223,4 +223,34 @@ describe MessagePack::Packer do
223
223
  expect(two[:packer]).to eq(:to_msgpack_ext)
224
224
  end
225
225
  end
226
+
227
+ describe "ext formats" do
228
+ [1, 2, 4, 8, 16].zip([0xd4, 0xd5, 0xd6, 0xd7, 0xd8]).each do |n,b|
229
+ it "msgpack fixext #{n} format" do
230
+ MessagePack::ExtensionValue.new(1, "a"*n).to_msgpack.should ==
231
+ [b, 1].pack('CC') + "a"*n
232
+ end
233
+ end
234
+
235
+ it "msgpack ext 8 format" do
236
+ MessagePack::ExtensionValue.new(1, "").to_msgpack.should ==
237
+ [0xc7, 0, 1].pack('CCC') + ""
238
+ MessagePack::ExtensionValue.new(-1, "a"*255).to_msgpack.should ==
239
+ [0xc7, 255, -1].pack('CCC') + "a"*255
240
+ end
241
+
242
+ it "msgpack ext 16 format" do
243
+ MessagePack::ExtensionValue.new(1, "a"*256).to_msgpack.should ==
244
+ [0xc8, 256, 1].pack('CnC') + "a"*256
245
+ MessagePack::ExtensionValue.new(-1, "a"*65535).to_msgpack.should ==
246
+ [0xc8, 65535, -1].pack('CnC') + "a"*65535
247
+ end
248
+
249
+ it "msgpack ext 32 format" do
250
+ MessagePack::ExtensionValue.new(1, "a"*65536).to_msgpack.should ==
251
+ [0xc9, 65536, 1].pack('CNC') + "a"*65536
252
+ MessagePack::ExtensionValue.new(-1, "a"*65538).to_msgpack.should ==
253
+ [0xc9, 65538, -1].pack('CNC') + "a"*65538
254
+ end
255
+ end
226
256
  end
@@ -260,6 +260,33 @@ describe MessagePack::Unpacker do
260
260
  MessagePack.unpack([0xc6, 0x00, 0x00, 0x00, 0x02].pack('C*') + 'aa').should == "aa"
261
261
  end
262
262
 
263
+ describe "ext formats" do
264
+ let(:unpacker) { MessagePack::Unpacker.new(allow_unknown_ext: true) }
265
+
266
+ [1, 2, 4, 8, 16].zip([0xd4, 0xd5, 0xd6, 0xd7, 0xd8]).each do |n,b|
267
+ it "msgpack fixext #{n} format" do
268
+ unpacker.feed([b, 1].pack('CC') + "a"*n).unpack.should == MessagePack::ExtensionValue.new(1, "a"*n)
269
+ unpacker.feed([b, -1].pack('CC') + "a"*n).unpack.should == MessagePack::ExtensionValue.new(-1, "a"*n)
270
+ end
271
+ end
272
+
273
+ it "msgpack ext 8 format" do
274
+ unpacker.feed([0xc7, 0, 1].pack('CCC')).unpack.should == MessagePack::ExtensionValue.new(1, "")
275
+ unpacker.feed([0xc7, 255, -1].pack('CCC') + "a"*255).unpack.should == MessagePack::ExtensionValue.new(-1, "a"*255)
276
+ end
277
+
278
+ it "msgpack ext 16 format" do
279
+ unpacker.feed([0xc8, 0, 1].pack('CnC')).unpack.should == MessagePack::ExtensionValue.new(1, "")
280
+ unpacker.feed([0xc8, 256, -1].pack('CnC') + "a"*256).unpack.should == MessagePack::ExtensionValue.new(-1, "a"*256)
281
+ end
282
+
283
+ it "msgpack ext 32 format" do
284
+ unpacker.feed([0xc9, 0, 1].pack('CNC')).unpack.should == MessagePack::ExtensionValue.new(1, "")
285
+ unpacker.feed([0xc9, 256, -1].pack('CNC') + "a"*256).unpack.should == MessagePack::ExtensionValue.new(-1, "a"*256)
286
+ unpacker.feed([0xc9, 65536, -1].pack('CNC') + "a"*65536).unpack.should == MessagePack::ExtensionValue.new(-1, "a"*65536)
287
+ end
288
+ end
289
+
263
290
  class ValueOne
264
291
  attr_reader :num
265
292
  def initialize(num)
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.7.0
4
+ version: 0.7.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: 2015-10-24 00:00:00.000000000 Z
13
+ date: 2015-11-20 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler