Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions check/fixes.frm
Original file line number Diff line number Diff line change
Expand Up @@ -1409,6 +1409,49 @@ assert stdout =~ exact_pattern(<<'EOF')
F
EOF
*--#] Issue129_2 :
*--#[ Issue138_1 :
CFunction f,a,b,c,d;
Symbol x,y;
Local F = (1+f((a+b)^2,(a+b)*(c*d)))^20;
.sort
Identify f(x?,y?) = f(gcd_(x,y));
ToPolynomial;
.sort
FromPolynomial;
Identify f(a+b) = -1;
Print;
.end
assert succeeded?
assert result("F") =~ expr("0")
*--#] Issue138_1 :
*--#[ Issue138_2 :
CFunction f,g;
Symbol x,y;
Local F = (1+f((g(x)+g(y))^2))^20;
FactArg f;
ToPolynomial;
.sort
FromPolynomial;
Identify f(g(x)+g(y),g(x)+g(y)) = -1;
Print;
.end
assert succeeded?
assert result("F") =~ expr("0")
*--#] Issue138_2 :
*--#[ Issue138_3 :
CFunction f,g;
Symbol x,y;
Local F = (1+f((g(x)+g(y))^2))^20;
FactArg f;
ArgToExtraSymbol g;
.sort
FromPolynomial;
Identify f(g(x)+g(y),g(x)+g(y)) = -1;
Print;
.end
assert succeeded?
assert result("F") =~ expr("0")
*--#] Issue138_3 :
*--#[ Issue139 :
* Corrupted characters in printing f(-2147483648)
CF f;
Expand Down
13 changes: 9 additions & 4 deletions sources/argument.c
Original file line number Diff line number Diff line change
Expand Up @@ -2078,7 +2078,7 @@ int ArgFactorize(PHEAD WORD *argin, WORD *argout)
#endif
WORD startebuf = cbuf[AT.ebufnum].numrhs,oldword;
WORD oldsorttype = AR.SortType, numargs;
int error = 0, action = 0, i, ii, number, sign = 1;
int error = 0, action = 0, i, ii, locked = 0, number, sign = 1;

*argout = 0;
/*
Expand Down Expand Up @@ -2254,9 +2254,10 @@ int ArgFactorize(PHEAD WORD *argin, WORD *argout)
argextra = AT.WorkPointer;
NewSort(BHEAD0);
while ( t < tstop ) {
if ( LocalConvertToPoly(BHEAD t,argextra,startebuf,0) < 0 ) {
if ( LocalConvertToPoly(BHEAD t,argextra,startebuf,0,&locked) < 0 ) {
error = -1;
getout:
UnlockLocalPolynomial(&locked);
AR.SortType = oldsorttype;
TermFree(argcopy,"argcopy");
if ( argfree != argin ) TermFree(argfree,"argfree");
Expand Down Expand Up @@ -2350,6 +2351,7 @@ int ArgFactorize(PHEAD WORD *argin, WORD *argout)
for ( i = 0; i <= *argcopy; i++ ) a[i] = argcopy[i];
}
}
UnlockLocalPolynomial(&locked);
/*
#] step 6 :
#[ step 7 : Add this one to the tables.
Expand Down Expand Up @@ -2526,9 +2528,12 @@ WORD FindArg(PHEAD WORD *a)
{
int number;
if ( AN.ncmod != 0 ) return(0); /* no room for mod stuff */
number = FindTree(AT.fbufnum,a);
/* FindTree is not strictly thread safe, but AT.fbufnum is thread local */
number = FindTree(AT.fbufnum,a,1);
if ( number >= 0 ) return(number+1);
number = FindTree(AC.ffbufnum,a);
/* AC.ffbufnum is global, but currently unused. If it becomes used, we need
* to lock here! */
number = FindTree(AC.ffbufnum,a,1);
if ( number >= 0 ) return(-number-1);
return(0);
}
Expand Down
19 changes: 2 additions & 17 deletions sources/compcomm.c
Original file line number Diff line number Diff line change
Expand Up @@ -2223,11 +2223,6 @@ int CoSplitLastArg(UBYTE *s) { return(DoArgument(s,TYPESPLITLASTARG)); }
*/

int CoFactArg(UBYTE *s) {
if ( ( AC.topolynomialflag & TOPOLYNOMIALFLAG ) != 0 ) {
MesPrint("&ToPolynomial statement and FactArg statement are not allowed in the same module");
return(1);
}
AC.topolynomialflag |= FACTARGFLAG;
return(DoArgument(s,TYPEFACTARG));
}

Expand Down Expand Up @@ -5953,9 +5948,8 @@ int CoDropSymbols(UBYTE *s)

Converts the current term as much as possible to symbols.
Keeps a list of all objects converted to symbols in AM.sbufnum.
Note that this cannot be executed in parallel because we have only
a single compiler buffer for this. Hence we switch on the noparallel
module option.
There is only a single compiler buffer for this. In TFORM we protect access
to it with AM.sbuflock; in ParFORM the statement is executed on the master.

Option(s):
OnlyFunctions [,name1][,name2][,...,namem];
Expand All @@ -5965,10 +5959,6 @@ int CoToPolynomial(UBYTE *inp)
{
int error = 0;
while ( *inp == ' ' || *inp == ',' || *inp == '\t' ) inp++;
if ( ( AC.topolynomialflag & ~TOPOLYNOMIALFLAG ) != 0 ) {
MesPrint("&ToPolynomial statement and FactArg statement are not allowed in the same module");
return(1);
}
if ( AO.OptimizeResult.code != NULL ) {
MesPrint("&Using ToPolynomial statement when there are still optimization results active.");
MesPrint("&Please use #ClearOptimize instruction first.");
Expand Down Expand Up @@ -6067,11 +6057,6 @@ int CoArgToExtraSymbol(UBYTE *s)
CBUF *C = cbuf + AC.cbufnum;
WORD *lhs;

/* TODO: resolve interference with rational arithmetic. (#138) */
if ( ( AC.topolynomialflag & ~TOPOLYNOMIALFLAG ) != 0 ) {
MesPrint("&ArgToExtraSymbol statement and FactArg statement are not allowed in the same module");
return(1);
}
if ( AO.OptimizeResult.code != NULL ) {
MesPrint("&Using ArgToExtraSymbol statement when there are still optimization results active.");
MesPrint("&Please use #ClearOptimize instruction first.");
Expand Down
8 changes: 6 additions & 2 deletions sources/comtool.c
Original file line number Diff line number Diff line change
Expand Up @@ -526,9 +526,11 @@ balance:;
Returns -1 if the element is not in the tree.
The advantage of this routine over InsTree is that this routine
can be run in parallel.
Note that this is not strictly thread safe when "usage" is updated.
This update is controlled with the "updateusage" parameter.
*/

int FindTree(int bufnum, WORD *subexpr)
int FindTree(int bufnum, WORD *subexpr, int updateusage)
{
CBUF *C = cbuf + bufnum;
COMPTREE *boomlijst = C->boomlijst, *q = boomlijst + C->rootnum, *p;
Expand All @@ -552,7 +554,9 @@ int FindTree(int bufnum, WORD *subexpr)
else { return(-1); }
}
else {
p->usage++;
if ( updateusage ) {
p->usage++;
}
return(p->value);
}
}
Expand Down
8 changes: 5 additions & 3 deletions sources/declare.h
Original file line number Diff line number Diff line change
Expand Up @@ -1245,7 +1245,7 @@ extern int CompleteTerm(WORD *,UWORD *,UWORD *,WORD,WORD,int);
extern int CodeFactors(SBYTE *s);
extern WORD GenerateFactors(WORD,WORD);
extern int InsTree(int,int);
extern int FindTree(int,WORD *);
extern int FindTree(int,WORD *,int);
extern void RedoTree(CBUF *,int);
extern void ClearTree(int);
extern int CatchDollar(int);
Expand Down Expand Up @@ -1576,8 +1576,10 @@ extern int RunHtoZArg(PHEAD WORD *fun, WORD *args);
extern int NormPolyTerm(PHEAD WORD *);
extern WORD ComparePoly(WORD *, WORD *, WORD);
extern int ConvertToPoly(PHEAD WORD *, WORD *,WORD *,WORD);
extern int LocalConvertToPoly(PHEAD WORD *, WORD *, WORD,WORD);
extern int LocalConvertToPoly(PHEAD WORD *, WORD *, WORD,WORD,int *);
extern int ConvertFromPoly(PHEAD WORD *, WORD *, WORD, WORD, WORD, WORD);
extern int LockLocalPolynomial(void);
extern void UnlockLocalPolynomial(int*);
extern int FindSubterm(WORD *);
extern int FindLocalSubterm(PHEAD WORD *, WORD);
extern void PrintSubtermList(int,int);
Expand Down Expand Up @@ -1606,7 +1608,7 @@ extern WORD *PolyDiv(PHEAD WORD *,WORD *,char *);
extern void GCDclean(PHEAD WORD *, WORD *);
extern WORD *TakeSymbolContent(PHEAD WORD *,WORD *);
extern int GCDterms(PHEAD WORD *,WORD *,WORD *);
extern WORD *PutExtraSymbols(PHEAD WORD *,WORD,int *);
extern WORD *PutExtraSymbols(PHEAD WORD *,WORD,int *,int *);
extern WORD *TakeExtraSymbols(PHEAD WORD *,WORD);
extern WORD *MultiplyWithTerm(PHEAD WORD *, WORD *,WORD);
extern WORD *TakeContent(PHEAD WORD *, WORD *);
Expand Down
9 changes: 7 additions & 2 deletions sources/dollar.c
Original file line number Diff line number Diff line change
Expand Up @@ -2947,7 +2947,7 @@ int DollarFactorize(PHEAD WORD numdollar)
#ifdef STEP2
WORD *tstop, pow, *r;
#endif
int i, j, jj, action = 0, sign = 1;
int i, j, jj, action = 0, locked = 0, sign = 1;
LONG insize, ii;
WORD startebuf = cbuf[AT.ebufnum].numrhs;
WORD nfactors, factorsincontent, extrafactor = 0;
Expand Down Expand Up @@ -3144,8 +3144,9 @@ int DollarFactorize(PHEAD WORD numdollar)
NewSort(BHEAD0);
NewSort(BHEAD0);
while ( *t ) {
if ( LocalConvertToPoly(BHEAD t,termextra,startebuf,0) < 0 ) {
if ( LocalConvertToPoly(BHEAD t,termextra,startebuf,0,&locked) < 0 ) {
getout:
UnlockLocalPolynomial(&locked);
AR.SortType = oldsorttype;
M_free(buf1,"DollarFactorize-2");
if ( buf1content ) TermFree(buf1content,"DollarContent");
Expand All @@ -3169,6 +3170,7 @@ int DollarFactorize(PHEAD WORD numdollar)
#[ Step 4: Now the hard work.
*/
if ( ( buf3 = poly_factorize_dollar(BHEAD buf2) ) == 0 ) {
UnlockLocalPolynomial(&locked);
MesCall("DollarFactorize");
AR.SortType = oldsorttype;
if ( buf2 != buf1 && buf2 ) M_free(buf2,"DollarFactorize-3");
Expand Down Expand Up @@ -3247,6 +3249,7 @@ int DollarFactorize(PHEAD WORD numdollar)
if ( buf2 != buf1 && buf2 ) M_free(buf2,"DollarFactorize-4");
M_free(buf1,"DollarFactorize-4");
if ( buf1content ) TermFree(buf1content,"DollarContent");
UnlockLocalPolynomial(&locked);
return(0);
}
else {
Expand Down Expand Up @@ -3278,6 +3281,7 @@ int DollarFactorize(PHEAD WORD numdollar)
,startebuf-numxsymbol,1) <= 0 ) {
LowerSortLevel();
getout2: AR.SortType = oldsorttype;
UnlockLocalPolynomial(&locked);
M_free(d->factors,"factors in dollar");
d->factors = 0;
#ifdef WITHPTHREADS
Expand Down Expand Up @@ -3336,6 +3340,7 @@ getout2: AR.SortType = oldsorttype;
d->factors[i].size = t - d->factors[i].where;
}
}
UnlockLocalPolynomial(&locked);
d->nfactors = nfactors + factorsincontent;
/*
#] Step 5: ConvertFromPoly
Expand Down
1 change: 0 additions & 1 deletion sources/ftypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -1043,7 +1043,6 @@ typedef int (*TFUN1)(UBYTE *,int);
#define NOLYNDON 2

#define TOPOLYNOMIALFLAG 1
#define FACTARGFLAG 2

#define OLDFACTARG 1
#define NEWFACTARG 0
Expand Down
Loading
Loading