57
57
#include "tsearch/ts_locale.h"
58
58
#include "access/htup_details.h"
59
59
#include "funcapi.h"
60
+ #include "utils/builtins.h"
60
61
61
62
#include "shared_ispell.h"
62
63
#include "tsearch/dicts/spell.h"
63
- #include "regex/regguts.h"
64
64
65
65
PG_MODULE_MAGIC ;
66
66
@@ -247,6 +247,28 @@ get_shared_stop_list(char *stop)
247
247
return NULL ;
248
248
}
249
249
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
+
250
272
/*
251
273
* Initializes the dictionary for use in backends - checks whether such dictionary
252
274
* 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)
278
300
/* lookup if the dictionary (words and affixes) is already loaded in the shared segment */
279
301
shdict = get_shared_dict (dictFile , affFile );
280
302
303
+ /* clear dict affix sources */
304
+ clean_dict_affix (& (info -> dict ));
305
+
281
306
/* load affix list */
282
307
NIStartBuild (& (info -> dict ));
283
308
NIImportAffixes (& (info -> dict ), get_tsearch_config_filename (affFile , "affix" ));
@@ -397,7 +422,7 @@ PG_FUNCTION_INFO_V1(dispell_list_stoplists);
397
422
398
423
/*
399
424
* 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
401
426
* a dictionary is no longer needed or needs to be reloaded (e.g. to update
402
427
* list of words / affixes).
403
428
*/
@@ -791,7 +816,6 @@ dispell_list_dicts(PG_FUNCTION_ARGS)
791
816
{
792
817
FuncCallContext * funcctx ;
793
818
TupleDesc tupdesc ;
794
- AttInMetadata * attinmeta ;
795
819
SharedIspellDict * dict ;
796
820
797
821
/* init on the first call */
@@ -817,8 +841,7 @@ dispell_list_dicts(PG_FUNCTION_ARGS)
817
841
* generate attribute metadata needed later to produce tuples from raw
818
842
* C strings
819
843
*/
820
- attinmeta = TupleDescGetAttInMetadata (tupdesc );
821
- funcctx -> attinmeta = attinmeta ;
844
+ funcctx -> attinmeta = TupleDescGetAttInMetadata (tupdesc );
822
845
funcctx -> tuple_desc = tupdesc ;
823
846
824
847
/* switch back to the old context */
@@ -844,14 +867,14 @@ dispell_list_dicts(PG_FUNCTION_ARGS)
844
867
845
868
memset (nulls , 0 , sizeof (nulls ));
846
869
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 );
849
872
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);
852
875
853
- strcpy (VARDATA ( dictname ) , dict -> dictFile );
854
- strcpy (VARDATA ( affname ) , dict -> affixFile );
876
+ // strcpy(dictname, dict->dictFile);
877
+ // strcpy(affname, dict->affixFile);
855
878
856
879
values [0 ] = PointerGetDatum (dictname );
857
880
values [1 ] = PointerGetDatum (affname );
@@ -884,7 +907,6 @@ dispell_list_stoplists(PG_FUNCTION_ARGS)
884
907
{
885
908
FuncCallContext * funcctx ;
886
909
TupleDesc tupdesc ;
887
- AttInMetadata * attinmeta ;
888
910
SharedStopList * stoplist ;
889
911
890
912
/* init on the first call */
@@ -910,8 +932,7 @@ dispell_list_stoplists(PG_FUNCTION_ARGS)
910
932
* generate attribute metadata needed later to produce tuples from raw
911
933
* C strings
912
934
*/
913
- attinmeta = TupleDescGetAttInMetadata (tupdesc );
914
- funcctx -> attinmeta = attinmeta ;
935
+ funcctx -> attinmeta = TupleDescGetAttInMetadata (tupdesc );
915
936
funcctx -> tuple_desc = tupdesc ;
916
937
917
938
/* switch back to the old context */
@@ -936,11 +957,11 @@ dispell_list_stoplists(PG_FUNCTION_ARGS)
936
957
937
958
memset (nulls , 0 , sizeof (nulls ));
938
959
939
- stopname = ( text * ) palloc ( strlen ( stoplist -> stopFile ) + VARHDRSZ );
960
+ stopname = cstring_to_text ( stoplist -> stopFile );
940
961
941
- SET_VARSIZE (stopname , strlen (stoplist -> stopFile ) + VARHDRSZ );
962
+ // SET_VARSIZE(stopname, strlen(stoplist->stopFile) + VARHDRSZ);
942
963
943
- strcpy (VARDATA (stopname ), stoplist -> stopFile );
964
+ // strcpy(VARDATA(stopname), stoplist->stopFile);
944
965
945
966
values [0 ] = PointerGetDatum (stopname );
946
967
values [1 ] = UInt32GetDatum (stoplist -> stop .len );
0 commit comments