Const-ify a couple of datetime parsing subroutines.

More could be done in this line, but I just grabbed some low-hanging
fruit.  Principal objective was to remove the need for several ugly
unconstify() usages in formatting.c.
This commit is contained in:
Tom Lane 2022-12-09 10:43:45 -05:00
parent ccff2d20ed
commit bad5116957
3 changed files with 11 additions and 11 deletions

View File

@ -3145,7 +3145,7 @@ DecodeNumberField(int len, char *str, int fmask,
* Return 0 if okay (and set *tzp), a DTERR code if not okay. * Return 0 if okay (and set *tzp), a DTERR code if not okay.
*/ */
int int
DecodeTimezone(char *str, int *tzp) DecodeTimezone(const char *str, int *tzp)
{ {
int tz; int tz;
int hr, int hr,
@ -3223,7 +3223,7 @@ DecodeTimezone(char *str, int *tzp)
* will be related in format. * will be related in format.
*/ */
int int
DecodeTimezoneAbbrev(int field, char *lowtoken, DecodeTimezoneAbbrev(int field, const char *lowtoken,
int *offset, pg_tz **tz) int *offset, pg_tz **tz)
{ {
int type; int type;
@ -3278,7 +3278,7 @@ DecodeTimezoneAbbrev(int field, char *lowtoken,
* will be related in format. * will be related in format.
*/ */
int int
DecodeSpecial(int field, char *lowtoken, int *val) DecodeSpecial(int field, const char *lowtoken, int *val)
{ {
int type; int type;
const datetkn *tp; const datetkn *tp;
@ -3985,7 +3985,7 @@ DecodeISO8601Interval(char *str,
* will be related in format. * will be related in format.
*/ */
int int
DecodeUnits(int field, char *lowtoken, int *val) DecodeUnits(int field, const char *lowtoken, int *val)
{ {
int type; int type;
const datetkn *tp; const datetkn *tp;

View File

@ -4246,7 +4246,7 @@ to_timestamp(PG_FUNCTION_ARGS)
/* Use the specified time zone, if any. */ /* Use the specified time zone, if any. */
if (tm.tm_zone) if (tm.tm_zone)
{ {
int dterr = DecodeTimezone(unconstify(char *, tm.tm_zone), &tz); int dterr = DecodeTimezone(tm.tm_zone, &tz);
if (dterr) if (dterr)
DateTimeParseError(dterr, text_to_cstring(date_txt), "timestamptz"); DateTimeParseError(dterr, text_to_cstring(date_txt), "timestamptz");
@ -4343,7 +4343,7 @@ parse_datetime(text *date_txt, text *fmt, Oid collid, bool strict,
if (tm.tm_zone) if (tm.tm_zone)
{ {
int dterr = DecodeTimezone(unconstify(char *, tm.tm_zone), tz); int dterr = DecodeTimezone(tm.tm_zone, tz);
if (dterr) if (dterr)
DateTimeParseError(dterr, text_to_cstring(date_txt), "timestamptz"); DateTimeParseError(dterr, text_to_cstring(date_txt), "timestamptz");
@ -4429,7 +4429,7 @@ parse_datetime(text *date_txt, text *fmt, Oid collid, bool strict,
if (tm.tm_zone) if (tm.tm_zone)
{ {
int dterr = DecodeTimezone(unconstify(char *, tm.tm_zone), tz); int dterr = DecodeTimezone(tm.tm_zone, tz);
if (dterr) if (dterr)
RETURN_ERROR(DateTimeParseError(dterr, text_to_cstring(date_txt), "timetz")); RETURN_ERROR(DateTimeParseError(dterr, text_to_cstring(date_txt), "timetz"));

View File

@ -296,7 +296,7 @@ extern int ParseDateTime(const char *timestr, char *workbuf, size_t buflen,
extern int DecodeDateTime(char **field, int *ftype, extern int DecodeDateTime(char **field, int *ftype,
int nf, int *dtype, int nf, int *dtype,
struct pg_tm *tm, fsec_t *fsec, int *tzp); struct pg_tm *tm, fsec_t *fsec, int *tzp);
extern int DecodeTimezone(char *str, int *tzp); extern int DecodeTimezone(const char *str, int *tzp);
extern int DecodeTimeOnly(char **field, int *ftype, extern int DecodeTimeOnly(char **field, int *ftype,
int nf, int *dtype, int nf, int *dtype,
struct pg_tm *tm, fsec_t *fsec, int *tzp); struct pg_tm *tm, fsec_t *fsec, int *tzp);
@ -322,10 +322,10 @@ extern void EncodeSpecialTimestamp(Timestamp dt, char *str);
extern int ValidateDate(int fmask, bool isjulian, bool is2digits, bool bc, extern int ValidateDate(int fmask, bool isjulian, bool is2digits, bool bc,
struct pg_tm *tm); struct pg_tm *tm);
extern int DecodeTimezoneAbbrev(int field, char *lowtoken, extern int DecodeTimezoneAbbrev(int field, const char *lowtoken,
int *offset, pg_tz **tz); int *offset, pg_tz **tz);
extern int DecodeSpecial(int field, char *lowtoken, int *val); extern int DecodeSpecial(int field, const char *lowtoken, int *val);
extern int DecodeUnits(int field, char *lowtoken, int *val); extern int DecodeUnits(int field, const char *lowtoken, int *val);
extern int j2day(int date); extern int j2day(int date);