[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v2 2/5] cmocka: Move some additional definitions to cmocka_extra.h


cmocka.h is quite large and it begins with a lot of
ifndefs which are not directly related to cmocka API.

This commits move all those ifndefs and typedefs to
separate header file called cmocka_extra.h.

Signed-off-by: Krzysztof Opasiak <k.opasiak@xxxxxxxxxxx>
---
 include/CMakeLists.txt |    1 +
 include/cmocka.h       |  116 +----------------------------------------
 include/cmocka_extra.h |  134 ++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 136 insertions(+), 115 deletions(-)
 create mode 100644 include/cmocka_extra.h

diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt
index 4cca031..b4f9a5c 100644
--- a/include/CMakeLists.txt
+++ b/include/CMakeLists.txt
@@ -3,6 +3,7 @@ project(cmocka-headers C)
 set(cmocka_HDRS
   cmocka.h
   cmocka_pbc.h
+  cmocka_extra.h
 )
 
 install(
diff --git a/include/cmocka.h b/include/cmocka.h
index c5614e5..1d6abd1 100644
--- a/include/cmocka.h
+++ b/include/cmocka.h
@@ -16,24 +16,7 @@
 #ifndef CMOCKA_H_
 #define CMOCKA_H_
 
-#ifdef _WIN32
-# ifdef _MSC_VER
-
-# ifndef inline
-#define inline __inline
-# endif /* inline */
-
-#  if _MSC_VER < 1500
-#   ifdef __cplusplus
-extern "C" {
-#   endif   /* __cplusplus */
-int __stdcall IsDebuggerPresent();
-#   ifdef __cplusplus
-} /* extern "C" */
-#   endif   /* __cplusplus */
-#  endif  /* _MSC_VER < 1500 */
-# endif /* _MSC_VER */
-#endif  /* _WIN32 */
+#include <cmocka_extra.h>
 
 /**
  * @defgroup cmocka The CMocka API
@@ -51,103 +34,6 @@ int __stdcall IsDebuggerPresent();
  * @{
  */
 
-/* For those who are used to __func__ from gcc. */
-#ifndef __func__
-#define __func__ __FUNCTION__
-#endif
-
-/*
- * Largest integral type.  This type should be large enough to hold any
- * pointer or integer supported by the compiler.
- */
-
-/* If __WORDSIZE is not set, try to figure it out and default to 32 bit. */
-#ifndef __WORDSIZE
-# if defined(__x86_64__) && !defined(__ILP32__)
-#  define __WORDSIZE 64
-# else
-#  define __WORDSIZE 32
-# endif
-#endif
-
-#ifndef LargestIntegralType
-# if __WORDSIZE == 64
-#  define LargestIntegralType unsigned long int
-# else
-#  define LargestIntegralType unsigned long long int
-# endif
-#endif /* LargestIntegralType */
-
-/* Printf format used to display LargestIntegralType. */
-#ifndef LargestIntegralTypePrintfFormat
-# ifdef _WIN32
-#  define LargestIntegralTypePrintfFormat "0x%I64x"
-# else
-#  if __WORDSIZE == 64
-#   define LargestIntegralTypePrintfFormat "%#lx"
-#  else
-#   define LargestIntegralTypePrintfFormat "%#llx"
-#  endif
-# endif /* _WIN32 */
-#endif /* LargestIntegralTypePrintfFormat */
-
-/* Perform an unsigned cast to LargestIntegralType. */
-#define cast_to_largest_integral_type(value) \
-    ((LargestIntegralType)(value))
-
-/* Smallest integral type capable of holding a pointer. */
-#if !defined(_UINTPTR_T) && !defined(_UINTPTR_T_DEFINED)
-# if defined(_WIN32)
-    /* WIN32 is an ILP32 platform */
-    typedef unsigned int uintptr_t;
-# elif defined(_WIN64)
-    typedef unsigned long int uintptr_t
-# else /* _WIN32 */
-
-/* ILP32 and LP64 platforms */
-#  ifdef __WORDSIZE /* glibc */
-#   if __WORDSIZE == 64
-      typedef unsigned long int uintptr_t;
-#   else
-      typedef unsigned int uintptr_t;
-#   endif /* __WORDSIZE == 64 */
-#  else /* __WORDSIZE */
-#   if defined(_LP64) || defined(_I32LPx)
-      typedef unsigned long int uintptr_t;
-#   else
-      typedef unsigned int uintptr_t;
-#   endif
-#  endif /* __WORDSIZE */
-# endif /* _WIN32 */
-
-# define _UINTPTR_T
-# define _UINTPTR_T_DEFINED
-#endif /* !defined(_UINTPTR_T) || !defined(_UINTPTR_T_DEFINED) */
-
-/* Perform an unsigned cast to uintptr_t. */
-#define cast_to_pointer_integral_type(value) \
-    ((uintptr_t)((size_t)(value)))
-
-/* Perform a cast of a pointer to uintmax_t */
-#define cast_ptr_to_largest_integral_type(value) \
-cast_to_largest_integral_type(cast_to_pointer_integral_type(value))
-
-/* GCC have printf type attribute check.  */
-#ifdef __GNUC__
-#define CMOCKA_PRINTF_ATTRIBUTE(a,b) \
-    __attribute__ ((__format__ (__printf__, a, b)))
-#else
-#define CMOCKA_PRINTF_ATTRIBUTE(a,b)
-#endif /* __GNUC__ */
-
-#if defined(__GNUC__)
-#define CMOCKA_DEPRECATED __attribute__ ((deprecated))
-#elif defined(_MSC_VER)
-#define CMOCKA_DEPRECATED __declspec(deprecated)
-#else
-#define CMOCKA_DEPRECATED
-#endif
-
 /**
  * @defgroup cmocka_mock Mock Objects
  * @ingroup cmocka
diff --git a/include/cmocka_extra.h b/include/cmocka_extra.h
new file mode 100644
index 0000000..1a96abd
--- /dev/null
+++ b/include/cmocka_extra.h
@@ -0,0 +1,134 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef CMOCKA_EXTRA_H_
+#define CMOCKA_EXTRA_H_
+
+#ifdef _WIN32
+# ifdef _MSC_VER
+
+# ifndef inline
+#define inline __inline
+# endif /* inline */
+
+#  if _MSC_VER < 1500
+#   ifdef __cplusplus
+extern "C" {
+#   endif   /* __cplusplus */
+int __stdcall IsDebuggerPresent();
+#   ifdef __cplusplus
+} /* extern "C" */
+#   endif   /* __cplusplus */
+#  endif  /* _MSC_VER < 1500 */
+# endif /* _MSC_VER */
+#endif  /* _WIN32 */
+
+/* For those who are used to __func__ from gcc. */
+#ifndef __func__
+#define __func__ __FUNCTION__
+#endif
+
+/* If __WORDSIZE is not set, try to figure it out and default to 32 bit. */
+#ifndef __WORDSIZE
+# if defined(__x86_64__) && !defined(__ILP32__)
+#  define __WORDSIZE 64
+# else
+#  define __WORDSIZE 32
+# endif
+#endif
+
+/*
+ * Largest integral type.  This type should be large enough to hold any
+ * pointer or integer supported by the compiler.
+ */
+#ifndef LargestIntegralType
+# if __WORDSIZE == 64
+#  define LargestIntegralType unsigned long int
+# else
+#  define LargestIntegralType unsigned long long int
+# endif
+#endif /* LargestIntegralType */
+
+/* Printf format used to display LargestIntegralType. */
+#ifndef LargestIntegralTypePrintfFormat
+# ifdef _WIN32
+#  define LargestIntegralTypePrintfFormat "0x%I64x"
+# else
+#  if __WORDSIZE == 64
+#   define LargestIntegralTypePrintfFormat "%#lx"
+#  else
+#   define LargestIntegralTypePrintfFormat "%#llx"
+#  endif
+# endif /* _WIN32 */
+#endif /* LargestIntegralTypePrintfFormat */
+
+/* Perform an unsigned cast to LargestIntegralType. */
+#define cast_to_largest_integral_type(value) \
+    ((LargestIntegralType)(value))
+
+/* Smallest integral type capable of holding a pointer. */
+#if !defined(_UINTPTR_T) && !defined(_UINTPTR_T_DEFINED)
+# if defined(_WIN32)
+    /* WIN32 is an ILP32 platform */
+    typedef unsigned int uintptr_t;
+# elif defined(_WIN64)
+    typedef unsigned long int uintptr_t
+# else /* _WIN32 */
+
+/* ILP32 and LP64 platforms */
+#  ifdef __WORDSIZE /* glibc */
+#   if __WORDSIZE == 64
+      typedef unsigned long int uintptr_t;
+#   else
+      typedef unsigned int uintptr_t;
+#   endif /* __WORDSIZE == 64 */
+#  else /* __WORDSIZE */
+#   if defined(_LP64) || defined(_I32LPx)
+      typedef unsigned long int uintptr_t;
+#   else
+      typedef unsigned int uintptr_t;
+#   endif
+#  endif /* __WORDSIZE */
+# endif /* _WIN32 */
+
+# define _UINTPTR_T
+# define _UINTPTR_T_DEFINED
+#endif /* !defined(_UINTPTR_T) || !defined(_UINTPTR_T_DEFINED) */
+
+/* Perform an unsigned cast to uintptr_t. */
+#define cast_to_pointer_integral_type(value) \
+  ((uintptr_t)(size_t)(value))
+
+/* Perform a cast of a pointer to uintmax_t */
+#define cast_ptr_to_largest_integral_type(value) \
+cast_to_largest_integral_type(cast_to_pointer_integral_type(value))
+
+/* GCC have printf type attribute check.  */
+#ifdef __GNUC__
+#define CMOCKA_PRINTF_ATTRIBUTE(a,b) \
+    __attribute__ ((__format__ (__printf__, a, b)))
+#else
+#define CMOCKA_PRINTF_ATTRIBUTE(a,b)
+#endif /* __GNUC__ */
+
+#if defined(__GNUC__)
+#define CMOCKA_DEPRECATED __attribute__ ((deprecated))
+#elif defined(_MSC_VER)
+#define CMOCKA_DEPRECATED __declspec(deprecated)
+#else
+#define CMOCKA_DEPRECATED
+#endif
+
+
+#endif /* CMOCKA_EXTRA_H_ */
-- 
1.7.9.5



Follow-Ups:
Re: [PATCH v2 2/5] cmocka: Move some additional definitions to cmocka_extra.hAndreas Schneider <asn@xxxxxxxxxxxxxx>
References:
[PATCH v2 0/5] cmocka: Make casting macros publicKrzysztof Opasiak <k.opasiak@xxxxxxxxxxx>