Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 0bd6154

Browse files
committed
Solve the 'Turkish problem' with undesirable locale behavior for case
conversion of basic ASCII letters. Remove all uses of strcasecmp and strncasecmp in favor of new functions pg_strcasecmp and pg_strncasecmp; remove most but not all direct uses of toupper and tolower in favor of pg_toupper and pg_tolower. These functions use the same notions of case folding already developed for identifier case conversion. I left the straight locale-based folding in place for situations where we are just manipulating user data and not trying to match it to built-in strings --- for example, the SQL upper() function is still locale dependent. Perhaps this will prove not to be what's wanted, but at the moment we can initdb and pass regression tests in Turkish locale.
1 parent 4d46274 commit 0bd6154

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+819
-922
lines changed

configure

+1-2
Original file line numberDiff line numberDiff line change
@@ -11744,8 +11744,7 @@ fi
1174411744

1174511745

1174611746

11747-
11748-
for ac_func in crypt fseeko getopt getrusage inet_aton random rint srandom strcasecmp strdup strerror strtol strtoul unsetenv
11747+
for ac_func in crypt fseeko getopt getrusage inet_aton random rint srandom strdup strerror strtol strtoul unsetenv
1174911748
do
1175011749
as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
1175111750
echo "$as_me:$LINENO: checking for $ac_func" >&5

configure.in

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
dnl Process this file with autoconf to produce a configure script.
2-
dnl $PostgreSQL: pgsql/configure.in,v 1.344 2004/05/05 21:18:29 tgl Exp $
2+
dnl $PostgreSQL: pgsql/configure.in,v 1.345 2004/05/07 00:24:57 tgl Exp $
33
dnl
44
dnl Developers, please strive to achieve this order:
55
dnl
@@ -858,7 +858,7 @@ else
858858
AC_CHECK_FUNCS([fpclass fp_class fp_class_d class], [break])
859859
fi
860860

861-
AC_REPLACE_FUNCS([crypt fseeko getopt getrusage inet_aton random rint srandom strcasecmp strdup strerror strtol strtoul unsetenv])
861+
AC_REPLACE_FUNCS([crypt fseeko getopt getrusage inet_aton random rint srandom strdup strerror strtol strtoul unsetenv])
862862

863863
# system's version of getaddrinfo(), if any, may be used only if we found
864864
# a definition for struct addrinfo; see notes in src/include/getaddrinfo.h

contrib/ltree/lquery_op.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ checkLevel(lquery_level * curq, ltree_level * curt)
9191

9292
for (i = 0; i < curq->numvar; i++)
9393
{
94-
cmpptr = (curvar->flag & LVAR_INCASE) ? strncasecmp : strncmp;
94+
cmpptr = (curvar->flag & LVAR_INCASE) ? pg_strncasecmp : strncmp;
9595

9696
if (curvar->flag & LVAR_SUBLEXEM)
9797
{

contrib/ltree/ltxtquery_op.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ checkcondition_str(void *checkval, ITEM * val)
5454
char *op = ((CHKVAL *) checkval)->operand + val->distance;
5555
int (*cmpptr) (const char *, const char *, size_t);
5656

57-
cmpptr = (val->flag & LVAR_INCASE) ? strncasecmp : strncmp;
57+
cmpptr = (val->flag & LVAR_INCASE) ? pg_strncasecmp : strncmp;
5858
while (tlen > 0)
5959
{
6060
if (val->flag & LVAR_SUBLEXEM)

contrib/pgcrypto/internal.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2727
* SUCH DAMAGE.
2828
*
29-
* $PostgreSQL: pgsql/contrib/pgcrypto/internal.c,v 1.12 2003/11/29 22:39:28 pgsql Exp $
29+
* $PostgreSQL: pgsql/contrib/pgcrypto/internal.c,v 1.13 2004/05/07 00:24:57 tgl Exp $
3030
*/
3131

3232

@@ -561,7 +561,7 @@ px_find_digest(const char *name, PX_MD ** res)
561561
PX_MD *h;
562562

563563
for (p = int_digest_list; p->name; p++)
564-
if (!strcasecmp(p->name, name))
564+
if (pg_strcasecmp(p->name, name) == 0)
565565
{
566566
h = px_alloc(sizeof(*h));
567567
p->init(h);

contrib/pgcrypto/md5.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/contrib/pgcrypto/md5.c,v 1.10 2003/11/29 22:39:28 pgsql Exp $ */
1+
/* $PostgreSQL: pgsql/contrib/pgcrypto/md5.c,v 1.11 2004/05/07 00:24:57 tgl Exp $ */
22
/* $KAME: md5.c,v 1.3 2000/02/22 14:01:17 itojun Exp $ */
33

44
/*
@@ -141,7 +141,7 @@ md5_init(md5_ctxt * ctxt)
141141
ctxt->md5_stb = MD5_B0;
142142
ctxt->md5_stc = MD5_C0;
143143
ctxt->md5_std = MD5_D0;
144-
bzero(ctxt->md5_buf, sizeof(ctxt->md5_buf));
144+
memset(ctxt->md5_buf, 0, sizeof(ctxt->md5_buf));
145145
}
146146

147147
void

contrib/pgcrypto/mhash.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2727
* SUCH DAMAGE.
2828
*
29-
* $PostgreSQL: pgsql/contrib/pgcrypto/mhash.c,v 1.9 2003/11/29 22:39:28 pgsql Exp $
29+
* $PostgreSQL: pgsql/contrib/pgcrypto/mhash.c,v 1.10 2004/05/07 00:24:57 tgl Exp $
3030
*/
3131

3232
#include <postgres.h>
@@ -217,9 +217,9 @@ find_hashid(const char *name)
217217
mname = mhash_get_hash_name(i);
218218
if (mname == NULL)
219219
continue;
220-
b = strcasecmp(name, mname);
220+
b = pg_strcasecmp(name, mname);
221221
free(mname);
222-
if (!b)
222+
if (b == 0)
223223
{
224224
res = i;
225225
break;
@@ -312,7 +312,7 @@ px_find_cipher(const char *name, PX_Cipher ** res)
312312

313313
PX_Cipher *c;
314314

315-
strcpy(nbuf, name);
315+
StrNCpy(nbuf, name, sizeof(nbuf));
316316

317317
if ((p = strrchr(nbuf, '-')) != NULL)
318318
{

contrib/pgcrypto/pgcrypto.c

+12-21
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,16 @@
2626
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2727
* SUCH DAMAGE.
2828
*
29-
* $PostgreSQL: pgsql/contrib/pgcrypto/pgcrypto.c,v 1.15 2003/11/29 22:39:28 pgsql Exp $
29+
* $PostgreSQL: pgsql/contrib/pgcrypto/pgcrypto.c,v 1.16 2004/05/07 00:24:57 tgl Exp $
3030
*/
3131

32-
#include <postgres.h>
33-
#include <fmgr.h>
32+
#include "postgres.h"
33+
3434
#include <ctype.h>
3535

36+
#include "fmgr.h"
37+
#include "parser/scansup.h"
38+
3639
#include "px.h"
3740
#include "px-crypt.h"
3841
#include "pgcrypto.h"
@@ -554,26 +557,12 @@ find_provider(text *name,
554557
char *desc, int silent)
555558
{
556559
void *res;
557-
char buf[PX_MAX_NAMELEN + 1],
558-
*p;
559-
unsigned len;
560-
unsigned i;
560+
char *buf;
561561
int err;
562562

563-
len = VARSIZE(name) - VARHDRSZ;
564-
if (len > PX_MAX_NAMELEN)
565-
{
566-
if (silent)
567-
return NULL;
568-
ereport(ERROR,
569-
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
570-
errmsg("%s type does not exist (name too long)", desc)));
571-
}
572-
573-
p = VARDATA(name);
574-
for (i = 0; i < len; i++)
575-
buf[i] = tolower((unsigned char) p[i]);
576-
buf[len] = 0;
563+
buf = downcase_truncate_identifier(VARDATA(name),
564+
VARSIZE(name) - VARHDRSZ,
565+
false);
577566

578567
err = provider_lookup(buf, &res);
579568

@@ -582,5 +571,7 @@ find_provider(text *name,
582571
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
583572
errmsg("%s type does not exist: \"%s\"", desc, buf)));
584573

574+
pfree(buf);
575+
585576
return err ? NULL : res;
586577
}

contrib/pgcrypto/px-crypt.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2727
* SUCH DAMAGE.
2828
*
29-
* $PostgreSQL: pgsql/contrib/pgcrypto/px-crypt.c,v 1.7 2003/11/29 22:39:28 pgsql Exp $
29+
* $PostgreSQL: pgsql/contrib/pgcrypto/px-crypt.c,v 1.8 2004/05/07 00:24:57 tgl Exp $
3030
*/
3131

3232
#include <postgres.h>
@@ -170,7 +170,7 @@ px_gen_salt(const char *salt_type, char *buf, int rounds)
170170
for (i = 0; gen_list[i].name; i++)
171171
{
172172
g = &gen_list[i];
173-
if (strcasecmp(g->name, salt_type) != 0)
173+
if (pg_strcasecmp(g->name, salt_type) != 0)
174174
continue;
175175

176176
if (g->def_rounds)

contrib/pgcrypto/px.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2727
* SUCH DAMAGE.
2828
*
29-
* $PostgreSQL: pgsql/contrib/pgcrypto/px.c,v 1.8 2003/11/29 22:39:28 pgsql Exp $
29+
* $PostgreSQL: pgsql/contrib/pgcrypto/px.c,v 1.9 2004/05/07 00:24:57 tgl Exp $
3030
*/
3131

3232
#include <postgres.h>
@@ -39,7 +39,7 @@ px_resolve_alias(const PX_Alias * list, const char *name)
3939
{
4040
while (list->name)
4141
{
42-
if (!strcasecmp(list->alias, name))
42+
if (pg_strcasecmp(list->alias, name) == 0)
4343
return list->name;
4444
list++;
4545
}

contrib/pgcrypto/sha1.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/contrib/pgcrypto/sha1.c,v 1.12 2003/11/29 22:39:28 pgsql Exp $ */
1+
/* $PostgreSQL: pgsql/contrib/pgcrypto/sha1.c,v 1.13 2004/05/07 00:24:57 tgl Exp $ */
22
/* $KAME: sha1.c,v 1.3 2000/02/22 14:01:18 itojun Exp $ */
33

44
/*
@@ -227,15 +227,15 @@ sha1_step(struct sha1_ctxt * ctxt)
227227
H(3) = H(3) + d;
228228
H(4) = H(4) + e;
229229

230-
bzero(&ctxt->m.b8[0], 64);
230+
memset(&ctxt->m.b8[0], 0, 64);
231231
}
232232

233233
/*------------------------------------------------------------*/
234234

235235
void
236236
sha1_init(struct sha1_ctxt * ctxt)
237237
{
238-
bzero(ctxt, sizeof(struct sha1_ctxt));
238+
memset(ctxt, 0, sizeof(struct sha1_ctxt));
239239
H(0) = 0x67452301;
240240
H(1) = 0xefcdab89;
241241
H(2) = 0x98badcfe;
@@ -255,14 +255,14 @@ sha1_pad(struct sha1_ctxt * ctxt)
255255
padlen = 64 - padstart;
256256
if (padlen < 8)
257257
{
258-
bzero(&ctxt->m.b8[padstart], padlen);
258+
memset(&ctxt->m.b8[padstart], 0, padlen);
259259
COUNT += padlen;
260260
COUNT %= 64;
261261
sha1_step(ctxt);
262262
padstart = COUNT % 64; /* should be 0 */
263263
padlen = 64 - padstart; /* should be 64 */
264264
}
265-
bzero(&ctxt->m.b8[padstart], padlen - 8);
265+
memset(&ctxt->m.b8[padstart], 0, padlen - 8);
266266
COUNT += (padlen - 8);
267267
COUNT %= 64;
268268
#if BYTE_ORDER == BIG_ENDIAN

contrib/spi/timetravel.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ findTTStatus(char *name)
498498
TTOffList *pp;
499499

500500
for (pp = TTOff.next; pp; pp = pp->next)
501-
if (strcasecmp(name, pp->name) == 0)
501+
if (pg_strcasecmp(name, pp->name) == 0)
502502
return 0;
503503
return 1;
504504
}

contrib/tsearch2/dict_ispell.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ spell_init(PG_FUNCTION_ARGS)
6262
pcfg = cfg;
6363
while (pcfg->key)
6464
{
65-
if (strcasecmp("DictFile", pcfg->key) == 0)
65+
if (pg_strcasecmp("DictFile", pcfg->key) == 0)
6666
{
6767
if (dictloaded)
6868
{
@@ -81,7 +81,7 @@ spell_init(PG_FUNCTION_ARGS)
8181
}
8282
dictloaded = true;
8383
}
84-
else if (strcasecmp("AffFile", pcfg->key) == 0)
84+
else if (pg_strcasecmp("AffFile", pcfg->key) == 0)
8585
{
8686
if (affloaded)
8787
{
@@ -100,7 +100,7 @@ spell_init(PG_FUNCTION_ARGS)
100100
}
101101
affloaded = true;
102102
}
103-
else if (strcasecmp("StopFile", pcfg->key) == 0)
103+
else if (pg_strcasecmp("StopFile", pcfg->key) == 0)
104104
{
105105
text *tmp = char2text(pcfg->value);
106106

contrib/tsearch2/ispell/spell.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#define MAX_NORM 1024
1111
#define MAXNORMLEN 256
1212

13-
#define STRNCASECMP(x,y) (strncasecmp(x,y,strlen(y)))
13+
#define STRNCASECMP(x,y) pg_strncasecmp(x, y, strlen(y))
1414
#define GETWCHAR(W,L,N,T) ( ((uint8*)(W))[ ((T)=='p') ? (N) : ( (L) - 1 - (N) ) ] )
1515
#define GETCHAR(A,N,T) GETWCHAR( (A)->repl, (A)->replen, N, T )
1616

@@ -304,19 +304,19 @@ NIImportAffixes(IspellDict * Conf, const char *filename)
304304
continue;
305305
}
306306
}
307-
if (!STRNCASECMP(str, "suffixes"))
307+
if (STRNCASECMP(str, "suffixes")==0)
308308
{
309309
suffixes = 1;
310310
prefixes = 0;
311311
continue;
312312
}
313-
if (!STRNCASECMP(str, "prefixes"))
313+
if (STRNCASECMP(str, "prefixes")==0)
314314
{
315315
suffixes = 0;
316316
prefixes = 1;
317317
continue;
318318
}
319-
if (!STRNCASECMP(str, "flag "))
319+
if (STRNCASECMP(str, "flag ")==0)
320320
{
321321
s = str + 5;
322322
flagflags=0;

contrib/tsearch2/wparser_def.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -210,15 +210,15 @@ prsd_headline(PG_FUNCTION_ARGS)
210210

211211
while (mptr && mptr->key)
212212
{
213-
if (strcasecmp(mptr->key, "MaxWords") == 0)
213+
if (pg_strcasecmp(mptr->key, "MaxWords") == 0)
214214
max_words = pg_atoi(mptr->value, 4, 1);
215-
else if (strcasecmp(mptr->key, "MinWords") == 0)
215+
else if (pg_strcasecmp(mptr->key, "MinWords") == 0)
216216
min_words = pg_atoi(mptr->value, 4, 1);
217-
else if (strcasecmp(mptr->key, "ShortWord") == 0)
217+
else if (pg_strcasecmp(mptr->key, "ShortWord") == 0)
218218
shortword = pg_atoi(mptr->value, 4, 1);
219-
else if (strcasecmp(mptr->key, "StartSel") == 0)
219+
else if (pg_strcasecmp(mptr->key, "StartSel") == 0)
220220
prs->startsel = pstrdup(mptr->value);
221-
else if (strcasecmp(mptr->key, "StopSel") == 0)
221+
else if (pg_strcasecmp(mptr->key, "StopSel") == 0)
222222
prs->stopsel = pstrdup(mptr->value);
223223

224224
pfree(mptr->key);

src/Makefile.global.in

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*-makefile-*-
2-
# $PostgreSQL: pgsql/src/Makefile.global.in,v 1.180 2004/04/30 15:01:25 momjian Exp $
2+
# $PostgreSQL: pgsql/src/Makefile.global.in,v 1.181 2004/05/07 00:24:57 tgl Exp $
33

44
#------------------------------------------------------------------------------
55
# All PostgreSQL makefiles include this file and use the variables it sets,
@@ -339,7 +339,7 @@ endif
339339
#
340340
# substitute implementations of the C library
341341

342-
LIBOBJS = @LIBOBJS@ noblock.o path.o pgsleep.o sprompt.o thread.o
342+
LIBOBJS = @LIBOBJS@ noblock.o path.o pgsleep.o pgstrcasecmp.o sprompt.o thread.o
343343

344344
ifneq (,$(LIBOBJS))
345345
LIBS += -lpgport

src/backend/access/transam/xlog.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.139 2004/04/19 17:42:57 momjian Exp $
10+
* $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.140 2004/05/07 00:24:57 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -3778,27 +3778,27 @@ assign_xlog_sync_method(const char *method, bool doit, GucSource source)
37783778
int new_sync_method;
37793779
int new_sync_bit;
37803780

3781-
if (strcasecmp(method, "fsync") == 0)
3781+
if (pg_strcasecmp(method, "fsync") == 0)
37823782
{
37833783
new_sync_method = SYNC_METHOD_FSYNC;
37843784
new_sync_bit = 0;
37853785
}
37863786
#ifdef HAVE_FDATASYNC
3787-
else if (strcasecmp(method, "fdatasync") == 0)
3787+
else if (pg_strcasecmp(method, "fdatasync") == 0)
37883788
{
37893789
new_sync_method = SYNC_METHOD_FDATASYNC;
37903790
new_sync_bit = 0;
37913791
}
37923792
#endif
37933793
#ifdef OPEN_SYNC_FLAG
3794-
else if (strcasecmp(method, "open_sync") == 0)
3794+
else if (pg_strcasecmp(method, "open_sync") == 0)
37953795
{
37963796
new_sync_method = SYNC_METHOD_OPEN;
37973797
new_sync_bit = OPEN_SYNC_FLAG;
37983798
}
37993799
#endif
38003800
#ifdef OPEN_DATASYNC_FLAG
3801-
else if (strcasecmp(method, "open_datasync") == 0)
3801+
else if (pg_strcasecmp(method, "open_datasync") == 0)
38023802
{
38033803
new_sync_method = SYNC_METHOD_OPEN;
38043804
new_sync_bit = OPEN_DATASYNC_FLAG;

0 commit comments

Comments
 (0)