mirror of
https://github.com/postgres/postgres.git
synced 2025-08-09 17:03:00 +03:00
Define integer limits independently from the system definitions.
In 83ff1618
we defined integer limits iff they're not provided by the
system. That turns out not to be the greatest idea because there's
different ways some datatypes can be represented. E.g. on OSX PG's 64bit
datatype will be a 'long int', but OSX unconditionally uses 'long
long'. That disparity then can lead to warnings, e.g. around printf
formats.
One way to fix that would be to back int64 using stdint.h's
int64_t. While a good idea it's not that easy to implement. We would
e.g. need to include stdint.h in our external headers, which we don't
today. Also computing the correct int64 printf formats in that case is
nontrivial.
Instead simply prefix the integer limits with PG_ and define them
unconditionally. I've adjusted all the references to them in code, but
not the ones in comments; the latter seems unnecessary to me.
Discussion: 20150331141423.GK4878@alap3.anarazel.de
This commit is contained in:
@@ -249,36 +249,6 @@ typedef uint8 bits8; /* >= 8 bits */
|
||||
typedef uint16 bits16; /* >= 16 bits */
|
||||
typedef uint32 bits32; /* >= 32 bits */
|
||||
|
||||
/* should be defined in stdint.h, but we guarantee them here */
|
||||
#ifndef INT8_MIN
|
||||
#define INT8_MIN (-0x7F-1)
|
||||
#endif
|
||||
#ifndef INT8_MAX
|
||||
#define INT8_MAX (0x7F)
|
||||
#endif
|
||||
#ifndef INT16_MIN
|
||||
#define INT16_MIN (-0x7FFF-1)
|
||||
#endif
|
||||
#ifndef INT16_MAX
|
||||
#define INT16_MAX (0x7FFF)
|
||||
#endif
|
||||
#ifndef INT32_MIN
|
||||
#define INT32_MIN (-0x7FFFFFFF-1)
|
||||
#endif
|
||||
#ifndef INT32_MAX
|
||||
#define INT32_MAX (0x7FFFFFFF)
|
||||
#endif
|
||||
|
||||
#ifndef UINT8_MAX
|
||||
#define UINT8_MAX (0xFF)
|
||||
#endif
|
||||
#ifndef UINT16_MAX
|
||||
#define UINT16_MAX (0xFFFF)
|
||||
#endif
|
||||
#ifndef UINT32_MAX
|
||||
#define UINT32_MAX (0xFFFFFFFF)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* 64-bit integers
|
||||
*/
|
||||
@@ -314,26 +284,10 @@ typedef unsigned long long int uint64;
|
||||
#define UINT64CONST(x) ((uint64) x)
|
||||
#endif
|
||||
|
||||
/* should be defined in stdint.h, but we guarantee them here */
|
||||
#ifndef INT64_MIN
|
||||
#define INT64_MIN (-INT64CONST(0x7FFFFFFFFFFFFFFF) - 1)
|
||||
#endif
|
||||
#ifndef INT64_MAX
|
||||
#define INT64_MAX INT64CONST(0x7FFFFFFFFFFFFFFF)
|
||||
#endif
|
||||
#ifndef UINT64_MAX
|
||||
#define UINT64_MAX UINT64CONST(0xFFFFFFFFFFFFFFFF)
|
||||
#endif
|
||||
|
||||
/* snprintf format strings to use for 64-bit integers */
|
||||
#define INT64_FORMAT "%" INT64_MODIFIER "d"
|
||||
#define UINT64_FORMAT "%" INT64_MODIFIER "u"
|
||||
|
||||
/* Select timestamp representation (float8 or int64) */
|
||||
#ifdef USE_INTEGER_DATETIMES
|
||||
#define HAVE_INT64_TIMESTAMP
|
||||
#endif
|
||||
|
||||
/*
|
||||
* 128-bit signed and unsigned integers
|
||||
* There currently is only a limited support for the type. E.g. 128bit
|
||||
@@ -345,6 +299,28 @@ typedef PG_INT128_TYPE int128;
|
||||
typedef unsigned PG_INT128_TYPE uint128;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* stdint.h limits aren't guaranteed to be present and aren't guaranteed to
|
||||
* have compatible types with our fixed width types. So just define our own.
|
||||
*/
|
||||
#define PG_INT8_MIN (-0x7F-1)
|
||||
#define PG_INT8_MAX (0x7F)
|
||||
#define PG_UINT8_MAX (0xFF)
|
||||
#define PG_INT16_MIN (-0x7FFF-1)
|
||||
#define PG_INT16_MAX (0x7FFF)
|
||||
#define PG_UINT16_MAX (0xFFFF)
|
||||
#define PG_INT32_MIN (-0x7FFFFFFF-1)
|
||||
#define PG_INT32_MAX (0x7FFFFFFF)
|
||||
#define PG_UINT32_MAX (0xFFFFFFFF)
|
||||
#define PG_INT64_MIN (-INT64CONST(0x7FFFFFFFFFFFFFFF) - 1)
|
||||
#define PG_INT64_MAX INT64CONST(0x7FFFFFFFFFFFFFFF)
|
||||
#define PG_UINT64_MAX UINT64CONST(0xFFFFFFFFFFFFFFFF)
|
||||
|
||||
/* Select timestamp representation (float8 or int64) */
|
||||
#ifdef USE_INTEGER_DATETIMES
|
||||
#define HAVE_INT64_TIMESTAMP
|
||||
#endif
|
||||
|
||||
/* sig_atomic_t is required by ANSI C, but may be missing on old platforms */
|
||||
#ifndef HAVE_SIG_ATOMIC_T
|
||||
typedef int sig_atomic_t;
|
||||
|
Reference in New Issue
Block a user