@@ -655,17 +655,6 @@ FindWord(IspellDict *Conf, const char *word, const char *affixflag, int flag)
655
655
return 0 ;
656
656
}
657
657
658
- /*
659
- * Context reset/delete callback for a regular expression used in an affix
660
- */
661
- static void
662
- regex_affix_deletion_callback (void * arg )
663
- {
664
- aff_regex_struct * pregex = (aff_regex_struct * ) arg ;
665
-
666
- pg_regfree (& (pregex -> regex ));
667
- }
668
-
669
658
/*
670
659
* Adds a new affix rule to the Affix field.
671
660
*
@@ -728,7 +717,6 @@ NIAddAffix(IspellDict *Conf, const char *flag, char flagflags, const char *mask,
728
717
int err ;
729
718
pg_wchar * wmask ;
730
719
char * tmask ;
731
- aff_regex_struct * pregex ;
732
720
733
721
Affix -> issimple = 0 ;
734
722
Affix -> isregis = 0 ;
@@ -743,31 +731,23 @@ NIAddAffix(IspellDict *Conf, const char *flag, char flagflags, const char *mask,
743
731
wmasklen = pg_mb2wchar_with_len (tmask , wmask , masklen );
744
732
745
733
/*
746
- * The regex engine stores its stuff using malloc not palloc, so we
747
- * must arrange to explicitly clean up the regex when the dictionary's
748
- * context is cleared. That means the regex_t has to stay in a fixed
749
- * location within the context; we can't keep it directly in the AFFIX
750
- * struct, since we may sort and resize the array of AFFIXes.
734
+ * The regex and all internal state created by pg_regcomp are
735
+ * allocated in the dictionary's memory context, and will be freed
736
+ * automatically when it is destroyed.
751
737
*/
752
- Affix -> reg .pregex = pregex = palloc (sizeof (aff_regex_struct ));
753
-
754
- err = pg_regcomp (& (pregex -> regex ), wmask , wmasklen ,
738
+ Affix -> reg .pregex = palloc (sizeof (regex_t ));
739
+ err = pg_regcomp (Affix -> reg .pregex , wmask , wmasklen ,
755
740
REG_ADVANCED | REG_NOSUB ,
756
741
DEFAULT_COLLATION_OID );
757
742
if (err )
758
743
{
759
744
char errstr [100 ];
760
745
761
- pg_regerror (err , & ( pregex -> regex ) , errstr , sizeof (errstr ));
746
+ pg_regerror (err , Affix -> reg . pregex , errstr , sizeof (errstr ));
762
747
ereport (ERROR ,
763
748
(errcode (ERRCODE_INVALID_REGULAR_EXPRESSION ),
764
749
errmsg ("invalid regular expression: %s" , errstr )));
765
750
}
766
-
767
- pregex -> mcallback .func = regex_affix_deletion_callback ;
768
- pregex -> mcallback .arg = (void * ) pregex ;
769
- MemoryContextRegisterResetCallback (CurrentMemoryContext ,
770
- & pregex -> mcallback );
771
751
}
772
752
773
753
Affix -> flagflags = flagflags ;
@@ -2161,7 +2141,7 @@ CheckAffix(const char *word, size_t len, AFFIX *Affix, int flagflags, char *neww
2161
2141
data = (pg_wchar * ) palloc ((newword_len + 1 ) * sizeof (pg_wchar ));
2162
2142
data_len = pg_mb2wchar_with_len (newword , data , newword_len );
2163
2143
2164
- if (pg_regexec (& ( Affix -> reg .pregex -> regex ) , data , data_len ,
2144
+ if (pg_regexec (Affix -> reg .pregex , data , data_len ,
2165
2145
0 , NULL , 0 , NULL , 0 ) == REG_OKAY )
2166
2146
{
2167
2147
pfree (data );
0 commit comments