msgpack 1.5.1 → 1.7.2

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.
Files changed (91) hide show
  1. checksums.yaml +4 -4
  2. data/ChangeLog +55 -0
  3. data/README.md +30 -1
  4. data/ext/java/org/msgpack/jruby/Buffer.java +3 -3
  5. data/ext/java/org/msgpack/jruby/ExtensionRegistry.java +11 -20
  6. data/ext/java/org/msgpack/jruby/ExtensionValue.java +1 -1
  7. data/ext/java/org/msgpack/jruby/Factory.java +11 -50
  8. data/ext/java/org/msgpack/jruby/Packer.java +9 -24
  9. data/ext/java/org/msgpack/jruby/Unpacker.java +15 -32
  10. data/ext/msgpack/buffer.c +54 -69
  11. data/ext/msgpack/buffer.h +16 -18
  12. data/ext/msgpack/buffer_class.c +138 -37
  13. data/ext/msgpack/buffer_class.h +1 -0
  14. data/ext/msgpack/compat.h +0 -99
  15. data/ext/msgpack/extconf.rb +25 -39
  16. data/ext/msgpack/factory_class.c +75 -86
  17. data/ext/msgpack/packer.c +12 -39
  18. data/ext/msgpack/packer.h +1 -11
  19. data/ext/msgpack/packer_class.c +73 -99
  20. data/ext/msgpack/packer_class.h +11 -0
  21. data/ext/msgpack/packer_ext_registry.c +31 -28
  22. data/ext/msgpack/packer_ext_registry.h +10 -14
  23. data/ext/msgpack/rbinit.c +1 -1
  24. data/ext/msgpack/rmem.c +3 -4
  25. data/ext/msgpack/sysdep.h +5 -2
  26. data/ext/msgpack/unpacker.c +66 -94
  27. data/ext/msgpack/unpacker.h +13 -12
  28. data/ext/msgpack/unpacker_class.c +64 -80
  29. data/ext/msgpack/unpacker_class.h +11 -0
  30. data/ext/msgpack/unpacker_ext_registry.c +4 -16
  31. data/ext/msgpack/unpacker_ext_registry.h +3 -7
  32. data/lib/msgpack/buffer.rb +9 -0
  33. data/lib/msgpack/factory.rb +90 -63
  34. data/lib/msgpack/packer.rb +10 -1
  35. data/lib/msgpack/unpacker.rb +14 -1
  36. data/lib/msgpack/version.rb +1 -1
  37. data/lib/msgpack.rb +1 -0
  38. data/msgpack.gemspec +7 -3
  39. metadata +33 -56
  40. data/.github/workflows/ci.yaml +0 -57
  41. data/.gitignore +0 -23
  42. data/.rubocop.yml +0 -36
  43. data/Gemfile +0 -9
  44. data/Rakefile +0 -70
  45. data/appveyor.yml +0 -18
  46. data/bench/pack.rb +0 -23
  47. data/bench/pack_log.rb +0 -33
  48. data/bench/pack_log_long.rb +0 -65
  49. data/bench/pack_symbols.rb +0 -28
  50. data/bench/run.sh +0 -14
  51. data/bench/run_long.sh +0 -35
  52. data/bench/run_symbols.sh +0 -26
  53. data/bench/unpack.rb +0 -21
  54. data/bench/unpack_log.rb +0 -34
  55. data/bench/unpack_log_long.rb +0 -67
  56. data/doclib/msgpack/buffer.rb +0 -193
  57. data/doclib/msgpack/core_ext.rb +0 -101
  58. data/doclib/msgpack/error.rb +0 -19
  59. data/doclib/msgpack/extension_value.rb +0 -9
  60. data/doclib/msgpack/factory.rb +0 -145
  61. data/doclib/msgpack/packer.rb +0 -209
  62. data/doclib/msgpack/time.rb +0 -22
  63. data/doclib/msgpack/timestamp.rb +0 -44
  64. data/doclib/msgpack/unpacker.rb +0 -183
  65. data/doclib/msgpack.rb +0 -87
  66. data/msgpack.org.md +0 -46
  67. data/spec/bigint_spec.rb +0 -26
  68. data/spec/cases.json +0 -1
  69. data/spec/cases.msg +0 -0
  70. data/spec/cases_compact.msg +0 -0
  71. data/spec/cases_spec.rb +0 -39
  72. data/spec/cruby/buffer_io_spec.rb +0 -255
  73. data/spec/cruby/buffer_packer.rb +0 -29
  74. data/spec/cruby/buffer_spec.rb +0 -575
  75. data/spec/cruby/buffer_unpacker.rb +0 -19
  76. data/spec/cruby/unpacker_spec.rb +0 -70
  77. data/spec/ext_value_spec.rb +0 -99
  78. data/spec/exttypes.rb +0 -51
  79. data/spec/factory_spec.rb +0 -654
  80. data/spec/format_spec.rb +0 -301
  81. data/spec/jruby/benchmarks/shootout_bm.rb +0 -73
  82. data/spec/jruby/benchmarks/symbolize_keys_bm.rb +0 -25
  83. data/spec/jruby/unpacker_spec.rb +0 -186
  84. data/spec/msgpack_spec.rb +0 -214
  85. data/spec/pack_spec.rb +0 -61
  86. data/spec/packer_spec.rb +0 -575
  87. data/spec/random_compat.rb +0 -24
  88. data/spec/spec_helper.rb +0 -65
  89. data/spec/timestamp_spec.rb +0 -159
  90. data/spec/unpack_spec.rb +0 -57
  91. data/spec/unpacker_spec.rb +0 -847
@@ -19,53 +19,48 @@
19
19
  #include "unpacker.h"
20
20
  #include "rmem.h"
21
21
  #include "extension_value_class.h"
22
+ #include <assert.h>
22
23
 
23
- #if !defined(DISABLE_RMEM) && !defined(DISABLE_UNPACKER_STACK_RMEM) && \
24
- MSGPACK_UNPACKER_STACK_CAPACITY * MSGPACK_UNPACKER_STACK_SIZE <= MSGPACK_RMEM_PAGE_SIZE
25
- #define UNPACKER_STACK_RMEM
24
+ #if !defined(HAVE_RB_PROC_CALL_WITH_BLOCK)
25
+ #define rb_proc_call_with_block(recv, argc, argv, block) rb_funcallv(recv, rb_intern("call"), argc, argv)
26
26
  #endif
27
27
 
28
28
  static int RAW_TYPE_STRING = 256;
29
29
  static int RAW_TYPE_BINARY = 257;
30
30
 
31
- static ID s_call;
32
-
33
- #ifdef UNPACKER_STACK_RMEM
34
31
  static msgpack_rmem_t s_stack_rmem;
35
- #endif
36
32
 
37
- void msgpack_unpacker_static_init()
33
+ #if !defined(HAVE_RB_HASH_NEW_CAPA)
34
+ static inline VALUE rb_hash_new_capa(long capa)
38
35
  {
39
- #ifdef UNPACKER_STACK_RMEM
40
- msgpack_rmem_init(&s_stack_rmem);
36
+ return rb_hash_new();
37
+ }
41
38
  #endif
42
39
 
43
- s_call = rb_intern("call");
40
+ void msgpack_unpacker_static_init(void)
41
+ {
42
+ assert(sizeof(msgpack_unpacker_stack_entry_t) * MSGPACK_UNPACKER_STACK_CAPACITY <= MSGPACK_RMEM_PAGE_SIZE);
43
+
44
+ msgpack_rmem_init(&s_stack_rmem);
44
45
  }
45
46
 
46
- void msgpack_unpacker_static_destroy()
47
+ void msgpack_unpacker_static_destroy(void)
47
48
  {
48
- #ifdef UNPACKER_STACK_RMEM
49
49
  msgpack_rmem_destroy(&s_stack_rmem);
50
- #endif
51
50
  }
52
51
 
53
52
  #define HEAD_BYTE_REQUIRED 0xc1
54
53
 
55
54
  static inline msgpack_unpacker_stack_t* _msgpack_unpacker_new_stack(void) {
56
- #ifdef UNPACKER_STACK_RMEM
57
- return msgpack_rmem_alloc(&s_stack_rmem);
55
+ msgpack_unpacker_stack_t *stack = ZALLOC(msgpack_unpacker_stack_t);
56
+ stack->capacity = MSGPACK_UNPACKER_STACK_CAPACITY;
57
+ stack->data = msgpack_rmem_alloc(&s_stack_rmem);
58
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
59
+ return stack;
63
60
  }
64
61
 
65
- msgpack_unpacker_t* _msgpack_unpacker_new(void)
62
+ void _msgpack_unpacker_init(msgpack_unpacker_t* uk)
66
63
  {
67
- msgpack_unpacker_t* uk = ZALLOC_N(msgpack_unpacker_t, 1);
68
-
69
64
  msgpack_buffer_init(UNPACKER_BUFFER_(uk));
70
65
 
71
66
  uk->head_byte = HEAD_BYTE_REQUIRED;
@@ -74,17 +69,13 @@ msgpack_unpacker_t* _msgpack_unpacker_new(void)
74
69
  uk->reading_raw = Qnil;
75
70
 
76
71
  uk->stack = _msgpack_unpacker_new_stack();
77
- uk->stack_capacity = MSGPACK_UNPACKER_STACK_CAPACITY;
78
-
79
- return uk;
80
72
  }
81
73
 
82
74
  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
75
+ if (!msgpack_rmem_free(&s_stack_rmem, stack->data)) {
76
+ rb_bug("Failed to free an rmem pointer, memory leak?");
77
+ }
78
+ xfree(stack);
88
79
  }
89
80
 
90
81
  void _msgpack_unpacker_destroy(msgpack_unpacker_t* uk)
@@ -93,21 +84,28 @@ void _msgpack_unpacker_destroy(msgpack_unpacker_t* uk)
93
84
  msgpack_buffer_destroy(UNPACKER_BUFFER_(uk));
94
85
  }
95
86
 
87
+ void msgpack_unpacker_mark_stack(msgpack_unpacker_stack_t* stack)
88
+ {
89
+ while (stack) {
90
+ msgpack_unpacker_stack_entry_t* s = stack->data;
91
+ msgpack_unpacker_stack_entry_t* send = stack->data + stack->depth;
92
+ for(; s < send; s++) {
93
+ rb_gc_mark(s->object);
94
+ rb_gc_mark(s->key);
95
+ }
96
+ stack = stack->parent;
97
+ }
98
+ }
99
+
96
100
  void msgpack_unpacker_mark(msgpack_unpacker_t* uk)
97
101
  {
98
102
  rb_gc_mark(uk->last_object);
99
103
  rb_gc_mark(uk->reading_raw);
100
-
101
- msgpack_unpacker_stack_t* s = uk->stack;
102
- msgpack_unpacker_stack_t* send = uk->stack + uk->stack_depth;
103
- for(; s < send; s++) {
104
- rb_gc_mark(s->object);
105
- rb_gc_mark(s->key);
106
- }
107
-
104
+ msgpack_unpacker_mark_stack(uk->stack);
108
105
  /* See MessagePack_Buffer_wrap */
109
106
  /* msgpack_buffer_mark(UNPACKER_BUFFER_(uk)); */
110
107
  rb_gc_mark(uk->buffer_ref);
108
+ rb_gc_mark(uk->self);
111
109
  }
112
110
 
113
111
  void _msgpack_unpacker_reset(msgpack_unpacker_t* uk)
@@ -116,9 +114,8 @@ void _msgpack_unpacker_reset(msgpack_unpacker_t* uk)
116
114
 
117
115
  uk->head_byte = HEAD_BYTE_REQUIRED;
118
116
 
119
- /*memset(uk->stack, 0, sizeof(msgpack_unpacker_t) * uk->stack_depth);*/
120
- uk->stack_depth = 0;
121
-
117
+ /*memset(uk->stack, 0, sizeof(msgpack_unpacker_t) * uk->stack->depth);*/
118
+ uk->stack->depth = 0;
122
119
  uk->last_object = Qnil;
123
120
  uk->reading_raw = Qnil;
124
121
  uk->reading_raw_remaining = 0;
@@ -170,6 +167,9 @@ static inline int object_complete_symbol(msgpack_unpacker_t* uk, VALUE object)
170
167
  static inline int object_complete_ext(msgpack_unpacker_t* uk, int ext_type, VALUE str)
171
168
  {
172
169
  if (uk->optimized_symbol_ext_type && ext_type == uk->symbol_ext_type) {
170
+ if (RB_UNLIKELY(NIL_P(str))) { // empty extension is returned as Qnil
171
+ return object_complete_symbol(uk, ID2SYM(rb_intern3("", 0, rb_utf8_encoding())));
172
+ }
173
173
  return object_complete_symbol(uk, rb_str_intern(str));
174
174
  }
175
175
 
@@ -178,7 +178,8 @@ static inline int object_complete_ext(msgpack_unpacker_t* uk, int ext_type, VALU
178
178
 
179
179
  if(proc != Qnil) {
180
180
  VALUE obj;
181
- obj = rb_funcall(proc, s_call, 1, str == Qnil ? rb_str_buf_new(0) : str);
181
+ VALUE arg = (str == Qnil ? rb_str_buf_new(0) : str);
182
+ obj = rb_proc_call_with_block(proc, 1, &arg, Qnil);
182
183
  return object_complete(uk, obj);
183
184
  }
184
185
 
@@ -191,37 +192,37 @@ static inline int object_complete_ext(msgpack_unpacker_t* uk, int ext_type, VALU
191
192
  }
192
193
 
193
194
  /* stack funcs */
194
- static inline msgpack_unpacker_stack_t* _msgpack_unpacker_stack_top(msgpack_unpacker_t* uk)
195
+ static inline msgpack_unpacker_stack_entry_t* _msgpack_unpacker_stack_entry_top(msgpack_unpacker_t* uk)
195
196
  {
196
- return &uk->stack[uk->stack_depth-1];
197
+ return &uk->stack->data[uk->stack->depth-1];
197
198
  }
198
199
 
199
200
  static inline int _msgpack_unpacker_stack_push(msgpack_unpacker_t* uk, enum stack_type_t type, size_t count, VALUE object)
200
201
  {
201
202
  reset_head_byte(uk);
202
203
 
203
- if(uk->stack_capacity - uk->stack_depth <= 0) {
204
+ if(uk->stack->capacity - uk->stack->depth <= 0) {
204
205
  return PRIMITIVE_STACK_TOO_DEEP;
205
206
  }
206
207
 
207
- msgpack_unpacker_stack_t* next = &uk->stack[uk->stack_depth];
208
+ msgpack_unpacker_stack_entry_t* next = &uk->stack->data[uk->stack->depth];
208
209
  next->count = count;
209
210
  next->type = type;
210
211
  next->object = object;
211
212
  next->key = Qnil;
212
213
 
213
- uk->stack_depth++;
214
+ uk->stack->depth++;
214
215
  return PRIMITIVE_CONTAINER_START;
215
216
  }
216
217
 
217
218
  static inline VALUE msgpack_unpacker_stack_pop(msgpack_unpacker_t* uk)
218
219
  {
219
- return --uk->stack_depth;
220
+ return --uk->stack->depth;
220
221
  }
221
222
 
222
223
  static inline bool msgpack_unpacker_stack_is_empty(msgpack_unpacker_t* uk)
223
224
  {
224
- return uk->stack_depth == 0;
225
+ return uk->stack->depth == 0;
225
226
  }
226
227
 
227
228
  #ifdef USE_CASE_RANGE
@@ -249,8 +250,8 @@ static inline bool msgpack_unpacker_stack_is_empty(msgpack_unpacker_t* uk)
249
250
 
250
251
  static inline bool is_reading_map_key(msgpack_unpacker_t* uk)
251
252
  {
252
- if(uk->stack_depth > 0) {
253
- msgpack_unpacker_stack_t* top = _msgpack_unpacker_stack_top(uk);
253
+ if(uk->stack->depth > 0) {
254
+ msgpack_unpacker_stack_entry_t* top = _msgpack_unpacker_stack_entry_top(uk);
254
255
  if(top->type == STACK_TYPE_MAP_KEY) {
255
256
  return true;
256
257
  }
@@ -302,25 +303,17 @@ static inline int read_raw_body_begin(msgpack_unpacker_t* uk, int raw_type)
302
303
  VALUE obj;
303
304
  uk->last_object = Qnil;
304
305
  reset_head_byte(uk);
305
- size_t ext_size = uk->reading_raw_remaining;
306
306
  uk->reading_raw_remaining = 0;
307
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;
308
+ msgpack_unpacker_stack_t* child_stack = _msgpack_unpacker_new_stack();
309
+ child_stack->parent = uk->stack;
310
+ uk->stack = child_stack;
315
311
 
316
- obj = rb_funcall(proc, s_call, 1, uk->buffer.owner);
312
+ obj = rb_proc_call_with_block(proc, 1, &uk->self, Qnil);
317
313
 
318
- _msgpack_unpacker_free_stack(uk->stack);
319
- uk->stack = stack;
320
- uk->stack_depth = stack_depth;
321
- uk->stack_capacity = stack_capacity;
314
+ uk->stack = child_stack->parent;
315
+ _msgpack_unpacker_free_stack(child_stack);
322
316
 
323
- msgpack_buffer_skip(UNPACKER_BUFFER_(uk), ext_size);
324
317
  return object_complete(uk, obj);
325
318
  }
326
319
  }
@@ -373,9 +366,6 @@ static int read_primitive(msgpack_unpacker_t* uk)
373
366
 
374
367
  SWITCH_RANGE(b, 0xa0, 0xbf) // FixRaw / fixstr
375
368
  int count = b & 0x1f;
376
- if(count == 0) {
377
- return object_complete(uk, rb_utf8_str_new_static("", 0));
378
- }
379
369
  /* read_raw_body_begin sets uk->reading_raw */
380
370
  uk->reading_raw_remaining = count;
381
371
  return read_raw_body_begin(uk, RAW_TYPE_STRING);
@@ -392,7 +382,7 @@ static int read_primitive(msgpack_unpacker_t* uk)
392
382
  if(count == 0) {
393
383
  return object_complete(uk, rb_hash_new());
394
384
  }
395
- return _msgpack_unpacker_stack_push(uk, STACK_TYPE_MAP_KEY, count*2, rb_hash_new());
385
+ return _msgpack_unpacker_stack_push(uk, STACK_TYPE_MAP_KEY, count*2, rb_hash_new_capa(count));
396
386
 
397
387
  SWITCH_RANGE(b, 0xc0, 0xdf) // Variable
398
388
  switch(b) {
@@ -475,7 +465,7 @@ static int read_primitive(msgpack_unpacker_t* uk)
475
465
  {
476
466
  READ_CAST_BLOCK_OR_RETURN_EOF(cb, uk, 4);
477
467
  uint32_t u32 = _msgpack_be32(cb->u32);
478
- return object_complete(uk, ULONG2NUM((unsigned long)u32));
468
+ return object_complete(uk, ULONG2NUM(u32)); // long at least 32 bits
479
469
  }
480
470
 
481
471
  case 0xcf: // unsigned int 64
@@ -503,7 +493,7 @@ static int read_primitive(msgpack_unpacker_t* uk)
503
493
  {
504
494
  READ_CAST_BLOCK_OR_RETURN_EOF(cb, uk, 4);
505
495
  int32_t i32 = _msgpack_be32(cb->i32);
506
- return object_complete(uk, LONG2NUM((long)i32));
496
+ return object_complete(uk, LONG2NUM(i32)); // long at least 32 bits
507
497
  }
508
498
 
509
499
  case 0xd3: // signed int 64
@@ -558,9 +548,6 @@ static int read_primitive(msgpack_unpacker_t* uk)
558
548
  {
559
549
  READ_CAST_BLOCK_OR_RETURN_EOF(cb, uk, 1);
560
550
  uint8_t count = cb->u8;
561
- if(count == 0) {
562
- return object_complete(uk, rb_utf8_str_new_static("", 0));
563
- }
564
551
  /* read_raw_body_begin sets uk->reading_raw */
565
552
  uk->reading_raw_remaining = count;
566
553
  return read_raw_body_begin(uk, RAW_TYPE_STRING);
@@ -570,9 +557,6 @@ static int read_primitive(msgpack_unpacker_t* uk)
570
557
  {
571
558
  READ_CAST_BLOCK_OR_RETURN_EOF(cb, uk, 2);
572
559
  uint16_t count = _msgpack_be16(cb->u16);
573
- if(count == 0) {
574
- return object_complete(uk, rb_utf8_str_new_static("", 0));
575
- }
576
560
  /* read_raw_body_begin sets uk->reading_raw */
577
561
  uk->reading_raw_remaining = count;
578
562
  return read_raw_body_begin(uk, RAW_TYPE_STRING);
@@ -582,9 +566,6 @@ static int read_primitive(msgpack_unpacker_t* uk)
582
566
  {
583
567
  READ_CAST_BLOCK_OR_RETURN_EOF(cb, uk, 4);
584
568
  uint32_t count = _msgpack_be32(cb->u32);
585
- if(count == 0) {
586
- return object_complete(uk, rb_utf8_str_new_static("", 0));
587
- }
588
569
  /* read_raw_body_begin sets uk->reading_raw */
589
570
  uk->reading_raw_remaining = count;
590
571
  return read_raw_body_begin(uk, RAW_TYPE_STRING);
@@ -594,9 +575,6 @@ static int read_primitive(msgpack_unpacker_t* uk)
594
575
  {
595
576
  READ_CAST_BLOCK_OR_RETURN_EOF(cb, uk, 1);
596
577
  uint8_t count = cb->u8;
597
- if(count == 0) {
598
- return object_complete(uk, rb_str_new_static("", 0));
599
- }
600
578
  /* read_raw_body_begin sets uk->reading_raw */
601
579
  uk->reading_raw_remaining = count;
602
580
  return read_raw_body_begin(uk, RAW_TYPE_BINARY);
@@ -606,9 +584,6 @@ static int read_primitive(msgpack_unpacker_t* uk)
606
584
  {
607
585
  READ_CAST_BLOCK_OR_RETURN_EOF(cb, uk, 2);
608
586
  uint16_t count = _msgpack_be16(cb->u16);
609
- if(count == 0) {
610
- return object_complete(uk, rb_str_new_static("", 0));
611
- }
612
587
  /* read_raw_body_begin sets uk->reading_raw */
613
588
  uk->reading_raw_remaining = count;
614
589
  return read_raw_body_begin(uk, RAW_TYPE_BINARY);
@@ -618,9 +593,6 @@ static int read_primitive(msgpack_unpacker_t* uk)
618
593
  {
619
594
  READ_CAST_BLOCK_OR_RETURN_EOF(cb, uk, 4);
620
595
  uint32_t count = _msgpack_be32(cb->u32);
621
- if(count == 0) {
622
- return object_complete(uk, rb_str_new_static("", 0));
623
- }
624
596
  /* read_raw_body_begin sets uk->reading_raw */
625
597
  uk->reading_raw_remaining = count;
626
598
  return read_raw_body_begin(uk, RAW_TYPE_BINARY);
@@ -653,7 +625,7 @@ static int read_primitive(msgpack_unpacker_t* uk)
653
625
  if(count == 0) {
654
626
  return object_complete(uk, rb_hash_new());
655
627
  }
656
- return _msgpack_unpacker_stack_push(uk, STACK_TYPE_MAP_KEY, count*2, rb_hash_new());
628
+ return _msgpack_unpacker_stack_push(uk, STACK_TYPE_MAP_KEY, count*2, rb_hash_new_capa(count));
657
629
  }
658
630
 
659
631
  case 0xdf: // map 32
@@ -663,7 +635,7 @@ static int read_primitive(msgpack_unpacker_t* uk)
663
635
  if(count == 0) {
664
636
  return object_complete(uk, rb_hash_new());
665
637
  }
666
- return _msgpack_unpacker_stack_push(uk, STACK_TYPE_MAP_KEY, count*2, rb_hash_new());
638
+ return _msgpack_unpacker_stack_push(uk, STACK_TYPE_MAP_KEY, count*2, rb_hash_new_capa(count));
667
639
  }
668
640
 
669
641
  default:
@@ -750,7 +722,7 @@ int msgpack_unpacker_read(msgpack_unpacker_t* uk, size_t target_stack_depth)
750
722
 
751
723
  container_completed:
752
724
  {
753
- msgpack_unpacker_stack_t* top = _msgpack_unpacker_stack_top(uk);
725
+ msgpack_unpacker_stack_entry_t* top = _msgpack_unpacker_stack_entry_top(uk);
754
726
  switch(top->type) {
755
727
  case STACK_TYPE_ARRAY:
756
728
  rb_ary_push(top->object, uk->last_object);
@@ -800,7 +772,7 @@ int msgpack_unpacker_skip(msgpack_unpacker_t* uk, size_t target_stack_depth)
800
772
 
801
773
  container_completed:
802
774
  {
803
- msgpack_unpacker_stack_t* top = _msgpack_unpacker_stack_top(uk);
775
+ msgpack_unpacker_stack_entry_t* top = _msgpack_unpacker_stack_entry_top(uk);
804
776
 
805
777
  /* this section optimized out */
806
778
  // TODO object_complete still creates objects which should be optimized out
@@ -21,12 +21,11 @@
21
21
  #include "buffer.h"
22
22
  #include "unpacker_ext_registry.h"
23
23
 
24
- #ifndef MSGPACK_UNPACKER_STACK_CAPACITY
25
24
  #define MSGPACK_UNPACKER_STACK_CAPACITY 128
26
- #endif
27
25
 
28
26
  struct msgpack_unpacker_t;
29
27
  typedef struct msgpack_unpacker_t msgpack_unpacker_t;
28
+ typedef struct msgpack_unpacker_stack_t msgpack_unpacker_stack_t;
30
29
 
31
30
  enum stack_type_t {
32
31
  STACK_TYPE_ARRAY,
@@ -39,19 +38,21 @@ typedef struct {
39
38
  enum stack_type_t type;
40
39
  VALUE object;
41
40
  VALUE key;
42
- } msgpack_unpacker_stack_t;
41
+ } msgpack_unpacker_stack_entry_t;
43
42
 
44
- #define MSGPACK_UNPACKER_STACK_SIZE (8+4+8+8) /* assumes size_t <= 64bit, enum <= 32bit, VALUE <= 64bit */
43
+ struct msgpack_unpacker_stack_t {
44
+ size_t depth;
45
+ size_t capacity;
46
+ msgpack_unpacker_stack_entry_t *data;
47
+ msgpack_unpacker_stack_t *parent;
48
+ };
45
49
 
46
50
  struct msgpack_unpacker_t {
47
51
  msgpack_buffer_t buffer;
48
-
52
+ msgpack_unpacker_stack_t *stack;
49
53
  unsigned int head_byte;
50
54
 
51
- msgpack_unpacker_stack_t* stack;
52
- size_t stack_depth;
53
- size_t stack_capacity;
54
-
55
+ VALUE self;
55
56
  VALUE last_object;
56
57
 
57
58
  VALUE reading_raw;
@@ -82,11 +83,11 @@ enum msgpack_unpacker_object_type {
82
83
  TYPE_MAP,
83
84
  };
84
85
 
85
- void msgpack_unpacker_static_init();
86
+ void msgpack_unpacker_static_init(void);
86
87
 
87
- void msgpack_unpacker_static_destroy();
88
+ void msgpack_unpacker_static_destroy(void);
88
89
 
89
- msgpack_unpacker_t* _msgpack_unpacker_new(void);
90
+ void _msgpack_unpacker_init(msgpack_unpacker_t*);
90
91
 
91
92
  void _msgpack_unpacker_destroy(msgpack_unpacker_t* uk);
92
93