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

Commit9d6b160

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 parenta057220 commit9d6b160

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
@@ -14254,24 +14254,6 @@ cat >>confdefs.h <<_ACEOF
1425414254
_ACEOF
1425514255

1425614256

14257-
14258-
iftest x"$HAVE_LONG_LONG_INT_64" = xyes;then
14259-
cat confdefs.h -<<_ACEOF >conftest.$ac_ext
14260-
/* end confdefs.h. */
14261-
14262-
#define INT64CONST(x) x##LL
14263-
long long int foo = INT64CONST(0x1234567890123456);
14264-
14265-
_ACEOF
14266-
if ac_fn_c_try_compile"$LINENO";then:
14267-
14268-
$as_echo"#define HAVE_LL_CONSTANTS 1">>confdefs.h
14269-
14270-
fi
14271-
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
14272-
fi
14273-
14274-
1427514257
# If we found "long int" is 64 bits, assume snprintf handles it. If
1427614258
# we found we need to use "long long int", better check. We cope with
1427714259
# 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
@@ -1735,18 +1735,6 @@ fi
17351735
AC_DEFINE_UNQUOTED(PG_INT64_TYPE, $pg_int64_type,
17361736
[Define to the name of a signed 64-bit integer type.])
17371737

1738-
dnl If we need to use "long long int", figure out whether nnnLL notation works.
1739-
1740-
if test x"$HAVE_LONG_LONG_INT_64" = xyes ; then
1741-
AC_COMPILE_IFELSE([AC_LANG_SOURCE([
1742-
#define INT64CONST(x) x##LL
1743-
long long int foo = INT64CONST(0x1234567890123456);
1744-
])],
1745-
[AC_DEFINE(HAVE_LL_CONSTANTS, 1, [Define to 1 if constants of type 'long long int' should have the suffix LL.])],
1746-
[])
1747-
fi
1748-
1749-
17501738
# If we found "long int" is 64 bits, assume snprintf handles it. If
17511739
# we found we need to use "long long int", better check. We cope with
17521740
# 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
@@ -288,6 +288,8 @@ typedef long int int64;
288288
#ifndefHAVE_UINT64
289289
typedefunsigned longintuint64;
290290
#endif
291+
#defineINT64CONST(x) (x##L)
292+
#defineUINT64CONST(x) (x##UL)
291293
#elif defined(HAVE_LONG_LONG_INT_64)
292294
/* We have working support for "long long int", use that */
293295

@@ -297,20 +299,13 @@ typedef long long int int64;
297299
#ifndefHAVE_UINT64
298300
typedefunsigned long longintuint64;
299301
#endif
302+
#defineINT64CONST(x) (x##LL)
303+
#defineUINT64CONST(x) (x##ULL)
300304
#else
301305
/* neither HAVE_LONG_INT_64 nor HAVE_LONG_LONG_INT_64 */
302306
#error must have a working 64-bit integer datatype
303307
#endif
304308

305-
/* Decide if we need to decorate 64-bit constants */
306-
#ifdefHAVE_LL_CONSTANTS
307-
#defineINT64CONST(x) ((int64) x##LL)
308-
#defineUINT64CONST(x) ((uint64) x##ULL)
309-
#else
310-
#defineINT64CONST(x) ((int64) x)
311-
#defineUINT64CONST(x) ((uint64) x)
312-
#endif
313-
314309
/* snprintf format strings to use for 64-bit integers */
315310
#defineINT64_FORMAT "%" INT64_MODIFIER "d"
316311
#defineUINT64_FORMAT "%" INT64_MODIFIER "u"
@@ -338,14 +333,18 @@ typedef unsigned PG_INT128_TYPE uint128;
338333
#definePG_UINT16_MAX(0xFFFF)
339334
#definePG_INT32_MIN(-0x7FFFFFFF-1)
340335
#definePG_INT32_MAX(0x7FFFFFFF)
341-
#definePG_UINT32_MAX(0xFFFFFFFF)
336+
#definePG_UINT32_MAX(0xFFFFFFFFU)
342337
#definePG_INT64_MIN(-INT64CONST(0x7FFFFFFFFFFFFFFF) - 1)
343338
#definePG_INT64_MAXINT64CONST(0x7FFFFFFFFFFFFFFF)
344339
#definePG_UINT64_MAXUINT64CONST(0xFFFFFFFFFFFFFFFF)
345340

346341
/* Max value of size_t might also be missing if we don't have stdint.h */
347342
#ifndefSIZE_MAX
348-
#defineSIZE_MAX ((size_t) -1)
343+
#ifSIZEOF_SIZE_T==8
344+
#defineSIZE_MAX PG_UINT64_MAX
345+
#else
346+
#defineSIZE_MAX PG_UINT32_MAX
347+
#endif
349348
#endif
350349

351350
/*

‎src/include/pg_config.h.in

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

342-
/* Define to 1 if constants of type 'long long int' should have the suffix LL.
343-
*/
344-
#undef HAVE_LL_CONSTANTS
345-
346342
/* Define to 1 if the system has the type `locale_t'. */
347343
#undef HAVE_LOCALE_T
348344

‎src/include/pg_config.h.win32

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

226-
/* Define to 1 if constants of type 'long long int' should have the suffix LL.
227-
*/
228-
#if (_MSC_VER > 1200)
229-
#define HAVE_LL_CONSTANTS 1
230-
#endif
231-
232226
/* Define to 1 if the system has the type `locale_t'. */
233227
#define HAVE_LOCALE_T 1
234228

@@ -237,7 +231,7 @@
237231

238232
/* Define to 1 if `long long int' works and is 64 bits. */
239233
#if (_MSC_VER > 1200)
240-
#define HAVE_LONG_LONG_INT_64
234+
#define HAVE_LONG_LONG_INT_64 1
241235
#endif
242236

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp