msgpack 1.5.0 → 1.5.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
  SHA256:
3
- metadata.gz: c9e04f0f240684f2b81a5f00f9afd951feac68ee06cf4dd6e229fa8d5925c5b0
4
- data.tar.gz: 8bf61d049bcf041bcff6e33631dbc3a821de096aca8b1c5069478934a49cd2e6
3
+ metadata.gz: 2c5ae461c691018c21ea088c4b629510c0626a31c16e640d7128d1d4be70276a
4
+ data.tar.gz: 32ac330fedeb8fdcf90e172df4480d05564185ef9b3e72f430c83de04eea90b1
5
5
  SHA512:
6
- metadata.gz: 58acbb7f3c139dfa153b21445242d202335dea3b1dab6f3f8cd6eac9d427122ea6ec9d4629a5f82674dda53fd9f8b546051d704555c1e1db40c566d9cb617ff9
7
- data.tar.gz: cb3ec4aba6ef01722ef39fc3188ed43f1f3305daae900dc7bab2a15ff1e074512f75b482331c9d962f8e9ce258bee93bf2d6dbfb29cd2a0c8abccd3fcff58fd8
6
+ metadata.gz: 2a5a1c96cbfdc2030c38cf559a61aaacc466a5b4fcaaa6af809b8d062f3042a44ee6df0f731fe77bbdf1ebba0a123da2b9db033e7117baabcc6e9664dd6f56ef
7
+ data.tar.gz: 07c313bd70f92996b0131a0c5ce9836f025dd4fa98fdbe365ad04fa860b2bd6ca81c62fbd90cc2296a75eddd2a9b648b3ca48b8838a40ffab72a5845dfd6e724
data/ChangeLog CHANGED
@@ -1,3 +1,7 @@
1
+ 2022-04-07 version 1.5.1:
2
+
3
+ * Fix bug about packing/unpacking ext type objects with the recursive option
4
+
1
5
  2022-04-06 version 1.5.0:
2
6
 
3
7
  * Add recursive option on Factory#register_type to operate Packer/Unpacker manually
@@ -415,6 +415,7 @@ public class Encoder {
415
415
  if (entry.isRecursive()) {
416
416
  ByteBuffer oldBuffer = buffer;
417
417
  buffer = ByteBuffer.allocate(CACHE_LINE_SIZE - ARRAY_HEADER_SIZE);
418
+ boolean previousRecursiveExtension = recursiveExtension;
418
419
  recursiveExtension = true;
419
420
 
420
421
  ByteList payload;
@@ -423,7 +424,7 @@ public class Encoder {
423
424
  proc.callMethod(runtime.getCurrentContext(), "call", args);
424
425
  payload = new ByteList(buffer.array(), 0, buffer.position(), binaryEncoding, false);
425
426
  } finally {
426
- recursiveExtension = false;
427
+ recursiveExtension = previousRecursiveExtension;
427
428
  buffer = oldBuffer;
428
429
  }
429
430
  appendExt(type, payload);
@@ -52,6 +52,16 @@ void msgpack_unpacker_static_destroy()
52
52
 
53
53
  #define HEAD_BYTE_REQUIRED 0xc1
54
54
 
55
+ static inline msgpack_unpacker_stack_t* _msgpack_unpacker_new_stack(void) {
56
+ #ifdef UNPACKER_STACK_RMEM
57
+ return msgpack_rmem_alloc(&s_stack_rmem);
58
+ /*memset(uk->stack, 0, MSGPACK_UNPACKER_STACK_CAPACITY);*/
59
+ #else
60
+ /*uk->stack = calloc(MSGPACK_UNPACKER_STACK_CAPACITY, sizeof(msgpack_unpacker_stack_t));*/
61
+ return xmalloc(MSGPACK_UNPACKER_STACK_CAPACITY * sizeof(msgpack_unpacker_stack_t));
62
+ #endif
63
+ }
64
+
55
65
  msgpack_unpacker_t* _msgpack_unpacker_new(void)
56
66
  {
57
67
  msgpack_unpacker_t* uk = ZALLOC_N(msgpack_unpacker_t, 1);
@@ -63,26 +73,23 @@ msgpack_unpacker_t* _msgpack_unpacker_new(void)
63
73
  uk->last_object = Qnil;
64
74
  uk->reading_raw = Qnil;
65
75
 
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 = xmalloc(MSGPACK_UNPACKER_STACK_CAPACITY * sizeof(msgpack_unpacker_stack_t));
72
- #endif
76
+ uk->stack = _msgpack_unpacker_new_stack();
73
77
  uk->stack_capacity = MSGPACK_UNPACKER_STACK_CAPACITY;
74
78
 
75
79
  return uk;
76
80
  }
77
81
 
82
+ static inline void _msgpack_unpacker_free_stack(msgpack_unpacker_stack_t* stack) {
83
+ #ifdef UNPACKER_STACK_RMEM
84
+ msgpack_rmem_free(&s_stack_rmem, stack);
85
+ #else
86
+ xfree(stack);
87
+ #endif
88
+ }
89
+
78
90
  void _msgpack_unpacker_destroy(msgpack_unpacker_t* uk)
79
91
  {
80
- #ifdef UNPACKER_STACK_RMEM
81
- msgpack_rmem_free(&s_stack_rmem, uk->stack);
82
- #else
83
- xfree(uk->stack);
84
- #endif
85
-
92
+ _msgpack_unpacker_free_stack(uk->stack);
86
93
  msgpack_buffer_destroy(UNPACKER_BUFFER_(uk));
87
94
  }
88
95
 
@@ -297,7 +304,22 @@ static inline int read_raw_body_begin(msgpack_unpacker_t* uk, int raw_type)
297
304
  reset_head_byte(uk);
298
305
  size_t ext_size = uk->reading_raw_remaining;
299
306
  uk->reading_raw_remaining = 0;
307
+
308
+ msgpack_unpacker_stack_t* stack = uk->stack;
309
+ size_t stack_depth = uk->stack_depth;
310
+ size_t stack_capacity = uk->stack_capacity;
311
+
312
+ uk->stack = _msgpack_unpacker_new_stack();
313
+ uk->stack_depth = 0;
314
+ uk->stack_capacity = MSGPACK_UNPACKER_STACK_CAPACITY;
315
+
300
316
  obj = rb_funcall(proc, s_call, 1, uk->buffer.owner);
317
+
318
+ _msgpack_unpacker_free_stack(uk->stack);
319
+ uk->stack = stack;
320
+ uk->stack_depth = stack_depth;
321
+ uk->stack_capacity = stack_capacity;
322
+
301
323
  msgpack_buffer_skip(UNPACKER_BUFFER_(uk), ext_size);
302
324
  return object_complete(uk, obj);
303
325
  }
@@ -1,5 +1,5 @@
1
1
  module MessagePack
2
- VERSION = "1.5.0"
2
+ VERSION = "1.5.1"
3
3
  # Note for maintainers:
4
4
  # Don't miss building/releasing the JRuby version (rake buld:java)
5
5
  # See "How to build -java rubygems" in README for more details.
data/spec/factory_spec.rb CHANGED
@@ -423,6 +423,27 @@ describe MessagePack::Factory do
423
423
  3,
424
424
  ]
425
425
  end
426
+
427
+ it 'can be nested' do
428
+ factory = MessagePack::Factory.new
429
+ factory.register_type(
430
+ 0x02,
431
+ Set,
432
+ packer: ->(set, packer) do
433
+ packer.write(set.to_a)
434
+ nil
435
+ end,
436
+ unpacker: ->(unpacker) do
437
+ unpacker.read.to_set
438
+ end,
439
+ recursive: true,
440
+ )
441
+
442
+ expected = Set[1, Set[2, Set[3]]]
443
+ payload = factory.dump(expected)
444
+ expect(payload).to be == "\xC7\v\x02\x92\x01\xC7\x06\x02\x92\x02\xD5\x02\x91\x03".b
445
+ expect(factory.load(factory.dump(expected))).to be == expected
446
+ end
426
447
  end
427
448
  end
428
449
 
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require "set"
1
2
 
2
3
  if ENV['SIMPLE_COV']
3
4
  require 'simplecov'
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.5.0
4
+ version: 1.5.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: 2022-04-06 00:00:00.000000000 Z
13
+ date: 2022-04-07 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler