Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3a0f8e7

Browse files
committed
Make [U]INT64CONST safe for use in #if conditions.
Instead of using a cast to force the constant to be the right width,assume we can plaster on an L, UL, LL, or ULL suffix as appropriate.The old approach to this is very hoary, dating from before we werewilling to require compilers to have working int64 types.This fix makes the PG_INT64_MIN, PG_INT64_MAX, and PG_UINT64_MAXconstants safe to use in preprocessor conditions, where a castdoesn't work. Other symbolic constants that might be defined using[U]INT64CONST are likewise safer than before.Also fix the SIZE_MAX macro to be similarly safe, if we are forcedto provide a definition for that. The test added in commit2e70d6bhappens to do what we want even with the hack "(size_t) -1" definition,but we could easily get burnt on other tests in future.Back-patch to all supported branches, like the previous commits.Discussion:https://postgr.es/m/15883.1504278595@sss.pgh.pa.us
1 parente50d401 commit3a0f8e7

File tree

5 files changed

+11
-52
lines changed

5 files changed

+11
-52
lines changed

‎configure

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13726,24 +13726,6 @@ cat >>confdefs.h <<_ACEOF
1372613726
_ACEOF
1372713727

1372813728

13729-
13730-
iftest x"$HAVE_LONG_LONG_INT_64" = xyes;then
13731-
cat confdefs.h -<<_ACEOF >conftest.$ac_ext
13732-
/* end confdefs.h. */
13733-
13734-
#define INT64CONST(x) x##LL
13735-
long long int foo = INT64CONST(0x1234567890123456);
13736-
13737-
_ACEOF
13738-
if ac_fn_c_try_compile"$LINENO";then:
13739-
13740-
$as_echo"#define HAVE_LL_CONSTANTS 1">>confdefs.h
13741-
13742-
fi
13743-
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
13744-
fi
13745-
13746-
1374713729
# If we found "long int" is 64 bits, assume snprintf handles it. If
1374813730
# we found we need to use "long long int", better check. We cope with
1374913731
# snprintfs that use %lld, %qd, or %I64d as the format. If none of these

‎configure.in

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1751,18 +1751,6 @@ fi
17511751
AC_DEFINE_UNQUOTED(PG_INT64_TYPE, $pg_int64_type,
17521752
[Define to the name of a signed 64-bit integer type.])
17531753

1754-
dnl If we need to use "long long int", figure out whether nnnLL notation works.
1755-
1756-
if test x"$HAVE_LONG_LONG_INT_64" = xyes ; then
1757-
AC_COMPILE_IFELSE([AC_LANG_SOURCE([
1758-
#define INT64CONST(x) x##LL
1759-
long long int foo = INT64CONST(0x1234567890123456);
1760-
])],
1761-
[AC_DEFINE(HAVE_LL_CONSTANTS, 1, [Define to 1 if constants of type 'long long int' should have the suffix LL.])],
1762-
[])
1763-
fi
1764-
1765-
17661754
# If we found "long int" is 64 bits, assume snprintf handles it. If
17671755
# we found we need to use "long long int", better check. We cope with
17681756
# snprintfs that use %lld, %qd, or %I64d as the format. If none of these

‎src/include/c.h

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,8 @@ typedef long int int64;
285285
#ifndefHAVE_UINT64
286286
typedefunsigned longintuint64;
287287
#endif
288+
#defineINT64CONST(x) (x##L)
289+
#defineUINT64CONST(x) (x##UL)
288290
#elif defined(HAVE_LONG_LONG_INT_64)
289291
/* We have working support for "long long int", use that */
290292

@@ -294,20 +296,13 @@ typedef long long int int64;
294296
#ifndefHAVE_UINT64
295297
typedefunsigned long longintuint64;
296298
#endif
299+
#defineINT64CONST(x) (x##LL)
300+
#defineUINT64CONST(x) (x##ULL)
297301
#else
298302
/* neither HAVE_LONG_INT_64 nor HAVE_LONG_LONG_INT_64 */
299303
#error must have a working 64-bit integer datatype
300304
#endif
301305

302-
/* Decide if we need to decorate 64-bit constants */
303-
#ifdefHAVE_LL_CONSTANTS
304-
#defineINT64CONST(x) ((int64) x##LL)
305-
#defineUINT64CONST(x) ((uint64) x##ULL)
306-
#else
307-
#defineINT64CONST(x) ((int64) x)
308-
#defineUINT64CONST(x) ((uint64) x)
309-
#endif
310-
311306
/* snprintf format strings to use for 64-bit integers */
312307
#defineINT64_FORMAT "%" INT64_MODIFIER "d"
313308
#defineUINT64_FORMAT "%" INT64_MODIFIER "u"
@@ -335,14 +330,18 @@ typedef unsigned PG_INT128_TYPE uint128;
335330
#definePG_UINT16_MAX(0xFFFF)
336331
#definePG_INT32_MIN(-0x7FFFFFFF-1)
337332
#definePG_INT32_MAX(0x7FFFFFFF)
338-
#definePG_UINT32_MAX(0xFFFFFFFF)
333+
#definePG_UINT32_MAX(0xFFFFFFFFU)
339334
#definePG_INT64_MIN(-INT64CONST(0x7FFFFFFFFFFFFFFF) - 1)
340335
#definePG_INT64_MAXINT64CONST(0x7FFFFFFFFFFFFFFF)
341336
#definePG_UINT64_MAXUINT64CONST(0xFFFFFFFFFFFFFFFF)
342337

343338
/* Max value of size_t might also be missing if we don't have stdint.h */
344339
#ifndefSIZE_MAX
345-
#defineSIZE_MAX ((size_t) -1)
340+
#ifSIZEOF_SIZE_T==8
341+
#defineSIZE_MAX PG_UINT64_MAX
342+
#else
343+
#defineSIZE_MAX PG_UINT32_MAX
344+
#endif
346345
#endif
347346

348347
/* Select timestamp representation (float8 or int64) */

‎src/include/pg_config.h.in

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -333,10 +333,6 @@
333333
/* Define to 1 if you have the `z' library (-lz). */
334334
#undef HAVE_LIBZ
335335

336-
/* Define to 1 if constants of type 'long long int' should have the suffix LL.
337-
*/
338-
#undef HAVE_LL_CONSTANTS
339-
340336
/* Define to 1 if the system has the type `locale_t'. */
341337
#undef HAVE_LOCALE_T
342338

‎src/include/pg_config.h.win32

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -217,12 +217,6 @@
217217
/* Define to 1 if you have the `z' library (-lz). */
218218
/* #undef HAVE_LIBZ */
219219

220-
/* Define to 1 if constants of type 'long long int' should have the suffix LL.
221-
*/
222-
#if (_MSC_VER > 1200)
223-
#define HAVE_LL_CONSTANTS 1
224-
#endif
225-
226220
/* Define to 1 if the system has the type `locale_t'. */
227221
#define HAVE_LOCALE_T 1
228222

@@ -231,7 +225,7 @@
231225

232226
/* Define to 1 if `long long int' works and is 64 bits. */
233227
#if (_MSC_VER > 1200)
234-
#define HAVE_LONG_LONG_INT_64
228+
#define HAVE_LONG_LONG_INT_64 1
235229
#endif
236230

237231
/* Define to 1 if you have the `mbstowcs_l' function. */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp