goto fail;
}
- /* We assume PRIu64 exists on all Unix platforms: it's ISO C99, and the
- * only non-C99 platform we support is MSVC on Windows. */
if (!_dbus_string_append_printf (&path,
- "/org/freedesktop/DBus/Containers1/c%" PRIu64,
+ "/org/freedesktop/DBus/Containers1/c%" DBUS_INT64_MODIFIER "u",
containers->next_container_id++))
{
BUS_SET_OOM (error);
set(DBUS_INT64_TYPE "int")
set(DBUS_INT64_CONSTANT "(val)")
set(DBUS_UINT64_CONSTANT "(val##U)")
+ set(DBUS_INT64_MODIFIER "")
elseif(SIZEOF_LONG EQUAL 8)
set(DBUS_INT64_TYPE "long")
set(DBUS_INT64_CONSTANT "(val##L)")
set(DBUS_UINT64_CONSTANT "(val##UL)")
+ set(DBUS_INT64_MODIFIER "l")
elseif(SIZEOF_LONG_LONG EQUAL 8)
set(DBUS_INT64_TYPE "long long")
set(DBUS_INT64_CONSTANT "(val##LL)")
set(DBUS_UINT64_CONSTANT "(val##ULL)")
+ set(DBUS_INT64_MODIFIER "ll")
elseif(SIZEOF___INT64 EQUAL 8)
set(DBUS_INT64_TYPE "__int64")
set(DBUS_INT64_CONSTANT "(val##i64)")
set(DBUS_UINT64_CONSTANT "(val##ui64)")
+ set(DBUS_INT64_MODIFIER "I64")
else(SIZEOF_INT EQUAL 8)
message(FATAL_ERROR "Could not find a 64-bit integer type")
endif()
+# MSVCRT.dll printf() doesn't support %lld
+if(WIN32 AND NOT CYGWIN)
+ set(DBUS_INT64_MODIFIER "I64")
+endif()
+
# DBUS_INT32_TYPE
if(SIZEOF_INT EQUAL 4)
set(DBUS_INT32_TYPE "int")
dbusint64=int
dbusint64_constant='(val)'
dbusuint64_constant='(val)'
+ dbusint64_modifier=""
;;
$ac_cv_sizeof_long)
dbusint64=long
dbusint64_constant='(val##L)'
dbusuint64_constant='(val##UL)'
+ dbusint64_modifier="l"
;;
$ac_cv_sizeof_long_long)
dbusint64='long long'
dbusint64_constant='(val##LL)'
dbusuint64_constant='(val##ULL)'
+ dbusint64_modifier="ll"
;;
$ac_cv_sizeof___int64)
dbusint64=__int64
dbusint64_constant='(val##i64)'
dbusuint64_constant='(val##ui64)'
+ dbusint64_modifier="I64"
;;
esac
+# MSVCRT.dll printf() doesn't support %lld
+AS_IF([test "$dbus_win" = yes], [dbusint64_modifier="I64"])
+
AS_IF(
[test -z "$dbusint64"],
[AC_MSG_RESULT([not found])
DBUS_INT64_TYPE="$dbusint64"
DBUS_INT64_CONSTANT="$dbusint64_constant"
DBUS_UINT64_CONSTANT="$dbusuint64_constant"
+ DBUS_INT64_MODIFIER="$dbusint64_modifier"
AC_MSG_RESULT($DBUS_INT64_TYPE)
])
AC_SUBST(DBUS_INT64_TYPE)
AC_SUBST(DBUS_INT64_CONSTANT)
AC_SUBST(DBUS_UINT64_CONSTANT)
+AC_SUBST(DBUS_INT64_MODIFIER)
### see what 32-bit int is called
AC_MSG_CHECKING([32-bit integer type])
#define DBUS_HAVE_INT64 1
_DBUS_GNUC_EXTENSION typedef @DBUS_INT64_TYPE@ dbus_int64_t;
_DBUS_GNUC_EXTENSION typedef unsigned @DBUS_INT64_TYPE@ dbus_uint64_t;
+#define DBUS_INT64_MODIFIER "@DBUS_INT64_MODIFIER@"
#define DBUS_INT64_CONSTANT(val) (_DBUS_GNUC_EXTENSION @DBUS_INT64_CONSTANT@)
#define DBUS_UINT64_CONSTANT(val) (_DBUS_GNUC_EXTENSION @DBUS_UINT64_CONSTANT@)
#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)
if (i > 7 &&
_DBUS_ALIGN_ADDRESS (&data[i], 8) == &data[i])
{
- _dbus_verbose (" u64: 0x%" PRIx64,
+ _dbus_verbose (" u64: 0x%" DBUS_INT64_MODIFIER "x",
*(dbus_uint64_t*)&data[i-8]);
_dbus_verbose (" dbl: %g",
*(double*)&data[i-8]);
* giving a literal such as "325145246765ULL"
*/
+/**
+ * @def DBUS_INT64_MODIFIER
+ *
+ * A string literal for a length modifier that is appropriate to print
+ * the #dbus_int64_t and #dbus_uint64_t types.
+ * For example, it might be an empty string, "l", "ll", or "I64".
+ *
+ * This modifier needs to be concatenated with a literal "%" and a
+ * conversion specifier that can print signed or unsigned integers,
+ * for example:
+ *
+ * @code
+ * dbus_int64_t i = -123;
+ * dbus_uint64_t u = 456;
+ *
+ * printf ("signed: %" DBUS_INT64_MODIFIER "d\n", i);
+ * printf ("unsigned decimal: %" DBUS_INT64_MODIFIER "u\n", u);
+ * printf ("unsigned hex: 0x%" DBUS_INT64_MODIFIER "x\n", x);
+ * @endcode
+ */
+
/**
* An 8-byte struct you could use to access int64 without having
* int64 support. Use #dbus_int64_t or #dbus_uint64_t instead.
test_assertions_LDADD = libdbus-testutils.la $(GLIB_LIBS)
test_printf_SOURCES = internals/printf.c
-test_printf_LDADD = $(top_builddir)/dbus/libdbus-internal.la
+test_printf_LDADD = libdbus-testutils.la
test_refs_SOURCES = internals/refs.c
test_refs_LDADD = libdbus-testutils.la $(GLIB_LIBS)
#include <dbus/dbus-test-tap.h>
#include <string.h>
-#if !defined(PRIx64) && defined(DBUS_WIN)
-#define PRIx64 "I64x"
-#endif
-
/** turn this on to get deluged in TypeWriter verbose spam */
#define RECURSIVE_MARSHAL_WRITE_TRACE 0
expected = double_from_seed (seed);
if (!_DBUS_DOUBLES_BITWISE_EQUAL (v, expected))
- _dbus_test_fatal ("Expected double %g got %g\n bits = 0x%" PRIx64 " vs.\n bits = 0x%" PRIx64,
+ _dbus_test_fatal ("Expected double %g got %g\n"
+ " bits = 0x%" DBUS_INT64_MODIFIER "x vs.\n"
+ " bits = 0x%" DBUS_INT64_MODIFIER "x",
expected, v,
*(dbus_uint64_t*)(char*)&expected,
*(dbus_uint64_t*)(char*)&v);
#define X_TIMES_512 X_TIMES_256 X_TIMES_256
#define X_TIMES_1024 X_TIMES_512 X_TIMES_512
+static void
+print64 (void)
+{
+ dbus_int64_t i = -123;
+ dbus_uint64_t u = 456;
+ DBusString buf = _DBUS_STRING_INIT_INVALID;
+ const char expected[] = "i=-123;u=456;x=1c8";
+
+ if (!_dbus_string_init (&buf))
+ _dbus_test_fatal ("out of memory");
+
+ if (!_dbus_string_append_printf (&buf,
+ "i=%" DBUS_INT64_MODIFIER "d;"
+ "u=%" DBUS_INT64_MODIFIER "u;"
+ "x=%" DBUS_INT64_MODIFIER "x",
+ i, u, u))
+ _dbus_test_fatal ("out of memory");
+
+ if (_dbus_string_get_length (&buf) != (int) strlen (expected) ||
+ strcmp (_dbus_string_get_const_data (&buf), expected) != 0)
+ _dbus_test_fatal ("expected: \"%s\", got: %d chars \"%s\"",
+ expected,
+ _dbus_string_get_length (&buf),
+ _dbus_string_get_const_data (&buf));
+
+ _dbus_string_free (&buf);
+}
+
/* This test outputs TAP syntax: http://testanything.org/ */
int
main (int argc,
}
printf ("ok %d\n", ++test_num);
+ print64 ();
+ printf ("ok %d\n", ++test_num);
+
/* Tell the TAP driver that we have done all the tests we plan to do.
* This is how it can distinguish between an unexpected exit and
* successful completion. */
#include <inttypes.h>
#endif
-#if defined(DBUS_WIN)
-#if !defined(PRId64)
-#define PRId64 "I64d"
-#endif
-#if !defined(PRIu64)
-#define PRIu64 "I64u"
-#endif
-#endif
-
#ifndef HAVE_SOCKLEN_T
#define socklen_t int
#endif
{
dbus_int64_t val;
dbus_message_iter_get_basic (iter, &val);
- printf ("int64 %" PRId64 "\n", val);
+ printf ("int64 %" DBUS_INT64_MODIFIER "d\n", val);
break;
}
{
dbus_uint64_t val;
dbus_message_iter_get_basic (iter, &val);
- printf ("uint64 %" PRIu64 "\n", val);
+ printf ("uint64 %" DBUS_INT64_MODIFIER "u\n", val);
break;
}