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

Commit6cf86f4

Browse files
committed
Change internal integer representation of Value node
A Value node would store an integer as a long. This causes needlessportability risks, as long can be of varying sizes. Change it to useint instead. All code using this was already careful to only store32-bit values anyway.Reviewed-by: Michael Paquier <michael@paquier.xyz>
1 parent377b5ac commit6cf86f4

File tree

7 files changed

+17
-27
lines changed

7 files changed

+17
-27
lines changed

‎src/backend/nodes/outfuncs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3235,7 +3235,7 @@ _outValue(StringInfo str, const Value *value)
32353235
switch (value->type)
32363236
{
32373237
caseT_Integer:
3238-
appendStringInfo(str,"%ld",value->val.ival);
3238+
appendStringInfo(str,"%d",value->val.ival);
32393239
break;
32403240
caseT_Float:
32413241

‎src/backend/nodes/read.c

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -224,13 +224,9 @@ nodeTokenType(char *token, int length)
224224

225225
errno=0;
226226
val=strtol(token,&endptr,10);
227-
(void)val;/* avoid compiler warning if unused */
228-
if (endptr!=token+length||errno==ERANGE
229-
#ifdefHAVE_LONG_INT_64
230-
/* if long > 32 bits, check for overflow of int4 */
231-
||val!= (long) ((int32)val)
232-
#endif
233-
)
227+
if (endptr!=token+length||errno==ERANGE||
228+
/* check for overflow of int */
229+
val!= (int)val)
234230
returnT_Float;
235231
returnT_Integer;
236232
}
@@ -387,9 +383,9 @@ nodeRead(char *token, int tok_len)
387383
caseT_Integer:
388384

389385
/*
390-
* we know that the token terminates on a charatol will stop at
386+
* we know that the token terminates on a charatoi will stop at
391387
*/
392-
result= (Node*)makeInteger(atol(token));
388+
result= (Node*)makeInteger(atoi(token));
393389
break;
394390
caseT_Float:
395391
{

‎src/backend/nodes/value.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
*makeInteger
2121
*/
2222
Value*
23-
makeInteger(longi)
23+
makeInteger(inti)
2424
{
2525
Value*v=makeNode(Value);
2626

‎src/backend/parser/scan.l

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,12 +1216,9 @@ process_integer_literal(const char *token, YYSTYPE *lval)
12161216

12171217
errno =0;
12181218
val =strtol(token, &endptr,10);
1219-
if (*endptr !='\0' || errno == ERANGE
1220-
#ifdef HAVE_LONG_INT_64
1221-
/* if long > 32 bits, check for overflow of int4 */
1222-
|| val != (long) ((int32) val)
1223-
#endif
1224-
)
1219+
if (*endptr !='\0' || errno == ERANGE ||
1220+
/* check for overflow of int */
1221+
val != (int) val)
12251222
{
12261223
/* integer too large, treat it as a float */
12271224
lval->str =pstrdup(token);

‎src/backend/utils/misc/guc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6913,7 +6913,7 @@ flatten_set_variable_args(const char *name, List *args)
69136913
switch (nodeTag(&con->val))
69146914
{
69156915
caseT_Integer:
6916-
appendStringInfo(&buf,"%ld",intVal(&con->val));
6916+
appendStringInfo(&buf,"%d",intVal(&con->val));
69176917
break;
69186918
caseT_Float:
69196919
/* represented as a string, so just copy it */

‎src/include/nodes/value.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
* better to use the more general representation.)
3535
*
3636
* Note that an integer-looking string will get lexed as T_Float if
37-
* the value is too large to fit ina 'long'.
37+
* the value is too large to fit inan 'int'.
3838
*
3939
* Nulls, of course, don't need the value part at all.
4040
*----------------------
@@ -44,7 +44,7 @@ typedef struct Value
4444
NodeTagtype;/* tag appropriately (eg. T_String) */
4545
unionValUnion
4646
{
47-
longival;/* machine integer */
47+
intival;/* machine integer */
4848
char*str;/* string */
4949
}val;
5050
}Value;
@@ -53,7 +53,7 @@ typedef struct Value
5353
#definefloatVal(v)atof(((Value *)(v))->val.str)
5454
#definestrVal(v)(((Value *)(v))->val.str)
5555

56-
externValue*makeInteger(longi);
56+
externValue*makeInteger(inti);
5757
externValue*makeFloat(char*numericStr);
5858
externValue*makeString(char*str);
5959
externValue*makeBitString(char*str);

‎src/interfaces/ecpg/preproc/pgc.l

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -732,12 +732,9 @@ cppline{space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})((\/\*[^*/]*\*+
732732

733733
errno =0;
734734
val =strtol((char *)yytext, &endptr,10);
735-
if (*endptr !='\0' || errno == ERANGE
736-
#ifdef HAVE_LONG_INT_64
737-
/* if long > 32 bits, check for overflow of int4 */
738-
|| val != (long) ((int32) val)
739-
#endif
740-
)
735+
if (*endptr !='\0' || errno == ERANGE ||
736+
/* check for overflow of int */
737+
val != (int) val)
741738
{
742739
errno =0;
743740
base_yylval.str =mm_strdup(yytext);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp