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

Eric Anholt eric at anholt.net
Tue Dec 1 12:30:26 PST 2015


Brian Paul <brianp at vmware.com> writes:

> 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',"
> +
>              string_offsets[ enum ] = i
>              i += len(name) + 1
>  
> -        print '   ;'
> +        print '};'
>          print ''

For others reading the patch, the generated code is:

LONGSTRING static const char enum_string_table[] = {
'G', 'L', '_', 'N', 'O', '_', 'E', 'R', 'R', 'O', 'R', '\0',
'G', 'L', '_', 'T', 'R', 'U', 'E', '\0',
'G', 'L', '_', 'L', 'I', 'N', 'E', '_', 'L', 'O', 'O', 'P', '\0',
'G', 'L', '_', 'L', 'I', 'N', 'E', '_', 'S', 'T', 'R', 'I', 'P', '\0',
.....
'G', 'L', '_', 'F', 'O', 'G', '_', 'C', 'O', 'O', 'R', 'D', 'I', 'N', 'A', 'T', 'E', '_', 'A', 'R', 'R', 'A', 'Y', '_', 'L', 'I', 'S', 'T', '_', 'S', 'T', 'R', 'I', 'D', 'E', '_', 'I', 'B', 'M', '\0',
'G', 'L', '_', 'S', 'E', 'C', 'O', 'N', 'D', 'A', 'R', 'Y', '_', 'C', 'O', 'L', 'O', 'R', '_', 'A', 'R', 'R', 'A', 'Y', '_', 'L', 'I', 'S', 'T', '_', 'S', 'T', 'R', 'I', 'D', 'E', '_', 'I', 'B', 'M', '\0',
};

I'd love a comment in the .py about the MSVC limitation, and for reading
the generated file it would be nice to keep the indentation before each
line, but regardless:

Reviewed-by: Eric Anholt <eric at anholt.net>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 818 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20151201/e884770d/attachment.sig>


More information about the mesa-dev mailing list