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

Commit6eefd24

Browse files
committed
Remove typedef celt from the regex library, along with macro NOCELT.
The regex library used to have a notion of a "collating element" that wasdistinct from a "character", but Henry Spencer never actually implementedhis planned support for multi-character collating elements, and the Tclcrew ripped out most of the stubs for that years ago. The only thing leftthat distinguished the "celt" typedef from the "chr" typedef was that"celt" was supposed to also be able to hold the not-a-character "NOCELT"value. However, NOCELT was not used anywhere after the MCCE stub removalchanges, which means there's no need for celt to be different from chr.Removing the separate typedef simplifies matters and also removes a trapfor the unwary, in that celt is signed while chr may not be, so comparisonscould mean different things. There's no bug there today because werestrict CHR_MAX to be less than INT_MAX, but I think there may have beensuch bugs before we did that, and there could be again if anyone everdecides to fool with the range of chr.This patch also removes assorted unnecessary casts to "chr" of valuesthat are already chrs. Many of these seem to be leftover from days whenthe code was compatible with pre-ANSI C.
1 parent5285c5e commit6eefd24

File tree

5 files changed

+33
-38
lines changed

5 files changed

+33
-38
lines changed

‎src/backend/regex/regc_cvec.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ addchr(struct cvec * cv,/* character vector */
7878
chrc)/* character to add */
7979
{
8080
assert(cv->nchrs<cv->chrspace);
81-
cv->chrs[cv->nchrs++]=(chr)c;
81+
cv->chrs[cv->nchrs++]=c;
8282
}
8383

8484
/*
@@ -90,8 +90,8 @@ addrange(struct cvec * cv,/* character vector */
9090
chrto)/* last character of range */
9191
{
9292
assert(cv->nranges<cv->rangespace);
93-
cv->ranges[cv->nranges*2]=(chr)from;
94-
cv->ranges[cv->nranges*2+1]=(chr)to;
93+
cv->ranges[cv->nranges*2]=from;
94+
cv->ranges[cv->nranges*2+1]=to;
9595
cv->nranges++;
9696
}
9797

‎src/backend/regex/regc_lex.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,7 @@ lexescape(struct vars * v)
870870
if (v->now==save|| ((int)c>0&& (int)c <=v->nsubexp))
871871
{
872872
NOTE(REG_UBACKREF);
873-
RETV(BACKREF,(chr)c);
873+
RETV(BACKREF,c);
874874
}
875875
/* oops, doesn't look like it's a backref after all... */
876876
v->now=save;
@@ -986,10 +986,8 @@ lexdigits(struct vars * v,
986986
*/
987987
staticint/* 1 normal, 0 failure */
988988
brenext(structvars*v,
989-
chrpc)
989+
chrc)
990990
{
991-
chrc= (chr)pc;
992-
993991
switch (c)
994992
{
995993
caseCHR('*'):
@@ -1153,7 +1151,7 @@ chrnamed(struct vars * v,
11531151
constchr*endp,/* just past end of name */
11541152
chrlastresort)/* what to return if name lookup fails */
11551153
{
1156-
celtc;
1154+
chrc;
11571155
interrsave;
11581156
inte;
11591157
structcvec*cv;
@@ -1165,10 +1163,10 @@ chrnamed(struct vars * v,
11651163
v->err=errsave;
11661164

11671165
if (e!=0)
1168-
return(chr)lastresort;
1166+
returnlastresort;
11691167

11701168
cv=range(v,c,c,0);
11711169
if (cv->nchrs==0)
1172-
return(chr)lastresort;
1170+
returnlastresort;
11731171
returncv->chrs[0];
11741172
}

‎src/backend/regex/regc_locale.c

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -361,9 +361,9 @@ static const struct cname
361361

362362

363363
/*
364-
* element - map collating-element name tocelt
364+
* element - map collating-element name tochr
365365
*/
366-
staticcelt
366+
staticchr
367367
element(structvars*v,/* context */
368368
constchr*startp,/* points to start of name */
369369
constchr*endp)/* points just past end of name */
@@ -401,13 +401,13 @@ element(struct vars * v,/* context */
401401
*/
402402
staticstructcvec*
403403
range(structvars*v,/* context */
404-
celta,/* range start */
405-
celtb,/* range end, might equal a */
404+
chra,/* range start */
405+
chrb,/* range end, might equal a */
406406
intcases)/* case-independent? */
407407
{
408408
intnchrs;
409409
structcvec*cv;
410-
celtc,
410+
chrc,
411411
cc;
412412

413413
if (a!=b&& !before(a,b))
@@ -444,7 +444,7 @@ range(struct vars * v,/* context */
444444

445445
for (c=a;c <=b;c++)
446446
{
447-
cc=pg_wc_tolower((chr)c);
447+
cc=pg_wc_tolower(c);
448448
if (cc!=c&&
449449
(before(cc,a)||before(b,cc)))
450450
{
@@ -455,7 +455,7 @@ range(struct vars * v,/* context */
455455
}
456456
addchr(cv,cc);
457457
}
458-
cc=pg_wc_toupper((chr)c);
458+
cc=pg_wc_toupper(c);
459459
if (cc!=c&&
460460
(before(cc,a)||before(b,cc)))
461461
{
@@ -477,10 +477,10 @@ range(struct vars * v,/* context */
477477
}
478478

479479
/*
480-
* before - iscelt x beforecelt y, for purposes of range legality?
480+
* before - ischr x beforechr y, for purposes of range legality?
481481
*/
482482
staticint/* predicate */
483-
before(celtx,celty)
483+
before(chrx,chry)
484484
{
485485
if (x<y)
486486
return1;
@@ -493,7 +493,7 @@ before(celt x, celt y)
493493
*/
494494
staticstructcvec*
495495
eclass(structvars*v,/* context */
496-
celtc,/* Collating element representing the
496+
chrc,/* Collating element representing the
497497
* equivalence class. */
498498
intcases)/* all cases? */
499499
{
@@ -503,12 +503,12 @@ eclass(struct vars * v,/* context */
503503
if ((v->cflags&REG_FAKE)&&c=='x')
504504
{
505505
cv=getcvec(v,4,0);
506-
addchr(cv,(chr)'x');
507-
addchr(cv,(chr)'y');
506+
addchr(cv,CHR('x'));
507+
addchr(cv,CHR('y'));
508508
if (cases)
509509
{
510-
addchr(cv,(chr)'X');
511-
addchr(cv,(chr)'Y');
510+
addchr(cv,CHR('X'));
511+
addchr(cv,CHR('Y'));
512512
}
513513
returncv;
514514
}
@@ -518,7 +518,7 @@ eclass(struct vars * v,/* context */
518518
returnallcases(v,c);
519519
cv=getcvec(v,1,0);
520520
assert(cv!=NULL);
521-
addchr(cv,(chr)c);
521+
addchr(cv,c);
522522
returncv;
523523
}
524524

@@ -673,15 +673,14 @@ cclass(struct vars * v,/* context */
673673
*/
674674
staticstructcvec*
675675
allcases(structvars*v,/* context */
676-
chrpc)/* character to get case equivs of */
676+
chrc)/* character to get case equivs of */
677677
{
678678
structcvec*cv;
679-
chrc= (chr)pc;
680679
chrlc,
681680
uc;
682681

683-
lc=pg_wc_tolower((chr)c);
684-
uc=pg_wc_toupper((chr)c);
682+
lc=pg_wc_tolower(c);
683+
uc=pg_wc_toupper(c);
685684

686685
cv=getcvec(v,2,0);
687686
addchr(cv,lc);

‎src/backend/regex/regcomp.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -210,10 +210,10 @@ static pg_wchar pg_wc_toupper(pg_wchar c);
210210
staticpg_wcharpg_wc_tolower(pg_wcharc);
211211

212212
/* === regc_locale.c === */
213-
staticceltelement(structvars*,constchr*,constchr*);
214-
staticstructcvec*range(structvars*,celt,celt,int);
215-
staticintbefore(celt,celt);
216-
staticstructcvec*eclass(structvars*,celt,int);
213+
staticchrelement(structvars*,constchr*,constchr*);
214+
staticstructcvec*range(structvars*,chr,chr,int);
215+
staticintbefore(chr,chr);
216+
staticstructcvec*eclass(structvars*,chr,int);
217217
staticstructcvec*cclass(structvars*,constchr*,constchr*,int);
218218
staticstructcvec*allcases(structvars*,chr);
219219
staticintcmp(constchr*,constchr*,size_t);
@@ -1424,8 +1424,8 @@ brackpart(struct vars * v,
14241424
structstate*lp,
14251425
structstate*rp)
14261426
{
1427-
celtstartc;
1428-
celtendc;
1427+
chrstartc;
1428+
chrendc;
14291429
structcvec*cv;
14301430
constchr*startp;
14311431
constchr*endp;

‎src/include/regex/regcustom.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,13 @@
5858
/* internal character type and related */
5959
typedefpg_wcharchr;/* the type itself */
6060
typedefunsigneduchr;/* unsigned type that will hold a chr */
61-
typedefintcelt;/* type to hold chr, or NOCELT */
6261

63-
#defineNOCELT(-1)/* celt value which is not valid chr */
6462
#defineCHR(c)((unsigned char) (c))/* turn char literal into chr literal */
6563
#defineDIGITVAL(c) ((c)-'0')/* turn chr digit into its value */
6664
#defineCHRBITS 32/* bits in a chr; must not use sizeof */
6765
#defineCHR_MIN 0x00000000/* smallest and largest chr; the value */
6866
#defineCHR_MAX 0x7ffffffe/* CHR_MAX-CHR_MIN+1 must fit in an int, and
69-
* CHR_MAX+1 must fit inboth chrand celt */
67+
* CHR_MAX+1 must fit ina chrvariable */
7068

7169
/*
7270
* Check if a chr value is in range. Ideally we'd just write this as

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp