[cogl/wip/public-atlas-apis: 4/9] eglib: simplify compiler checks



commit 3691a0358d8dcda2294456d2e255b3a4d518cc9b
Author: Robert Bragg <robert linux intel com>
Date:   Thu Feb 13 17:37:14 2014 +0000

    eglib: simplify compiler checks
    
    This removes a number of ./configure time compiler checks in favour of
    compile time checks and also assumes you are building with a modern
    compiler. For example we assume <stdint.h> and <inttypes.h> headers are
    available.
    
    These changes will make it easier to maintain the ability to build Cogl
    on Android via an Android.mk file where it's not usual to use the build
    system to check compiler features.

 configure.ac                     |   83 ------------------------
 deps/eglib/src/eglib-config.h.in |   27 --------
 deps/eglib/src/glib.h            |  131 +++++++++++++++++++++-----------------
 deps/eglib/test/sizes.c          |   18 +----
 4 files changed, 75 insertions(+), 184 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index af50a97..066577a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1415,25 +1415,6 @@ dnl ================================================================
 dnl eglib checks.
 dnl ================================================================
 
-GNUC_PRETTY=
-GNUC_UNUSED=
-BREAKPOINT="G_STMT_START { raise (SIGTRAP); } G_STMT_END"
-if test x$GCC = xyes; then
-   GNUC_UNUSED='__attribute__((__unused__))'
-   GNUC_NORETURN='__attribute__((__noreturn__))'
-   case $host_cpu in
-     i*86|x86_64) BREAKPOINT="G_STMT_START { __asm__ (\"int \$03\"); } G_STMT_END" ;;
-   esac
-fi
-AC_SUBST(GNUC_PRETTY)
-AC_SUBST(GNUC_UNUSED)
-AC_SUBST(GNUC_NORETURN)
-AC_SUBST(BREAKPOINT)
-
-AC_CHECK_SIZEOF(int)
-AC_CHECK_SIZEOF(void *)
-AC_CHECK_SIZEOF(long)
-AC_CHECK_SIZEOF(long long)
 AC_CHECK_FUNCS(strlcpy stpcpy strtok_r rewinddir vasprintf)
 
 #
@@ -1459,75 +1440,11 @@ if test $found_export_dynamic = no; then
         LDFLAGS="${old_ldflags}"
 fi
 
-AC_MSG_CHECKING(for varargs macros)
-AC_TRY_COMPILE([],[
-int foo (int i, int j);
-#define bar(...) foo (1, __VA_ARGS__)
-void main () {
-         bar (2);
-}
-],have_iso_varargs=yes,have_iso_varargs=no)
-AC_MSG_RESULT($have_iso_varargs)
-G_HAVE_ISO_VARARGS=0
-if test "x$have_iso_varargs" = "xyes"; then
-   G_HAVE_ISO_VARARGS=1
-fi
-AC_SUBST(G_HAVE_ISO_VARARGS)
-
 AC_CHECK_HEADERS(getopt.h sys/time.h sys/wait.h pwd.h langinfo.h iconv.h localcharset.h sys/types.h)
 AC_CHECK_HEADER(alloca.h, [HAVE_ALLOCA_H=1], [HAVE_ALLOCA_H=0])
 AC_SUBST(HAVE_ALLOCA_H)
 
 
-if test $ac_cv_sizeof_void_p = $ac_cv_sizeof_int; then
-   GPOINTER_TO_INT="((gint) (ptr))"
-   GPOINTER_TO_UINT="((guint) (ptr))"
-   GINT_TO_POINTER="((gpointer) (v))"
-   GUINT_TO_POINTER="((gpointer) (v))"
-   GSIZE="int"
-   GSIZE_FORMAT='"u"'
-   G_GUINT64_FORMAT='"llu"'
-   G_GINT64_FORMAT='"lld"'
-   G_GUINT32_FORMAT='"lu"'
-   G_GINT32_FORMAT='"ld"'
-elif test $ac_cv_sizeof_void_p = $ac_cv_sizeof_long; then
-   GPOINTER_TO_INT="((gint)(long) (ptr))"
-   GPOINTER_TO_UINT="((guint)(long) (ptr))"
-   GINT_TO_POINTER="((gpointer)(glong) (v))"
-   GUINT_TO_POINTER="((gpointer)(gulong) (v))"
-   GSIZE="long"
-   GSIZE_FORMAT='"lu"'
-   G_GUINT64_FORMAT='"lu"'
-   G_GINT64_FORMAT='"ld"'
-   G_GUINT32_FORMAT='"u"'
-   G_GINT32_FORMAT='"d"'
-elif test $ac_cv_sizeof_void_p = $ac_cv_sizeof_long_long; then
-   GPOINTER_TO_INT="((gint)(long long) (ptr))"
-   GPOINTER_TO_UINT="((guint)(unsigned long long) (ptr))"
-   GINT_TO_POINTER="((gpointer)(long long) (v))"
-   GUINT_TO_POINTER="((gpointer)(unsigned long long) (v))"
-   GSIZE="long long"
-   GSIZE_FORMAT='"I64u"'
-   G_GUINT64_FORMAT='"I64u"'
-   G_GINT64_FORMAT='"I64i"'
-   G_GUINT32_FORMAT='"I32u"'
-   G_GINT32_FORMAT='"I32i"'
-else
-   AC_MSG_ERROR([unsupported pointer size])
-fi
-
-AC_SUBST(GPOINTER_TO_INT)
-AC_SUBST(GPOINTER_TO_UINT)
-AC_SUBST(GINT_TO_POINTER)
-AC_SUBST(GUINT_TO_POINTER)
-AC_SUBST(GSIZE)
-AC_SUBST(GSIZE_FORMAT)
-AC_SUBST(G_GUINT64_FORMAT)
-AC_SUBST(G_GINT64_FORMAT)
-AC_SUBST(G_GUINT32_FORMAT)
-AC_SUBST(G_GINT32_FORMAT)
-
-
 dnl ================================================================
 dnl Platform values
 dnl ================================================================
diff --git a/deps/eglib/src/eglib-config.h.in b/deps/eglib/src/eglib-config.h.in
index ba0f93f..a2dfc2b 100644
--- a/deps/eglib/src/eglib-config.h.in
+++ b/deps/eglib/src/eglib-config.h.in
@@ -4,43 +4,16 @@
 /*
  * System-dependent settings
  */
-#define G_GNUC_PRETTY_FUNCTION   @GNUC_PRETTY@
-#define G_GNUC_UNUSED            @GNUC_UNUSED@
-#define G_BYTE_ORDER             @ORDER@
-#define G_GNUC_NORETURN          @GNUC_NORETURN@
 #define G_SEARCHPATH_SEPARATOR_S "@SEARCHSEP@"
 #define G_SEARCHPATH_SEPARATOR   '@SEARCHSEP@'
 #define G_DIR_SEPARATOR          '@PATHSEP@'
 #define G_DIR_SEPARATOR_S        "@PATHSEP@"
-#define G_BREAKPOINT()           @BREAKPOINT@
 #define G_OS_ OS@
-#define GPOINTER_TO_INT(ptr)   @GPOINTER_TO_INT@
-#define GPOINTER_TO_UINT(ptr)  @GPOINTER_TO_UINT@
-#define GINT_TO_POINTER(v)     @GINT_TO_POINTER@
-#define GUINT_TO_POINTER(v)    @GUINT_TO_POINTER@
 
 #if @HAVE_ALLOCA_H@ == 1
 #define G_HAVE_ALLOCA_H
 #endif
 
-typedef unsigned @GSIZE@ gsize;
-typedef signed   @GSIZE@ gssize;
-
-#define G_GSIZE_FORMAT   @GSIZE_FORMAT@
-#define G_GUINT64_FORMAT @G_GUINT64_FORMAT@
-#define G_GINT64_FORMAT @G_GINT64_FORMAT@
-#define G_GUINT32_FORMAT @G_GUINT32_FORMAT@
-#define G_GINT32_FORMAT @G_GINT32_FORMAT@
-
-#if @G_HAVE_ISO_VARARGS@ == 1
-#define G_HAVE_ISO_VARARGS
-#endif
-
-#if defined (__native_client__)
-#undef G_BREAKPOINT
-#define G_BREAKPOINT()
-#endif
-
 typedef @PIDTYPE@ GPid;
 
 #endif
diff --git a/deps/eglib/src/glib.h b/deps/eglib/src/glib.h
index c717eed..a277448 100644
--- a/deps/eglib/src/glib.h
+++ b/deps/eglib/src/glib.h
@@ -14,11 +14,8 @@
 #pragma include_alias(<eglib-config.h>, <eglib-config.hw>)
 #endif
 
-/* VS 2010 and later have stdint.h */
-#if defined(_MSC_VER) && _MSC_VER < 1600
-#else
 #include <stdint.h>
-#endif
+#include <inttypes.h>
 
 #include <eglib-config.h>
 
@@ -67,21 +64,9 @@ typedef const void *   gconstpointer;
 typedef char           gchar;
 typedef unsigned char  guchar;
 
-/* VS 2010 and later have stdint.h */
-#if defined(_MSC_VER) && _MSC_VER < 1600
-typedef __int8                 gint8;
-typedef unsigned __int8                guint8;
-typedef __int16                        gint16;
-typedef unsigned __int16       guint16;
-typedef __int32                        gint32;
-typedef unsigned __int32       guint32;
-typedef __int64                        gint64;
-typedef unsigned __int64       guint64;
-typedef float                  gfloat;
-typedef double                 gdouble;
-typedef int                    gboolean;
-#else
-/* Types defined in terms of the stdint.h */
+typedef size_t         gsize;
+typedef ssize_t        gssize;
+
 typedef int8_t         gint8;
 typedef uint8_t        guint8;
 typedef int16_t        gint16;
@@ -93,7 +78,6 @@ typedef uint64_t       guint64;
 typedef float          gfloat;
 typedef double         gdouble;
 typedef int32_t        gboolean;
-#endif
 
 typedef guint16 gunichar2;
 typedef guint32 gunichar;
@@ -123,6 +107,11 @@ typedef guint32 gunichar;
 #define G_MAXUINT64         UINT64_MAX
 #define G_MAXFLOAT           FLT_MAX
 
+#define G_GUINT64_FORMAT     PRIu64
+#define G_GINT64_FORMAT      PRId64
+#define G_GUINT32_FORMAT     PRIu32
+#define G_GINT32_FORMAT      PRId32
+
 #define G_LITTLE_ENDIAN 1234
 #define G_BIG_ENDIAN    4321
 #define G_STMT_START    do
@@ -135,9 +124,10 @@ typedef guint32 gunichar;
 #define G_GINT64_CONSTANT(val)  (val##LL)
 #define G_GUINT64_CONSTANT(val) (val##UL)
 
-#ifndef ABS
-#define ABS(a)         ((a) > 0 ? (a) : -(a))
-#endif
+#define GPOINTER_TO_INT(ptr)   ((gint)(intptr_t)(ptr))
+#define GPOINTER_TO_UINT(ptr)  ((guint)(uintptr_t)(ptr))
+#define GINT_TO_POINTER(v)     ((gpointer)(intptr_t)(v))
+#define GUINT_TO_POINTER(v)    ((gpointer)(uintptr_t)(v))
 
 #define G_STRUCT_OFFSET(p_type,field) offsetof(p_type,field)
 
@@ -145,6 +135,65 @@ typedef guint32 gunichar;
 
 #define G_CONST_RETURN const
 
+#define G_BYTE_ORDER G_LITTLE_ENDIAN
+
+#if defined(__GNUC__)
+#  define G_GNUC_UNUSED                       __attribute__((__unused__))
+#  define G_GNUC_NORETURN                     __attribute__((__noreturn__))
+#  define G_LIKELY(expr)                      (__builtin_expect ((expr) != 0, 1))
+#  define G_UNLIKELY(expr)                    (__builtin_expect ((expr) != 0, 0))
+#  define G_GNUC_PRINTF(format_idx, arg_idx)  __attribute__((__format__ (__printf__, format_idx, arg_idx)))
+#else
+#  define G_GNUC_UNUSED
+#  define G_GNUC_NORETURN
+#  define G_LIKELY(expr) (expr)
+#  define G_UNLIKELY(expr) (expr)
+#  define G_GNUC_PRINTF(format_idx, arg_idx)
+#endif
+
+#if defined(__GNUC__)
+#  define G_STRFUNC ((const char *)(__PRETTY_FUNCTION__))
+#elif defined (_MSC_VER)
+#  define G_STRFUNC ((const char*) (__FUNCTION__))
+#else
+#  define G_STRFUNC ((const char*) (__func__))
+#endif
+
+#if defined (_MSC_VER)
+#  define G_VA_COPY(dest, src) ((dest) = (src))
+#else
+#  define G_VA_COPY(dest, src) va_copy (dest, src)
+#endif
+
+#ifdef OS_UNIX
+#define G_BREAKPOINT() G_STMT_START { raise (SIGTRAP); } G_STMT_END
+#else
+#define G_BREAKPOINT()
+#endif
+
+#if defined (__native_client__)
+#undef G_BREAKPOINT
+#define G_BREAKPOINT()
+#endif
+
+#ifndef ABS
+#define ABS(a)    ((a) > 0 ? (a) : -(a))
+#endif
+
+#ifndef MAX
+#define MAX(a,b)  (((a)>(b)) ? (a) : (b))
+#endif
+
+#ifndef MIN
+#define MIN(a,b)  (((a)<(b)) ? (a) : (b))
+#endif
+
+#ifndef CLAMP
+#define CLAMP(a,low,high) (((a) < (low)) ? (low) : (((a) > (high)) ? (high) : (a)))
+#endif
+
+
+
 /*
  * Allocation
  */
@@ -807,42 +856,6 @@ gboolean       g_unichar_isxdigit (gunichar c);
 gint           g_unichar_xdigit_value (gunichar c);
 GUnicodeBreakType   g_unichar_break_type (gunichar c);
 
-#ifndef MAX
-#define MAX(a,b) (((a)>(b)) ? (a) : (b))
-#endif
-
-#ifndef MIN
-#define MIN(a,b) (((a)<(b)) ? (a) : (b))
-#endif
-
-#ifndef CLAMP
-#define CLAMP(a,low,high) (((a) < (low)) ? (low) : (((a) > (high)) ? (high) : (a)))
-#endif
-
-#if defined(__GNUC__)
-#  define G_LIKELY(expr) (__builtin_expect ((expr) != 0, 1))
-#  define G_UNLIKELY(expr) (__builtin_expect ((expr) != 0, 0))
-#  define G_GNUC_PRINTF(format_idx, arg_idx) __attribute__((__format__ (__printf__, format_idx, arg_idx)))
-#else
-#  define G_LIKELY(expr) (expr)
-#  define G_UNLIKELY(expr) (expr)
-#  define G_GNUC_PRINTF(format_idx, arg_idx)
-#endif
-
-#if defined(__GNUC__)
-#  define G_STRFUNC ((const char *)(__PRETTY_FUNCTION__))
-#elif defined (_MSC_VER)
-#  define G_STRFUNC ((const char*) (__FUNCTION__))
-#else
-#  define G_STRFUNC ((const char*) (__func__))
-#endif
-
-#if defined (_MSC_VER)
-#  define G_VA_COPY(dest, src) ((dest) = (src))
-#else
-#  define G_VA_COPY(dest, src) va_copy (dest, src)
-#endif
-
 #define  g_assert(x)     G_STMT_START { if (G_UNLIKELY (!(x))) g_assertion_message ("* Assertion at %s:%d, 
condition `%s' not met\n", __FILE__, __LINE__, #x);  } G_STMT_END
 #define  g_assert_not_reached() G_STMT_START { g_assertion_message ("* Assertion: should not be reached at 
%s:%d\n", __FILE__, __LINE__); } G_STMT_END
 
diff --git a/deps/eglib/test/sizes.c b/deps/eglib/test/sizes.c
index 06ed8a5..f3657da 100644
--- a/deps/eglib/test/sizes.c
+++ b/deps/eglib/test/sizes.c
@@ -12,17 +12,6 @@
 #include "test.h"
 
 RESULT
-test_formats ()
-{
-       char buffer [1024];
-       gsize a = 1;
-       
-       sprintf (buffer, "%" G_GSIZE_FORMAT, a);
-
-       return NULL;
-}
-
-RESULT
 test_ptrconv ()
 {
        int iv, iv2;
@@ -64,7 +53,7 @@ test_ptrconv ()
        uv2 = GPOINTER_TO_UINT (ptr);
        if (uv != uv2)
                return FAILED ("uint to pointer and back conversions fail %u != %d", uv, uv2);
-       
+
        uv = 1;
        ptr = GUINT_TO_POINTER (uv);
        uv2 = GPOINTER_TO_UINT (ptr);
@@ -78,7 +67,7 @@ test_ptrconv ()
                return FAILED ("uint to pointer and back conversions fail %u != %d", uv, uv2);
 
        return NULL;
-       
+
 }
 
 typedef struct {
@@ -91,7 +80,7 @@ test_offset ()
 {
        if (G_STRUCT_OFFSET (my_struct, a) != 0)
                return FAILED ("offset of a is not zero");
-       
+
        if (G_STRUCT_OFFSET (my_struct, b) != 4 && G_STRUCT_OFFSET (my_struct, b) != 8)
                return FAILED ("offset of b is 4 or 8, macro might be busted");
 
@@ -99,7 +88,6 @@ test_offset ()
 }
 
 static Test size_tests [] = {
-       {"formats", test_formats},
        {"ptrconv", test_ptrconv},
        {"g_struct_offset", test_offset},
        {NULL, NULL}


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