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

Commitdf1e965

Browse files
committed
Sync our regex code with upstream changes since last time we did this, which
was Tcl 8.4.8. The main changes are to remove the never-fully-implementedcode for multi-character collating elements, and to const-ify some stuff abit more fully. In combination with the recent security patch, this commitbrings us into line with Tcl 8.5.0.Note that I didn't make any effort to duplicate a lot of cosmetic changesthat they made to bring their copy into line with their own styleguidelines, such as adding braces around single-line IF bodies. Most ofthose we either had done already (such as ANSI-fication of function headers)or there is no point because pgindent would undo the change anyway.
1 parent423abf4 commitdf1e965

File tree

9 files changed

+165
-546
lines changed

9 files changed

+165
-546
lines changed

‎src/backend/regex/regc_color.c

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
2929
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3030
*
31-
* $PostgreSQL: pgsql/src/backend/regex/regc_color.c,v 1.8 2008/01/03 20:47:55 tgl Exp $
31+
* $PostgreSQL: pgsql/src/backend/regex/regc_color.c,v 1.9 2008/02/14 17:33:37 tgl Exp $
3232
*
3333
*
3434
* Note that there are some incestuous relationships between this code and
@@ -222,7 +222,6 @@ static color/* COLORLESS for error */
222222
newcolor(structcolormap*cm)
223223
{
224224
structcolordesc*cd;
225-
structcolordesc*new;
226225
size_tn;
227226

228227
if (CISERR())
@@ -245,24 +244,25 @@ newcolor(struct colormap * cm)
245244
else
246245
{
247246
/* oops, must allocate more */
247+
structcolordesc*newCd;
248+
248249
n=cm->ncds*2;
249250
if (cm->cd==cm->cdspace)
250251
{
251-
new= (structcolordesc*)MALLOC(n*
252-
sizeof(structcolordesc));
253-
if (new!=NULL)
254-
memcpy(VS(new),VS(cm->cdspace),cm->ncds*
252+
newCd= (structcolordesc*)MALLOC(n*sizeof(structcolordesc));
253+
if (newCd!=NULL)
254+
memcpy(VS(newCd),VS(cm->cdspace),cm->ncds*
255255
sizeof(structcolordesc));
256256
}
257257
else
258-
new= (structcolordesc*)REALLOC(cm->cd,
259-
n*sizeof(structcolordesc));
260-
if (new==NULL)
258+
newCd= (structcolordesc*)
259+
REALLOC(cm->cd,n*sizeof(structcolordesc));
260+
if (newCd==NULL)
261261
{
262262
CERR(REG_ESPACE);
263263
returnCOLORLESS;
264264
}
265-
cm->cd=new;
265+
cm->cd=newCd;
266266
cm->ncds=n;
267267
assert(cm->max<cm->ncds-1);
268268
cm->max++;
@@ -634,21 +634,6 @@ uncolorchain(struct colormap * cm,
634634
a->colorchainRev=NULL;
635635
}
636636

637-
/*
638-
* singleton - is this character in its own color?
639-
*/
640-
staticint/* predicate */
641-
singleton(structcolormap*cm,
642-
chrc)
643-
{
644-
colorco;/* color of c */
645-
646-
co=GETCOLOR(cm,c);
647-
if (cm->cd[co].nchrs==1&&cm->cd[co].sub==NOSUB)
648-
return1;
649-
return0;
650-
}
651-
652637
/*
653638
* rainbow - add arcs of all full colors (but one) between specified states
654639
*/

‎src/backend/regex/regc_cvec.c

Lines changed: 15 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -28,33 +28,31 @@
2828
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
2929
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3030
*
31-
* $PostgreSQL: pgsql/src/backend/regex/regc_cvec.c,v 1.5 2005/10/15 02:49:24 momjian Exp $
31+
* $PostgreSQL: pgsql/src/backend/regex/regc_cvec.c,v 1.6 2008/02/14 17:33:37 tgl Exp $
3232
*
3333
*/
3434

35+
/*
36+
* Notes:
37+
* Only (selected) functions in _this_ file should treat chr* as non-constant.
38+
*/
39+
3540
/*
3641
* newcvec - allocate a new cvec
3742
*/
3843
staticstructcvec*
3944
newcvec(intnchrs,/* to hold this many chrs... */
40-
intnranges,/* ... and this many ranges... */
41-
intnmcces)/* ... and this many MCCEs */
45+
intnranges)/* ... and this many ranges */
4246
{
43-
size_tn;
44-
size_tnc;
45-
structcvec*cv;
47+
size_tnc= (size_t)nchrs+ (size_t)nranges*2;
48+
size_tn=sizeof(structcvec)+nc*sizeof(chr);
49+
structcvec*cv= (structcvec*)MALLOC(n);
4650

47-
nc= (size_t)nchrs+ (size_t)nmcces*(MAXMCCE+1)+ (size_t)nranges*2;
48-
49-
n=sizeof(structcvec)+ (size_t) (nmcces-1)*sizeof(chr*)
50-
+nc*sizeof(chr);
51-
cv= (structcvec*)MALLOC(n);
5251
if (cv==NULL)
5352
returnNULL;
5453
cv->chrspace=nchrs;
55-
cv->chrs= (chr*)&cv->mcces[nmcces];/* chrs just after MCCE ptrs */
56-
cv->mccespace=nmcces;
57-
cv->ranges=cv->chrs+nchrs+nmcces* (MAXMCCE+1);
54+
cv->chrs= (chr*) (((char*)cv)+sizeof(structcvec));
55+
cv->ranges=cv->chrs+nchrs;
5856
cv->rangespace=nranges;
5957
returnclearcvec(cv);
6058
}
@@ -66,17 +64,9 @@ newcvec(int nchrs,/* to hold this many chrs... */
6664
staticstructcvec*
6765
clearcvec(structcvec*cv)
6866
{
69-
inti;
70-
7167
assert(cv!=NULL);
7268
cv->nchrs=0;
73-
assert(cv->chrs== (chr*)&cv->mcces[cv->mccespace]);
74-
cv->nmcces=0;
75-
cv->nmccechrs=0;
7669
cv->nranges=0;
77-
for (i=0;i<cv->mccespace;i++)
78-
cv->mcces[i]=NULL;
79-
8070
returncv;
8171
}
8272

@@ -87,7 +77,6 @@ static void
8777
addchr(structcvec*cv,/* character vector */
8878
chrc)/* character to add */
8979
{
90-
assert(cv->nchrs<cv->chrspace-cv->nmccechrs);
9180
cv->chrs[cv->nchrs++]= (chr)c;
9281
}
9382

@@ -105,73 +94,21 @@ addrange(struct cvec * cv,/* character vector */
10594
cv->nranges++;
10695
}
10796

108-
/*
109-
* addmcce - add an MCCE to a cvec
110-
*/
111-
staticvoid
112-
addmcce(structcvec*cv,/* character vector */
113-
chr*startp,/* beginning of text */
114-
chr*endp)/* just past end of text */
115-
{
116-
intlen;
117-
inti;
118-
chr*s;
119-
chr*d;
120-
121-
if (startp==NULL&&endp==NULL)
122-
return;
123-
len=endp-startp;
124-
assert(len>0);
125-
assert(cv->nchrs+len<cv->chrspace-cv->nmccechrs);
126-
assert(cv->nmcces<cv->mccespace);
127-
d=&cv->chrs[cv->chrspace-cv->nmccechrs-len-1];
128-
cv->mcces[cv->nmcces++]=d;
129-
for (s=startp,i=len;i>0;s++,i--)
130-
*d++=*s;
131-
*d++=0;/* endmarker */
132-
assert(d==&cv->chrs[cv->chrspace-cv->nmccechrs]);
133-
cv->nmccechrs+=len+1;
134-
}
135-
136-
/*
137-
* haschr - does a cvec contain this chr?
138-
*/
139-
staticint/* predicate */
140-
haschr(structcvec*cv,/* character vector */
141-
chrc)/* character to test for */
142-
{
143-
inti;
144-
chr*p;
145-
146-
for (p=cv->chrs,i=cv->nchrs;i>0;p++,i--)
147-
{
148-
if (*p==c)
149-
return1;
150-
}
151-
for (p=cv->ranges,i=cv->nranges;i>0;p+=2,i--)
152-
{
153-
if ((*p <=c)&& (c <=*(p+1)))
154-
return1;
155-
}
156-
return0;
157-
}
158-
15997
/*
16098
* getcvec - get a cvec, remembering it as v->cv
16199
*/
162100
staticstructcvec*
163101
getcvec(structvars*v,/* context */
164102
intnchrs,/* to hold this many chrs... */
165-
intnranges,/* ... and this many ranges... */
166-
intnmcces)/* ... and this many MCCEs */
103+
intnranges)/* ... and this many ranges */
167104
{
168105
if (v->cv!=NULL&&nchrs <=v->cv->chrspace&&
169-
nranges <=v->cv->rangespace&&nmcces <=v->cv->mccespace)
106+
nranges <=v->cv->rangespace)
170107
returnclearcvec(v->cv);
171108

172109
if (v->cv!=NULL)
173110
freecvec(v->cv);
174-
v->cv=newcvec(nchrs,nranges,nmcces);
111+
v->cv=newcvec(nchrs,nranges);
175112
if (v->cv==NULL)
176113
ERR(REG_ESPACE);
177114

‎src/backend/regex/regc_lex.c

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
2929
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3030
*
31-
* $PostgreSQL: pgsql/src/backend/regex/regc_lex.c,v 1.7 2008/01/03 20:47:55 tgl Exp $
31+
* $PostgreSQL: pgsql/src/backend/regex/regc_lex.c,v 1.8 2008/02/14 17:33:37 tgl Exp $
3232
*
3333
*/
3434

@@ -201,8 +201,8 @@ prefixes(struct vars * v)
201201
*/
202202
staticvoid
203203
lexnest(structvars*v,
204-
chr*beginp,/* start of interpolation */
205-
chr*endp)/* one past end of interpolation */
204+
constchr*beginp,/* start of interpolation */
205+
constchr*endp)/* one past end of interpolation */
206206
{
207207
assert(v->savenow==NULL);/* only one level of nesting */
208208
v->savenow=v->now;
@@ -214,47 +214,47 @@ lexnest(struct vars * v,
214214
/*
215215
* string constants to interpolate as expansions of things like \d
216216
*/
217-
staticchrbackd[]= {/* \d */
217+
staticconstchrbackd[]= {/* \d */
218218
CHR('['),CHR('['),CHR(':'),
219219
CHR('d'),CHR('i'),CHR('g'),CHR('i'),CHR('t'),
220220
CHR(':'),CHR(']'),CHR(']')
221221
};
222-
staticchrbackD[]= {/* \D */
222+
staticconstchrbackD[]= {/* \D */
223223
CHR('['),CHR('^'),CHR('['),CHR(':'),
224224
CHR('d'),CHR('i'),CHR('g'),CHR('i'),CHR('t'),
225225
CHR(':'),CHR(']'),CHR(']')
226226
};
227-
staticchrbrbackd[]= {/* \d within brackets */
227+
staticconstchrbrbackd[]= {/* \d within brackets */
228228
CHR('['),CHR(':'),
229229
CHR('d'),CHR('i'),CHR('g'),CHR('i'),CHR('t'),
230230
CHR(':'),CHR(']')
231231
};
232-
staticchrbacks[]= {/* \s */
232+
staticconstchrbacks[]= {/* \s */
233233
CHR('['),CHR('['),CHR(':'),
234234
CHR('s'),CHR('p'),CHR('a'),CHR('c'),CHR('e'),
235235
CHR(':'),CHR(']'),CHR(']')
236236
};
237-
staticchrbackS[]= {/* \S */
237+
staticconstchrbackS[]= {/* \S */
238238
CHR('['),CHR('^'),CHR('['),CHR(':'),
239239
CHR('s'),CHR('p'),CHR('a'),CHR('c'),CHR('e'),
240240
CHR(':'),CHR(']'),CHR(']')
241241
};
242-
staticchrbrbacks[]= {/* \s within brackets */
242+
staticconstchrbrbacks[]= {/* \s within brackets */
243243
CHR('['),CHR(':'),
244244
CHR('s'),CHR('p'),CHR('a'),CHR('c'),CHR('e'),
245245
CHR(':'),CHR(']')
246246
};
247-
staticchrbackw[]= {/* \w */
247+
staticconstchrbackw[]= {/* \w */
248248
CHR('['),CHR('['),CHR(':'),
249249
CHR('a'),CHR('l'),CHR('n'),CHR('u'),CHR('m'),
250250
CHR(':'),CHR(']'),CHR('_'),CHR(']')
251251
};
252-
staticchrbackW[]= {/* \W */
252+
staticconstchrbackW[]= {/* \W */
253253
CHR('['),CHR('^'),CHR('['),CHR(':'),
254254
CHR('a'),CHR('l'),CHR('n'),CHR('u'),CHR('m'),
255255
CHR(':'),CHR(']'),CHR('_'),CHR(']')
256256
};
257-
staticchrbrbackw[]= {/* \w within brackets */
257+
staticconstchrbrbackw[]= {/* \w within brackets */
258258
CHR('['),CHR(':'),
259259
CHR('a'),CHR('l'),CHR('n'),CHR('u'),CHR('m'),
260260
CHR(':'),CHR(']'),CHR('_')
@@ -722,7 +722,7 @@ lexescape(struct vars * v)
722722
staticchresc[]= {
723723
CHR('E'),CHR('S'),CHR('C')
724724
};
725-
chr*save;
725+
constchr*save;
726726

727727
assert(v->cflags&REG_ADVF);
728728

@@ -1080,7 +1080,7 @@ brenext(struct vars * v,
10801080
staticvoid
10811081
skip(structvars*v)
10821082
{
1083-
chr*start=v->now;
1083+
constchr*start=v->now;
10841084

10851085
assert(v->cflags&REG_EXPANDED);
10861086

@@ -1119,8 +1119,8 @@ newline(void)
11191119
*/
11201120
staticchr
11211121
chrnamed(structvars*v,
1122-
chr*startp,/* start of name */
1123-
chr*endp,/* just past end of name */
1122+
constchr*startp,/* start of name */
1123+
constchr*endp,/* just past end of name */
11241124
chrlastresort)/* what to return if name lookup fails */
11251125
{
11261126
celtc;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp