Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit960af47

Browse files
committed
Const-ify the arguments of str_tolower() and friends to suppress compile
warnings. Clean up various unneeded cruft that was left behind aftercreating those routines. Introduce some convenience functions str_tolower_zetc to eliminate tedious and error-prone double arguments in formatting.c.(Currently there seems no need to export the latter, but maybe reconsiderthis later.)
1 parent27cb66f commit960af47

File tree

3 files changed

+66
-86
lines changed

3 files changed

+66
-86
lines changed

‎src/backend/utils/adt/formatting.c

Lines changed: 55 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* -----------------------------------------------------------------------
22
* formatting.c
33
*
4-
* $PostgreSQL: pgsql/src/backend/utils/adt/formatting.c,v 1.144 2008/06/26 16:06:37teodor Exp $
4+
* $PostgreSQL: pgsql/src/backend/utils/adt/formatting.c,v 1.145 2008/07/12 00:44:37tgl Exp $
55
*
66
*
77
* Portions Copyright (c) 1999-2008, PostgreSQL Global Development Group
@@ -945,13 +945,6 @@ static NUMCacheEntry *NUM_cache_search(char *str);
945945
staticNUMCacheEntry*NUM_cache_getnew(char*str);
946946
staticvoidNUM_cache_remove(NUMCacheEntry*ent);
947947

948-
#ifdefUSE_WIDE_UPPER_LOWER
949-
/* externs are in oracle_compat.c */
950-
externchar*wstring_upper(char*str);
951-
externchar*wstring_lower(char*str);
952-
externwchar_t*texttowcs(consttext*txt);
953-
externtext*wcstotext(constwchar_t*str,intncodes);
954-
#endif
955948

956949
/* ----------
957950
* Fast sequential search, use index for data selection which
@@ -1431,14 +1424,14 @@ str_numth(char *dest, char *num, int type)
14311424
* by LC_CTYPE.
14321425
*/
14331426

1434-
/* ----------
1427+
/*
14351428
* wide-character-aware lower function
1429+
*
14361430
* We pass the number of bytes so we can pass varlena and char*
1437-
* to this function.
1438-
* ----------
1431+
* to this function. The result is a palloc'd, null-terminated string.
14391432
*/
14401433
char*
1441-
str_tolower(char*buff,size_tnbytes)
1434+
str_tolower(constchar*buff,size_tnbytes)
14421435
{
14431436
char*result;
14441437

@@ -1479,14 +1472,14 @@ str_tolower(char *buff, size_t nbytes)
14791472
returnresult;
14801473
}
14811474

1482-
/* ----------
1475+
/*
14831476
* wide-character-aware upper function
1477+
*
14841478
* We pass the number of bytes so we can pass varlena and char*
1485-
* to this function.
1486-
* ----------
1479+
* to this function. The result is a palloc'd, null-terminated string.
14871480
*/
14881481
char*
1489-
str_toupper(char*buff,size_tnbytes)
1482+
str_toupper(constchar*buff,size_tnbytes)
14901483
{
14911484
char*result;
14921485

@@ -1527,14 +1520,14 @@ str_toupper(char *buff, size_t nbytes)
15271520
returnresult;
15281521
}
15291522

1530-
/* ----------
1523+
/*
15311524
* wide-character-aware initcap function
1525+
*
15321526
* We pass the number of bytes so we can pass varlena and char*
1533-
* to this function.
1534-
* ----------
1527+
* to this function. The result is a palloc'd, null-terminated string.
15351528
*/
15361529
char*
1537-
str_initcap(char*buff,size_tnbytes)
1530+
str_initcap(constchar*buff,size_tnbytes)
15381531
{
15391532
char*result;
15401533
boolwasalnum= false;
@@ -1588,6 +1581,27 @@ str_initcap(char *buff, size_t nbytes)
15881581
returnresult;
15891582
}
15901583

1584+
/* convenience routines for when the input is null-terminated */
1585+
1586+
staticchar*
1587+
str_tolower_z(constchar*buff)
1588+
{
1589+
returnstr_tolower(buff,strlen(buff));
1590+
}
1591+
1592+
staticchar*
1593+
str_toupper_z(constchar*buff)
1594+
{
1595+
returnstr_toupper(buff,strlen(buff));
1596+
}
1597+
1598+
staticchar*
1599+
str_initcap_z(constchar*buff)
1600+
{
1601+
returnstr_initcap(buff,strlen(buff));
1602+
}
1603+
1604+
15911605
/* ----------
15921606
* Sequential search with to upper/lower conversion
15931607
* ----------
@@ -1791,8 +1805,7 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out)
17911805
FormatNode*n;
17921806
char*s;
17931807
structpg_tm*tm=&in->tm;
1794-
charbuff[DCH_CACHE_SIZE],
1795-
workbuff[32];
1808+
charbuff[DCH_CACHE_SIZE];
17961809
inti;
17971810

17981811
/* cache localized days and months */
@@ -1895,9 +1908,9 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out)
18951908
INVALID_FOR_INTERVAL;
18961909
if (tmtcTzn(in))
18971910
{
1898-
char*p=pstrdup(tmtcTzn(in));
1911+
char*p=str_tolower_z(tmtcTzn(in));
18991912

1900-
strcpy(s,str_tolower(p,strlen(p)));
1913+
strcpy(s,p);
19011914
pfree(p);
19021915
s+=strlen(s);
19031916
}
@@ -1939,23 +1952,18 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out)
19391952
if (!tm->tm_mon)
19401953
break;
19411954
if (S_TM(n->suffix))
1942-
strcpy(s,str_toupper(localized_full_months[tm->tm_mon-1],
1943-
strlen(localized_full_months[tm->tm_mon-1])));
1955+
strcpy(s,str_toupper_z(localized_full_months[tm->tm_mon-1]));
19441956
else
1945-
{
1946-
strcpy(workbuff,months_full[tm->tm_mon-1]);
19471957
sprintf(s,"%*s",S_FM(n->suffix) ?0 :-9,
1948-
str_toupper(workbuff,strlen(workbuff)));
1949-
}
1958+
str_toupper_z(months_full[tm->tm_mon-1]));
19501959
s+=strlen(s);
19511960
break;
19521961
caseDCH_Month:
19531962
INVALID_FOR_INTERVAL;
19541963
if (!tm->tm_mon)
19551964
break;
19561965
if (S_TM(n->suffix))
1957-
strcpy(s,str_initcap(localized_full_months[tm->tm_mon-1],
1958-
strlen(localized_full_months[tm->tm_mon-1])));
1966+
strcpy(s,str_initcap_z(localized_full_months[tm->tm_mon-1]));
19591967
else
19601968
sprintf(s,"%*s",S_FM(n->suffix) ?0 :-9,months_full[tm->tm_mon-1]);
19611969
s+=strlen(s);
@@ -1965,8 +1973,7 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out)
19651973
if (!tm->tm_mon)
19661974
break;
19671975
if (S_TM(n->suffix))
1968-
strcpy(s,str_tolower(localized_full_months[tm->tm_mon-1],
1969-
strlen(localized_full_months[tm->tm_mon-1])));
1976+
strcpy(s,str_tolower_z(localized_full_months[tm->tm_mon-1]));
19701977
else
19711978
{
19721979
sprintf(s,"%*s",S_FM(n->suffix) ?0 :-9,months_full[tm->tm_mon-1]);
@@ -1979,20 +1986,17 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out)
19791986
if (!tm->tm_mon)
19801987
break;
19811988
if (S_TM(n->suffix))
1982-
strcpy(s,str_toupper(localized_abbrev_months[tm->tm_mon-1],
1983-
strlen(localized_abbrev_months[tm->tm_mon-1])));
1989+
strcpy(s,str_toupper_z(localized_abbrev_months[tm->tm_mon-1]));
19841990
else
1985-
strcpy(s,str_toupper(months[tm->tm_mon-1],
1986-
strlen(months[tm->tm_mon-1])));
1991+
strcpy(s,str_toupper_z(months[tm->tm_mon-1]));
19871992
s+=strlen(s);
19881993
break;
19891994
caseDCH_Mon:
19901995
INVALID_FOR_INTERVAL;
19911996
if (!tm->tm_mon)
19921997
break;
19931998
if (S_TM(n->suffix))
1994-
strcpy(s,str_initcap(localized_abbrev_months[tm->tm_mon-1],
1995-
strlen(localized_abbrev_months[tm->tm_mon-1])));
1999+
strcpy(s,str_initcap_z(localized_abbrev_months[tm->tm_mon-1]));
19962000
else
19972001
strcpy(s,months[tm->tm_mon-1]);
19982002
s+=strlen(s);
@@ -2002,8 +2006,7 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out)
20022006
if (!tm->tm_mon)
20032007
break;
20042008
if (S_TM(n->suffix))
2005-
strcpy(s,str_tolower(localized_abbrev_months[tm->tm_mon-1],
2006-
strlen(localized_abbrev_months[tm->tm_mon-1])));
2009+
strcpy(s,str_tolower_z(localized_abbrev_months[tm->tm_mon-1]));
20072010
else
20082011
{
20092012
strcpy(s,months[tm->tm_mon-1]);
@@ -2020,30 +2023,24 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out)
20202023
caseDCH_DAY:
20212024
INVALID_FOR_INTERVAL;
20222025
if (S_TM(n->suffix))
2023-
strcpy(s,str_toupper(localized_full_days[tm->tm_wday],
2024-
strlen(localized_full_days[tm->tm_wday])));
2026+
strcpy(s,str_toupper_z(localized_full_days[tm->tm_wday]));
20252027
else
2026-
{
2027-
strcpy(workbuff,days[tm->tm_wday]);
20282028
sprintf(s,"%*s",S_FM(n->suffix) ?0 :-9,
2029-
str_toupper(workbuff,strlen(workbuff)));
2030-
}
2029+
str_toupper_z(days[tm->tm_wday]));
20312030
s+=strlen(s);
20322031
break;
20332032
caseDCH_Day:
20342033
INVALID_FOR_INTERVAL;
20352034
if (S_TM(n->suffix))
2036-
strcpy(s,str_initcap(localized_full_days[tm->tm_wday],
2037-
strlen(localized_full_days[tm->tm_wday])));
2035+
strcpy(s,str_initcap_z(localized_full_days[tm->tm_wday]));
20382036
else
20392037
sprintf(s,"%*s",S_FM(n->suffix) ?0 :-9,days[tm->tm_wday]);
20402038
s+=strlen(s);
20412039
break;
20422040
caseDCH_day:
20432041
INVALID_FOR_INTERVAL;
20442042
if (S_TM(n->suffix))
2045-
strcpy(s,str_tolower(localized_full_days[tm->tm_wday],
2046-
strlen(localized_full_days[tm->tm_wday])));
2043+
strcpy(s,str_tolower_z(localized_full_days[tm->tm_wday]));
20472044
else
20482045
{
20492046
sprintf(s,"%*s",S_FM(n->suffix) ?0 :-9,days[tm->tm_wday]);
@@ -2054,27 +2051,23 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out)
20542051
caseDCH_DY:
20552052
INVALID_FOR_INTERVAL;
20562053
if (S_TM(n->suffix))
2057-
strcpy(s,str_toupper(localized_abbrev_days[tm->tm_wday],
2058-
strlen(localized_abbrev_days[tm->tm_wday])));
2054+
strcpy(s,str_toupper_z(localized_abbrev_days[tm->tm_wday]));
20592055
else
2060-
strcpy(s,str_toupper(days_short[tm->tm_wday],
2061-
strlen(days_short[tm->tm_wday])));
2056+
strcpy(s,str_toupper_z(days_short[tm->tm_wday]));
20622057
s+=strlen(s);
20632058
break;
20642059
caseDCH_Dy:
20652060
INVALID_FOR_INTERVAL;
20662061
if (S_TM(n->suffix))
2067-
strcpy(s,str_initcap(localized_abbrev_days[tm->tm_wday],
2068-
strlen(localized_abbrev_days[tm->tm_wday])));
2062+
strcpy(s,str_initcap_z(localized_abbrev_days[tm->tm_wday]));
20692063
else
20702064
strcpy(s,days_short[tm->tm_wday]);
20712065
s+=strlen(s);
20722066
break;
20732067
caseDCH_dy:
20742068
INVALID_FOR_INTERVAL;
20752069
if (S_TM(n->suffix))
2076-
strcpy(s,str_tolower(localized_abbrev_days[tm->tm_wday],
2077-
strlen(localized_abbrev_days[tm->tm_wday])));
2070+
strcpy(s,str_tolower_z(localized_abbrev_days[tm->tm_wday]));
20782071
else
20792072
{
20802073
strcpy(s,days_short[tm->tm_wday]);
@@ -4339,14 +4332,12 @@ NUM_processor(FormatNode *node, NUMDesc *Num, char *inout, char *number,
43394332
caseNUM_rn:
43404333
if (IS_FILLMODE(Np->Num))
43414334
{
4342-
strcpy(Np->inout_p,str_tolower(Np->number_p,
4343-
strlen(Np->number_p)));
4335+
strcpy(Np->inout_p,str_tolower_z(Np->number_p));
43444336
Np->inout_p+=strlen(Np->inout_p)-1;
43454337
}
43464338
else
43474339
{
4348-
sprintf(Np->inout_p,"%15s",str_tolower(Np->number_p,
4349-
strlen(Np->number_p)));
4340+
sprintf(Np->inout_p,"%15s",str_tolower_z(Np->number_p));
43504341
Np->inout_p+=strlen(Np->inout_p)-1;
43514342
}
43524343
break;

‎src/backend/utils/adt/oracle_compat.c

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,14 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
*$PostgreSQL: pgsql/src/backend/utils/adt/oracle_compat.c,v 1.81 2008/06/23 19:27:19 momjian Exp $
12+
*$PostgreSQL: pgsql/src/backend/utils/adt/oracle_compat.c,v 1.82 2008/07/12 00:44:37 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
1616
#include"postgres.h"
1717

18-
#include<ctype.h>
19-
#include<limits.h>
20-
/*
21-
* towlower() and friends should be in <wctype.h>, but some pre-C99 systems
22-
* declare them in <wchar.h>.
23-
*/
24-
#ifdefHAVE_WCHAR_H
25-
#include<wchar.h>
26-
#endif
27-
#ifdefHAVE_WCTYPE_H
28-
#include<wctype.h>
29-
#endif
30-
3118
#include"utils/builtins.h"
3219
#include"utils/formatting.h"
33-
#include"utils/pg_locale.h"
3420
#include"mb/pg_wchar.h"
3521

3622

@@ -60,7 +46,8 @@ lower(PG_FUNCTION_ARGS)
6046
char*out_string;
6147
text*result;
6248

63-
out_string=str_tolower(VARDATA_ANY(in_string),VARSIZE_ANY_EXHDR(in_string));
49+
out_string=str_tolower(VARDATA_ANY(in_string),
50+
VARSIZE_ANY_EXHDR(in_string));
6451
result=cstring_to_text(out_string);
6552
pfree(out_string);
6653

@@ -89,7 +76,8 @@ upper(PG_FUNCTION_ARGS)
8976
char*out_string;
9077
text*result;
9178

92-
out_string=str_toupper(VARDATA_ANY(in_string),VARSIZE_ANY_EXHDR(in_string));
79+
out_string=str_toupper(VARDATA_ANY(in_string),
80+
VARSIZE_ANY_EXHDR(in_string));
9381
result=cstring_to_text(out_string);
9482
pfree(out_string);
9583

@@ -121,7 +109,8 @@ initcap(PG_FUNCTION_ARGS)
121109
char*out_string;
122110
text*result;
123111

124-
out_string=str_initcap(VARDATA_ANY(in_string),VARSIZE_ANY_EXHDR(in_string));
112+
out_string=str_initcap(VARDATA_ANY(in_string),
113+
VARSIZE_ANY_EXHDR(in_string));
125114
result=cstring_to_text(out_string);
126115
pfree(out_string);
127116

‎src/include/utils/formatting.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/* -----------------------------------------------------------------------
33
* formatting.h
44
*
5-
* $PostgreSQL: pgsql/src/include/utils/formatting.h,v 1.19 2008/06/23 19:27:19 momjian Exp $
5+
* $PostgreSQL: pgsql/src/include/utils/formatting.h,v 1.20 2008/07/12 00:44:38 tgl Exp $
66
*
77
*
88
* Portions Copyright (c) 1999-2008, PostgreSQL Global Development Group
@@ -21,9 +21,9 @@
2121
#include"fmgr.h"
2222

2323

24-
externchar*str_tolower(char*buff,size_tnbytes);
25-
externchar*str_toupper(char*buff,size_tnbytes);
26-
externchar*str_initcap(char*buff,size_tnbytes);
24+
externchar*str_tolower(constchar*buff,size_tnbytes);
25+
externchar*str_toupper(constchar*buff,size_tnbytes);
26+
externchar*str_initcap(constchar*buff,size_tnbytes);
2727

2828
externDatumtimestamp_to_char(PG_FUNCTION_ARGS);
2929
externDatumtimestamptz_to_char(PG_FUNCTION_ARGS);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp