public inbox for intel-gfx@lists.freedesktop.org
 help / color / mirror / Atom feed
From: Jani Nikula <jani.nikula@intel.com>
To: intel-gfx@lists.freedesktop.org
Cc: jani.nikula@intel.com
Subject: [PATCH i-g-t 2/2] lib/igt_aux: define actual functions for kmstest_*_str
Date: Wed, 11 May 2016 12:42:06 +0300	[thread overview]
Message-ID: <1462959726-7246-2-git-send-email-jani.nikula@intel.com> (raw)
In-Reply-To: <1462959726-7246-1-git-send-email-jani.nikula@intel.com>

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);
+}
 
-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

  reply	other threads:[~2016-05-11  9:42 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 ` Jani Nikula [this message]
2016-05-17  9:56   ` [PATCH i-g-t 2/2] lib/igt_aux: define actual functions for kmstest_*_str Daniel Vetter
2016-05-17 10:05     ` Jani Nikula
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=1462959726-7246-2-git-send-email-jani.nikula@intel.com \
    --to=jani.nikula@intel.com \
    --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