make sure we don't generate an heapexpansion in the middle of a write.
This commit is contained in:
parent
a58e3d812d
commit
3a3220d1a1
19
C/write.c
19
C/write.c
@ -539,16 +539,21 @@ writeTerm(Term t, int p, int depth, int rinfixarg, struct write_globs *wglb)
|
|||||||
char *s;
|
char *s;
|
||||||
s = (char *) Yap_PreAllocCodeSpace();
|
s = (char *) Yap_PreAllocCodeSpace();
|
||||||
while (s+3+mpz_sizeinbase(big, 10) >= (char *)AuxSp) {
|
while (s+3+mpz_sizeinbase(big, 10) >= (char *)AuxSp) {
|
||||||
if (!Yap_ExpandPreAllocCodeSpace(mpz_sizeinbase(big, 10),NULL)) {
|
#if USE_SYSTEM_MALLOC
|
||||||
|
/* may require stack expansion */
|
||||||
|
if (!Yap_ExpandPreAllocCodeSpace(3+mpz_sizeinbase(big, 10),NULL)) {
|
||||||
s = NULL;
|
s = NULL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
s = (char *) Yap_PreAllocCodeSpace();
|
s = (char *) Yap_PreAllocCodeSpace();
|
||||||
|
#else
|
||||||
|
s = NULL;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
if (!s) {
|
if (!s) {
|
||||||
s = (char *)TR;
|
s = (char *)TR;
|
||||||
while (s+3+mpz_sizeinbase(big, 10) >= Yap_TrailTop) {
|
while (s+3+mpz_sizeinbase(big, 10) >= Yap_TrailTop) {
|
||||||
if (!Yap_growtrail(mpz_sizeinbase(big, 10)/sizeof(CELL), FALSE)) {
|
if (!Yap_growtrail((3+mpz_sizeinbase(big, 10))/sizeof(CELL), FALSE)) {
|
||||||
s = NULL;
|
s = NULL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -562,8 +567,6 @@ writeTerm(Term t, int p, int depth, int rinfixarg, struct write_globs *wglb)
|
|||||||
s = NULL;
|
s = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!s)
|
|
||||||
return;
|
|
||||||
if (mpz_sgn(big) < 0) {
|
if (mpz_sgn(big) < 0) {
|
||||||
if (lastw == symbol)
|
if (lastw == symbol)
|
||||||
wrputc(' ', wglb->writewch);
|
wrputc(' ', wglb->writewch);
|
||||||
@ -571,9 +574,17 @@ writeTerm(Term t, int p, int depth, int rinfixarg, struct write_globs *wglb)
|
|||||||
if (lastw == alphanum)
|
if (lastw == alphanum)
|
||||||
wrputc(' ', wglb->writewch);
|
wrputc(' ', wglb->writewch);
|
||||||
}
|
}
|
||||||
|
if (!s) {
|
||||||
|
s = mpz_get_str(NULL, 10, big);
|
||||||
|
if (!s)
|
||||||
|
return;
|
||||||
|
wrputs(s,wglb->writewch);
|
||||||
|
free(s);
|
||||||
|
} else {
|
||||||
mpz_get_str(s, 10, big);
|
mpz_get_str(s, 10, big);
|
||||||
wrputs(s,wglb->writewch);
|
wrputs(s,wglb->writewch);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
{
|
{
|
||||||
wrputs("0",wglb->writewch);
|
wrputs("0",wglb->writewch);
|
||||||
|
Reference in New Issue
Block a user