Skip to content

Commit bad5116

Browse files
committed
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.
1 parent ccff2d2 commit bad5116

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

src/backend/utils/adt/datetime.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3145,7 +3145,7 @@ DecodeNumberField(int len, char *str, int fmask,
31453145
* Return 0 if okay (and set *tzp), a DTERR code if not okay.
31463146
*/
31473147
int
3148-
DecodeTimezone(char *str, int *tzp)
3148+
DecodeTimezone(const char *str, int *tzp)
31493149
{
31503150
int tz;
31513151
int hr,
@@ -3223,7 +3223,7 @@ DecodeTimezone(char *str, int *tzp)
32233223
* will be related in format.
32243224
*/
32253225
int
3226-
DecodeTimezoneAbbrev(int field, char *lowtoken,
3226+
DecodeTimezoneAbbrev(int field, const char *lowtoken,
32273227
int *offset, pg_tz **tz)
32283228
{
32293229
int type;
@@ -3278,7 +3278,7 @@ DecodeTimezoneAbbrev(int field, char *lowtoken,
32783278
* will be related in format.
32793279
*/
32803280
int
3281-
DecodeSpecial(int field, char *lowtoken, int *val)
3281+
DecodeSpecial(int field, const char *lowtoken, int *val)
32823282
{
32833283
int type;
32843284
const datetkn *tp;
@@ -3985,7 +3985,7 @@ DecodeISO8601Interval(char *str,
39853985
* will be related in format.
39863986
*/
39873987
int
3988-
DecodeUnits(int field, char *lowtoken, int *val)
3988+
DecodeUnits(int field, const char *lowtoken, int *val)
39893989
{
39903990
int type;
39913991
const datetkn *tp;

src/backend/utils/adt/formatting.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4246,7 +4246,7 @@ to_timestamp(PG_FUNCTION_ARGS)
42464246
/* Use the specified time zone, if any. */
42474247
if (tm.tm_zone)
42484248
{
4249-
int dterr = DecodeTimezone(unconstify(char *, tm.tm_zone), &tz);
4249+
int dterr = DecodeTimezone(tm.tm_zone, &tz);
42504250

42514251
if (dterr)
42524252
DateTimeParseError(dterr, text_to_cstring(date_txt), "timestamptz");
@@ -4343,7 +4343,7 @@ parse_datetime(text *date_txt, text *fmt, Oid collid, bool strict,
43434343

43444344
if (tm.tm_zone)
43454345
{
4346-
int dterr = DecodeTimezone(unconstify(char *, tm.tm_zone), tz);
4346+
int dterr = DecodeTimezone(tm.tm_zone, tz);
43474347

43484348
if (dterr)
43494349
DateTimeParseError(dterr, text_to_cstring(date_txt), "timestamptz");
@@ -4429,7 +4429,7 @@ parse_datetime(text *date_txt, text *fmt, Oid collid, bool strict,
44294429

44304430
if (tm.tm_zone)
44314431
{
4432-
int dterr = DecodeTimezone(unconstify(char *, tm.tm_zone), tz);
4432+
int dterr = DecodeTimezone(tm.tm_zone, tz);
44334433

44344434
if (dterr)
44354435
RETURN_ERROR(DateTimeParseError(dterr, text_to_cstring(date_txt), "timetz"));

src/include/utils/datetime.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ extern int ParseDateTime(const char *timestr, char *workbuf, size_t buflen,
296296
extern int DecodeDateTime(char **field, int *ftype,
297297
int nf, int *dtype,
298298
struct pg_tm *tm, fsec_t *fsec, int *tzp);
299-
extern int DecodeTimezone(char *str, int *tzp);
299+
extern int DecodeTimezone(const char *str, int *tzp);
300300
extern int DecodeTimeOnly(char **field, int *ftype,
301301
int nf, int *dtype,
302302
struct pg_tm *tm, fsec_t *fsec, int *tzp);
@@ -322,10 +322,10 @@ extern void EncodeSpecialTimestamp(Timestamp dt, char *str);
322322
extern int ValidateDate(int fmask, bool isjulian, bool is2digits, bool bc,
323323
struct pg_tm *tm);
324324

325-
extern int DecodeTimezoneAbbrev(int field, char *lowtoken,
325+
extern int DecodeTimezoneAbbrev(int field, const char *lowtoken,
326326
int *offset, pg_tz **tz);
327-
extern int DecodeSpecial(int field, char *lowtoken, int *val);
328-
extern int DecodeUnits(int field, char *lowtoken, int *val);
327+
extern int DecodeSpecial(int field, const char *lowtoken, int *val);
328+
extern int DecodeUnits(int field, const char *lowtoken, int *val);
329329

330330
extern int j2day(int date);
331331

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy