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

Commit83ff161

Browse files
committed
Centralize definition of integer limits.
Several submitted and even committed patches have run into the problemthat C89, our baseline, does not provide minimum/maximum values forvarious integer datatypes. C99's stdint.h does, but we can't rely onit.Several parts of the code defined limits locally, so instead centralizethe definitions to c.h.This patch also changes the more obvious usages of literal limit values;there's more places that could be changed, but it's less clear whetherit's beneficial to change those.Author: Andrew GierthDiscussion: 87619tc5wc.fsf@news-spur.riddles.org.uk
1 parentbdc3d7f commit83ff161

File tree

18 files changed

+68
-36
lines changed

18 files changed

+68
-36
lines changed

‎contrib/btree_gist/btree_ts.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ ts_dist(PG_FUNCTION_ARGS)
153153
p->day=INT_MAX;
154154
p->month=INT_MAX;
155155
#ifdefHAVE_INT64_TIMESTAMP
156-
p->time=INT64CONST(0x7FFFFFFFFFFFFFFF);
156+
p->time=INT64_MAX;
157157
#else
158158
p->time=DBL_MAX;
159159
#endif
@@ -181,7 +181,7 @@ tstz_dist(PG_FUNCTION_ARGS)
181181
p->day=INT_MAX;
182182
p->month=INT_MAX;
183183
#ifdefHAVE_INT64_TIMESTAMP
184-
p->time=INT64CONST(0x7FFFFFFFFFFFFFFF);
184+
p->time=INT64_MAX;
185185
#else
186186
p->time=DBL_MAX;
187187
#endif

‎contrib/intarray/_int_gist.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
*/
44
#include"postgres.h"
55

6+
#include<limits.h>
7+
68
#include"access/gist.h"
79
#include"access/skey.h"
810

@@ -191,7 +193,7 @@ g_int_compress(PG_FUNCTION_ARGS)
191193
cand=1;
192194
while (len>MAXNUMRANGE*2)
193195
{
194-
min=0x7fffffff;
196+
min=INT_MAX;
195197
for (i=2;i<len;i+=2)
196198
if (min> (dr[i]-dr[i-1]))
197199
{

‎contrib/pgbench/pgbench.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,6 @@
4949
#include<sys/resource.h>/* for getrlimit */
5050
#endif
5151

52-
#ifndefINT64_MAX
53-
#defineINT64_MAXINT64CONST(0x7FFFFFFFFFFFFFFF)
54-
#endif
55-
5652
#ifndefM_PI
5753
#defineM_PI 3.14159265358979323846
5854
#endif
@@ -453,7 +449,7 @@ strtoint64(const char *str)
453449
*/
454450
if (strncmp(ptr,"9223372036854775808",19)==0)
455451
{
456-
result=-INT64CONST(0x7fffffffffffffff)-1;
452+
result=INT64_MIN;
457453
ptr+=19;
458454
gotogotdigits;
459455
}

‎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-
UINT64CONST(0xFFFFFFFFFFFFFFFF));
1411+
UINT64_MAX);
14121412
}
14131413
LWLockAcquireWithVar(&WALInsertLocks[i].l.lock,
14141414
&WALInsertLocks[i].l.insertingAt,

‎src/backend/tsearch/wparser_def.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
#include"postgres.h"
1616

17+
#include<limits.h>
18+
1719
#include"catalog/pg_collation.h"
1820
#include"commands/defrem.h"
1921
#include"tsearch/ts_locale.h"
@@ -2047,7 +2049,7 @@ hlCover(HeadlineParsedText *prs, TSQuery query, int *p, int *q)
20472049
intpos=*p;
20482050

20492051
*q=-1;
2050-
*p=0x7fffffff;
2052+
*p=INT_MAX;
20512053

20522054
for (j=0;j<query->size;j++)
20532055
{
@@ -2258,7 +2260,7 @@ mark_hl_fragments(HeadlineParsedText *prs, TSQuery query, int highlight,
22582260
for (f=0;f<max_fragments;f++)
22592261
{
22602262
maxitems=0;
2261-
minwords=0x7fffffff;
2263+
minwords=INT32_MAX;
22622264
minI=-1;
22632265

22642266
/*

‎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=-INT64CONST(0x7fffffffffffffff)-1;
81+
tmp=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==(-INT64CONST(0x7FFFFFFFFFFFFFFF)-1))
193+
if (value==INT64_MIN)
194194
{
195195
memcpy(a,"-9223372036854775808",21);
196196
return;

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,6 @@
4444

4545
#defineSAMESIGN(a,b)(((a) < 0) == ((b) < 0))
4646

47-
#ifndefINT64_MAX
48-
#defineINT64_MAXINT64CONST(0x7FFFFFFFFFFFFFFF)
49-
#endif
50-
51-
#ifndefINT64_MIN
52-
#defineINT64_MIN(-INT64CONST(0x7FFFFFFFFFFFFFFF) - 1)
53-
#endif
54-
5547
/* Set at postmaster start */
5648
TimestampTzPgStartTime;
5749

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
*/
1414
#include"postgres.h"
1515

16+
#include<limits.h>
1617
#include<math.h>
1718

1819
#include"tsearch/ts_utils.h"
@@ -555,7 +556,7 @@ Cover(DocRepresentation *doc, int len, QueryRepresentation *qr, CoverExt *ext)
555556

556557
memset(qr->operandexist,0,sizeof(bool)*qr->query->size);
557558

558-
ext->p=0x7fffffff;
559+
ext->p=INT_MAX;
559560
ext->q=0;
560561
ptr=doc+ext->pos;
561562

‎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_TXIDUINT64CONST(0x7FFFFFFFFFFFFFFF)
37+
#defineMAX_TXID((uint64) INT64_MAX)
3838

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

‎src/include/c.h

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,36 @@ 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+
252282
/*
253283
* 64-bit integers
254284
*/
@@ -284,6 +314,17 @@ typedef unsigned long long int uint64;
284314
#defineUINT64CONST(x) ((uint64) x)
285315
#endif
286316

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+
287328
/* snprintf format strings to use for 64-bit integers */
288329
#defineINT64_FORMAT "%" INT64_MODIFIER "d"
289330
#defineUINT64_FORMAT "%" INT64_MODIFIER "u"

‎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_NOBEGIN(-INT64CONST(0x7fffffffffffffff) - 1)
123-
#defineDT_NOEND(INT64CONST(0x7fffffffffffffff))
122+
#defineDT_NOBEGININT64_MIN
123+
#defineDT_NOENDINT64_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=0x7FFFFFFF
41+
INSTRUMENT_ALL=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=0x7FFFFFFF
590+
CREATE_TABLE_LIKE_ALL=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_MAXVALUEINT64CONST(0x7FFFFFFFFFFFFFFF)
51+
#defineSEQ_MAXVALUEINT64_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_VALUE(0x7FFFFFFF)
188+
#defineMAX_RANDOM_VALUEINT32_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_!=-INT64CONST(0x7FFFFFFFFFFFFFFF)-1);
492+
Assert(sub_!=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_!=-INT64CONST(0x7FFFFFFFFFFFFFFF)-1);
521+
Assert(sub_!=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)UINT64CONST(0xFFFFFFFFFFFFFFFF))
36+
#defineInvalidSerCommitSeqNo((SerCommitSeqNo)UINT64_MAX)
3737
#defineRecoverySerCommitSeqNo((SerCommitSeqNo) 1)
3838
#defineFirstNormalSerCommitSeqNo((SerCommitSeqNo) 2)
3939

‎src/include/utils/date.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,9 @@ typedef struct
3535

3636
/*
3737
* Infinity and minus infinity must be the max and min values of DateADT.
38-
* We could use INT_MIN and INT_MAX here, but seems better to not assume that
39-
* int32 == int.
4038
*/
41-
#defineDATEVAL_NOBEGIN((DateADT)(-0x7fffffff - 1))
42-
#defineDATEVAL_NOEND((DateADT)0x7fffffff)
39+
#defineDATEVAL_NOBEGIN((DateADT)INT32_MIN)
40+
#defineDATEVAL_NOEND((DateADT)INT32_MAX)
4341

4442
#defineDATE_NOBEGIN(j)((j) = DATEVAL_NOBEGIN)
4543
#defineDATE_IS_NOBEGIN(j)((j) == DATEVAL_NOBEGIN)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp