msgpack 1.7.2 → 1.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -31,6 +31,7 @@ enum stack_type_t {
31
31
  STACK_TYPE_ARRAY,
32
32
  STACK_TYPE_MAP_KEY,
33
33
  STACK_TYPE_MAP_VALUE,
34
+ STACK_TYPE_RECURSIVE,
34
35
  };
35
36
 
36
37
  typedef struct {
@@ -44,31 +45,34 @@ struct msgpack_unpacker_stack_t {
44
45
  size_t depth;
45
46
  size_t capacity;
46
47
  msgpack_unpacker_stack_entry_t *data;
47
- msgpack_unpacker_stack_t *parent;
48
48
  };
49
49
 
50
50
  struct msgpack_unpacker_t {
51
51
  msgpack_buffer_t buffer;
52
- msgpack_unpacker_stack_t *stack;
53
- unsigned int head_byte;
52
+ msgpack_unpacker_stack_t stack;
53
+ msgpack_key_cache_t key_cache;
54
54
 
55
55
  VALUE self;
56
56
  VALUE last_object;
57
57
 
58
58
  VALUE reading_raw;
59
59
  size_t reading_raw_remaining;
60
- int reading_raw_type;
61
60
 
62
61
  VALUE buffer_ref;
63
62
 
64
63
  msgpack_unpacker_ext_registry_t *ext_registry;
65
64
 
65
+ int reading_raw_type;
66
+ unsigned int head_byte;
67
+
66
68
  /* options */
67
- bool symbolize_keys;
68
- bool freeze;
69
- bool allow_unknown_ext;
70
- bool optimized_symbol_ext_type;
71
69
  int symbol_ext_type;
70
+
71
+ bool use_key_cache: 1;
72
+ bool symbolize_keys: 1;
73
+ bool freeze: 1;
74
+ bool allow_unknown_ext: 1;
75
+ bool optimized_symbol_ext_type: 1;
72
76
  };
73
77
 
74
78
  #define UNPACKER_BUFFER_(uk) (&(uk)->buffer)
@@ -100,6 +104,11 @@ static inline void msgpack_unpacker_set_symbolized_keys(msgpack_unpacker_t* uk,
100
104
  uk->symbolize_keys = enable;
101
105
  }
102
106
 
107
+ static inline void msgpack_unpacker_set_key_cache(msgpack_unpacker_t* uk, bool enable)
108
+ {
109
+ uk->use_key_cache = enable;
110
+ }
111
+
103
112
  static inline void msgpack_unpacker_set_freeze(msgpack_unpacker_t* uk, bool enable)
104
113
  {
105
114
  uk->freeze = enable;
@@ -119,6 +128,7 @@ static inline void msgpack_unpacker_set_allow_unknown_ext(msgpack_unpacker_t* uk
119
128
  #define PRIMITIVE_STACK_TOO_DEEP -3
120
129
  #define PRIMITIVE_UNEXPECTED_TYPE -4
121
130
  #define PRIMITIVE_UNEXPECTED_EXT_TYPE -5
131
+ #define PRIMITIVE_RECURSIVE_RAISED -6
122
132
 
123
133
  int msgpack_unpacker_read(msgpack_unpacker_t* uk, size_t target_stack_depth);
124
134
 
@@ -34,6 +34,7 @@ static VALUE eUnknownExtTypeError;
34
34
  static VALUE mTypeError; // obsoleted. only for backward compatibility. See #86.
35
35
 
36
36
  static VALUE sym_symbolize_keys;
37
+ static VALUE sym_key_cache;
37
38
  static VALUE sym_freeze;
38
39
  static VALUE sym_allow_unknown_ext;
39
40
 
@@ -58,14 +59,17 @@ static void Unpacker_mark(void *ptr)
58
59
 
59
60
  static size_t Unpacker_memsize(const void *ptr)
60
61
  {
62
+ const msgpack_unpacker_t* uk = ptr;
63
+
61
64
  size_t total_size = sizeof(msgpack_unpacker_t);
62
65
 
63
- const msgpack_unpacker_t* uk = ptr;
64
66
  if (uk->ext_registry) {
65
67
  total_size += sizeof(msgpack_unpacker_ext_registry_t) / (uk->ext_registry->borrow_count + 1);
66
68
  }
67
69
 
68
- total_size += (uk->stack->depth + 1) * sizeof(msgpack_unpacker_stack_t);
70
+ if (uk->stack.data) {
71
+ total_size += (uk->stack.depth + 1) * sizeof(msgpack_unpacker_stack_t);
72
+ }
69
73
 
70
74
  return total_size + msgpack_buffer_memsize(&uk->buffer);
71
75
  }
@@ -125,6 +129,9 @@ VALUE MessagePack_Unpacker_initialize(int argc, VALUE* argv, VALUE self)
125
129
  if(options != Qnil) {
126
130
  VALUE v;
127
131
 
132
+ v = rb_hash_aref(options, sym_key_cache);
133
+ msgpack_unpacker_set_key_cache(uk, RTEST(v));
134
+
128
135
  v = rb_hash_aref(options, sym_symbolize_keys);
129
136
  msgpack_unpacker_set_symbolized_keys(uk, RTEST(v));
130
137
 
@@ -156,20 +163,28 @@ static VALUE Unpacker_allow_unknown_ext_p(VALUE self)
156
163
  return uk->allow_unknown_ext ? Qtrue : Qfalse;
157
164
  }
158
165
 
159
- NORETURN(static void raise_unpacker_error(int r))
166
+ NORETURN(static void raise_unpacker_error(msgpack_unpacker_t *uk, int r))
160
167
  {
168
+ uk->stack.depth = 0;
161
169
  switch(r) {
162
170
  case PRIMITIVE_EOF:
163
171
  rb_raise(rb_eEOFError, "end of buffer reached");
172
+ break;
164
173
  case PRIMITIVE_INVALID_BYTE:
165
174
  rb_raise(eMalformedFormatError, "invalid byte");
175
+ break;
166
176
  case PRIMITIVE_STACK_TOO_DEEP:
167
177
  rb_raise(eStackError, "stack level too deep");
178
+ break;
168
179
  case PRIMITIVE_UNEXPECTED_TYPE:
169
180
  rb_raise(eUnexpectedTypeError, "unexpected type");
181
+ break;
170
182
  case PRIMITIVE_UNEXPECTED_EXT_TYPE:
171
- // rb_bug("unexpected extension type");
172
183
  rb_raise(eUnknownExtTypeError, "unexpected extension type");
184
+ break;
185
+ case PRIMITIVE_RECURSIVE_RAISED:
186
+ rb_exc_raise(msgpack_unpacker_get_last_object(uk));
187
+ break;
173
188
  default:
174
189
  rb_raise(eUnpackError, "logically unknown error %d", r);
175
190
  }
@@ -190,7 +205,7 @@ static VALUE Unpacker_read(VALUE self)
190
205
 
191
206
  int r = msgpack_unpacker_read(uk, 0);
192
207
  if(r < 0) {
193
- raise_unpacker_error(r);
208
+ raise_unpacker_error(uk, r);
194
209
  }
195
210
 
196
211
  return msgpack_unpacker_get_last_object(uk);
@@ -202,7 +217,7 @@ static VALUE Unpacker_skip(VALUE self)
202
217
 
203
218
  int r = msgpack_unpacker_skip(uk, 0);
204
219
  if(r < 0) {
205
- raise_unpacker_error(r);
220
+ raise_unpacker_error(uk, r);
206
221
  }
207
222
 
208
223
  return Qnil;
@@ -214,7 +229,7 @@ static VALUE Unpacker_skip_nil(VALUE self)
214
229
 
215
230
  int r = msgpack_unpacker_skip_nil(uk);
216
231
  if(r < 0) {
217
- raise_unpacker_error(r);
232
+ raise_unpacker_error(uk, r);
218
233
  }
219
234
 
220
235
  if(r) {
@@ -230,7 +245,7 @@ static VALUE Unpacker_read_array_header(VALUE self)
230
245
  uint32_t size;
231
246
  int r = msgpack_unpacker_read_array_header(uk, &size);
232
247
  if(r < 0) {
233
- raise_unpacker_error(r);
248
+ raise_unpacker_error(uk, r);
234
249
  }
235
250
 
236
251
  return ULONG2NUM(size); // long at least 32 bits
@@ -243,7 +258,7 @@ static VALUE Unpacker_read_map_header(VALUE self)
243
258
  uint32_t size;
244
259
  int r = msgpack_unpacker_read_map_header(uk, &size);
245
260
  if(r < 0) {
246
- raise_unpacker_error((int)r);
261
+ raise_unpacker_error(uk, r);
247
262
  }
248
263
 
249
264
  return ULONG2NUM(size); // long at least 32 bits
@@ -270,15 +285,9 @@ static VALUE Unpacker_each_impl(VALUE self)
270
285
  if(r == PRIMITIVE_EOF) {
271
286
  return Qnil;
272
287
  }
273
- raise_unpacker_error(r);
288
+ raise_unpacker_error(uk, r);
274
289
  }
275
290
  VALUE v = msgpack_unpacker_get_last_object(uk);
276
- #ifdef JRUBY
277
- /* TODO JRuby's rb_yield behaves differently from Ruby 1.9.3 or Rubinius. */
278
- if(rb_type(v) == T_ARRAY) {
279
- v = rb_ary_new3(1, v);
280
- }
281
- #endif
282
291
  rb_yield(v);
283
292
  }
284
293
  }
@@ -369,7 +378,7 @@ static VALUE Unpacker_full_unpack(VALUE self)
369
378
 
370
379
  int r = msgpack_unpacker_read(uk, 0);
371
380
  if(r < 0) {
372
- raise_unpacker_error(r);
381
+ raise_unpacker_error(uk, r);
373
382
  }
374
383
 
375
384
  /* raise if extra bytes follow */
@@ -408,6 +417,7 @@ void MessagePack_Unpacker_module_init(VALUE mMessagePack)
408
417
  eUnknownExtTypeError = rb_define_class_under(mMessagePack, "UnknownExtTypeError", eUnpackError);
409
418
 
410
419
  sym_symbolize_keys = ID2SYM(rb_intern("symbolize_keys"));
420
+ sym_key_cache = ID2SYM(rb_intern("key_cache"));
411
421
  sym_freeze = ID2SYM(rb_intern("freeze"));
412
422
  sym_allow_unknown_ext = ID2SYM(rb_intern("allow_unknown_ext"));
413
423
 
@@ -1,5 +1,5 @@
1
1
  module MessagePack
2
- VERSION = "1.7.2"
2
+ VERSION = "1.8.0"
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/msgpack.gemspec CHANGED
@@ -31,4 +31,6 @@ Gem::Specification.new do |s|
31
31
  s.add_development_dependency 'yard'
32
32
  s.add_development_dependency 'json'
33
33
  s.add_development_dependency 'benchmark-ips', ['~> 2.10.0']
34
+
35
+ s.metadata["changelog_uri"] = "https://github.com/msgpack/msgpack-ruby/blob/master/ChangeLog"
34
36
  end
metadata CHANGED
@@ -1,16 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: msgpack
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.2
4
+ version: 1.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sadayuki Furuhashi
8
8
  - Theo Hultberg
9
9
  - Satoshi Tagomori
10
- autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2023-07-18 00:00:00.000000000 Z
12
+ date: 2025-02-06 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: bundler
@@ -192,8 +191,8 @@ files:
192
191
  homepage: http://msgpack.org/
193
192
  licenses:
194
193
  - Apache 2.0
195
- metadata: {}
196
- post_install_message:
194
+ metadata:
195
+ changelog_uri: https://github.com/msgpack/msgpack-ruby/blob/master/ChangeLog
197
196
  rdoc_options: []
198
197
  require_paths:
199
198
  - lib
@@ -208,8 +207,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
208
207
  - !ruby/object:Gem::Version
209
208
  version: '0'
210
209
  requirements: []
211
- rubygems_version: 3.3.7
212
- signing_key:
210
+ rubygems_version: 3.6.2
213
211
  specification_version: 4
214
212
  summary: MessagePack, a binary-based efficient data interchange format.
215
213
  test_files: []