From 362173091d4fbf3fa52ccd43fab2751f19018d68 Mon Sep 17 00:00:00 2001 From: Alex Helfet Date: Thu, 23 Mar 2017 06:53:33 +0000 Subject: [PATCH] compiler: If an explicit symbol wasn't provided, make generated capn_val%d variables static. --- compiler/capnpc-c.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/compiler/capnpc-c.c b/compiler/capnpc-c.c index 4258f0a..51c382d 100644 --- a/compiler/capnpc-c.c +++ b/compiler/capnpc-c.c @@ -8,6 +8,7 @@ #include "schema.capnp.h" #include "str.h" +#include #include #include #include @@ -261,6 +262,7 @@ static void decode_value(struct value* v, Type_ptr type, Value_ptr value, const v->ptrval = p; + bool symbol_provided = symbol; if (!symbol) { static struct str buf = STR_INIT; v->intval = ++g_valc; @@ -268,7 +270,7 @@ static void decode_value(struct value* v, Type_ptr type, Value_ptr value, const } str_addf(&SRC, "%scapn_text %s = {%d,(char*)&capn_buf[%d],(struct capn_segment*)&capn_seg};\n", - symbol ? "" : "static ", + symbol_provided ? "" : "static ", symbol, p.len-1, (int) (p.data-p.seg->data-8)); @@ -291,13 +293,14 @@ static void decode_value(struct value* v, Type_ptr type, Value_ptr value, const v->ptrval = p; + bool symbol_provided = symbol; if (!symbol) { static struct str buf = STR_INIT; v->intval = ++g_valc; symbol = strf(&buf, "capn_val%d", (int) v->intval); } - str_addf(&SRC, "%s%s %s = {", symbol ? "" : "static ", v->tname, symbol); + str_addf(&SRC, "%s%s %s = {", symbol_provided ? "" : "static ", v->tname, symbol); if (strcmp(v->tname, "capn_ptr")) str_addf(&SRC, "{");