@@ -574,6 +574,7 @@ int AllocSetups(VOID)
574574 AM .S0 = 0 ;
575575 AM .S0 = AllocSort (LargeSize ,SmallSize ,SmallEsize ,TermsInSmall
576576 ,MaxPatches ,MaxFpatches ,IOsize );
577+ /* AM.S0->file.ziosize was already set to a (larger) value by AllocSort, here it is re-set. */
577578#ifdef WITHZLIB
578579 AM .S0 -> file .ziosize = IOsize ;
579580#ifndef WITHPTHREADS
@@ -848,20 +849,30 @@ VOID WriteSetup(VOID)
848849 To be used for the main allocation of the sort buffers, and
849850 in a later stage for the function and subroutine sort buffers.
850851*/
851-
852- SORTING * AllocSort (LONG LargeSize , LONG SmallSize , LONG SmallEsize , LONG TermsInSmall ,
853- int MaxPatches , int MaxFpatches , LONG IOsize )
852+ SORTING * AllocSort (LONG inLargeSize , LONG inSmallSize , LONG inSmallEsize , LONG inTermsInSmall ,
853+ int inMaxPatches , int inMaxFpatches , LONG inIOsize )
854854{
855- LONG allocation ,longer ,terms2insmall ,sortsize ,longerp ;
855+ LONG LargeSize = inLargeSize ;
856+ LONG SmallSize = inSmallSize ;
857+ LONG SmallEsize = inSmallEsize ;
858+ LONG TermsInSmall = inTermsInSmall ;
859+ int MaxPatches = inMaxPatches ;
860+ int MaxFpatches = inMaxFpatches ;
861+ LONG IOsize = inIOsize ;
862+
863+ #ifndef SPLITALLOC
864+ LONG allocation ;
865+ #endif
866+ LONG longer ,terms2insmall ,sortsize ,longerp ;
856867 LONG IObuffersize = IOsize ;
857868 LONG IOtry ;
858869 SORTING * sort ;
859- int i = 0 , j = 0 ;
870+ int fname2Size = 0 , j = 0 ;
860871 char * s ;
861872 if ( AM .S0 != 0 ) {
862- s = FG .fname2 ; i = 0 ;
863- while ( * s ) { s ++ ; i ++ ; }
864- i += 16 ;
873+ s = FG .fname2 ; fname2Size = 0 ;
874+ while ( * s ) { s ++ ; fname2Size ++ ; }
875+ fname2Size += 16 ;
865876 }
866877 if ( MaxFpatches < 4 ) MaxFpatches = 4 ;
867878 longer = MaxPatches > MaxFpatches ? MaxPatches : MaxFpatches ;
@@ -876,7 +887,6 @@ SORTING *AllocSort(LONG LargeSize, LONG SmallSize, LONG SmallEsize, LONG TermsIn
876887 terms2insmall = 2 * TermsInSmall ; /* Used to be just + 100 rather than *2 */
877888 if ( SmallEsize < (SmallSize * 3 )/2 ) SmallEsize = (SmallSize * 3 )/2 ;
878889 if ( LargeSize > 0 && LargeSize < 2 * SmallSize ) LargeSize = 2 * SmallSize ;
879- /* if ( SmallEsize < 3*AM.MaxTer ) SmallEsize = 3*AM.MaxTer; */
880890 SmallEsize = (SmallEsize + 15 ) & (-16L );
881891 if ( LargeSize < 0 ) LargeSize = 0 ;
882892 sortsize = sizeof (SORTING );
@@ -898,9 +908,23 @@ SORTING *AllocSort(LONG LargeSize, LONG SmallSize, LONG SmallEsize, LONG TermsIn
898908
899909 IOtry = ((LargeSize + SmallEsize )/MaxFpatches - 2 * AM .MaxTer )/sizeof (WORD )- COMPINC ;
900910
901- if ( (LONG )(IObuffersize * sizeof (WORD )) < IOtry )
902- IObuffersize = (IOtry + sizeof (WORD )- 1 )/sizeof (WORD );
911+ /* Here both IObuffersize and IOtry are in units of sizeof(WORD). */
912+ if ( IObuffersize < IOtry ) {
913+ IObuffersize = IOtry ;
914+ }
915+
916+ #if DEBUGGING
917+ if ( LargeSize != inLargeSize ) { MesPrint ("Warning: LargeSize adjusted: %l -> %l" , inLargeSize , LargeSize ); }
918+ if ( SmallSize != inSmallSize ) { MesPrint ("Warning: SmallSize adjusted: %l -> %l" , inSmallSize , SmallSize ); }
919+ if ( SmallEsize != inSmallEsize ) {MesPrint ("Warning: SmallEsize adjusted: %l -> %l" , inSmallEsize , SmallEsize ); }
920+ if ( TermsInSmall != inTermsInSmall ) { MesPrint ("Warning: TermsInSmall adjusted: %l -> %l" , inTermsInSmall , TermsInSmall ); }
921+ if ( MaxPatches != inMaxPatches ) { MesPrint ("Warning: MaxPatches adjusted: %d -> %d" , inMaxPatches , MaxPatches ); }
922+ if ( MaxFpatches != inMaxFpatches ) {MesPrint ("Warning: MaxFPatches adjusted: %d -> %d" , inMaxFpatches , MaxFpatches ); }
923+ /* This one is always changed if the LargeSize has not been... */
924+ /* if ( IObuffersize != inIOsize/(LONG)sizeof(WORD) ) { MesPrint("Warning: IOsize adjusted: %l -> %l", inIOsize/sizeof(WORD), IObuffersize); } */
925+ #endif
903926
927+ #ifndef SPLITALLOC
904928 allocation =
905929 3 * sizeof (POSITION )* (LONG )longer /* Filepositions!! */
906930 + 2 * sizeof (WORD * )* longer
@@ -914,7 +938,7 @@ SORTING *AllocSort(LONG LargeSize, LONG SmallSize, LONG SmallEsize, LONG TermsIn
914938 + LargeSize
915939 + SmallEsize
916940 + sortsize
917- + IObuffersize * sizeof (WORD ) + i + 16 ;
941+ + IObuffersize * sizeof (WORD ) + fname2Size + 16 ;
918942 sort = (SORTING * )Malloc1 (allocation ,"sort buffers" );
919943
920944 sort -> LargeSize = LargeSize /sizeof (WORD );
@@ -931,11 +955,13 @@ SORTING *AllocSort(LONG LargeSize, LONG SmallSize, LONG SmallEsize, LONG TermsIn
931955 sort -> pStop = sort -> Patches + longer ;
932956 sort -> poina = sort -> pStop + longer ;
933957 sort -> poin2a = sort -> poina + longerp ;
958+
934959 sort -> fPatches = (POSITION * )(sort -> poin2a + longerp );
935960 sort -> fPatchesStop = sort -> fPatches + longer ;
936961 sort -> inPatches = sort -> fPatchesStop + longer ;
937962 sort -> tree = (WORD * )(sort -> inPatches + longer );
938963 sort -> used = sort -> tree + longerp ;
964+
939965#ifdef WITHZLIB
940966 sort -> fpcompressed = sort -> used + longerp ;
941967 sort -> fpincompressed = sort -> fpcompressed + longerp + 2 ;
@@ -944,13 +970,16 @@ SORTING *AllocSort(LONG LargeSize, LONG SmallSize, LONG SmallEsize, LONG TermsIn
944970#else
945971 sort -> ktoi = sort -> used + longerp ;
946972#endif
973+
947974 sort -> lBuffer = (WORD * )(sort -> ktoi + longerp + 2 );
948975 sort -> lTop = sort -> lBuffer + sort -> LargeSize ;
976+
949977 sort -> sBuffer = sort -> lTop ;
950978 if ( sort -> LargeSize == 0 ) { sort -> lBuffer = 0 ; sort -> lTop = 0 ; }
951979 sort -> sTop = sort -> sBuffer + sort -> SmallSize ;
952980 sort -> sTop2 = sort -> sBuffer + sort -> SmallEsize ;
953981 sort -> sHalf = sort -> sBuffer + (LONG )((sort -> SmallSize + sort -> SmallEsize )>>1 );
982+
954983 sort -> file .PObuffer = (WORD * )(sort -> sTop2 );
955984 sort -> file .POstop = sort -> file .PObuffer + IObuffersize ;
956985 sort -> file .POsize = IObuffersize * sizeof (WORD );
@@ -975,6 +1004,77 @@ SORTING *AllocSort(LONG LargeSize, LONG SmallSize, LONG SmallEsize, LONG TermsIn
9751004 sort -> cBufferSize = 0 ;
9761005 sort -> f = 0 ;
9771006 sort -> PolyWise = 0 ;
1007+ #endif
1008+
1009+
1010+ #ifdef SPLITALLOC
1011+ // Separate buffers.
1012+ sort = Malloc1 (sizeof (* sort ), "SPLITALLOC sorting struct" );
1013+
1014+ sort -> LargeSize = LargeSize /sizeof (WORD );
1015+ sort -> SmallSize = SmallSize /sizeof (WORD );
1016+ sort -> SmallEsize = SmallEsize /sizeof (WORD );
1017+ sort -> MaxPatches = MaxPatches ;
1018+ sort -> MaxFpatches = MaxFpatches ;
1019+ sort -> TermsInSmall = TermsInSmall ;
1020+ sort -> Terms2InSmall = terms2insmall ;
1021+
1022+ sort -> sPointer = Malloc1 (sizeof (* (sort -> sPointer ))* terms2insmall , "SPLITALLOC sPointer" );
1023+ sort -> SplitScratch = Malloc1 (sizeof (* (sort -> SplitScratch ))* terms2insmall /2 , "SPLITALLOC SplitScratch" );
1024+ sort -> Patches = Malloc1 (sizeof (* (sort -> Patches ))* longer , "SPLITALLOC Patches" );
1025+ sort -> pStop = Malloc1 (sizeof (* (sort -> pStop ))* longer , "SPLITALLOC pStop" );
1026+ sort -> poina = Malloc1 (sizeof (* (sort -> poina ))* longerp , "SPLITALLOC poina" );
1027+ sort -> poin2a = Malloc1 (sizeof (* (sort -> poin2a ))* longerp , "SPLITALLOC poin2a" );
1028+
1029+ sort -> fPatches = Malloc1 (sizeof (* (sort -> fPatches ))* longer , "SPLITALLOC fPatches" );
1030+ sort -> fPatchesStop = Malloc1 (sizeof (* (sort -> fPatchesStop ))* longer , "SPLITALLOC fPatchesStop" );
1031+ sort -> inPatches = Malloc1 (sizeof (* (sort -> inPatches ))* longer , "SPLITALLOC inPatches" );
1032+ sort -> tree = Malloc1 (sizeof (* (sort -> tree ))* longerp , "SPLITALLOC tree" );
1033+ sort -> used = Malloc1 (sizeof (* (sort -> used ))* longerp , "SPLITALLOC used" );
1034+
1035+ #ifdef WITHZLIB
1036+ sort -> fpcompressed = Malloc1 (sizeof (* (sort -> fpcompressed ))* (longerp + 2 ), "SPLITALLOC fpcompressed" );
1037+ sort -> fpincompressed = Malloc1 (sizeof (* (sort -> fpincompressed ))* (longerp + 2 ), "SPLITALLOC fpincompressed" );
1038+ sort -> zsparray = 0 ;
1039+ #endif
1040+
1041+ sort -> ktoi = Malloc1 (sizeof (* (sort -> ktoi ))* (longerp + 2 ), "SPLITALLOC ktoi" );
1042+
1043+ // The combined Large buffer and Small buffer (+ extension) are used.
1044+ // They must be allocated together.
1045+ sort -> lBuffer = Malloc1 (sizeof (* (sort -> lBuffer ))* (sort -> LargeSize + sort -> SmallEsize ), "SPLITALLOC lBuffer+sBuffer" );
1046+ sort -> lTop = sort -> lBuffer + sort -> LargeSize ;
1047+
1048+ sort -> sBuffer = sort -> lTop ;
1049+ if ( sort -> LargeSize == 0 ) { sort -> lBuffer = 0 ; sort -> lTop = 0 ; }
1050+ sort -> sTop = sort -> sBuffer + sort -> SmallSize ;
1051+ sort -> sTop2 = sort -> sBuffer + sort -> SmallEsize ;
1052+ sort -> sHalf = sort -> sBuffer + (LONG )((sort -> SmallSize + sort -> SmallEsize )>>1 );
1053+
1054+ sort -> file .PObuffer = Malloc1 (IObuffersize * sizeof (* (sort -> file .PObuffer ))+ fname2Size + 16 , "SPLITALLOC PObuffer" );
1055+ sort -> file .POstop = sort -> file .PObuffer + IObuffersize ;
1056+ sort -> file .POsize = IObuffersize * sizeof (WORD );
1057+ sort -> file .POfill = sort -> file .POfull = sort -> file .PObuffer ;
1058+ sort -> file .active = 0 ;
1059+ sort -> file .handle = -1 ;
1060+ PUTZERO (sort -> file .POposition );
1061+ #ifdef WITHPTHREADS
1062+ sort -> file .pthreadslock = dummylock ;
1063+ #endif
1064+ #ifdef WITHZLIB
1065+ sort -> file .ziosize = IObuffersize * sizeof (WORD );
1066+ sort -> file .ziobuffer = 0 ;
1067+ #endif
1068+ if ( AM .S0 != 0 ) {
1069+ sort -> file .name = (char * )(sort -> file .PObuffer + IObuffersize );
1070+ AllocSortFileName (sort );
1071+ }
1072+ else sort -> file .name = 0 ;
1073+ sort -> cBuffer = 0 ;
1074+ sort -> cBufferSize = 0 ;
1075+ sort -> f = 0 ;
1076+ sort -> PolyWise = 0 ;
1077+ #endif
9781078
9791079 return (sort );
9801080}
0 commit comments