Const-ify a couple of datetime parsing subroutines.
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 9 Dec 2022 15:43:45 +0000 (10:43 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 9 Dec 2022 15:43:45 +0000 (10:43 -0500)
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.

src/backend/utils/adt/datetime.c
src/backend/utils/adt/formatting.c
src/include/utils/datetime.h

index 8cd10ab204a1b3f7dcca8b653a0546c774d808ea..6893c1ce09c4bfc05429af07f8b93e20c326eb73 100644 (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.
  */
 int
-DecodeTimezone(char *str, int *tzp)
+DecodeTimezone(const char *str, int *tzp)
 {
    int         tz;
    int         hr,
@@ -3223,7 +3223,7 @@ DecodeTimezone(char *str, int *tzp)
  * will be related in format.
  */
 int
-DecodeTimezoneAbbrev(int field, char *lowtoken,
+DecodeTimezoneAbbrev(int field, const char *lowtoken,
                     int *offset, pg_tz **tz)
 {
    int         type;
@@ -3278,7 +3278,7 @@ DecodeTimezoneAbbrev(int field, char *lowtoken,
  * will be related in format.
  */
 int
-DecodeSpecial(int field, char *lowtoken, int *val)
+DecodeSpecial(int field, const char *lowtoken, int *val)
 {
    int         type;
    const datetkn *tp;
@@ -3985,7 +3985,7 @@ DecodeISO8601Interval(char *str,
  * will be related in format.
  */
 int
-DecodeUnits(int field, char *lowtoken, int *val)
+DecodeUnits(int field, const char *lowtoken, int *val)
 {
    int         type;
    const datetkn *tp;
index 26f498b5df4d8eb280a0e6af69fd92d4ce0d89b7..311c9e748ba9e3eee7f58d78dcea20545ca172b6 100644 (file)
@@ -4246,7 +4246,7 @@ to_timestamp(PG_FUNCTION_ARGS)
    /* Use the specified time zone, if any. */
    if (tm.tm_zone)
    {
-       int         dterr = DecodeTimezone(unconstify(char *, tm.tm_zone), &tz);
+       int         dterr = DecodeTimezone(tm.tm_zone, &tz);
 
        if (dterr)
            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)
                {
-                   int         dterr = DecodeTimezone(unconstify(char *, tm.tm_zone), tz);
+                   int         dterr = DecodeTimezone(tm.tm_zone, tz);
 
                    if (dterr)
                        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)
            {
-               int         dterr = DecodeTimezone(unconstify(char *, tm.tm_zone), tz);
+               int         dterr = DecodeTimezone(tm.tm_zone, tz);
 
                if (dterr)
                    RETURN_ERROR(DateTimeParseError(dterr, text_to_cstring(date_txt), "timetz"));
index 2cae346beb042a5a91cf6632cf098ed3aca4ac9e..934cb56a3a54eaf7deab756aa7d57310a5dddeaf 100644 (file)
@@ -296,7 +296,7 @@ extern int  ParseDateTime(const char *timestr, char *workbuf, size_t buflen,
 extern int DecodeDateTime(char **field, int *ftype,
                           int nf, int *dtype,
                           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,
                           int nf, int *dtype,
                           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,
                         struct pg_tm *tm);
 
-extern int DecodeTimezoneAbbrev(int field, char *lowtoken,
+extern int DecodeTimezoneAbbrev(int field, const char *lowtoken,
                                 int *offset, pg_tz **tz);
-extern int DecodeSpecial(int field, char *lowtoken, int *val);
-extern int DecodeUnits(int field, char *lowtoken, int *val);
+extern int DecodeSpecial(int field, const char *lowtoken, int *val);
+extern int DecodeUnits(int field, const char *lowtoken, int *val);
 
 extern int j2day(int date);