template_execute: fixes embed stack

This commit is contained in:
frsyuki 2010-04-17 22:43:11 +09:00
parent 08b716c96d
commit c3f43fb0cf
2 changed files with 8 additions and 7 deletions

View File

@ -30,7 +30,7 @@ extern "C" {
#ifndef MSGPACK_EMBED_STACK_SIZE #ifndef MSGPACK_EMBED_STACK_SIZE
#define MSGPACK_EMBED_STACK_SIZE 1 #define MSGPACK_EMBED_STACK_SIZE 16
#endif #endif

View File

@ -99,6 +99,7 @@ msgpack_unpack_func(int, _execute)(msgpack_unpack_struct(_context)* ctx, const c
unsigned int cs = ctx->cs; unsigned int cs = ctx->cs;
unsigned int top = ctx->top; unsigned int top = ctx->top;
msgpack_unpack_struct(_stack)* stack = ctx->stack; msgpack_unpack_struct(_stack)* stack = ctx->stack;
unsigned int stack_size = ctx->stack_size;
msgpack_unpack_user* user = &ctx->user; msgpack_unpack_user* user = &ctx->user;
msgpack_unpack_object obj; msgpack_unpack_object obj;
@ -135,21 +136,21 @@ msgpack_unpack_func(int, _execute)(msgpack_unpack_struct(_context)* ctx, const c
++top; \ ++top; \
/*printf("container %d count %d stack %d\n",stack[top].obj,count_,top);*/ \ /*printf("container %d count %d stack %d\n",stack[top].obj,count_,top);*/ \
/*printf("stack push %d\n", top);*/ \ /*printf("stack push %d\n", top);*/ \
if(top >= ctx->stack_size) { \ if(top >= stack_size) { \
if(ctx->stack_size == MSGPACK_EMBED_STACK_SIZE) { \ if(stack_size == MSGPACK_EMBED_STACK_SIZE) { \
size_t csize = sizeof(msgpack_unpack_struct(_stack)) * MSGPACK_EMBED_STACK_SIZE; \ size_t csize = sizeof(msgpack_unpack_struct(_stack)) * MSGPACK_EMBED_STACK_SIZE; \
size_t nsize = csize * 2; \ size_t nsize = csize * 2; \
msgpack_unpack_struct(_stack)* tmp = (msgpack_unpack_struct(_stack)*)malloc(nsize); \ msgpack_unpack_struct(_stack)* tmp = (msgpack_unpack_struct(_stack)*)malloc(nsize); \
if(tmp == NULL) { goto _failed; } \ if(tmp == NULL) { goto _failed; } \
memcpy(tmp, ctx->stack, csize); \ memcpy(tmp, ctx->stack, csize); \
ctx->stack = tmp; \ ctx->stack = stack = tmp; \
ctx->stack_size = MSGPACK_EMBED_STACK_SIZE * 2; \ ctx->stack_size = stack_size = MSGPACK_EMBED_STACK_SIZE * 2; \
} else { \ } else { \
size_t nsize = sizeof(msgpack_unpack_struct(_stack)) * ctx->stack_size * 2; \ size_t nsize = sizeof(msgpack_unpack_struct(_stack)) * ctx->stack_size * 2; \
msgpack_unpack_struct(_stack)* tmp = (msgpack_unpack_struct(_stack)*)realloc(ctx->stack, nsize); \ msgpack_unpack_struct(_stack)* tmp = (msgpack_unpack_struct(_stack)*)realloc(ctx->stack, nsize); \
if(tmp == NULL) { goto _failed; } \ if(tmp == NULL) { goto _failed; } \
ctx->stack = tmp; \ ctx->stack = stack = tmp; \
ctx->stack_size *= 2; \ ctx->stack_size = stack_size = stack_size * 2; \
} \ } \
} \ } \
goto _header_again goto _header_again