Change internal integer representation of Value node
A Value node would store an integer as a long. This causes needless portability risks, as long can be of varying sizes. Change it to use int instead. All code using this was already careful to only store 32-bit values anyway. Reviewed-by: Michael Paquier <michael@paquier.xyz>
This commit is contained in:
parent
377b5ac484
commit
6cf86f4354
@ -3235,7 +3235,7 @@ _outValue(StringInfo str, const Value *value)
|
|||||||
switch (value->type)
|
switch (value->type)
|
||||||
{
|
{
|
||||||
case T_Integer:
|
case T_Integer:
|
||||||
appendStringInfo(str, "%ld", value->val.ival);
|
appendStringInfo(str, "%d", value->val.ival);
|
||||||
break;
|
break;
|
||||||
case T_Float:
|
case T_Float:
|
||||||
|
|
||||||
|
@ -224,13 +224,9 @@ nodeTokenType(char *token, int length)
|
|||||||
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
val = strtol(token, &endptr, 10);
|
val = strtol(token, &endptr, 10);
|
||||||
(void) val; /* avoid compiler warning if unused */
|
if (endptr != token + length || errno == ERANGE ||
|
||||||
if (endptr != token + length || errno == ERANGE
|
/* check for overflow of int */
|
||||||
#ifdef HAVE_LONG_INT_64
|
val != (int) val)
|
||||||
/* if long > 32 bits, check for overflow of int4 */
|
|
||||||
|| val != (long) ((int32) val)
|
|
||||||
#endif
|
|
||||||
)
|
|
||||||
return T_Float;
|
return T_Float;
|
||||||
return T_Integer;
|
return T_Integer;
|
||||||
}
|
}
|
||||||
@ -387,9 +383,9 @@ nodeRead(char *token, int tok_len)
|
|||||||
case T_Integer:
|
case T_Integer:
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* we know that the token terminates on a char atol will stop at
|
* we know that the token terminates on a char atoi will stop at
|
||||||
*/
|
*/
|
||||||
result = (Node *) makeInteger(atol(token));
|
result = (Node *) makeInteger(atoi(token));
|
||||||
break;
|
break;
|
||||||
case T_Float:
|
case T_Float:
|
||||||
{
|
{
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
* makeInteger
|
* makeInteger
|
||||||
*/
|
*/
|
||||||
Value *
|
Value *
|
||||||
makeInteger(long i)
|
makeInteger(int i)
|
||||||
{
|
{
|
||||||
Value *v = makeNode(Value);
|
Value *v = makeNode(Value);
|
||||||
|
|
||||||
|
@ -1216,12 +1216,9 @@ process_integer_literal(const char *token, YYSTYPE *lval)
|
|||||||
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
val = strtol(token, &endptr, 10);
|
val = strtol(token, &endptr, 10);
|
||||||
if (*endptr != '\0' || errno == ERANGE
|
if (*endptr != '\0' || errno == ERANGE ||
|
||||||
#ifdef HAVE_LONG_INT_64
|
/* check for overflow of int */
|
||||||
/* if long > 32 bits, check for overflow of int4 */
|
val != (int) val)
|
||||||
|| val != (long) ((int32) val)
|
|
||||||
#endif
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
/* integer too large, treat it as a float */
|
/* integer too large, treat it as a float */
|
||||||
lval->str = pstrdup(token);
|
lval->str = pstrdup(token);
|
||||||
|
@ -6913,7 +6913,7 @@ flatten_set_variable_args(const char *name, List *args)
|
|||||||
switch (nodeTag(&con->val))
|
switch (nodeTag(&con->val))
|
||||||
{
|
{
|
||||||
case T_Integer:
|
case T_Integer:
|
||||||
appendStringInfo(&buf, "%ld", intVal(&con->val));
|
appendStringInfo(&buf, "%d", intVal(&con->val));
|
||||||
break;
|
break;
|
||||||
case T_Float:
|
case T_Float:
|
||||||
/* represented as a string, so just copy it */
|
/* represented as a string, so just copy it */
|
||||||
|
@ -34,7 +34,7 @@
|
|||||||
* better to use the more general representation.)
|
* better to use the more general representation.)
|
||||||
*
|
*
|
||||||
* Note that an integer-looking string will get lexed as T_Float if
|
* Note that an integer-looking string will get lexed as T_Float if
|
||||||
* the value is too large to fit in a 'long'.
|
* the value is too large to fit in an 'int'.
|
||||||
*
|
*
|
||||||
* Nulls, of course, don't need the value part at all.
|
* Nulls, of course, don't need the value part at all.
|
||||||
*----------------------
|
*----------------------
|
||||||
@ -44,7 +44,7 @@ typedef struct Value
|
|||||||
NodeTag type; /* tag appropriately (eg. T_String) */
|
NodeTag type; /* tag appropriately (eg. T_String) */
|
||||||
union ValUnion
|
union ValUnion
|
||||||
{
|
{
|
||||||
long ival; /* machine integer */
|
int ival; /* machine integer */
|
||||||
char *str; /* string */
|
char *str; /* string */
|
||||||
} val;
|
} val;
|
||||||
} Value;
|
} Value;
|
||||||
@ -53,7 +53,7 @@ typedef struct Value
|
|||||||
#define floatVal(v) atof(((Value *)(v))->val.str)
|
#define floatVal(v) atof(((Value *)(v))->val.str)
|
||||||
#define strVal(v) (((Value *)(v))->val.str)
|
#define strVal(v) (((Value *)(v))->val.str)
|
||||||
|
|
||||||
extern Value *makeInteger(long i);
|
extern Value *makeInteger(int i);
|
||||||
extern Value *makeFloat(char *numericStr);
|
extern Value *makeFloat(char *numericStr);
|
||||||
extern Value *makeString(char *str);
|
extern Value *makeString(char *str);
|
||||||
extern Value *makeBitString(char *str);
|
extern Value *makeBitString(char *str);
|
||||||
|
@ -732,12 +732,9 @@ cppline {space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})((\/\*[^*/]*\*+
|
|||||||
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
val = strtol((char *)yytext, &endptr,10);
|
val = strtol((char *)yytext, &endptr,10);
|
||||||
if (*endptr != '\0' || errno == ERANGE
|
if (*endptr != '\0' || errno == ERANGE ||
|
||||||
#ifdef HAVE_LONG_INT_64
|
/* check for overflow of int */
|
||||||
/* if long > 32 bits, check for overflow of int4 */
|
val != (int) val)
|
||||||
|| val != (long) ((int32) val)
|
|
||||||
#endif
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
errno = 0;
|
errno = 0;
|
||||||
base_yylval.str = mm_strdup(yytext);
|
base_yylval.str = mm_strdup(yytext);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user