All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] drm/fourcc: introduce DRM_FOURCC_STANDALONE guard
@ 2021-02-04 11:37 Emil Velikov
  2021-02-04 17:37 ` James Park
  0 siblings, 1 reply; 8+ messages in thread
From: Emil Velikov @ 2021-02-04 11:37 UTC (permalink / raw)
  To: dri-devel; +Cc: Pekka Paalanen, emil.l.velikov, James Park

Currently, the drm_fourcc.h header depends on drm.h for __u32 and __u64.
At the same time drm.h pulls a lot of unneeded symbols.

Add new guard DRM_FOURCC_STANDALONE, which when set will use local
declaration of said symbols.

When used on linux - we pull linux/types.h which is used either way.
On other platforms, BSDs et al, we need a couple of typedefs.

Since those can trigger a warning in some corner-cases*, add some GCC
magic to silence them. Note that incorrect type redefinitions will still
be flagged, and the GCC pragma is ignored by other compilers.

*Corner-case:
If one sets DRM_FOURCC_STANDALONE and compiles with C99 or earlier while
also using -pedantic _and_ the header lives outside of the standard
/usr/include (like BSDs normally do).

v2:
 - Add corner-case handling, based on popular demand.

Cc: James Park <james.park@lagfreegames.com>
Cc: Pekka Paalanen <pekka.paalanen@collabora.com>
Cc: Simon Ser <contact@emersion.fr>
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
---
 include/uapi/drm/drm.h        | 10 ++++++++++
 include/uapi/drm/drm_fourcc.h | 29 +++++++++++++++++++++++++++++
 2 files changed, 39 insertions(+)

diff --git a/include/uapi/drm/drm.h b/include/uapi/drm/drm.h
index 808b48a93330..cd78950e05ce 100644
--- a/include/uapi/drm/drm.h
+++ b/include/uapi/drm/drm.h
@@ -53,6 +53,15 @@ typedef unsigned int drm_handle_t;
 #include <stdint.h>
 #include <sys/ioccom.h>
 #include <sys/types.h>
+
+/*
+ * When using C99 -pedantic the typedefs will trigger a warning.
+ * If the header is considered a system one (-isystem) those will be
+ * ignored, yet on the target platforms BSDs, et al - the headers live
+ * in a non-system location.
+ */
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wpedantic"
 typedef int8_t   __s8;
 typedef uint8_t  __u8;
 typedef int16_t  __s16;
@@ -63,6 +72,7 @@ typedef int64_t  __s64;
 typedef uint64_t __u64;
 typedef size_t   __kernel_size_t;
 typedef unsigned long drm_handle_t;
+#pragma GCC diagnostic pop
 
 #endif
 
diff --git a/include/uapi/drm/drm_fourcc.h b/include/uapi/drm/drm_fourcc.h
index 6f0628eb13a6..84a1f96cc4ef 100644
--- a/include/uapi/drm/drm_fourcc.h
+++ b/include/uapi/drm/drm_fourcc.h
@@ -24,7 +24,36 @@
 #ifndef DRM_FOURCC_H
 #define DRM_FOURCC_H
 
+/*
+ * Define DRM_FOURCC_STANDALONE you're interested only FOURCC and do not want
+ * to pull drm.h into your application.
+ */
+#ifdef DRM_FOURCC_STANDALONE
+#if defined(__linux__)
+
+#include <linux/types.h>
+
+#else /* One of the BSDs */
+
+#include <stdint.h>
+
+/*
+ * When using C99 -pedantic the typedefs will trigger a warning.
+ * If the header is considered a system one (-isystem) those will be
+ * ignored, yet on the target platforms BSDs, et al - the headers live
+ * in a non-system location.
+ */
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wpedantic"
+typedef uint32_t __u32;
+typedef uint64_t __u64;
+#pragma GCC diagnostic pop
+
+#endif /* __linux __ */
+
+#else
 #include "drm.h"
+#endif /* DRM_FOURCC_STANDALONE */
 
 #if defined(__cplusplus)
 extern "C" {
-- 
2.30.0

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-08-18  1:51 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-04 11:37 [PATCH v2] drm/fourcc: introduce DRM_FOURCC_STANDALONE guard Emil Velikov
2021-02-04 17:37 ` James Park
2021-02-04 18:17   ` James Park
2021-02-04 21:07     ` Emil Velikov
2021-02-04 21:15       ` James Park
2021-02-04 21:17         ` Simon Ser
2021-02-26  8:08       ` James Park
2021-08-18  1:51         ` James Park

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.