[Piglit] [PATCH 01/18] util/gl: Print numeric value of unrecognized enums.
Brian Paul
brianp at vmware.com
Tue Jan 9 18:42:21 UTC 2018
On 01/07/2018 03:13 PM, Fabian Bieler wrote:
> Use a static cyclic buffer of 4096 bytes. This should give returned
> strings a long enough lifetime.
> ---
> tests/util/piglit-util-gl-enum-gen.c.mako | 14 +++++++++++++-
> 1 file changed, 13 insertions(+), 1 deletion(-)
>
> diff --git a/tests/util/piglit-util-gl-enum-gen.c.mako b/tests/util/piglit-util-gl-enum-gen.c.mako
> index 1a878c945..3e07b9d69 100644
> --- a/tests/util/piglit-util-gl-enum-gen.c.mako
> +++ b/tests/util/piglit-util-gl-enum-gen.c.mako
> @@ -38,7 +38,19 @@ piglit_get_gl_enum_name(GLenum param)
> >-------case ${enum.c_num_literal}: return "${enum.name}";
> % endif
> % endfor
> ->-------default: return "(unrecognized enum)";
> +>-------default: {
> +>------->-------static const char *format = "(unrecognized enum: 0x%X)";
> +>------->-------static char buffer[4096];
> +>------->-------static char *position = buffer;
> +>------->-------const ptrdiff_t size_left = 4096 - (position - buffer);
> +>------->-------const size_t size_needed = strlen(format) + 8 - 2 + 1;
> +>------->-------if (size_left < size_needed)
> +>------->------->-------position = buffer;
> +>------->-------const int len = sprintf(position, format, param);
> +>------->-------const char *old_position = position;
> +>------->-------position += len + 1;
> +>------->-------return old_position;
> +>------->-------}
> >-------}
> }
>
>
I didn't do a super detailed review, but the series looks good.
Reviewed-by: Brian Paul <brianp at vmware.com>
More information about the Piglit
mailing list