26
26
*
27
27
* dispell_init
28
28
* -> init_shared_dict
29
- * -> get_shared_dict
29
+ * -> get_shared_dict (not found)
30
30
* -> NIStartBuild
31
31
* -> NIImportDictionary
32
32
* -> NIImportAffixes
35
35
* -> NIFinishBuild
36
36
* -> sizeIspellDict
37
37
* -> copyIspellDict
38
- * -> copyAffixNode (prefixes)
39
- * -> copyAffixNode (suffixes)
40
38
* -> copySPNode
41
39
* -> copy affix data
42
40
* -> copy compound affixes
41
+ *
42
+ * -> get_shared_dict (found -> reload affixes)
43
+ * -> NIStartBuild
44
+ * -> NIImportAffixes
45
+ * -> NISortAffixes
46
+ * -> NIFinishBuild
47
+ *
43
48
* -> get_shared_stop_list
44
49
* -> readstoplist
45
50
* -> copyStopList
@@ -362,6 +367,28 @@ void init_shared_dict(DictInfo * info, char * dictFile, char * affFile, char * s
362
367
shdict -> next = segment_info -> dict ;
363
368
segment_info -> dict = shdict ;
364
369
370
+ } else {
371
+
372
+ /* we got the dictionary, but we need to reload the affixes (to handle regex_t rules) */
373
+
374
+ dict = (IspellDict * )palloc0 (sizeof (IspellDict ));
375
+
376
+ NIStartBuild (dict );
377
+
378
+ NIImportAffixes (dict ,
379
+ get_tsearch_config_filename (affFile , "affix" ));
380
+
381
+ dict -> AffixData = shdict -> AffixData ;
382
+ dict -> lenAffixData = shdict -> lenAffixData ;
383
+ dict -> nAffixData = shdict -> nAffixData ;
384
+
385
+ NISortAffixes (dict );
386
+
387
+ NIFinishBuild (dict );
388
+
389
+ shdict -> Suffix = dict -> Suffix ;
390
+ shdict -> Prefix = dict -> Prefix ;
391
+
365
392
}
366
393
367
394
/* STOP WORDS */
@@ -723,139 +750,6 @@ int sizeSPNode(SPNode * node) {
723
750
return size ;
724
751
}
725
752
726
- /* RegisNode - simple regular expressions */
727
-
728
- static
729
- RegisNode * copyRegisNode (RegisNode * node ) {
730
-
731
- RegisNode * copy = (RegisNode * )shalloc (offsetof(RegisNode , data ) + node -> len );
732
-
733
- memcpy (copy , node , offsetof(RegisNode , data ) + node -> len );
734
-
735
- if (node -> next != NULL ) {
736
- copy -> next = copyRegisNode (node -> next );
737
- }
738
-
739
- return copy ;
740
- }
741
-
742
- static
743
- int sizeRegisNode (RegisNode * node ) {
744
-
745
- int size = MAXALIGN (offsetof(RegisNode , data ) + node -> len );
746
-
747
- if (node -> next != NULL ) {
748
- size += sizeRegisNode (node -> next );
749
- }
750
-
751
- return size ;
752
- }
753
-
754
- /* AFFIX - affix rules (simple, regis or full regular expressions). */
755
-
756
- static
757
- AFFIX * copyAffix (AFFIX * affix ) {
758
-
759
- AFFIX * copy = (AFFIX * )shalloc (sizeof (AFFIX ));
760
-
761
- memcpy (copy , affix , sizeof (AFFIX ));
762
-
763
- copy -> find = shstrcpy (affix -> find );
764
- copy -> repl = shstrcpy (affix -> repl );
765
-
766
- if (affix -> isregis ) {
767
- copy -> reg .regis .node = copyRegisNode (affix -> reg .regis .node );
768
- } else if (! affix -> issimple ) {
769
-
770
- /*FIXME Need to copy the regex_t properly. But a plain copy would not be
771
- * safe tu use by multiple processes at the same time, so each backend
772
- * needs to create it's own copy. */
773
- elog (ERROR , "This extension can't handle regex_t affixes yet." );
774
-
775
- }
776
-
777
- return copy ;
778
-
779
- }
780
-
781
- static
782
- int sizeAffix (AFFIX * affix ) {
783
-
784
- int size = MAXALIGN (sizeof (AFFIX ));
785
-
786
- size += MAXALIGN (strlen (affix -> find )+ 1 );
787
- size += MAXALIGN (strlen (affix -> repl )+ 1 );
788
-
789
- if (affix -> isregis ) {
790
- size += sizeRegisNode (affix -> reg .regis .node );
791
- } else if (! affix -> issimple ) {
792
-
793
- /*FIXME Need to copy the regex_t properly. But would a plain copy be
794
- * safe tu use by multiple processes at the same time? */
795
- elog (ERROR , "This extension can't handle regex_t affixes yet." );
796
-
797
- }
798
-
799
- return size ;
800
-
801
- }
802
-
803
- /* AffixNode */
804
-
805
- static
806
- AffixNode * copyAffixNode (AffixNode * node ) {
807
-
808
- int i , j ;
809
- AffixNode * copy = NULL ;
810
-
811
- if (node == NULL ) {
812
- return NULL ;
813
- }
814
-
815
- copy = (AffixNode * )shalloc (offsetof(AffixNode ,data ) + sizeof (AffixNodeData ) * node -> length );
816
- memcpy (copy , node , offsetof(AffixNode ,data ) + sizeof (AffixNodeData ) * node -> length );
817
-
818
- for (i = 0 ; i < node -> length ; i ++ ) {
819
-
820
- copy -> data [i ].node = copyAffixNode (node -> data [i ].node );
821
-
822
- copy -> data [i ].val = node -> data [i ].val ;
823
- copy -> data [i ].naff = node -> data [i ].naff ;
824
- copy -> data [i ].aff = (AFFIX * * )shalloc (sizeof (AFFIX * ) * node -> data [i ].naff );
825
-
826
- for (j = 0 ; j < node -> data [i ].naff ; j ++ ) {
827
- copy -> data [i ].aff [j ] = copyAffix (node -> data [i ].aff [j ]);
828
- }
829
- }
830
-
831
- return copy ;
832
- }
833
-
834
- static
835
- int sizeAffixNode (AffixNode * node ) {
836
-
837
- int i , j ;
838
- int size = 0 ;
839
-
840
- if (node == NULL ) {
841
- return 0 ;
842
- }
843
-
844
- size = MAXALIGN (offsetof(AffixNode ,data ) + sizeof (AffixNodeData ) * node -> length );
845
-
846
- for (i = 0 ; i < node -> length ; i ++ ) {
847
-
848
- size += sizeAffixNode (node -> data [i ].node );
849
- size += MAXALIGN (sizeof (AFFIX * ) * node -> data [i ].naff );
850
-
851
- for (j = 0 ; j < node -> data [i ].naff ; j ++ ) {
852
- size += sizeAffix (node -> data [i ].aff [j ]);
853
- }
854
- }
855
-
856
- return size ;
857
- }
858
-
859
753
/* StopList */
860
754
861
755
static
@@ -932,13 +826,6 @@ SharedIspellDict * copyIspellDict(IspellDict * dict, char * dictFile, char * aff
932
826
strcpy (copy -> dictFile , dictFile );
933
827
strcpy (copy -> affixFile , affixFile );
934
828
935
- copy -> naffixes = dict -> naffixes ;
936
-
937
- copy -> Affix = (AFFIX * )shalloc (sizeof (AFFIX ) * dict -> naffixes );
938
-
939
- copy -> Suffix = copyAffixNode (dict -> Suffix );
940
- copy -> Prefix = copyAffixNode (dict -> Prefix );
941
-
942
829
copy -> Dictionary = copySPNode (dict -> Dictionary );
943
830
944
831
/* copy affix data */
@@ -958,6 +845,11 @@ SharedIspellDict * copyIspellDict(IspellDict * dict, char * dictFile, char * aff
958
845
959
846
copy -> nbytes = size ;
960
847
copy -> nwords = words ;
848
+
849
+ /* use the affixes directly (no copy, we'll reload it anyway to handle regular expressions) */
850
+ copy -> naffixes = dict -> naffixes ;
851
+ copy -> Suffix = dict -> Suffix ;
852
+ copy -> Prefix = dict -> Prefix ;
961
853
962
854
return copy ;
963
855
@@ -975,11 +867,6 @@ int sizeIspellDict(IspellDict * dict, char * dictFile, char * affixFile) {
975
867
size += MAXALIGN (strlen (dictFile )+ 1 );
976
868
size += MAXALIGN (strlen (affixFile )+ 1 );
977
869
978
- size += MAXALIGN (sizeof (AFFIX ) * dict -> naffixes );
979
-
980
- size += MAXALIGN (sizeAffixNode (dict -> Suffix ));
981
- size += MAXALIGN (sizeAffixNode (dict -> Prefix ));
982
-
983
870
size += sizeSPNode (dict -> Dictionary );
984
871
985
872
/* copy affix data */
0 commit comments