4848
4949msgpack_unpack_struct_decl (_stack ) {
5050 msgpack_unpack_object obj ;
51+ size_t size ;
5152 size_t count ;
5253 unsigned int ct ;
5354 msgpack_unpack_object map_key ;
@@ -140,9 +141,12 @@ msgpack_unpack_func(int, _execute)(msgpack_unpack_struct(_context)* ctx, const c
140141#define start_container (func , count_ , ct_ ) \
141142 if(top >= MSGPACK_EMBED_STACK_SIZE) { goto _failed; } /* FIXME */ \
142143 if (msgpack_unpack_callback (func )(user , count_ , & stack [top ].obj ) < 0 ) { goto _failed ; } \
143- if ((count_ ) == 0 ) { obj = stack [top ].obj ; goto _push ; } \
144+ if ((count_ ) == 0 ) { obj = stack [top ].obj ; \
145+ msgpack_unpack_callback (func ##_end )(user , & obj ); \
146+ goto _push ; } \
144147 stack [top ].ct = ct_ ; \
145- stack [top ].count = count_ ; \
148+ stack [top ].size = count_ ; \
149+ stack [top ].count = 0 ; \
146150 ++ top ; \
147151 /*printf("container %d count %d stack %d\n",stack[top].obj,count_,top);*/ \
148152 /*printf("stack push %d\n", top);*/ \
@@ -336,9 +340,10 @@ msgpack_unpack_func(int, _execute)(msgpack_unpack_struct(_context)* ctx, const c
336340 c = & stack [top - 1 ];
337341 switch (c -> ct ) {
338342 case CT_ARRAY_ITEM :
339- if (msgpack_unpack_callback (_array_item )(user , & c -> obj , obj ) < 0 ) { goto _failed ; }
340- if (-- c -> count == 0 ) {
343+ if (msgpack_unpack_callback (_array_item )(user , c -> count , & c -> obj , obj ) < 0 ) { goto _failed ; }
344+ if (++ c -> count == c -> size ) {
341345 obj = c -> obj ;
346+ msgpack_unpack_callback (_array_end )(user , & obj );
342347 -- top ;
343348 /*printf("stack pop %d\n", top);*/
344349 goto _push ;
@@ -350,8 +355,9 @@ msgpack_unpack_func(int, _execute)(msgpack_unpack_struct(_context)* ctx, const c
350355 goto _header_again ;
351356 case CT_MAP_VALUE :
352357 if (msgpack_unpack_callback (_map_item )(user , & c -> obj , c -> map_key , obj ) < 0 ) { goto _failed ; }
353- if (-- c -> count == 0 ) {
358+ if (++ c -> count == c -> size ) {
354359 obj = c -> obj ;
360+ msgpack_unpack_callback (_map_end )(user , & obj );
355361 -- top ;
356362 /*printf("stack pop %d\n", top);*/
357363 goto _push ;
@@ -411,3 +417,4 @@ msgpack_unpack_func(int, _execute)(msgpack_unpack_struct(_context)* ctx, const c
411417
412418#undef NEXT_CS
413419
420+ /* vim: set ts=4 sw=4 noexpandtab */
0 commit comments