diff --git a/C/grow.c b/C/grow.c index e7216286e..72ae89a93 100644 --- a/C/grow.c +++ b/C/grow.c @@ -1307,6 +1307,10 @@ static int do_growtrail(long size, int contiguous_only, int in_parser, tr_fr_ptr UInt start_growth_time = Yap_cputime(), growth_time; int gc_verbose = Yap_is_gc_verbose(); +#if USE_SYSTEM_MALLOC + if (contiguous_only) + return FALSE; +#endif /* at least 64K for trail */ if (size < 64*1024) size = 64*1024; diff --git a/C/heapgc.c b/C/heapgc.c index 56c688aff..f038d1ee6 100644 --- a/C/heapgc.c +++ b/C/heapgc.c @@ -149,18 +149,12 @@ static rb_red_blk_node *db_root, *db_nil; static void gc_growtrail(int committed) { -#if USE_SYSTEM_MALLOC - TR = OldTR; - save_machine_regs(); - longjmp(Yap_gc_restore, 2); -#else if (!Yap_growtrail(64 * 1024L, TRUE)) { + TR = OldTR; /* could not find more trail */ save_machine_regs(); longjmp(Yap_gc_restore, 2); } -#endif - } inline static void @@ -1600,8 +1594,9 @@ mark_trail(tr_fr_ptr trail_ptr, tr_fr_ptr trail_base, CELL *gc_H, choiceptr gc_B tr_fr_ptr nsTR = (tr_fr_ptr)cont_top0; CELL *cptr = (CELL *)trail_cell; - if ((ADDR)nsTR > Yap_TrailTop-1024) - Yap_growtrail(64 * 1024L, TRUE); + if ((ADDR)nsTR > Yap_TrailTop-1024) { + gc_growtrail(TRUE); + } TrailTerm(nsTR) = (CELL)NULL; TrailTerm(nsTR+1) = *hp; TrailTerm(nsTR+2) = trail_cell; diff --git a/C/scanner.c b/C/scanner.c index fba18fa2f..5f3d75c27 100644 --- a/C/scanner.c +++ b/C/scanner.c @@ -128,13 +128,6 @@ typedef struct scanner_extra_alloc { void *filler; } ScannerExtraBlock; -/* Problem: we use realloc so we cannot guarantee beforehand pointers will shift or not */ -#if USE_SYSTEM_MALLOC -#define EXPAND_TRAIL FALSE -#else -#define EXPAND_TRAIL TRUE -#endif - static char * AllocScannerMemory(unsigned int size) { @@ -156,7 +149,7 @@ AllocScannerMemory(unsigned int size) if (size > alloc_size) alloc_size = size; - if(!EXPAND_TRAIL || !Yap_growtrail(alloc_size, TRUE)) { + if(!Yap_growtrail(alloc_size, TRUE)) { struct scanner_extra_alloc *ptr; if (!(ptr = (struct scanner_extra_alloc *)malloc(size+sizeof(ScannerExtraBlock)))) { diff --git a/C/write.c b/C/write.c index 24772dd3e..e42f5f367 100644 --- a/C/write.c +++ b/C/write.c @@ -453,12 +453,16 @@ writeTerm(Term t, int p, int depth, int rinfixarg, struct write_globs *wglb) #ifdef USE_GMP case (CELL)FunctorBigInt: { - char *s = (char *)TR; MP_INT *big = Yap_BigIntOfTerm(t); - while (s+2+mpz_sizeinbase(big, 10) > (char *)Yap_TrailTop) { - Yap_growtrail(2+mpz_sizeinbase(big, 10), TRUE); - big = Yap_BigIntOfTerm(t); + char *s = (char *)TR; + if (s+2+mpz_sizeinbase(big, 10) >= Yap_TrailTop) { + s = H; + if (s+2+mpz_sizeinbase(big, 10) >= ASP) { + return; + } } + if (!s) + return; if (mpz_sgn(big) < 0) { if (lastw == symbol) wrputc(' ', wglb->writech);