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

Commit62e2a8d

Browse files
committed
Define integer limits independently from the system definitions.
In83ff161 we defined integer limits iff they're not provided by thesystem. That turns out not to be the greatest idea because there'sdifferent ways some datatypes can be represented. E.g. on OSX PG's 64bitdatatype will be a 'long int', but OSX unconditionally uses 'longlong'. That disparity then can lead to warnings, e.g. around printfformats.One way to fix that would be to back int64 using stdint.h'sint64_t. While a good idea it's not that easy to implement. We woulde.g. need to include stdint.h in our external headers, which we don'ttoday. Also computing the correct int64 printf formats in that case isnontrivial.Instead simply prefix the integer limits with PG_ and define themunconditionally. I've adjusted all the references to them in code, butnot the ones in comments; the latter seems unnecessary to me.Discussion: 20150331141423.GK4878@alap3.anarazel.de
1 parente146ca6 commit62e2a8d

File tree

16 files changed

+45
-69
lines changed

16 files changed

+45
-69
lines changed

‎contrib/btree_gist/btree_ts.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ ts_dist(PG_FUNCTION_ARGS)
154154
p->day=INT_MAX;
155155
p->month=INT_MAX;
156156
#ifdefHAVE_INT64_TIMESTAMP
157-
p->time=INT64_MAX;
157+
p->time=PG_INT64_MAX;
158158
#else
159159
p->time=DBL_MAX;
160160
#endif
@@ -182,7 +182,7 @@ tstz_dist(PG_FUNCTION_ARGS)
182182
p->day=INT_MAX;
183183
p->month=INT_MAX;
184184
#ifdefHAVE_INT64_TIMESTAMP
185-
p->time=INT64_MAX;
185+
p->time=PG_INT64_MAX;
186186
#else
187187
p->time=DBL_MAX;
188188
#endif

‎contrib/pgbench/pgbench.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ strtoint64(const char *str)
449449
*/
450450
if (strncmp(ptr,"9223372036854775808",19)==0)
451451
{
452-
result=INT64_MIN;
452+
result=PG_INT64_MIN;
453453
ptr+=19;
454454
gotogotdigits;
455455
}
@@ -3521,7 +3521,7 @@ threadRun(void *arg)
35213521
FD_ZERO(&input_mask);
35223522

35233523
maxsock=-1;
3524-
min_usec=INT64_MAX;
3524+
min_usec=PG_INT64_MAX;
35253525
for (i=0;i<nstate;i++)
35263526
{
35273527
CState*st=&state[i];
@@ -3548,7 +3548,7 @@ threadRun(void *arg)
35483548
{
35493549
intthis_usec;
35503550

3551-
if (min_usec==INT64_MAX)
3551+
if (min_usec==PG_INT64_MAX)
35523552
{
35533553
instr_timenow;
35543554

@@ -3584,7 +3584,7 @@ threadRun(void *arg)
35843584
{
35853585
intnsocks;/* return from select(2) */
35863586

3587-
if (min_usec!=INT64_MAX)
3587+
if (min_usec!=PG_INT64_MAX)
35883588
{
35893589
structtimevaltimeout;
35903590

‎src/backend/access/transam/xlog.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1408,7 +1408,7 @@ WALInsertLockAcquireExclusive(void)
14081408
{
14091409
LWLockAcquireWithVar(&WALInsertLocks[i].l.lock,
14101410
&WALInsertLocks[i].l.insertingAt,
1411-
UINT64_MAX);
1411+
PG_UINT64_MAX);
14121412
}
14131413
LWLockAcquireWithVar(&WALInsertLocks[i].l.lock,
14141414
&WALInsertLocks[i].l.insertingAt,

‎src/backend/tsearch/wparser_def.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2260,7 +2260,7 @@ mark_hl_fragments(HeadlineParsedText *prs, TSQuery query, int highlight,
22602260
for (f=0;f<max_fragments;f++)
22612261
{
22622262
maxitems=0;
2263-
minwords=INT32_MAX;
2263+
minwords=PG_INT32_MAX;
22642264
minI=-1;
22652265

22662266
/*

‎src/backend/utils/adt/int8.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ scanint8(const char *str, bool errorOK, int64 *result)
7878
*/
7979
if (strncmp(ptr,"9223372036854775808",19)==0)
8080
{
81-
tmp=INT64_MIN;
81+
tmp=PG_INT64_MIN;
8282
ptr+=19;
8383
gotogotdigits;
8484
}

‎src/backend/utils/adt/numutils.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ pg_lltoa(int64 value, char *a)
190190
* Avoid problems with the most negative integer not being representable
191191
* as a positive integer.
192192
*/
193-
if (value==INT64_MIN)
193+
if (value==PG_INT64_MIN)
194194
{
195195
memcpy(a,"-9223372036854775808",21);
196196
return;

‎src/backend/utils/adt/timestamp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3309,7 +3309,7 @@ interval_mul(PG_FUNCTION_ARGS)
33093309
result->day+= (int32)month_remainder_days;
33103310
#ifdefHAVE_INT64_TIMESTAMP
33113311
result_double=rint(span->time*factor+sec_remainder*USECS_PER_SEC);
3312-
if (result_double>INT64_MAX||result_double<INT64_MIN)
3312+
if (result_double>PG_INT64_MAX||result_double<PG_INT64_MIN)
33133313
ereport(ERROR,
33143314
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
33153315
errmsg("interval out of range")));

‎src/backend/utils/adt/txid.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434

3535

3636
/* txid will be signed int8 in database, so must limit to 63 bits */
37-
#defineMAX_TXID ((uint64)INT64_MAX)
37+
#defineMAX_TXID ((uint64)PG_INT64_MAX)
3838

3939
/* Use unsigned variant internally */
4040
typedefuint64txid;

‎src/include/c.h

Lines changed: 22 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -249,36 +249,6 @@ typedef uint8 bits8;/* >= 8 bits */
249249
typedefuint16bits16;/* >= 16 bits */
250250
typedefuint32bits32;/* >= 32 bits */
251251

252-
/* should be defined in stdint.h, but we guarantee them here */
253-
#ifndefINT8_MIN
254-
#defineINT8_MIN(-0x7F-1)
255-
#endif
256-
#ifndefINT8_MAX
257-
#defineINT8_MAX(0x7F)
258-
#endif
259-
#ifndefINT16_MIN
260-
#defineINT16_MIN(-0x7FFF-1)
261-
#endif
262-
#ifndefINT16_MAX
263-
#defineINT16_MAX(0x7FFF)
264-
#endif
265-
#ifndefINT32_MIN
266-
#defineINT32_MIN(-0x7FFFFFFF-1)
267-
#endif
268-
#ifndefINT32_MAX
269-
#defineINT32_MAX(0x7FFFFFFF)
270-
#endif
271-
272-
#ifndefUINT8_MAX
273-
#defineUINT8_MAX(0xFF)
274-
#endif
275-
#ifndefUINT16_MAX
276-
#defineUINT16_MAX(0xFFFF)
277-
#endif
278-
#ifndefUINT32_MAX
279-
#defineUINT32_MAX(0xFFFFFFFF)
280-
#endif
281-
282252
/*
283253
* 64-bit integers
284254
*/
@@ -314,26 +284,10 @@ typedef unsigned long long int uint64;
314284
#defineUINT64CONST(x) ((uint64) x)
315285
#endif
316286

317-
/* should be defined in stdint.h, but we guarantee them here */
318-
#ifndefINT64_MIN
319-
#defineINT64_MIN(-INT64CONST(0x7FFFFFFFFFFFFFFF) - 1)
320-
#endif
321-
#ifndefINT64_MAX
322-
#defineINT64_MAXINT64CONST(0x7FFFFFFFFFFFFFFF)
323-
#endif
324-
#ifndefUINT64_MAX
325-
#defineUINT64_MAXUINT64CONST(0xFFFFFFFFFFFFFFFF)
326-
#endif
327-
328287
/* snprintf format strings to use for 64-bit integers */
329288
#defineINT64_FORMAT "%" INT64_MODIFIER "d"
330289
#defineUINT64_FORMAT "%" INT64_MODIFIER "u"
331290

332-
/* Select timestamp representation (float8 or int64) */
333-
#ifdefUSE_INTEGER_DATETIMES
334-
#defineHAVE_INT64_TIMESTAMP
335-
#endif
336-
337291
/*
338292
* 128-bit signed and unsigned integers
339293
*There currently is only a limited support for the type. E.g. 128bit
@@ -345,6 +299,28 @@ typedef PG_INT128_TYPE int128;
345299
typedefunsignedPG_INT128_TYPEuint128;
346300
#endif
347301

302+
/*
303+
* stdint.h limits aren't guaranteed to be present and aren't guaranteed to
304+
* have compatible types with our fixed width types. So just define our own.
305+
*/
306+
#definePG_INT8_MIN(-0x7F-1)
307+
#definePG_INT8_MAX(0x7F)
308+
#definePG_UINT8_MAX(0xFF)
309+
#definePG_INT16_MIN(-0x7FFF-1)
310+
#definePG_INT16_MAX(0x7FFF)
311+
#definePG_UINT16_MAX(0xFFFF)
312+
#definePG_INT32_MIN(-0x7FFFFFFF-1)
313+
#definePG_INT32_MAX(0x7FFFFFFF)
314+
#definePG_UINT32_MAX(0xFFFFFFFF)
315+
#definePG_INT64_MIN(-INT64CONST(0x7FFFFFFFFFFFFFFF) - 1)
316+
#definePG_INT64_MAXINT64CONST(0x7FFFFFFFFFFFFFFF)
317+
#definePG_UINT64_MAXUINT64CONST(0xFFFFFFFFFFFFFFFF)
318+
319+
/* Select timestamp representation (float8 or int64) */
320+
#ifdefUSE_INTEGER_DATETIMES
321+
#defineHAVE_INT64_TIMESTAMP
322+
#endif
323+
348324
/* sig_atomic_t is required by ANSI C, but may be missing on old platforms */
349325
#ifndefHAVE_SIG_ATOMIC_T
350326
typedefintsig_atomic_t;

‎src/include/datatype/timestamp.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ typedef struct
119119
* DT_NOBEGIN represents timestamp -infinity; DT_NOEND represents +infinity
120120
*/
121121
#ifdefHAVE_INT64_TIMESTAMP
122-
#defineDT_NOBEGININT64_MIN
123-
#defineDT_NOENDINT64_MAX
122+
#defineDT_NOBEGINPG_INT64_MIN
123+
#defineDT_NOENDPG_INT64_MAX
124124
#else/* !HAVE_INT64_TIMESTAMP */
125125
#ifdefHUGE_VAL
126126
#defineDT_NOBEGIN(-HUGE_VAL)

‎src/include/executor/instrument.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ typedef enum InstrumentOption
3838
INSTRUMENT_TIMER=1 <<0,/* needs timer (and row counts) */
3939
INSTRUMENT_BUFFERS=1 <<1,/* needs buffer usage */
4040
INSTRUMENT_ROWS=1 <<2,/* needs row count */
41-
INSTRUMENT_ALL=INT32_MAX
41+
INSTRUMENT_ALL=PG_INT32_MAX
4242
}InstrumentOption;
4343

4444
typedefstructInstrumentation

‎src/include/nodes/parsenodes.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ typedef enum TableLikeOption
587587
CREATE_TABLE_LIKE_INDEXES=1 <<2,
588588
CREATE_TABLE_LIKE_STORAGE=1 <<3,
589589
CREATE_TABLE_LIKE_COMMENTS=1 <<4,
590-
CREATE_TABLE_LIKE_ALL=INT32_MAX
590+
CREATE_TABLE_LIKE_ALL=PG_INT32_MAX
591591
}TableLikeOption;
592592

593593
/*

‎src/include/pg_config_manual.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
/*
4949
* Set the upper and lower bounds of sequence values.
5050
*/
51-
#defineSEQ_MAXVALUEINT64_MAX
51+
#defineSEQ_MAXVALUEPG_INT64_MAX
5252
#defineSEQ_MINVALUE(-SEQ_MAXVALUE)
5353

5454
/*
@@ -185,7 +185,7 @@
185185
* the older rand() function, which is often different from --- and
186186
* considerably inferior to --- random().
187187
*/
188-
#defineMAX_RANDOM_VALUEINT32_MAX
188+
#defineMAX_RANDOM_VALUEPG_INT32_MAX
189189

190190
/*
191191
* On PPC machines, decide whether to use the mutex hint bit in LWARX

‎src/include/port/atomics.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ STATIC_IF_INLINE uint64
489489
pg_atomic_fetch_sub_u64(volatilepg_atomic_uint64*ptr,int64sub_)
490490
{
491491
AssertPointerAlignment(ptr,8);
492-
Assert(sub_!=INT64_MIN);
492+
Assert(sub_!=PG_INT64_MIN);
493493
returnpg_atomic_fetch_sub_u64_impl(ptr,sub_);
494494
}
495495

@@ -518,7 +518,7 @@ STATIC_IF_INLINE uint64
518518
pg_atomic_sub_fetch_u64(volatilepg_atomic_uint64*ptr,int64sub_)
519519
{
520520
AssertPointerAlignment(ptr,8);
521-
Assert(sub_!=INT64_MIN);
521+
Assert(sub_!=PG_INT64_MIN);
522522
returnpg_atomic_sub_fetch_u64_impl(ptr,sub_);
523523
}
524524

‎src/include/storage/predicate_internals.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ typedef uint64 SerCommitSeqNo;
3333
* at that point. It's earlier than all normal sequence numbers,
3434
* and is only used by recovered prepared transactions
3535
*/
36-
#defineInvalidSerCommitSeqNo((SerCommitSeqNo)UINT64_MAX)
36+
#defineInvalidSerCommitSeqNo((SerCommitSeqNo)PG_UINT64_MAX)
3737
#defineRecoverySerCommitSeqNo((SerCommitSeqNo) 1)
3838
#defineFirstNormalSerCommitSeqNo((SerCommitSeqNo) 2)
3939

‎src/include/utils/date.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ typedef struct
3636
/*
3737
* Infinity and minus infinity must be the max and min values of DateADT.
3838
*/
39-
#defineDATEVAL_NOBEGIN((DateADT)INT32_MIN)
40-
#defineDATEVAL_NOEND((DateADT)INT32_MAX)
39+
#defineDATEVAL_NOBEGIN((DateADT)PG_INT32_MIN)
40+
#defineDATEVAL_NOEND((DateADT)PG_INT32_MAX)
4141

4242
#defineDATE_NOBEGIN(j)((j) = DATEVAL_NOBEGIN)
4343
#defineDATE_IS_NOBEGIN(j)((j) == DATEVAL_NOBEGIN)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp