diff options
author | Peter Eisentraut <peter@eisentraut.org> | 2022-10-10 08:51:07 +0200 |
---|---|---|
committer | Peter Eisentraut <peter@eisentraut.org> | 2022-10-10 09:01:17 +0200 |
commit | 357cfefb09115292cfb98d504199e6df8201c957 (patch) | |
tree | de61dcf6318f8de5c0f6126e9d1ee1b222150b46 /src | |
parent | 06dbd619bfbfe03fefa7223838690d4012f874ad (diff) | |
download | postgresql-357cfefb09115292cfb98d504199e6df8201c957.tar.gz postgresql-357cfefb09115292cfb98d504199e6df8201c957.zip |
Use C library functions instead of Abs() for int64
Instead of Abs() for int64, use the C standard functions labs() or
llabs() as appropriate. Define a small wrapper around them that
matches our definition of int64. (labs() is C90, llabs() is C99.)
Reviewed-by: Zhang Mingli <zmlpostgres@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://www.postgresql.org/message-id/flat/4beb42b5-216b-bce8-d452-d924d5794c63%40enterprisedb.com
Diffstat (limited to 'src')
-rw-r--r-- | src/backend/utils/adt/datetime.c | 8 | ||||
-rw-r--r-- | src/backend/utils/adt/dbsize.c | 2 | ||||
-rw-r--r-- | src/include/c.h | 9 |
3 files changed, 14 insertions, 5 deletions
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c index a8b025f43fa..4e9935e01dd 100644 --- a/src/backend/utils/adt/datetime.c +++ b/src/backend/utils/adt/datetime.c @@ -4468,7 +4468,7 @@ AddVerboseIntPart(char *cp, int64 value, const char *units, if (*is_zero) { *is_before = (value < 0); - value = Abs(value); + value = i64abs(value); } else if (*is_before) value = -value; @@ -4569,8 +4569,8 @@ EncodeInterval(struct pg_itm *itm, int style, char *str) sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:", year_sign, abs(year), abs(mon), - day_sign, (long long) Abs(mday), - sec_sign, (long long) Abs(hour), abs(min)); + day_sign, (long long) i64abs(mday), + sec_sign, (long long) i64abs(hour), abs(min)); cp += strlen(cp); cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true); *cp = '\0'; @@ -4642,7 +4642,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str) sprintf(cp, "%s%s%02lld:%02d:", is_zero ? "" : " ", (minus ? "-" : (is_before ? "+" : "")), - (long long) Abs(hour), abs(min)); + (long long) i64abs(hour), abs(min)); cp += strlen(cp); cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true); *cp = '\0'; diff --git a/src/backend/utils/adt/dbsize.c b/src/backend/utils/adt/dbsize.c index 34efa121b40..0a9b93f2634 100644 --- a/src/backend/utils/adt/dbsize.c +++ b/src/backend/utils/adt/dbsize.c @@ -564,7 +564,7 @@ pg_size_pretty(PG_FUNCTION_ARGS) uint8 bits; /* use this unit if there are no more units or we're below the limit */ - if (unit[1].name == NULL || Abs(size) < unit->limit) + if (unit[1].name == NULL || i64abs(size) < unit->limit) { if (unit->round) size = half_rounded(size); diff --git a/src/include/c.h b/src/include/c.h index c8f72e44d89..405d53cb56b 100644 --- a/src/include/c.h +++ b/src/include/c.h @@ -1283,6 +1283,15 @@ extern int fdatasync(int fildes); #endif /* + * Similarly, wrappers around labs()/llabs() matching our int64. + */ +#ifdef HAVE_LONG_INT_64 +#define i64abs(i) labs(i) +#else +#define i64abs(i) llabs(i) +#endif + +/* * Use "extern PGDLLIMPORT ..." to declare variables that are defined * in the core backend and need to be accessible by loadable modules. * No special marking is required on most ports. |