On Wed, May 11, 2016 at 12:42:06PM +0300, Jani Nikula wrote:
> Macro generated function definitions considered harmful. You can't find
> them with code search tools or grep. There may be places where such
> things might be useful, but this is not it.
> 
> Define actual functions for kmstest_encoder_type_str(),
> kmstest_connector_status_str() and kmstest_connector_type_str(). While
> at it, make the arrays static const.
> 
> Signed-off-by: Jani Nikula <[email protected]>
> ---
>  lib/igt_aux.c | 41 ++++++++++++++++++++++++++---------------
>  1 file changed, 26 insertions(+), 15 deletions(-)
> 
> diff --git a/lib/igt_aux.c b/lib/igt_aux.c
> index 5dbbe4dd4a85..22962dcf2be4 100644
> --- a/lib/igt_aux.c
> +++ b/lib/igt_aux.c
> @@ -941,17 +941,17 @@ struct type_name {
>       const char *name;
>  };
>  
> -#define type_name_fn(res) \
> -const char * kmstest_##res##_str(int type) {         \
> -     unsigned int i;                                 \
> -     for (i = 0; i < ARRAY_SIZE(res##_names); i++) { \
> -             if (res##_names[i].type == type)        \
> -                     return res##_names[i].name;     \
> -     }                                               \
> -     return "(invalid)";                             \
> +static const char *find_type_name(const struct type_name *names, int type)
> +{
> +     for (; names->name; names++) {
> +             if (names->type == type)
> +                     return names->name;
> +     }
> +
> +     return "(invalid)";
>  }
>  
> -struct type_name encoder_type_names[] = {
> +static const struct type_name encoder_type_names[] = {
>       { DRM_MODE_ENCODER_NONE, "none" },
>       { DRM_MODE_ENCODER_DAC, "DAC" },
>       { DRM_MODE_ENCODER_TMDS, "TMDS" },
> @@ -960,19 +960,27 @@ struct type_name encoder_type_names[] = {
>       { DRM_MODE_ENCODER_VIRTUAL, "Virtual" },
>       { DRM_MODE_ENCODER_DSI, "DSI" },
>       { DRM_MODE_ENCODER_DPMST, "DP MST" },
> +     {}
>  };
>  
> -type_name_fn(encoder_type)
> +const char *kmstest_encoder_type_str(int type)
> +{
> +     return find_type_name(encoder_type_names, type);
> +}

We should have gtkdoc for these now too, or maybe we had but somewhere
else?
-Daniel

>  
> -struct type_name connector_status_names[] = {
> +static const struct type_name connector_status_names[] = {
>       { DRM_MODE_CONNECTED, "connected" },
>       { DRM_MODE_DISCONNECTED, "disconnected" },
>       { DRM_MODE_UNKNOWNCONNECTION, "unknown" },
> +     {}
>  };
>  
> -type_name_fn(connector_status)
> +const char *kmstest_connector_status_str(int status)
> +{
> +     return find_type_name(connector_status_names, status);
> +}
>  
> -struct type_name connector_type_names[] = {
> +static const struct type_name connector_type_names[] = {
>       { DRM_MODE_CONNECTOR_Unknown, "unknown" },
>       { DRM_MODE_CONNECTOR_VGA, "VGA" },
>       { DRM_MODE_CONNECTOR_DVII, "DVI-I" },
> @@ -990,10 +998,13 @@ struct type_name connector_type_names[] = {
>       { DRM_MODE_CONNECTOR_eDP, "eDP" },
>       { DRM_MODE_CONNECTOR_VIRTUAL, "Virtual" },
>       { DRM_MODE_CONNECTOR_DSI, "DSI" },
> +     {}
>  };
>  
> -type_name_fn(connector_type)
> -
> +const char *kmstest_connector_type_str(int type)
> +{
> +     return find_type_name(connector_type_names, type);
> +}
>  
>  /**
>   * igt_lock_mem:
> -- 
> 2.1.4
> 
> _______________________________________________
> Intel-gfx mailing list
> [email protected]
> https://lists.freedesktop.org/mailman/listinfo/intel-gfx

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

Reply via email to