From e9f68fe3a34e769ac2f3e5d4b92c1358edd7af5c Mon Sep 17 00:00:00 2001 From: Chun-wei Fan Date: Fri, 5 Jun 2015 14:06:23 +0800 Subject: [PATCH] Fix generated code for building on MSVC 2013 This updates the script to generate code that is buildable by Visual Studio 2013 by: -Using a macro to define the compiler-specific way to do noinline for a function, and use it when needed. -Avoid using empty arrays and structs as that is a C99 feature that will likely be never support on Visual Studio as it is now an optional feature of C11. --- src/gen_dispatch.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/gen_dispatch.py b/src/gen_dispatch.py index 92f6358..326fdbc 100755 --- a/src/gen_dispatch.py +++ b/src/gen_dispatch.py @@ -577,8 +577,11 @@ class Generator(object): self.outln(' };') self.outln(' static const uint16_t entrypoints[] = {') - for provider in providers: - self.outln(' {0} /* "{1}" */,'.format(self.entrypoint_string_offset[provider.name], provider.name)) + if len(providers) > 1: + for provider in providers: + self.outln(' {0} /* "{1}" */,'.format(self.entrypoint_string_offset[provider.name], provider.name)) + else: + self.outln(' 0 /* None */,') self.outln(' };') self.outln(' return {0}_provider_resolver(entrypoint_strings + {1} /* "{2}" */,'.format(self.target, @@ -698,8 +701,8 @@ class Generator(object): self.outln('') single_resolver_proto = '{0}_single_resolver(enum {0}_provider provider, uint16_t entrypoint_offset)'.format(self.target) - self.outln('static void *') - self.outln('{0} __attribute__((noinline));'.format(single_resolver_proto)) + self.outln('EPOXY_NOINLINE static void *') + self.outln('{0};'.format(single_resolver_proto)) self.outln('') self.outln('static void *') self.outln('{0}'.format(single_resolver_proto)) @@ -728,6 +731,11 @@ class Generator(object): self.outln('#include "dispatch_common.h"') self.outln('#include "epoxy/{0}.h"'.format(self.target)) self.outln('') + self.outln('#ifdef __GNUC__') + self.outln('#define EPOXY_NOINLINE __attribute__((noinline))') + self.outln('#elif defined (_MSC_VER)') + self.outln('#define EPOXY_NOINLINE __declspec(noinline)') + self.outln('#endif') self.outln('struct dispatch_table {') for func in self.sorted_functions: