Bug 730805 - Provide mozilla/IntegerPrintfMacros.h to implement the PRI* macros portion of the <inttypes.h> interface. r=espindola

--HG--
extra : rebase_source : be80333003c6fec659e736a77463568c836d8348
This commit is contained in:
Jeff Walden 2011-12-15 00:27:42 -05:00
Родитель 2e1d99cde5
Коммит de9ce95170
12 изменённых файлов: 1358 добавлений и 135 удалений

Просмотреть файл

@ -1733,6 +1733,16 @@ case "$host" in
;;
esac
dnl Check for using a custom <inttypes.h> implementation
dnl ========================================================
AC_MSG_CHECKING(for custom <inttypes.h> implementation)
if test "$MOZ_CUSTOM_INTTYPES_H"; then
AC_DEFINE_UNQUOTED(MOZ_CUSTOM_INTTYPES_H, "$MOZ_CUSTOM_INTTYPES_H")
AC_MSG_RESULT(using $MOZ_CUSTOM_INTTYPES_H)
else
AC_MSG_RESULT(none specified)
fi
dnl Get mozilla version from central milestone file
MOZILLA_VERSION=`$PERL $srcdir/config/milestone.pl -topsrcdir $srcdir`
MOZILLA_UAVERSION=`$PERL $srcdir/config/milestone.pl -topsrcdir $srcdir -uaversion`

Просмотреть файл

@ -12,7 +12,7 @@
#include "base/port.h" // Types that only need exist on certain systems
#include "mozilla/Assertions.h"
#include <stdint.h>
#include "mozilla/IntegerPrintfMacros.h"
// A type to represent a Unicode code-point value. As of Unicode 4.0,
// such values require up to 21 bits.
@ -35,15 +35,10 @@ const int64_t kint64max = (( int64_t) GG_LONGLONG(0x7FFFFFFFFFFFFFFF));
// Platform- and hardware-dependent printf specifiers
# if defined(OS_POSIX)
# define __STDC_FORMAT_MACROS 1
# include <inttypes.h> // for 64-bit integer format macros
# define PRId64L "I64d"
# define PRIu64L "I64u"
# define PRIx64L "I64x"
# elif defined(OS_WIN)
# define PRId64 "I64d"
# define PRIu64 "I64u"
# define PRIx64 "I64x"
# define PRId64L L"I64d"
# define PRIu64L L"I64u"
# define PRIx64L L"I64x"

Просмотреть файл

@ -15,9 +15,17 @@
/*
* The c99 defining the limit macros (UINT32_MAX for example), says:
* C++ implementations should define these macros only when __STDC_LIMIT_MACROS
* is defined before <stdint.h> is included.
*
* C++ implementations should define these macros only when
* __STDC_LIMIT_MACROS is defined before <stdint.h> is included.
*
* The same also occurs with __STDC_CONSTANT_MACROS for the constant macros
* (INT8_C for example) used to specify a literal constant of the proper type,
* and with __STDC_FORMAT_MACROS for the format macros (PRId32 for example) used
* with the fprintf function family.
*/
#define __STDC_LIMIT_MACROS
#define __STDC_CONSTANT_MACROS
#define __STDC_FORMAT_MACROS
#endif /* js_RequiredDefines_h */

Просмотреть файл

@ -1359,6 +1359,16 @@ case "$host" in
;;
esac
dnl Check for using a custom <inttypes.h> implementation
dnl ========================================================
AC_MSG_CHECKING(for custom <inttypes.h> implementation)
if test "$MOZ_CUSTOM_INTTYPES_H"; then
AC_DEFINE_UNQUOTED(MOZ_CUSTOM_INTTYPES_H, "$MOZ_CUSTOM_INTTYPES_H")
AC_MSG_RESULT(using $MOZ_CUSTOM_INTTYPES_H)
else
AC_MSG_RESULT(none specified)
fi
MOZ_DOING_LTO(lto_is_enabled)
dnl ========================================================

Просмотреть файл

@ -0,0 +1,40 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
/* Implements the C99 <inttypes.h> interface, minus the SCN* format macros. */
#ifndef mozilla_IntegerPrintfMacros_h_
#define mozilla_IntegerPrintfMacros_h_
/*
* MSVC++ doesn't include <inttypes.h>, even in versions shipping <stdint.h>, so
* we have to reimplement it there. Note: <inttypes.h> #includes <stdint.h>.
*
* Note that this header DOES NOT implement <inttypes.h>'s scanf macros. MSVC's
* scanf doesn't have sufficient format specifier support to implement them
* (specifically, to implement scanning into an 8-bit location).
*
* http://stackoverflow.com/questions/3036396/scanfd-char-char-as-int-format-string
*
* Moreover, scanf is a footgun: if the input number exceeds the bounds of the
* target type, behavior is undefined (in the compiler sense: that is, this code
* could overwrite your hard drive with zeroes):
*
* uint8_t u;
* sscanf("256", "%" SCNu8, &u); // BAD
*
* This header will sometimes provide SCN* macros, by dint of being implemented
* using <inttypes.h>. But for these reasons, *never* use them!
*/
#if defined(MOZ_CUSTOM_INTTYPES_H)
# include MOZ_CUSTOM_INTTYPES_H
#elif defined(_MSC_VER)
# include "mozilla/MSIntTypes.h"
#else
# include <inttypes.h>
#endif
#endif /* mozilla_IntegerPrintfMacros_h_ */

Просмотреть файл

@ -40,7 +40,7 @@
#pragma once
#endif
#include "stdint.h"
#include <stdint.h>
// 7.8 Format conversion of integer types
@ -151,115 +151,8 @@ typedef struct {
#define PRIxPTR "Ix"
#define PRIXPTR "IX"
// The fscanf macros for signed integers are:
#define SCNd8 "d"
#define SCNi8 "i"
#define SCNdLEAST8 "d"
#define SCNiLEAST8 "i"
#define SCNdFAST8 "d"
#define SCNiFAST8 "i"
#define SCNd16 "hd"
#define SCNi16 "hi"
#define SCNdLEAST16 "hd"
#define SCNiLEAST16 "hi"
#define SCNdFAST16 "hd"
#define SCNiFAST16 "hi"
#define SCNd32 "ld"
#define SCNi32 "li"
#define SCNdLEAST32 "ld"
#define SCNiLEAST32 "li"
#define SCNdFAST32 "ld"
#define SCNiFAST32 "li"
#define SCNd64 "I64d"
#define SCNi64 "I64i"
#define SCNdLEAST64 "I64d"
#define SCNiLEAST64 "I64i"
#define SCNdFAST64 "I64d"
#define SCNiFAST64 "I64i"
#define SCNdMAX "I64d"
#define SCNiMAX "I64i"
#ifdef _WIN64 // [
# define SCNdPTR "I64d"
# define SCNiPTR "I64i"
#else // _WIN64 ][
# define SCNdPTR "ld"
# define SCNiPTR "li"
#endif // _WIN64 ]
// The fscanf macros for unsigned integers are:
#define SCNo8 "o"
#define SCNu8 "u"
#define SCNx8 "x"
#define SCNX8 "X"
#define SCNoLEAST8 "o"
#define SCNuLEAST8 "u"
#define SCNxLEAST8 "x"
#define SCNXLEAST8 "X"
#define SCNoFAST8 "o"
#define SCNuFAST8 "u"
#define SCNxFAST8 "x"
#define SCNXFAST8 "X"
#define SCNo16 "ho"
#define SCNu16 "hu"
#define SCNx16 "hx"
#define SCNX16 "hX"
#define SCNoLEAST16 "ho"
#define SCNuLEAST16 "hu"
#define SCNxLEAST16 "hx"
#define SCNXLEAST16 "hX"
#define SCNoFAST16 "ho"
#define SCNuFAST16 "hu"
#define SCNxFAST16 "hx"
#define SCNXFAST16 "hX"
#define SCNo32 "lo"
#define SCNu32 "lu"
#define SCNx32 "lx"
#define SCNX32 "lX"
#define SCNoLEAST32 "lo"
#define SCNuLEAST32 "lu"
#define SCNxLEAST32 "lx"
#define SCNXLEAST32 "lX"
#define SCNoFAST32 "lo"
#define SCNuFAST32 "lu"
#define SCNxFAST32 "lx"
#define SCNXFAST32 "lX"
#define SCNo64 "I64o"
#define SCNu64 "I64u"
#define SCNx64 "I64x"
#define SCNX64 "I64X"
#define SCNoLEAST64 "I64o"
#define SCNuLEAST64 "I64u"
#define SCNxLEAST64 "I64x"
#define SCNXLEAST64 "I64X"
#define SCNoFAST64 "I64o"
#define SCNuFAST64 "I64u"
#define SCNxFAST64 "I64x"
#define SCNXFAST64 "I64X"
#define SCNoMAX "I64o"
#define SCNuMAX "I64u"
#define SCNxMAX "I64x"
#define SCNXMAX "I64X"
#ifdef _WIN64 // [
# define SCNoPTR "I64o"
# define SCNuPTR "I64u"
# define SCNxPTR "I64x"
# define SCNXPTR "I64X"
#else // _WIN64 ][
# define SCNoPTR "lo"
# define SCNuPTR "lu"
# define SCNxPTR "lx"
# define SCNXPTR "lX"
#endif // _WIN64 ]
// DO NOT SUPPORT THE scanf MACROS! See the comment at the top of
// IntegerPrintfMacros.h.
#endif // __STDC_FORMAT_MACROS ]

Просмотреть файл

@ -28,6 +28,7 @@ EXPORTS_mozilla += \
FloatingPoint.h \
GuardObjects.h \
HashFunctions.h \
IntegerPrintfMacros.h \
Likely.h \
LinkedList.h \
MathAlgorithms.h \

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -79,24 +79,15 @@
* at all. Thus, it is not used here.
*/
#include "mozilla/IntegerPrintfMacros.h"
#include "mozilla/NullPtr.h"
// MAP_ANON(YMOUS) is not in any standard, and the C99 PRI* macros are
// not in C++98. Add defines as necessary.
#define __STDC_FORMAT_MACROS
// MAP_ANON(YMOUS) is not in any standard. Add defines as necessary.
#define _GNU_SOURCE 1
#define _DARWIN_C_SOURCE 1
#include <stddef.h>
#ifndef _WIN32
#include <inttypes.h>
#else
#define PRIxPTR "Ix"
typedef unsigned int uint32_t;
// MSVC defines uintptr_t in <crtdefs.h> which is brought in implicitly
#endif
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>

Просмотреть файл

@ -14,6 +14,7 @@ CPP_UNIT_TESTS += [
'TestEndian.cpp',
'TestEnumSet.cpp',
'TestFloatingPoint.cpp',
'TestIntegerPrintfMacros.cpp',
'TestSHA1.cpp',
'TestTypeTraits.cpp',
'TestWeakPtr.cpp',

Просмотреть файл

@ -8,13 +8,24 @@
@ALLDEFINES@
/* The c99 defining the limit macros (UINT32_MAX for example), says:
* C++ implementations should define these macros only when __STDC_LIMIT_MACROS
* is defined before <stdint.h> is included. */
/*
* The c99 defining the limit macros (UINT32_MAX for example), says:
*
* C++ implementations should define these macros only when
* __STDC_LIMIT_MACROS is defined before <stdint.h> is included.
*
* The same also occurs with __STDC_CONSTANT_MACROS for the constant macros
* (INT8_C for example) used to specify a literal constant of the proper type,
* and with __STDC_FORMAT_MACROS for the format macros (PRId32 for example) used
* with the fprintf function family.
*/
#define __STDC_LIMIT_MACROS
#define __STDC_CONSTANT_MACROS
#define __STDC_FORMAT_MACROS
/* Force-include hunspell_alloc_hooks.h and hunspell_fopen_hooks.h for hunspell,
* so that we don't need to modify it directly.
/*
* Force-include hunspell_alloc_hooks.h and hunspell_fopen_hooks.h for hunspell,
* so that we don't need to modify them directly.
*
* HUNSPELL_STATIC is defined in extensions/spellcheck/hunspell/src/Makefile.in,
* unless --enable-system-hunspell is defined.

Просмотреть файл

@ -10,7 +10,6 @@ VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
EXPORT_LIBRARY = 1
DEFINES += -D__STDC_CONSTANT_MACROS
include $(topsrcdir)/config/rules.mk