5757#include "tsearch/ts_locale.h"
5858#include "access/htup_details.h"
5959#include "funcapi.h"
60+ #include "utils/builtins.h"
6061
6162#include "shared_ispell.h"
6263#include "tsearch/dicts/spell.h"
63- #include "regex/regguts.h"
6464
6565PG_MODULE_MAGIC ;
6666
@@ -247,6 +247,28 @@ get_shared_stop_list(char *stop)
247247 return NULL ;
248248}
249249
250+ /*
251+ * Cleares IspellDict fields which are used for store affix list.
252+ */
253+ static void
254+ clean_dict_affix (IspellDict * dict )
255+ {
256+ dict -> maffixes = 0 ;
257+ dict -> naffixes = 0 ;
258+ dict -> Affix = NULL ;
259+
260+ dict -> Suffix = NULL ;
261+ dict -> Prefix = NULL ;
262+
263+ dict -> AffixData = NULL ;
264+ dict -> lenAffixData = 0 ;
265+ dict -> nAffixData = 0 ;
266+
267+ dict -> CompoundAffix = NULL ;
268+
269+ dict -> avail = 0 ;
270+ }
271+
250272/*
251273 * Initializes the dictionary for use in backends - checks whether such dictionary
252274 * and list of stopwords is already used, and if not then parses it and loads it into
@@ -278,6 +300,9 @@ init_shared_dict(DictInfo *info, char *dictFile, char *affFile, char *stopFile)
278300 /* lookup if the dictionary (words and affixes) is already loaded in the shared segment */
279301 shdict = get_shared_dict (dictFile , affFile );
280302
303+ /* clear dict affix sources */
304+ clean_dict_affix (& (info -> dict ));
305+
281306 /* load affix list */
282307 NIStartBuild (& (info -> dict ));
283308 NIImportAffixes (& (info -> dict ), get_tsearch_config_filename (affFile , "affix" ));
@@ -397,7 +422,7 @@ PG_FUNCTION_INFO_V1(dispell_list_stoplists);
397422
398423/*
399424 * Resets the shared dictionary memory, i.e. removes all the dictionaries. This
400- * is the only way to remove dictionaries from the memory - either when when
425+ * is the only way to remove dictionaries from the memory - either when
401426 * a dictionary is no longer needed or needs to be reloaded (e.g. to update
402427 * list of words / affixes).
403428 */
@@ -791,7 +816,6 @@ dispell_list_dicts(PG_FUNCTION_ARGS)
791816{
792817 FuncCallContext * funcctx ;
793818 TupleDesc tupdesc ;
794- AttInMetadata * attinmeta ;
795819 SharedIspellDict * dict ;
796820
797821 /* init on the first call */
@@ -817,8 +841,7 @@ dispell_list_dicts(PG_FUNCTION_ARGS)
817841 * generate attribute metadata needed later to produce tuples from raw
818842 * C strings
819843 */
820- attinmeta = TupleDescGetAttInMetadata (tupdesc );
821- funcctx -> attinmeta = attinmeta ;
844+ funcctx -> attinmeta = TupleDescGetAttInMetadata (tupdesc );
822845 funcctx -> tuple_desc = tupdesc ;
823846
824847 /* switch back to the old context */
@@ -844,14 +867,14 @@ dispell_list_dicts(PG_FUNCTION_ARGS)
844867
845868 memset (nulls , 0 , sizeof (nulls ));
846869
847- dictname = ( text * ) palloc ( strlen ( dict -> dictFile ) + VARHDRSZ );
848- affname = ( text * ) palloc ( strlen ( dict -> affixFile ) + VARHDRSZ );
870+ dictname = cstring_to_text ( dict -> dictFile );
871+ affname = cstring_to_text ( dict -> affixFile );
849872
850- SET_VARSIZE (dictname , strlen (dict -> dictFile ) + VARHDRSZ );
851- SET_VARSIZE (affname , strlen (dict -> affixFile ) + VARHDRSZ );
873+ // SET_VARSIZE(dictname, strlen(dict->dictFile) + VARHDRSZ);
874+ // SET_VARSIZE(affname, strlen(dict->affixFile) + VARHDRSZ);
852875
853- strcpy (VARDATA ( dictname ) , dict -> dictFile );
854- strcpy (VARDATA ( affname ) , dict -> affixFile );
876+ // strcpy(dictname, dict->dictFile);
877+ // strcpy(affname, dict->affixFile);
855878
856879 values [0 ] = PointerGetDatum (dictname );
857880 values [1 ] = PointerGetDatum (affname );
@@ -884,7 +907,6 @@ dispell_list_stoplists(PG_FUNCTION_ARGS)
884907{
885908 FuncCallContext * funcctx ;
886909 TupleDesc tupdesc ;
887- AttInMetadata * attinmeta ;
888910 SharedStopList * stoplist ;
889911
890912 /* init on the first call */
@@ -910,8 +932,7 @@ dispell_list_stoplists(PG_FUNCTION_ARGS)
910932 * generate attribute metadata needed later to produce tuples from raw
911933 * C strings
912934 */
913- attinmeta = TupleDescGetAttInMetadata (tupdesc );
914- funcctx -> attinmeta = attinmeta ;
935+ funcctx -> attinmeta = TupleDescGetAttInMetadata (tupdesc );
915936 funcctx -> tuple_desc = tupdesc ;
916937
917938 /* switch back to the old context */
@@ -936,11 +957,11 @@ dispell_list_stoplists(PG_FUNCTION_ARGS)
936957
937958 memset (nulls , 0 , sizeof (nulls ));
938959
939- stopname = ( text * ) palloc ( strlen ( stoplist -> stopFile ) + VARHDRSZ );
960+ stopname = cstring_to_text ( stoplist -> stopFile );
940961
941- SET_VARSIZE (stopname , strlen (stoplist -> stopFile ) + VARHDRSZ );
962+ // SET_VARSIZE(stopname, strlen(stoplist->stopFile) + VARHDRSZ);
942963
943- strcpy (VARDATA (stopname ), stoplist -> stopFile );
964+ // strcpy(VARDATA(stopname), stoplist->stopFile);
944965
945966 values [0 ] = PointerGetDatum (stopname );
946967 values [1 ] = UInt32GetDatum (stoplist -> stop .len );
0 commit comments