From ecce575a0a63bc0ad45bd08ef990fa1c67eedc71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADtor=20Santos=20Costa?= Date: Tue, 6 Jul 2010 15:31:17 +0100 Subject: [PATCH] fix stack calculation (ricardo rocha) --- C/absmi.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/C/absmi.c b/C/absmi.c index 5dcb178b0..33ce51927 100755 --- a/C/absmi.c +++ b/C/absmi.c @@ -1545,7 +1545,11 @@ Yap_absmi(int inp) LogUpdClause *cl = ClauseCodeToLogUpdClause(PREG); Term t; - ASP = YREG+E_CB; + if (YREG > (CELL *) PROTECT_FROZEN_B(B)) { + ASP = (CELL *) PROTECT_FROZEN_B(B); + } else { + ASP = YREG+E_CB; + } saveregs(); while ((t = Yap_FetchTermFromDB(cl->ClSource)) == 0L) { if (Yap_Error_TYPE == OUT_OF_ATTVARS_ERROR) { @@ -2665,6 +2669,8 @@ Yap_absmi(int inp) if (SREG <= ASP) { ASP = SREG-EnvSizeInCells; } + if (ASP > (CELL *)PROTECT_FROZEN_B(B)) + ASP = (CELL *)PROTECT_FROZEN_B(B); if (ActiveSignals & YAP_CDOVF_SIGNAL) { goto noheapleft; } @@ -7745,7 +7751,11 @@ Yap_absmi(int inp) ENDCACHE_Y(); Yap_PrologMode = UserCCallMode; - ASP = YREG; + if (YREG > (CELL *) PROTECT_FROZEN_B(B)) { + ASP = (CELL *) PROTECT_FROZEN_B(B); + } else { + ASP = YREG; + } /* for slots to work */ Yap_StartSlots(); saveregs(); @@ -13780,6 +13790,8 @@ Yap_absmi(int inp) PP = PredMetaCall; SREG = (CELL *) pen; ASP = ENV_YREG; + if (ASP > (CELL *)PROTECT_FROZEN_B(B)) + ASP = (CELL *)PROTECT_FROZEN_B(B); /* setup GB */ WRITEBACK_Y_AS_ENV(); YREG[E_CB] = (CELL) B; @@ -13977,6 +13989,8 @@ Yap_absmi(int inp) PP = PredMetaCall; SREG = (CELL *) pen; ASP = ENV_YREG; + if (ASP > (CELL *)PROTECT_FROZEN_B(B)) + ASP = (CELL *)PROTECT_FROZEN_B(B); /* setup GB */ WRITEBACK_Y_AS_ENV(); YREG[E_CB] = (CELL) B;