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

Commit2dd6733

Browse files
committed
Minor fixes to improve regex debugging code.
When REG_DEBUG is defined, ensure that an un-filled "struct cnfa"is all-zeroes, not just that it has nstates == 0. This is mainlyso that looking at "struct subre" structs in gdb doesn't distractone with a lot of garbage fields during regex compilation.Adjust some places that print debug output to have suitable fflushcalls afterwards.In passing, correct an erroneous ancient comment: the concatenationsubre-s created by parsebranch() have op == '.' not ','.Noted while fooling around with some regex performance improvements.
1 parentc7ecd6a commit2dd6733

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

‎src/backend/regex/regc_nfa.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2951,11 +2951,11 @@ carc_cmp(const void *a, const void *b)
29512951
staticvoid
29522952
freecnfa(structcnfa*cnfa)
29532953
{
2954-
assert(cnfa->nstates!=0);/* not empty already */
2955-
cnfa->nstates=0;
2954+
assert(!NULLCNFA(*cnfa));/* not empty already */
29562955
FREE(cnfa->stflags);
29572956
FREE(cnfa->states);
29582957
FREE(cnfa->arcs);
2958+
ZAPCNFA(*cnfa);
29592959
}
29602960

29612961
/*
@@ -3012,13 +3012,13 @@ dumpstate(struct state *s,
30123012
fprintf(f,"\tno out arcs\n");
30133013
else
30143014
dumparcs(s,f);
3015-
fflush(f);
30163015
for (a=s->ins;a!=NULL;a=a->inchain)
30173016
{
30183017
if (a->to!=s)
30193018
fprintf(f,"\tlink from %d to %d on %d's in-chain\n",
30203019
a->from->no,a->to->no,s->no);
30213020
}
3021+
fflush(f);
30223022
}
30233023

30243024
/*

‎src/backend/regex/regcomp.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,10 @@ pg_regcomp(regex_t *re,
479479

480480
#ifdefREG_DEBUG
481481
if (flags&REG_DUMP)
482+
{
482483
dump(re,stdout);
484+
fflush(stdout);
485+
}
483486
#endif
484487

485488
assert(v->err==0);
@@ -721,7 +724,7 @@ parse(struct vars *v,
721724
*
722725
* This mostly manages concatenation, working closely with parseqatom().
723726
* Concatenated things are bundled up as much as possible, with separate
724-
* ',' nodes introduced only when necessary due to substructure.
727+
* '.' nodes introduced only when necessary due to substructure.
725728
*/
726729
staticstructsubre*
727730
parsebranch(structvars*v,

‎src/include/regex/regguts.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,15 @@ struct cnfa
368368
structcarc*arcs;/* the area for the lists */
369369
};
370370

371+
/*
372+
* When debugging, it's helpful if an un-filled CNFA is all-zeroes.
373+
* In production, though, we only require nstates to be zero.
374+
*/
375+
#ifdefREG_DEBUG
376+
#defineZAPCNFA(cnfa)memset(&(cnfa), 0, sizeof(cnfa))
377+
#else
371378
#defineZAPCNFA(cnfa)((cnfa).nstates = 0)
379+
#endif
372380
#defineNULLCNFA(cnfa)((cnfa).nstates == 0)
373381

374382
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp