@@ -79,12 +79,9 @@ void msgpack_unpacker_static_destroy(void)
7979
8080#define HEAD_BYTE_REQUIRED 0xc1
8181
82- static inline msgpack_unpacker_stack_t * _msgpack_unpacker_new_stack (void ) {
83- msgpack_unpacker_stack_t * stack = ZALLOC (msgpack_unpacker_stack_t );
82+ static inline void _msgpack_unpacker_stack_init (msgpack_unpacker_stack_t * stack ) {
8483 stack -> capacity = MSGPACK_UNPACKER_STACK_CAPACITY ;
8584 stack -> data = msgpack_rmem_alloc (& s_stack_rmem );
86- /*memset(uk->stack, 0, MSGPACK_UNPACKER_STACK_CAPACITY);*/
87- return stack ;
8885}
8986
9087void _msgpack_unpacker_init (msgpack_unpacker_t * uk )
@@ -96,25 +93,26 @@ void _msgpack_unpacker_init(msgpack_unpacker_t* uk)
9693 uk -> last_object = Qnil ;
9794 uk -> reading_raw = Qnil ;
9895
99- uk -> stack = _msgpack_unpacker_new_stack ( );
96+ _msgpack_unpacker_stack_init ( & uk -> stack );
10097}
10198
10299static inline void _msgpack_unpacker_free_stack (msgpack_unpacker_stack_t * stack ) {
103100 if (!msgpack_rmem_free (& s_stack_rmem , stack -> data )) {
104101 rb_bug ("Failed to free an rmem pointer, memory leak?" );
105102 }
106- xfree (stack );
103+ stack -> data = NULL ;
104+ stack -> depth = 0 ;
107105}
108106
109107void _msgpack_unpacker_destroy (msgpack_unpacker_t * uk )
110108{
111- _msgpack_unpacker_free_stack (uk -> stack );
109+ _msgpack_unpacker_free_stack (& uk -> stack );
112110 msgpack_buffer_destroy (UNPACKER_BUFFER_ (uk ));
113111}
114112
115113void msgpack_unpacker_mark_stack (msgpack_unpacker_stack_t * stack )
116114{
117- if (stack ) {
115+ if (stack -> data ) {
118116 msgpack_unpacker_stack_entry_t * s = stack -> data ;
119117 msgpack_unpacker_stack_entry_t * send = stack -> data + stack -> depth ;
120118 for (; s < send ; s ++ ) {
@@ -128,7 +126,7 @@ void msgpack_unpacker_mark(msgpack_unpacker_t* uk)
128126{
129127 rb_gc_mark (uk -> last_object );
130128 rb_gc_mark (uk -> reading_raw );
131- msgpack_unpacker_mark_stack (uk -> stack );
129+ msgpack_unpacker_mark_stack (& uk -> stack );
132130 /* See MessagePack_Buffer_wrap */
133131 /* msgpack_buffer_mark(UNPACKER_BUFFER_(uk)); */
134132 rb_gc_mark (uk -> buffer_ref );
@@ -141,8 +139,8 @@ void _msgpack_unpacker_reset(msgpack_unpacker_t* uk)
141139
142140 uk -> head_byte = HEAD_BYTE_REQUIRED ;
143141
144- /*memset(uk->stack, 0, sizeof(msgpack_unpacker_t) * uk->stack-> depth);*/
145- uk -> stack -> depth = 0 ;
142+ /*memset(uk->stack, 0, sizeof(msgpack_unpacker_t) * uk->stack. depth);*/
143+ uk -> stack . depth = 0 ;
146144 uk -> last_object = Qnil ;
147145 uk -> reading_raw = Qnil ;
148146 uk -> reading_raw_remaining = 0 ;
@@ -226,35 +224,35 @@ static inline int object_complete_ext(msgpack_unpacker_t* uk, int ext_type, VALU
226224/* stack funcs */
227225static inline msgpack_unpacker_stack_entry_t * _msgpack_unpacker_stack_entry_top (msgpack_unpacker_t * uk )
228226{
229- return & uk -> stack -> data [uk -> stack -> depth - 1 ];
227+ return & uk -> stack . data [uk -> stack . depth - 1 ];
230228}
231229
232230static inline int _msgpack_unpacker_stack_push (msgpack_unpacker_t * uk , enum stack_type_t type , size_t count , VALUE object )
233231{
234232 reset_head_byte (uk );
235233
236- if (uk -> stack -> capacity - uk -> stack -> depth <= 0 ) {
234+ if (uk -> stack . capacity - uk -> stack . depth <= 0 ) {
237235 return PRIMITIVE_STACK_TOO_DEEP ;
238236 }
239237
240- msgpack_unpacker_stack_entry_t * next = & uk -> stack -> data [uk -> stack -> depth ];
238+ msgpack_unpacker_stack_entry_t * next = & uk -> stack . data [uk -> stack . depth ];
241239 next -> count = count ;
242240 next -> type = type ;
243241 next -> object = object ;
244242 next -> key = Qnil ;
245243
246- uk -> stack -> depth ++ ;
244+ uk -> stack . depth ++ ;
247245 return PRIMITIVE_CONTAINER_START ;
248246}
249247
250248static inline VALUE msgpack_unpacker_stack_pop (msgpack_unpacker_t * uk )
251249{
252- return -- uk -> stack -> depth ;
250+ return -- uk -> stack . depth ;
253251}
254252
255253static inline bool msgpack_unpacker_stack_is_empty (msgpack_unpacker_t * uk )
256254{
257- return uk -> stack -> depth == 0 ;
255+ return uk -> stack . depth == 0 ;
258256}
259257
260258#ifdef USE_CASE_RANGE
@@ -282,7 +280,7 @@ static inline bool msgpack_unpacker_stack_is_empty(msgpack_unpacker_t* uk)
282280
283281static inline bool is_reading_map_key (msgpack_unpacker_t * uk )
284282{
285- if (uk -> stack -> depth > 0 ) {
283+ if (uk -> stack . depth > 0 ) {
286284 msgpack_unpacker_stack_entry_t * top = _msgpack_unpacker_stack_entry_top (uk );
287285 if (top -> type == STACK_TYPE_MAP_KEY ) {
288286 return true;
0 commit comments