[Mesa-dev] [PATCH 2/2] glapi: work-around MSVC 65K string length limitation for enums.c

Ian Romanick idr at freedesktop.org
Tue Dec 1 13:13:31 PST 2015


On 12/01/2015 12:04 PM, Brian Paul wrote:
> String literals cannot exceed 65535 characters for MSVC.  Instead of
> emiting a string, emit an array of characters.
> ---
>  src/mapi/glapi/gen/gl_enums.py | 9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/src/mapi/glapi/gen/gl_enums.py b/src/mapi/glapi/gen/gl_enums.py
> index 6e18f15..7c6c51f 100644
> --- a/src/mapi/glapi/gen/gl_enums.py
> +++ b/src/mapi/glapi/gen/gl_enums.py
> @@ -156,14 +156,17 @@ _mesa_lookup_prim_by_nr(GLuint nr)
>          print '# define LONGSTRING'
>          print '#endif'
>          print ''
> -        print 'LONGSTRING static const char enum_string_table[] = '
> +        print 'LONGSTRING static const char enum_string_table[] = {'
>          for enum in sorted_enum_values:
>              (name, pri) = self.enum_table[enum]
> -            print '   "%s\\0"' % (name)
> +            for ch in name:
> +                print "'%c'," % ch,
> +            print "'\\0',"
> +

Good times.  There are a couple other generators that do similar things.
 I *think* the other scripts detect whether or not the work-around is
necessary so that we get readable output on non-MSVC builds.  I have a
vague recollection of doing that anyway.

We could refactor this to a common function emit_really_long_C_string()
that could be used everywhere.  That would be a good janitor task for
someone with Python skillz.

Either way, this patch is also

Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>

>              string_offsets[ enum ] = i
>              i += len(name) + 1
>  
> -        print '   ;'
> +        print '};'
>          print ''
>  
>  
> 



More information about the mesa-dev mailing list