2323#include "libpq/md5.h"
2424
2525#include "spell.h"
26+ #include "tsearch/dicts/spell.h"
2627
2728#ifdef PG_MODULE_MAGIC
2829PG_MODULE_MAGIC ;
@@ -231,25 +232,25 @@ void init_shared_dict(DictInfo * info, char * dictFile, char * affFile, char * s
231232
232233dict = (IspellDict * )palloc0 (sizeof (IspellDict ));
233234
234- SharedNIStartBuild (dict );
235+ NIStartBuild (dict );
235236
236- SharedNIImportDictionary (dict ,
237+ NIImportDictionary (dict ,
237238get_tsearch_config_filename (dictFile ,"dict" ));
238239
239- SharedNIImportAffixes (dict ,
240+ NIImportAffixes (dict ,
240241get_tsearch_config_filename (affFile ,"affix" ));
241242
242- SharedNISortDictionary (dict );
243- SharedNISortAffixes (dict );
243+ NISortDictionary (dict );
244+ NISortAffixes (dict );
244245
245- SharedNIFinishBuild (dict );
246+ NIFinishBuild (dict );
246247
247248shdict = copyIspellDict (dict ,dictFile ,affFile );
248249
249250shdict -> next = segment_info -> dict ;
250251segment_info -> dict = shdict ;
251252
252- elog (LOG ,"shared ispell init done, remaining %d B" ,segment_info -> available );
253+ elog (LOG ,"shared ispell init done, remaining %ld B" ,segment_info -> available );
253254
254255}
255256
@@ -602,10 +603,28 @@ SharedStopList * copyStopList(StopList * list, char * stopFile) {
602603return copy ;
603604}
604605
606+ static
607+ int countCMPDAffixes (CMPDAffix * affixes ) {
608+
609+ /* there's at least one affix */
610+ int count = 1 ;
611+ CMPDAffix * ptr = affixes ;
612+
613+ /* the last one is marked with (affix == NULL) */
614+ while (ptr -> affix )
615+ {
616+ ptr ++ ;
617+ count ++ ;
618+ }
619+
620+ return count ;
621+
622+ }
623+
605624static
606625SharedIspellDict * copyIspellDict (IspellDict * dict ,char * dictFile ,char * affixFile ) {
607626
608- int i ;
627+ int i , cnt ;
609628
610629SharedIspellDict * copy = (SharedIspellDict * )shalloc (sizeof (SharedIspellDict ));
611630
@@ -632,11 +651,10 @@ SharedIspellDict * copyIspellDict(IspellDict * dict, char * dictFile, char * aff
632651strcpy (copy -> AffixData [i ],dict -> AffixData [i ]);
633652}
634653
635- /* copy compound affixes */
636- /* FIXME How to copy this without the cmpaffixes? If we can get rid of this field, we
637- * could get rid of the local IspellDict copy. */
638- copy -> CompoundAffix = (CMPDAffix * )shalloc (sizeof (CMPDAffix )* dict -> cmpaffixes );
639- memcpy (copy -> CompoundAffix ,dict -> CompoundAffix ,sizeof (CMPDAffix )* dict -> cmpaffixes );
654+ /* copy compound affixes (there's at least one) */
655+ cnt = countCMPDAffixes (dict -> CompoundAffix );
656+ copy -> CompoundAffix = (CMPDAffix * )shalloc (sizeof (CMPDAffix )* cnt );
657+ memcpy (copy -> CompoundAffix ,dict -> CompoundAffix ,sizeof (CMPDAffix )* cnt );
640658
641659memcpy (copy -> flagval ,dict -> flagval ,255 );
642660copy -> usecompound = dict -> usecompound ;