kmod-0001-Add-configure-check-for-_Static_assert.patch 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. From d4a1e5daf0d50aa79ae0ed2f947f5657343cf2f7 Mon Sep 17 00:00:00 2001
  2. From: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
  3. Date: Wed, 28 Aug 2013 17:31:40 +0200
  4. Subject: [PATCH] Add configure check for _Static_assert()
  5. Commit 8efede20ef ("Use _Static_assert") introduced the usage of
  6. _Static_assert(). However, _Static_assert() is a fairly new thing,
  7. since it was introduced only in gcc 4.6. In order to support older
  8. compilers, this patch adds a configure.in test that checks whether
  9. _Static_assert() is usable or not, and adjust the behavior of the
  10. assert_cc() macro accordingly.
  11. Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
  12. Upstream-status: submitted
  13. http://article.gmane.org/gmane.linux.kernel.modules/1136
  14. ---
  15. configure.ac | 6 ++++++
  16. libkmod/macro.h | 4 ++++
  17. 2 files changed, 10 insertions(+)
  18. diff --git a/configure.ac b/configure.ac
  19. index 40e54cf..cbe12f3 100644
  20. --- a/configure.ac
  21. +++ b/configure.ac
  22. @@ -52,6 +52,12 @@ AC_CHECK_MEMBERS([struct stat.st_mtim], [], [], [#include <sys/stat.h>])
  23. # Check kernel headers
  24. AC_CHECK_HEADERS_ONCE([linux/module.h])
  25. +AC_MSG_CHECKING([whether _Static_assert() is supported])
  26. +AC_COMPILE_IFELSE(
  27. + [AC_LANG_SOURCE([[_Static_assert(1, "Test");]])],
  28. + [AC_DEFINE([HAVE_STATIC_ASSERT], [1], [Define is _Static_assert() is available])
  29. + AC_MSG_RESULT([yes])],
  30. + [AC_MSG_RESULT([no])])
  31. #####################################################################
  32. # --with-
  33. diff --git a/libkmod/macro.h b/libkmod/macro.h
  34. index c6ba855..5992026 100644
  35. --- a/libkmod/macro.h
  36. +++ b/libkmod/macro.h
  37. @@ -21,8 +21,12 @@
  38. #include <stddef.h>
  39. +#if defined(HAVE_STATIC_ASSERT)
  40. #define assert_cc(expr) \
  41. _Static_assert((expr), #expr)
  42. +#else
  43. +#define assert_cc(expr)
  44. +#endif
  45. #if HAVE_TYPEOF
  46. #define check_types_match(expr1, expr2) \
  47. --
  48. 1.8.1.2