]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
Use C99 standard PRI*64 for printing 64 bit integers
authorNatanael Copa <ncopa@alpinelinux.org>
Fri, 18 Sep 2015 13:27:50 +0000 (15:27 +0200)
committerSimon McVittie <simon.mcvittie@collabora.co.uk>
Wed, 30 Sep 2015 17:36:23 +0000 (18:36 +0100)
Use the standard C99 PRI*64 macros instead of checking for specific GNU
libc version. We also specifically check for windows which does not have
proper C99 support.

This fixes printing of int64 on non-GNU 32 bit systems (like musl libc).

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=92043
Reviewed-by: Thiago Macieira <thiago@kde.org>
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
[smcv: fix extra % in the Windows fallbacks; include <inttypes.h> where needed]

configure.ac
dbus/dbus-marshal-basic.c
dbus/dbus-marshal-recursive-util.c
tools/dbus-print-message.c

index fa960f537308357685dec845b74fbf69dc95ba77..b41b221daa835374a9bac048065658bf4da05858 100644 (file)
@@ -337,31 +337,6 @@ if test x$enable_compiler_coverage = xyes; then
      AC_DEFINE_UNQUOTED(DBUS_GCOV_ENABLED, 1, [Defined if gcov is enabled to force a rebuild due to config.h changing])
 fi
 
-# glibc21.m4 serial 3
-dnl Copyright (C) 2000-2002, 2004 Free Software Foundation, Inc.
-dnl This file is free software; the Free Software Foundation
-dnl gives unlimited permission to copy and/or distribute it,
-dnl with or without modifications, as long as this notice is preserved.
-
-# Test for the GNU C Library, version 2.1 or newer.
-# From Bruno Haible.
-
-AC_CACHE_CHECK(whether we are using the GNU C Library 2.1 or newer,
-  ac_cv_gnu_library_2_1,
-  [AC_EGREP_CPP([Lucky GNU user],
-    [
-#include <features.h>
-#ifdef __GNU_LIBRARY__
- #if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 1) || (__GLIBC__ > 2)
-  Lucky GNU user
- #endif
-#endif
-    ],
-    ac_cv_gnu_library_2_1=yes,
-    ac_cv_gnu_library_2_1=no)
-  ]
-)
-
 #### Integer sizes
 
 AC_CHECK_SIZEOF(char)
@@ -380,32 +355,21 @@ $ac_cv_sizeof_int)
   dbusint64=int
   dbusint64_constant='(val)'
   dbusuint64_constant='(val)'
-  dbusint64_printf_modifier='""'
   ;;
 $ac_cv_sizeof_long)
   dbusint64=long
   dbusint64_constant='(val##L)'
   dbusuint64_constant='(val##UL)'
-  dbusint64_printf_modifier='"l"'
   ;;
 $ac_cv_sizeof_long_long)
   dbusint64='long long'
   dbusint64_constant='(val##LL)'
   dbusuint64_constant='(val##ULL)'
-  # Ideally we discover what the format is, but this is
-  # only used in verbose mode, so eh...
-  if test x"$ac_cv_gnu_library_2_1" = xyes; then
-    dbusint64_printf_modifier='"ll"'
-  fi
   ;;
 $ac_cv_sizeof___int64)
   dbusint64=__int64
   dbusint64_constant='(val##i64)'
   dbusuint64_constant='(val##ui64)'
-  # See above case
-  if test x"$ac_cv_gnu_library_2_1" = xyes; then
-    dbusint64_printf_modifier='"ll"'
-  fi
   ;;
 esac
 
@@ -423,9 +387,6 @@ Please report a bug here with details of your platform and compiler:
         DBUS_INT64_TYPE="$dbusint64"
         DBUS_INT64_CONSTANT="$dbusint64_constant"
         DBUS_UINT64_CONSTANT="$dbusuint64_constant"
-       if test x"$dbusint64_printf_modifier" != x; then
-               AC_DEFINE_UNQUOTED(DBUS_INT64_PRINTF_MODIFIER, [$dbusint64_printf_modifier], [Define to printf modifier for 64 bit integer type])
-       fi
         AC_MSG_RESULT($DBUS_INT64_TYPE)
   ])
 
index 74fe3f913ed45a48a7ca5d09d287ed48629327eb..855c8691c7ce92a9a1409d6394b53fa886ec7fc5 100644 (file)
 
 #include <string.h>
 
+#if !defined(PRIx64) && defined(DBUS_WIN)
+#define PRIx64 "I64x"
+#endif
+
 #if defined(__GNUC__) && (__GNUC__ >= 4)
 # define _DBUS_ASSERT_ALIGNMENT(type, op, val) \
   _DBUS_STATIC_ASSERT (__extension__ __alignof__ (type) op val)
@@ -1334,10 +1338,8 @@ _dbus_verbose_bytes (const unsigned char *data,
           if (i > 7 &&
               _DBUS_ALIGN_ADDRESS (&data[i], 8) == &data[i])
             {
-#ifdef DBUS_INT64_PRINTF_MODIFIER
-              _dbus_verbose (" u64: 0x%" DBUS_INT64_PRINTF_MODIFIER "x",
+              _dbus_verbose (" u64: 0x%" PRIx64,
                              *(dbus_uint64_t*)&data[i-8]);
-#endif
               _dbus_verbose (" dbl: %g",
                              *(double*)&data[i-8]);
             }
index 3bc26a8c3d5ab00b7f49d8eed4b80c8683a1b0ea..309da267cb0ad836dde813e1c33c38e29fbd27f4 100644 (file)
 #include "dbus-internals.h"
 #include <string.h>
 
+#if !defined(PRIx64) && defined(DBUS_WIN)
+#define PRIx64 "I64x"
+#endif
+
 static void
 basic_value_zero (DBusBasicValue *value)
 {
@@ -2644,12 +2648,10 @@ double_read_value (TestTypeNode   *node,
 
   if (!_DBUS_DOUBLES_BITWISE_EQUAL (v, expected))
     {
-#ifdef DBUS_INT64_PRINTF_MODIFIER
-      _dbus_warn ("Expected double %g got %g\n bits = 0x%" DBUS_INT64_PRINTF_MODIFIER "x vs.\n bits = 0x%" DBUS_INT64_PRINTF_MODIFIER "x)\n",
+      _dbus_warn ("Expected double %g got %g\n bits = 0x%" PRIx64 " vs.\n bits = 0x%" PRIx64 ")\n",
                   expected, v,
                   *(dbus_uint64_t*)(char*)&expected,
                   *(dbus_uint64_t*)(char*)&v);
-#endif
       _dbus_assert_not_reached ("test failed");
     }
 
index 80c969861b5c3a47b03a39a0bd1d793069741748..b747e877d3dd5c19c970273c108793b1343f51df 100644 (file)
 
 #include "tool-common.h"
 
+#ifdef HAVE_INTTYPES_H
+#include <inttypes.h>
+#endif
+
+#if defined(DBUS_WIN)
+#if !defined(PRId64)
+#define PRId64 "I64d"
+#endif
+#if !defined(PRIu64)
+#define PRIu64 "I64u"
+#endif
+#endif
+
 static const char*
 type_to_name (int message_type)
 {
@@ -384,11 +397,7 @@ print_iter (DBusMessageIter *iter, dbus_bool_t literal, int depth)
           {
             dbus_int64_t val;
             dbus_message_iter_get_basic (iter, &val);
-#ifdef DBUS_INT64_PRINTF_MODIFIER
-        printf ("int64 %" DBUS_INT64_PRINTF_MODIFIER "d\n", val);
-#else
-        printf ("int64 (omitted)\n");
-#endif
+            printf ("int64 %" PRId64 "\n", val);
             break;
           }
 
@@ -396,11 +405,7 @@ print_iter (DBusMessageIter *iter, dbus_bool_t literal, int depth)
           {
             dbus_uint64_t val;
             dbus_message_iter_get_basic (iter, &val);
-#ifdef DBUS_INT64_PRINTF_MODIFIER
-        printf ("uint64 %" DBUS_INT64_PRINTF_MODIFIER "u\n", val);
-#else
-        printf ("uint64 (omitted)\n");
-#endif
+            printf ("uint64 %" PRIu64 "\n", val);
             break;
           }