Skip to content

Commit 519e784

Browse files
committed
Add preprocessor instruction #sortreallocate
Enable the reallocation for a single module. If specified in the same module as "Off sortreallocate;", the reallocation will still happen in that module.
1 parent 036b1f4 commit 519e784

File tree

5 files changed

+36
-1
lines changed

5 files changed

+36
-1
lines changed

sources/compcomm.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,14 @@ int CoOff(UBYTE *s)
628628
AC.TestValue = 0;
629629
}
630630
}
631+
else if ( StrICont(t,(UBYTE *)"sortreallocate") == 0 ) {
632+
if ( AC.SortReallocateFlag == 2 ) {
633+
/* The flag has been set by #sortreallocate, and it was off before. Leave it as 2,
634+
so that the reallocation still happens in the current module. It will be turned
635+
off after the reallocation is done. */
636+
return(0);
637+
}
638+
}
631639
*s = c;
632640
*onoffoptions[i].var = onoffoptions[i].flags;
633641
AR.SortType = AC.SortType;

sources/declare.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -957,6 +957,7 @@ extern int DoPrePrintTimes(UBYTE *);
957957
extern int DoPreWrite(UBYTE *);
958958
extern int DoPreClose(UBYTE *);
959959
extern int DoPreRemove(UBYTE *);
960+
extern int DoPreSortReallocate(UBYTE *);
960961
extern int DoCommentChar(UBYTE *);
961962
extern int DoPrcExtension(UBYTE *);
962963
extern int DoPreReset(UBYTE *);

sources/execute.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,6 +1078,11 @@ if ( AC.SwitchInArray > 0 ) {
10781078
}
10791079
#endif
10801080
}
1081+
if ( AC.SortReallocateFlag == 2 ) {
1082+
/* The Flag was set for a single module by the preprocessor #sortreallocate,
1083+
so turn it off again. */
1084+
AC.SortReallocateFlag = 0;
1085+
}
10811086

10821087
return(RetCode);
10831088
}

sources/pre.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ static KEYWORD precommands[] = {
104104
,{"setrandom" , DoSetRandom , 0, 0}
105105
,{"show" , DoPreShow , 0, 0}
106106
,{"skipextrasymbols" , DoSkipExtraSymbols , 0, 0}
107+
,{"sortreallocate", DoPreSortReallocate , 0, 0}
107108
#ifdef WITHFLOAT
108109
,{"startfloat" , DoStartFloat , 0, 0}
109110
#endif
@@ -3777,6 +3778,23 @@ int DoPrePrintTimes(UBYTE *s)
37773778

37783779
/*
37793780
#] DoPrePrintTimes :
3781+
#[ DoPreSortReallocate :
3782+
*/
3783+
3784+
int DoPreSortReallocate(UBYTE *s)
3785+
{
3786+
DUMMYUSE(s);
3787+
if ( AC.SortReallocateFlag == 0 ) {
3788+
/* Currently off, so set to 2. Then the reallocation code knows the flag was
3789+
set here, since "On sortreallocate;" sets it to 1. */
3790+
AC.SortReallocateFlag = 2;
3791+
}
3792+
/* If the flag is already on, do nothing. */
3793+
return(0);
3794+
}
3795+
3796+
/*
3797+
#] DoPreSortReallocate :
37803798
#[ DoPreAppend :
37813799
37823800
Syntax:

sources/structs.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1867,7 +1867,10 @@ struct C_const {
18671867
int MemDebugFlag; /* Only used when MALLOCDEBUG in tools.c */
18681868
int OldGCDflag;
18691869
int WTimeStatsFlag;
1870-
int SortReallocateFlag; /* Controls reallocation of large+small buffer at module end */
1870+
int SortReallocateFlag; /* Controls reallocation of large+small buffer at module end.
1871+
0 : Off
1872+
1 : On, every module (set by On sortreallocate;)
1873+
2 : On, single module (set by #sortreallocate) */
18711874
int doloopstacksize;
18721875
int dolooplevel;
18731876
int CheckpointFlag; /**< Tells preprocessor whether checkpoint code must executed.

0 commit comments

Comments
 (0)