From cc29958d34e43ed889536ad4a723fce819544785 Mon Sep 17 00:00:00 2001 From: Steffen Siering Date: Sun, 11 Nov 2012 22:48:21 +0000 Subject: Fix STATIC_ASSERT macro when using multiple .proto files. The __COUNTER__ macro (used for generating unique names) is at least supported by gcc, clang and Visual Studio. With this change test_compiles.c is compilable, since no more typedefs are redefined. Compilers/Preprocessors not supporting __COUNTER__ error's are still possible which are hopfully handled by the usage of __LINE__ in most sittuations. Added unit test for the problem. --- generator/nanopb_generator.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'generator') diff --git a/generator/nanopb_generator.py b/generator/nanopb_generator.py index 6aac1b8c..2a3cab28 100644 --- a/generator/nanopb_generator.py +++ b/generator/nanopb_generator.py @@ -493,7 +493,9 @@ def generate_header(dependencies, headername, enums, messages): worst = 0 worst_field = '' checks = [] + checks_msgnames = [] for msg in messages: + checks_msgnames.append(msg.name) for field in msg.fields: status = field.largest_field_value() if isinstance(status, (str, unicode)): @@ -511,7 +513,8 @@ def generate_header(dependencies, headername, enums, messages): yield '#error Field descriptor for %s is too large. Define PB_FIELD_16BIT to fix this.\n' % worst_field else: assertion = ' && '.join(str(c) + ' < 256' for c in checks) - yield 'STATIC_ASSERT((%s), YOU_MUST_DEFINE_PB_FIELD_16BIT)\n' % assertion + msgs = '_'.join(str(n) for n in checks_msgnames) + yield 'STATIC_ASSERT((%s), YOU_MUST_DEFINE_PB_FIELD_16BIT_FOR_MESSAGES_%s)\n'%(assertion,msgs) yield '#endif\n\n' if worst > 65535 or checks: @@ -520,7 +523,8 @@ def generate_header(dependencies, headername, enums, messages): yield '#error Field descriptor for %s is too large. Define PB_FIELD_32BIT to fix this.\n' % worst_field else: assertion = ' && '.join(str(c) + ' < 65536' for c in checks) - yield 'STATIC_ASSERT((%s), YOU_MUST_DEFINE_PB_FIELD_32BIT)\n' % assertion + msgs = '_'.join(str(n) for n in checks_msgnames) + yield 'STATIC_ASSERT((%s), YOU_MUST_DEFINE_PB_FIELD_32BIT_FOR_MESSAGES_%s)\n'%(assertion,msgs) yield '#endif\n' yield '\n#ifdef __cplusplus\n' -- cgit 1.2.3-korg