From 4ccfeba5b8ed71c99567fc568b8f22cc1ad66db2 Mon Sep 17 00:00:00 2001 From: vermaseren Date: Sat, 15 Oct 2016 13:52:47 +0200 Subject: [PATCH] Resolved crashesin issue #122, but does not generate everything. --- sources/function.c | 6 +++++- sources/pattern.c | 8 +++++++- sources/structs.h | 7 ++++--- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/sources/function.c b/sources/function.c index fcc7adb7..d1f3a902 100644 --- a/sources/function.c +++ b/sources/function.c @@ -1612,6 +1612,7 @@ WORD ScanFunctions(PHEAD WORD *inpat, WORD *inter, WORD par) int ntwa = AN.NumTotWildArgs; LONG oldcpointer = C->Pointer - C->Buffer; WORD oldSignCheck = AN.SignCheck; + AT.FunDepth++; instart = inter; /* Only active for the last function in the pattern. @@ -1885,13 +1886,15 @@ trythis:; Failure: AN.SignCheck = oldSignCheck; AT.WorkPointer = OldWork; + AT.FunDepth--; return(0); OnSuccess: - if ( AT.idallflag ) { + if ( AT.idallflag && AT.FunDepth <= 1 ) { if ( AT.idallmaxnum > 0 && AT.idallnum >= AT.idallmaxnum ) { AN.terfirstcomm = Oterfirstcomm; AN.SignCheck = oldSignCheck; AT.WorkPointer = OldWork; + AT.FunDepth--; return(0); } SubsInAll(BHEAD0); @@ -1941,6 +1944,7 @@ NextFor:; } doesmatch: AT.WorkPointer = OldWork; + AT.FunDepth--; return(1); } diff --git a/sources/pattern.c b/sources/pattern.c index 1ba022c0..9c3a46a3 100644 --- a/sources/pattern.c +++ b/sources/pattern.c @@ -99,7 +99,7 @@ WORD TestMatch(PHEAD WORD *term, WORD *level) GETBIDENTITY WORD *ll, *m, *w, *llf, *OldWork, *StartWork, *ww, *mm, *t, *OldTermBuffer = 0; WORD power = 0, match = 0, i, msign = 0, ll2; - int numdollars = 0, protosize, oldallnumrhs; + int numdollars = 0, protosize, oldallnumrhs, oldFunDepth; CBUF *C = cbuf+AM.rbufnum, *CC; AT.idallflag = 0; do { @@ -330,6 +330,7 @@ WORD TestMatch(PHEAD WORD *term, WORD *level) } AN.DisOrderFlag = ll2 & SUBDISORDER; AN.nogroundlevel = 0; + oldFunDepth = AT.FunDepth; switch ( ll2 & SUBMASK ) { case SUBONLY : /* Must be an exact match */ @@ -364,6 +365,7 @@ WORD TestMatch(PHEAD WORD *term, WORD *level) MLOCK(ErrorMessageLock); MesWork(); MUNLOCK(ErrorMessageLock); + AT.FunDepth = oldFunDepth; return(-1); } /* @@ -397,6 +399,7 @@ WORD TestMatch(PHEAD WORD *term, WORD *level) MLOCK(ErrorMessageLock); MesWork(); MUNLOCK(ErrorMessageLock); + AT.FunDepth = oldFunDepth; return(-1); } /* @@ -430,6 +433,7 @@ WORD TestMatch(PHEAD WORD *term, WORD *level) MLOCK(ErrorMessageLock); MesWork(); MUNLOCK(ErrorMessageLock); + AT.FunDepth = oldFunDepth; return(-1); } /* @@ -597,6 +601,7 @@ WORD TestMatch(PHEAD WORD *term, WORD *level) AT.idallflag = 0; CC->Pointer[0] = 0; TransferBuffer(AT.aebufnum,AT.ebufnum,AT.allbufnum); + AT.FunDepth = oldFunDepth; return(1); } AT.idallflag = 0; @@ -629,6 +634,7 @@ nextlevel:; } while ( (*level)++ < AR.Cnumlhs && C->lhs[*level][0] == TYPEIDOLD ); (*level)--; AT.WorkPointer = AN.RepFunList; + AT.FunDepth = oldFunDepth; return(match); } diff --git a/sources/structs.h b/sources/structs.h index 60a971a5..70f3e71f 100644 --- a/sources/structs.h +++ b/sources/structs.h @@ -1978,6 +1978,7 @@ struct T_const { int numpoly; int LeaveNegative; int TrimPower; /* Indicates trimming in polyratfun expansion */ + int FunDepth; /* Depth in pattern matching */ WORD small_power_maxx; /* size of the cache for small powers */ WORD small_power_maxn; /* size of the cache for small powers */ WORD dummysubexp[SUBEXPSIZE+4]; /* () used in normal.c */ @@ -2005,12 +2006,12 @@ struct T_const { WORD fromindex; /* Tells the compare routine whether call from index */ #ifdef WITHPTHREADS #ifdef WITHSORTBOTS - PADPOINTER(4,25,100+SUBEXPSIZE*4+FUNHEAD*2+ARGHEAD*2,0); + PADPOINTER(4,26,100+SUBEXPSIZE*4+FUNHEAD*2+ARGHEAD*2,0); #else - PADPOINTER(4,23,100+SUBEXPSIZE*4+FUNHEAD*2+ARGHEAD*2,0); + PADPOINTER(4,24,100+SUBEXPSIZE*4+FUNHEAD*2+ARGHEAD*2,0); #endif #else - PADPOINTER(4,21,100+SUBEXPSIZE*4+FUNHEAD*2+ARGHEAD*2,0); + PADPOINTER(4,22,100+SUBEXPSIZE*4+FUNHEAD*2+ARGHEAD*2,0); #endif }; /*