From c3f43fb0cf14f596a9ebb1c30b0417b3a8ba9958 Mon Sep 17 00:00:00 2001 From: frsyuki Date: Sat, 17 Apr 2010 22:43:11 +0900 Subject: [PATCH] template_execute: fixes embed stack --- msgpack/unpack_define.h | 2 +- msgpack/unpack_template.h | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/msgpack/unpack_define.h b/msgpack/unpack_define.h index cb02a3bb..71412eea 100644 --- a/msgpack/unpack_define.h +++ b/msgpack/unpack_define.h @@ -30,7 +30,7 @@ extern "C" { #ifndef MSGPACK_EMBED_STACK_SIZE -#define MSGPACK_EMBED_STACK_SIZE 1 +#define MSGPACK_EMBED_STACK_SIZE 16 #endif diff --git a/msgpack/unpack_template.h b/msgpack/unpack_template.h index 72f8e593..4b8cd14f 100644 --- a/msgpack/unpack_template.h +++ b/msgpack/unpack_template.h @@ -99,6 +99,7 @@ msgpack_unpack_func(int, _execute)(msgpack_unpack_struct(_context)* ctx, const c unsigned int cs = ctx->cs; unsigned int top = ctx->top; msgpack_unpack_struct(_stack)* stack = ctx->stack; + unsigned int stack_size = ctx->stack_size; msgpack_unpack_user* user = &ctx->user; msgpack_unpack_object obj; @@ -135,21 +136,21 @@ msgpack_unpack_func(int, _execute)(msgpack_unpack_struct(_context)* ctx, const c ++top; \ /*printf("container %d count %d stack %d\n",stack[top].obj,count_,top);*/ \ /*printf("stack push %d\n", top);*/ \ - if(top >= ctx->stack_size) { \ - if(ctx->stack_size == MSGPACK_EMBED_STACK_SIZE) { \ + if(top >= stack_size) { \ + if(stack_size == MSGPACK_EMBED_STACK_SIZE) { \ size_t csize = sizeof(msgpack_unpack_struct(_stack)) * MSGPACK_EMBED_STACK_SIZE; \ size_t nsize = csize * 2; \ msgpack_unpack_struct(_stack)* tmp = (msgpack_unpack_struct(_stack)*)malloc(nsize); \ if(tmp == NULL) { goto _failed; } \ memcpy(tmp, ctx->stack, csize); \ - ctx->stack = tmp; \ - ctx->stack_size = MSGPACK_EMBED_STACK_SIZE * 2; \ + ctx->stack = stack = tmp; \ + ctx->stack_size = stack_size = MSGPACK_EMBED_STACK_SIZE * 2; \ } else { \ 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); \ if(tmp == NULL) { goto _failed; } \ - ctx->stack = tmp; \ - ctx->stack_size *= 2; \ + ctx->stack = stack = tmp; \ + ctx->stack_size = stack_size = stack_size * 2; \ } \ } \ goto _header_again