mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-03-20 13:33:51 +01:00
template_execute: fixes embed stack
This commit is contained in:
parent
08b716c96d
commit
c3f43fb0cf
@ -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
|
||||||
|
|
||||||
|
|
||||||
|
@ -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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user