mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-27 13:53:31 +01:00
Require stdint.h and inttypes.h
We've been silently requiring stdint.h for a while now, and nobody has complained. Closes ticket 26626.
This commit is contained in:
parent
a01b4d7f87
commit
e2a94dc481
3
changes/ticket26626
Normal file
3
changes/ticket26626
Normal file
@ -0,0 +1,3 @@
|
||||
o Code simplification and refactoring:
|
||||
- Tor now assumes that you have standards-conformant stdint.h and
|
||||
inttypes.h headers when compiling. Closes ticket 26626.
|
17
configure.ac
17
configure.ac
@ -1393,7 +1393,6 @@ AC_CHECK_HEADERS([errno.h \
|
||||
netinet/in6.h \
|
||||
pwd.h \
|
||||
readpassphrase.h \
|
||||
stdint.h \
|
||||
stdatomic.h \
|
||||
sys/eventfd.h \
|
||||
sys/file.h \
|
||||
@ -1517,22 +1516,6 @@ AC_CHECK_MEMBERS([struct timeval.tv_sec], , ,
|
||||
#include <sys/time.h>
|
||||
#endif])
|
||||
|
||||
dnl In case we aren't given a working stdint.h, we'll need to grow our own.
|
||||
dnl Watch out.
|
||||
|
||||
AC_CHECK_SIZEOF(int8_t)
|
||||
AC_CHECK_SIZEOF(int16_t)
|
||||
AC_CHECK_SIZEOF(int32_t)
|
||||
AC_CHECK_SIZEOF(int64_t)
|
||||
AC_CHECK_SIZEOF(uint8_t)
|
||||
AC_CHECK_SIZEOF(uint16_t)
|
||||
AC_CHECK_SIZEOF(uint32_t)
|
||||
AC_CHECK_SIZEOF(uint64_t)
|
||||
AC_CHECK_SIZEOF(intptr_t)
|
||||
AC_CHECK_SIZEOF(uintptr_t)
|
||||
|
||||
dnl AC_CHECK_TYPES([int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, uint32_t, uint64_t, intptr_t, uintptr_t])
|
||||
|
||||
AC_CHECK_SIZEOF(char)
|
||||
AC_CHECK_SIZEOF(short)
|
||||
AC_CHECK_SIZEOF(int)
|
||||
|
@ -7,6 +7,7 @@
|
||||
#define TOR_COMPAT_COMPILER_H
|
||||
|
||||
#include "orconfig.h"
|
||||
#include <inttypes.h>
|
||||
|
||||
#if defined(__has_feature)
|
||||
# if __has_feature(address_sanitizer)
|
||||
@ -183,53 +184,19 @@
|
||||
#define OP_EQ ==
|
||||
#define OP_NE !=
|
||||
|
||||
#ifdef _MSC_VER
|
||||
/** Casts the uint64_t value in <b>a</b> to the right type for an argument
|
||||
* to printf. */
|
||||
#define U64_PRINTF_ARG(a) (a)
|
||||
/** Casts the uint64_t* value in <b>a</b> to the right type for an argument
|
||||
* to scanf. */
|
||||
#define U64_SCANF_ARG(a) (a)
|
||||
/** Expands to a literal uint64_t-typed constant for the value <b>n</b>. */
|
||||
#define U64_LITERAL(n) (n ## ui64)
|
||||
#define I64_PRINTF_ARG(a) (a)
|
||||
#define I64_SCANF_ARG(a) (a)
|
||||
#define I64_LITERAL(n) (n ## i64)
|
||||
#else /* !(defined(_MSC_VER)) */
|
||||
#define U64_PRINTF_ARG(a) ((long long unsigned int)(a))
|
||||
#define U64_SCANF_ARG(a) ((long long unsigned int*)(a))
|
||||
#define U64_LITERAL(n) (n ## llu)
|
||||
#define I64_PRINTF_ARG(a) ((long long signed int)(a))
|
||||
#define I64_SCANF_ARG(a) ((long long signed int*)(a))
|
||||
#define I64_LITERAL(n) (n ## ll)
|
||||
#endif /* defined(_MSC_VER) */
|
||||
|
||||
#if defined(__MINGW32__) || defined(__MINGW64__)
|
||||
#define MINGW_ANY
|
||||
#endif
|
||||
|
||||
#if defined(_MSC_VER) || defined(MINGW_ANY)
|
||||
/** The formatting string used to put a uint64_t value in a printf() or
|
||||
* scanf() function. See also U64_PRINTF_ARG and U64_SCANF_ARG. */
|
||||
#define U64_FORMAT "%I64u"
|
||||
#define I64_FORMAT "%I64d"
|
||||
#else /* !(defined(_MSC_VER) || defined(MINGW_ANY)) */
|
||||
#define U64_FORMAT "%llu"
|
||||
#define I64_FORMAT "%lld"
|
||||
#endif /* defined(_MSC_VER) || defined(MINGW_ANY) */
|
||||
|
||||
#if (SIZEOF_INTPTR_T == SIZEOF_INT)
|
||||
#define INTPTR_T_FORMAT "%d"
|
||||
#define INTPTR_PRINTF_ARG(x) ((int)(x))
|
||||
#elif (SIZEOF_INTPTR_T == SIZEOF_LONG)
|
||||
#define INTPTR_T_FORMAT "%ld"
|
||||
#define INTPTR_PRINTF_ARG(x) ((long)(x))
|
||||
#elif (SIZEOF_INTPTR_T == 8)
|
||||
#define INTPTR_T_FORMAT I64_FORMAT
|
||||
#define INTPTR_PRINTF_ARG(x) I64_PRINTF_ARG(x)
|
||||
#else
|
||||
#error Unknown: SIZEOF_INTPTR_T
|
||||
#endif /* (SIZEOF_INTPTR_T == SIZEOF_INT) || ... */
|
||||
#define U64_PRINTF_ARG(a) ((uint64_t)a)
|
||||
#define U64_SCANF_ARG(a) (a)
|
||||
#define U64_LITERAL(n) UINT64_C(n)
|
||||
#define I64_PRINTF_ARG(a) ((int64_t)a)
|
||||
#define I64_SCANF_ARG(a) (a)
|
||||
#define I64_LITERAL(n) INT64_C(n)
|
||||
#define U64_FORMAT "%"PRIu64
|
||||
#define I64_FORMAT "%"PRId64
|
||||
#define INTPTR_T_FORMAT "%"PRIuPTR
|
||||
|
||||
/** Macro: yield a pointer to the field at position <b>off</b> within the
|
||||
* structure <b>st</b>. Example:
|
||||
|
@ -19,189 +19,16 @@
|
||||
|
||||
#include "orconfig.h"
|
||||
|
||||
#ifdef HAVE_STDINT_H
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
#include <stdbool.h>
|
||||
#include <limits.h>
|
||||
|
||||
#ifdef HAVE_SYS_TYPES_H
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
#ifdef HAVE_LIMITS_H
|
||||
#include <limits.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_LIMITS_H
|
||||
#include <sys/limits.h>
|
||||
#endif
|
||||
#ifdef HAVE_MACHINE_LIMITS_H
|
||||
#if !defined(__FreeBSD__) && !defined(__FreeBSD_kernel__)
|
||||
/* FreeBSD has a bug where it complains that this file is obsolete,
|
||||
and I should migrate to using sys/limits. It complains even when
|
||||
I include both.
|
||||
__FreeBSD_kernel__ is defined by Debian GNU/kFreeBSD which
|
||||
does the same thing (but doesn't defined __FreeBSD__).
|
||||
*/
|
||||
#include <machine/limits.h>
|
||||
#endif /* !defined(__FreeBSD__) && !defined(__FreeBSD_kernel__) */
|
||||
#endif /* defined(HAVE_MACHINE_LIMITS_H) */
|
||||
#ifdef HAVE_INTTYPES_H
|
||||
#include <inttypes.h>
|
||||
#endif
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#if (SIZEOF_INT8_T != 0)
|
||||
#define HAVE_INT8_T
|
||||
#endif
|
||||
#if (SIZEOF_INT16_T != 0)
|
||||
#define HAVE_INT16_T
|
||||
#endif
|
||||
#if (SIZEOF_INT32_T != 0)
|
||||
#define HAVE_INT32_T
|
||||
#endif
|
||||
#if (SIZEOF_INT64_T != 0)
|
||||
#define HAVE_INT64_T
|
||||
#endif
|
||||
#if (SIZEOF_UINT8_T != 0)
|
||||
#define HAVE_UINT8_T
|
||||
#endif
|
||||
#if (SIZEOF_UINT16_T != 0)
|
||||
#define HAVE_UINT16_T
|
||||
#endif
|
||||
#if (SIZEOF_UINT32_T != 0)
|
||||
#define HAVE_UINT32_T
|
||||
#endif
|
||||
#if (SIZEOF_UINT64_T != 0)
|
||||
#define HAVE_UINT64_T
|
||||
#endif
|
||||
#if (SIZEOF_INTPTR_T != 0)
|
||||
#define HAVE_INTPTR_T
|
||||
#endif
|
||||
#if (SIZEOF_UINTPTR_T != 0)
|
||||
#define HAVE_UINTPTR_T
|
||||
#endif
|
||||
|
||||
#if (SIZEOF_CHAR == 1)
|
||||
#ifndef HAVE_INT8_T
|
||||
typedef signed char int8_t;
|
||||
#define HAVE_INT8_T
|
||||
#endif
|
||||
#ifndef HAVE_UINT8_T
|
||||
typedef unsigned char uint8_t;
|
||||
#define HAVE_UINT8_T
|
||||
#endif
|
||||
#endif /* (SIZEOF_CHAR == 1) */
|
||||
|
||||
#if (SIZEOF_SHORT == 2)
|
||||
#ifndef HAVE_INT16_T
|
||||
typedef signed short int16_t;
|
||||
#define HAVE_INT16_T
|
||||
#endif
|
||||
#ifndef HAVE_UINT16_T
|
||||
typedef unsigned short uint16_t;
|
||||
#define HAVE_UINT16_T
|
||||
#endif
|
||||
#endif /* (SIZEOF_SHORT == 2) */
|
||||
|
||||
#if (SIZEOF_INT == 2)
|
||||
#ifndef HAVE_INT16_T
|
||||
typedef signed int int16_t;
|
||||
#define HAVE_INT16_T
|
||||
#endif
|
||||
#ifndef HAVE_UINT16_T
|
||||
typedef unsigned int uint16_t;
|
||||
#define HAVE_UINT16_T
|
||||
#endif
|
||||
#elif (SIZEOF_INT == 4)
|
||||
#ifndef HAVE_INT32_T
|
||||
typedef signed int int32_t;
|
||||
#define HAVE_INT32_T
|
||||
#endif
|
||||
#ifndef HAVE_UINT32_T
|
||||
typedef unsigned int uint32_t;
|
||||
#define HAVE_UINT32_T
|
||||
#endif
|
||||
#ifndef UINT16_MAX
|
||||
#define UINT16_MAX 0xffffu
|
||||
#endif
|
||||
#ifndef INT16_MAX
|
||||
#define INT16_MAX 0x7fff
|
||||
#endif
|
||||
#ifndef INT16_MIN
|
||||
#define INT16_MIN (-INT16_MAX-1)
|
||||
#endif
|
||||
#ifndef UINT32_MAX
|
||||
#define UINT32_MAX 0xffffffffu
|
||||
#endif
|
||||
#ifndef INT32_MAX
|
||||
#define INT32_MAX 0x7fffffff
|
||||
#endif
|
||||
#ifndef INT32_MIN
|
||||
#define INT32_MIN (-2147483647-1)
|
||||
#endif
|
||||
#endif /* (SIZEOF_INT == 2) || ... */
|
||||
|
||||
#if (SIZEOF_LONG == 4)
|
||||
#ifndef HAVE_INT32_T
|
||||
typedef signed long int32_t;
|
||||
#define HAVE_INT32_T
|
||||
#endif
|
||||
#ifndef HAVE_UINT32_T
|
||||
typedef unsigned long uint32_t;
|
||||
#define HAVE_UINT32_T
|
||||
#ifndef UINT32_MAX
|
||||
#define UINT32_MAX 0xfffffffful
|
||||
#endif
|
||||
#endif /* !defined(HAVE_UINT32_T) */
|
||||
#elif (SIZEOF_LONG == 8)
|
||||
#ifndef HAVE_INT64_T
|
||||
typedef signed long int64_t;
|
||||
#define HAVE_INT64_T
|
||||
#endif
|
||||
#ifndef HAVE_UINT32_T
|
||||
typedef unsigned long uint64_t;
|
||||
#define HAVE_UINT32_T
|
||||
#endif
|
||||
#ifndef UINT64_MAX
|
||||
#define UINT64_MAX 0xfffffffffffffffful
|
||||
#endif
|
||||
#endif /* (SIZEOF_LONG == 4) || ... */
|
||||
|
||||
#if (SIZEOF_LONG_LONG == 8)
|
||||
#ifndef HAVE_INT64_T
|
||||
typedef signed long long int64_t;
|
||||
#define HAVE_INT64_T
|
||||
#endif
|
||||
#ifndef HAVE_UINT64_T
|
||||
typedef unsigned long long uint64_t;
|
||||
#define HAVE_UINT64_T
|
||||
#endif
|
||||
#ifndef UINT64_MAX
|
||||
#define UINT64_MAX 0xffffffffffffffffull
|
||||
#endif
|
||||
#ifndef INT64_MAX
|
||||
#define INT64_MAX 0x7fffffffffffffffll
|
||||
#endif
|
||||
#endif /* (SIZEOF_LONG_LONG == 8) */
|
||||
|
||||
#if (SIZEOF___INT64 == 8)
|
||||
#ifndef HAVE_INT64_T
|
||||
typedef signed __int64 int64_t;
|
||||
#define HAVE_INT64_T
|
||||
#endif
|
||||
#ifndef HAVE_UINT64_T
|
||||
typedef unsigned __int64 uint64_t;
|
||||
#define HAVE_UINT64_T
|
||||
#endif
|
||||
#ifndef UINT64_MAX
|
||||
#define UINT64_MAX 0xffffffffffffffffui64
|
||||
#endif
|
||||
#ifndef INT64_MAX
|
||||
#define INT64_MAX 0x7fffffffffffffffi64
|
||||
#endif
|
||||
#endif /* (SIZEOF___INT64 == 8) */
|
||||
|
||||
#ifndef INT64_MIN
|
||||
#define INT64_MIN ((- INT64_MAX) - 1)
|
||||
#endif
|
||||
|
||||
#ifndef SIZE_MAX
|
||||
#if SIZEOF_SIZE_T == 8
|
||||
@ -223,100 +50,12 @@ typedef int32_t ssize_t;
|
||||
#endif /* SIZEOF_SIZE_T == 8 || ... */
|
||||
#endif /* !defined(HAVE_SSIZE_T) */
|
||||
|
||||
#if (SIZEOF_VOID_P > 4 && SIZEOF_VOID_P <= 8)
|
||||
#ifndef HAVE_INTPTR_T
|
||||
typedef int64_t intptr_t;
|
||||
#define SIZEOF_INTPTR_T 8
|
||||
#endif
|
||||
#ifndef HAVE_UINTPTR_T
|
||||
typedef uint64_t uintptr_t;
|
||||
#define SIZEOF_UINTPTR_T 8
|
||||
#endif
|
||||
#elif (SIZEOF_VOID_P > 2 && SIZEOF_VOID_P <= 4)
|
||||
#ifndef HAVE_INTPTR_T
|
||||
typedef int32_t intptr_t;
|
||||
#define SIZEOF_INTPTR_T 4
|
||||
#endif
|
||||
#ifndef HAVE_UINTPTR_T
|
||||
typedef uint32_t uintptr_t;
|
||||
#define SIZEOF_UINTPTR_T 4
|
||||
#endif
|
||||
#else
|
||||
#error "void * is either >8 bytes or <= 2. In either case, I am confused."
|
||||
#endif /* (SIZEOF_VOID_P > 4 && SIZEOF_VOID_P <= 8) || ... */
|
||||
|
||||
#ifndef HAVE_INT8_T
|
||||
#error "Missing type int8_t"
|
||||
#endif
|
||||
#ifndef HAVE_UINT8_T
|
||||
#error "Missing type uint8_t"
|
||||
#endif
|
||||
#ifndef HAVE_INT16_T
|
||||
#error "Missing type int16_t"
|
||||
#endif
|
||||
#ifndef HAVE_UINT16_T
|
||||
#error "Missing type uint16_t"
|
||||
#endif
|
||||
#ifndef HAVE_INT32_T
|
||||
#error "Missing type int32_t"
|
||||
#endif
|
||||
#ifndef HAVE_UINT32_T
|
||||
#error "Missing type uint32_t"
|
||||
#endif
|
||||
#ifndef HAVE_INT64_T
|
||||
#error "Missing type int64_t"
|
||||
#endif
|
||||
#ifndef HAVE_UINT64_T
|
||||
#error "Missing type uint64_t"
|
||||
#endif
|
||||
|
||||
/* This assumes a sane (2's-complement) representation. But if you
|
||||
* aren't 2's complement, and you don't define LONG_MAX, then you're so
|
||||
* bizarre that I want nothing to do with you. */
|
||||
#ifndef USING_TWOS_COMPLEMENT
|
||||
#error "Seems that your platform doesn't use 2's complement arithmetic. Argh."
|
||||
#endif
|
||||
#ifndef LONG_MAX
|
||||
#if (SIZEOF_LONG == 4)
|
||||
#define LONG_MAX 0x7fffffffL
|
||||
#elif (SIZEOF_LONG == 8)
|
||||
#define LONG_MAX 0x7fffffffffffffffL
|
||||
#else
|
||||
#error "Can't define LONG_MAX"
|
||||
#endif /* (SIZEOF_LONG == 4) || ... */
|
||||
#endif /* !defined(LONG_MAX) */
|
||||
|
||||
#ifndef INT_MAX
|
||||
#if (SIZEOF_INT == 4)
|
||||
#define INT_MAX 0x7fffffffL
|
||||
#elif (SIZEOF_INT == 8)
|
||||
#define INT_MAX 0x7fffffffffffffffL
|
||||
#else
|
||||
#error "Can't define INT_MAX"
|
||||
#endif /* (SIZEOF_INT == 4) || ... */
|
||||
#endif /* !defined(INT_MAX) */
|
||||
|
||||
#ifndef UINT_MAX
|
||||
#if (SIZEOF_INT == 2)
|
||||
#define UINT_MAX 0xffffu
|
||||
#elif (SIZEOF_INT == 4)
|
||||
#define UINT_MAX 0xffffffffu
|
||||
#elif (SIZEOF_INT == 8)
|
||||
#define UINT_MAX 0xffffffffffffffffu
|
||||
#else
|
||||
#error "Can't define UINT_MAX"
|
||||
#endif /* (SIZEOF_INT == 2) || ... */
|
||||
#endif /* !defined(UINT_MAX) */
|
||||
|
||||
#ifndef SHORT_MAX
|
||||
#if (SIZEOF_SHORT == 2)
|
||||
#define SHORT_MAX 0x7fff
|
||||
#elif (SIZEOF_SHORT == 4)
|
||||
#define SHORT_MAX 0x7fffffff
|
||||
#else
|
||||
#error "Can't define SHORT_MAX"
|
||||
#endif /* (SIZEOF_SHORT == 2) || ... */
|
||||
#endif /* !defined(SHORT_MAX) */
|
||||
|
||||
#ifndef TIME_MAX
|
||||
|
||||
@ -356,6 +95,10 @@ typedef uint32_t uintptr_t;
|
||||
#endif /* (SIZEOF_SIZE_T == 4) || ... */
|
||||
#endif /* !defined(SIZE_MAX) */
|
||||
|
||||
#ifndef SHORT_MAX
|
||||
#define SHORT_MAX SHRT_MAX
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
# ifdef _WIN64
|
||||
# define TOR_PRIuSZ PRIu64
|
||||
|
Loading…
Reference in New Issue
Block a user