Monday, September 1, 2008

Re: [HACKERS] [PATCH] Cleanup of GUC units code

diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c
index 4ca25dc..b10be22 100644
--- a/src/backend/utils/misc/guc.c
+++ b/src/backend/utils/misc/guc.c
@@ -4182,7 +4182,7 @@ parse_int(const char *value, int *result, int flags, const char **hintmsg)
#error XLOG_BLCKSZ must be between 1KB and 1MB
#endif

- if (strncmp(endptr, "kB", 2) == 0)
+ if (pg_strncasecmp(endptr, "kB", 2) == 0)
{
endptr += 2;
switch (flags & GUC_UNIT_MEMORY)
@@ -4195,7 +4195,7 @@ parse_int(const char *value, int *result, int flags, const char **hintmsg)
break;
}
}
- else if (strncmp(endptr, "MB", 2) == 0)
+ else if (pg_strncasecmp(endptr, "MB", 2) == 0)
{
endptr += 2;
switch (flags & GUC_UNIT_MEMORY)
@@ -4211,7 +4211,7 @@ parse_int(const char *value, int *result, int flags, const char **hintmsg)
break;
}
}
- else if (strncmp(endptr, "GB", 2) == 0)
+ else if (pg_strncasecmp(endptr, "GB", 2) == 0)
{
endptr += 2;
switch (flags & GUC_UNIT_MEMORY)
@@ -4234,7 +4234,7 @@ parse_int(const char *value, int *result, int flags, const char **hintmsg)
if (hintmsg)
*hintmsg = gettext_noop("Valid units for this parameter are \"ms\", \"s\", \"min\", \"h\", and \"d\".");

- if (strncmp(endptr, "ms", 2) == 0)
+ if (pg_strncasecmp(endptr, "ms", 2) == 0)
{
endptr += 2;
switch (flags & GUC_UNIT_TIME)
@@ -4247,7 +4247,7 @@ parse_int(const char *value, int *result, int flags, const char **hintmsg)
break;
}
}
- else if (strncmp(endptr, "s", 1) == 0)
+ else if (pg_strncasecmp(endptr, "s", 1) == 0)
{
endptr += 1;
switch (flags & GUC_UNIT_TIME)
@@ -4260,7 +4260,7 @@ parse_int(const char *value, int *result, int flags, const char **hintmsg)
break;
}
}
- else if (strncmp(endptr, "min", 3) == 0)
+ else if (pg_strncasecmp(endptr, "min", 3) == 0)
{
endptr += 3;
switch (flags & GUC_UNIT_TIME)
@@ -4273,7 +4273,7 @@ parse_int(const char *value, int *result, int flags, const char **hintmsg)
break;
}
}
- else if (strncmp(endptr, "h", 1) == 0)
+ else if (pg_strncasecmp(endptr, "h", 1) == 0)
{
endptr += 1;
switch (flags & GUC_UNIT_TIME)
@@ -4289,7 +4289,7 @@ parse_int(const char *value, int *result, int flags, const char **hintmsg)
break;
}
}
- else if (strncmp(endptr, "d", 1) == 0)
+ else if (pg_strncasecmp(endptr, "d", 1) == 0)
{
endptr += 1;
switch (flags & GUC_UNIT_TIME)
On 9/1/08, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Marko Kreen <markokr@gmail.com> writes:
> > - In attempt to preserve maximum range of values for INT64_IS_BUSTED
> > systems, the code is written rather non-obvious way.
>
> I do not personally object a bit to making the units comparisons
> case-insensitive (I think it's mainly Peter who wants to be strict
> about it). I don't think there are any other good ideas in this
> patch, however, and exposing ourselves to intermediate overflows in
> the name of simplicity is definitely not one.

For all practical purposes, the overflow is insignificant when int64
works. I'll look if I can avoid it on INT64_IS_BUSTED case.

In the meantime, here is simple patch for case-insensivity.

--
marko

No comments: