[Piglit] [PATCH 1/3] piglit-util-gl: Add piglit_get_gl_enum_from_name
Emil Velikov
emil.l.velikov at gmail.com
Wed Feb 18 15:15:24 PST 2015
On 18 February 2015 at 22:32, Jordan Justen <jordan.l.justen at intel.com> wrote:
> Signed-off-by: Jordan Justen <jordan.l.justen at intel.com>
> Reviewed-by: Chad Versace <chad.versace at intel.com>
> ---
> tests/util/gen_dispatch.py | 21 ++++++++++++++++++-
> tests/util/piglit-util-gl-enum-gen.c.mako | 35 +++++++++++++++++++++++++++++++
> tests/util/piglit-util-gl.h | 9 ++++++++
> 3 files changed, 64 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 e22a75d..729abef 100644
> --- a/tests/util/piglit-util-gl-enum-gen.c.mako
> +++ b/tests/util/piglit-util-gl-enum-gen.c.mako
> @@ -50,4 +50,39 @@ piglit_get_prim_name(GLenum prim)
> >-------default: return "(unrecognized enum)";
> >-------}
> }
> +
> +struct gl_name_to_enum {
> +>-------const char *name;
> +>-------GLenum _enum;
> +};
> +
> +static int
> +compare_enum_name(const void *a, const void *b)
> +{
> +>-------return strcmp(((struct gl_name_to_enum*)a)->name,
> +>------- ((struct gl_name_to_enum*)b)->name);
> +}
> +
> +GLenum
> +piglit_get_gl_enum_from_name(const char *name)
> +{
> +>-------static struct gl_name_to_enum names[] = {
Depending on how friendly the compiler is one might want to make this
"static const" and move the table outside of the function.
> +% for enum in sorted_enums_by_name:
> +>------->-------{ "${enum.name}", ${enum.c_num_literal} },
> +% endfor
> +>-------};
> +>-------struct gl_name_to_enum key = { name, 0 };
> +>-------struct gl_name_to_enum *result;
> +
> +>-------result = (struct gl_name_to_enum*)
> +>------->-------bsearch(&key,
> +>------->------- names, ARRAY_SIZE(names), sizeof names[0],
> +>------->------- compare_enum_name);
> +
> +>-------if (result == NULL)
> +>------->-------abort();
Is it me or does this look a bit excessive - none of the other util_gl
functions go that far. How about just printing a catchy error message
:-P
Cheers,
Emil
More information about the Piglit
mailing list