From: Jani Nikula <jani.nikula@intel.com>
To: Daniel Vetter <daniel@ffwll.ch>
Cc: intel-gfx@lists.freedesktop.org
Subject: Re: [PATCH i-g-t 2/2] lib/igt_aux: define actual functions for kmstest_*_str
Date: Tue, 17 May 2016 13:05:13 +0300 [thread overview]
Message-ID: <87a8jpov8m.fsf@intel.com> (raw)
In-Reply-To: <20160517095643.GS27098@phenom.ffwll.local>
On Tue, 17 May 2016, Daniel Vetter <daniel@ffwll.ch> wrote:
> 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 <jani.nikula@intel.com>
>> ---
>> 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?
We still do, in igt_kms.h, where they didn't help me in the least
finding the definitions...
BR,
Jani.
> -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
>> Intel-gfx@lists.freedesktop.org
>> https://lists.freedesktop.org/mailman/listinfo/intel-gfx
--
Jani Nikula, Intel Open Source Technology Center
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
next prev parent reply other threads:[~2016-05-17 10:05 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-11 9:42 [PATCH i-g-t 1/2] lib/igt_aux: update encoder and type names Jani Nikula
2016-05-11 9:42 ` [PATCH i-g-t 2/2] lib/igt_aux: define actual functions for kmstest_*_str Jani Nikula
2016-05-17 9:56 ` Daniel Vetter
2016-05-17 10:05 ` Jani Nikula [this message]
2016-05-17 11:11 ` Daniel Vetter
2016-05-17 11:44 ` [PATCH] lib/igt_kms: move gtk-doc comments next to the definition Jani Nikula
2016-05-11 15:24 ` [PATCH i-g-t 1/2] lib/igt_aux: update encoder and type names Marius Vlad
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87a8jpov8m.fsf@intel.com \
--to=jani.nikula@intel.com \
--cc=daniel@ffwll.ch \
--cc=intel-gfx@lists.freedesktop.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox