From 33207cac910c61028c39e878fe9225c2ff636948 Mon Sep 17 00:00:00 2001 From: vsc Date: Sun, 31 Oct 2004 02:18:04 +0000 Subject: [PATCH] fix bug in handling Yap heap overflow while adding new clause. git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@1169 b08c6af1-5177-4d33-ba66-4b1c6b8b522a --- C/c_interface.c | 12 ++++++++++-- C/cdmgr.c | 22 +++++++++++++++------- H/clause.h | 2 +- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/C/c_interface.c b/C/c_interface.c index 1b00a5351..da7154dee 100644 --- a/C/c_interface.c +++ b/C/c_interface.c @@ -10,8 +10,15 @@ * File: c_interface.c * * comments: c_interface primitives definition * * * -* Last rev: $Date: 2004-10-28 20:12:20 $,$Author: vsc $ * +* Last rev: $Date: 2004-10-31 02:18:03 $,$Author: vsc $ * * $Log: not supported by cvs2svn $ +* Revision 1.55 2004/10/28 20:12:20 vsc +* Use Doug Lea's malloc as an alternative to YAP's standard malloc +* don't use TR directly in scanner/parser, this avoids trouble with ^C while +* consulting large files. +* pass gcc -mno-cygwin to library compilation in cygwin environment (cygwin should +* compile out of the box now). +* * Revision 1.54 2004/10/06 16:55:46 vsc * change configure to support big mem configs * get rid of extra globals @@ -968,6 +975,7 @@ YAP_CompileClause(Term t) { yamop *codeaddr; int mod = CurrentModule; + Term tn = TermNil BACKUP_MACHINE_REGS(); @@ -977,7 +985,7 @@ YAP_CompileClause(Term t) codeaddr = Yap_cclause (t,0, mod, t); if (codeaddr != NULL) { t = Deref(ARG1); /* just in case there was an heap overflow */ - Yap_addclause (t, codeaddr, TRUE, mod, TermNil); + Yap_addclause (t, codeaddr, TRUE, mod, &tn); } YAPLeaveCriticalSection(); diff --git a/C/cdmgr.c b/C/cdmgr.c index 7d81bf47d..3f6efc830 100644 --- a/C/cdmgr.c +++ b/C/cdmgr.c @@ -11,8 +11,15 @@ * File: cdmgr.c * * comments: Code manager * * * -* Last rev: $Date: 2004-10-28 20:12:21 $,$Author: vsc $ * +* Last rev: $Date: 2004-10-31 02:18:03 $,$Author: vsc $ * * $Log: not supported by cvs2svn $ +* Revision 1.139 2004/10/28 20:12:21 vsc +* Use Doug Lea's malloc as an alternative to YAP's standard malloc +* don't use TR directly in scanner/parser, this avoids trouble with ^C while +* consulting large files. +* pass gcc -mno-cygwin to library compilation in cygwin environment (cygwin should +* compile out of the box now). +* * Revision 1.138 2004/10/26 20:15:51 vsc * More bug fixes for overflow handling * @@ -1482,7 +1489,7 @@ is_fact(Term t) } static int -addclause(Term t, yamop *cp, int mode, Term mod, Term t4ref) +addclause(Term t, yamop *cp, int mode, Term mod, Term *t4ref) /* * mode @@ -1608,8 +1615,8 @@ addclause(Term t, yamop *cp, int mode, Term mod, Term t4ref) } else { tf = Yap_MkStaticRefTerm((StaticClause *)cp); } - if (t4ref != TermNil) { - if (!Yap_unify(t4ref,tf)) { + if (*t4ref != TermNil) { + if (!Yap_unify(*t4ref,tf)) { return FALSE; } } @@ -1628,7 +1635,7 @@ addclause(Term t, yamop *cp, int mode, Term mod, Term t4ref) } int -Yap_addclause(Term t, yamop *cp, int mode, Term mod, Term t4ref) { +Yap_addclause(Term t, yamop *cp, int mode, Term mod, Term *t4ref) { return addclause(t, cp, mode, mod, t4ref); } @@ -1875,6 +1882,7 @@ p_compile(void) Term t = Deref(ARG1); Term t1 = Deref(ARG2); Term mod = Deref(ARG4); + Term tn = TermNil; yamop *codeadr; if (IsVarTerm(t1) || !IsIntTerm(t1)) @@ -1887,7 +1895,7 @@ p_compile(void) to cclause in case there is overflow */ t = Deref(ARG1); /* just in case there was an heap overflow */ if (!Yap_ErrorMessage) - addclause(t, codeadr, (int) (IntOfTerm(t1) & 3), mod, TermNil); + addclause(t, codeadr, (int) (IntOfTerm(t1) & 3), mod, &tn); YAPLeaveCriticalSection(); if (Yap_ErrorMessage) { if (IntOfTerm(t1) & 4) { @@ -1922,7 +1930,7 @@ p_compile_dynamic(void) if (!Yap_ErrorMessage) { optimizer_on = old_optimize; - addclause(t, code_adr, (int) (IntOfTerm(t1) & 3), mod, ARG5); + addclause(t, code_adr, (int) (IntOfTerm(t1) & 3), mod, &ARG5); } if (Yap_ErrorMessage) { if (IntOfTerm(t1) & 4) { diff --git a/H/clause.h b/H/clause.h index 5a45b928f..8d17154a3 100644 --- a/H/clause.h +++ b/H/clause.h @@ -185,7 +185,7 @@ void STD_PROTO(Yap_InitComma,(void)); /* cdmgr.c */ void STD_PROTO(Yap_IPred,(PredEntry *, UInt)); -int STD_PROTO(Yap_addclause,(Term,yamop *,int,Term,Term)); +int STD_PROTO(Yap_addclause,(Term,yamop *,int,Term,Term*)); void STD_PROTO(Yap_add_logupd_clause,(PredEntry *,LogUpdClause *,int)); void STD_PROTO(Yap_kill_iblock,(ClauseUnion *,ClauseUnion *,PredEntry *)); void STD_PROTO(Yap_cleanup_dangling_indices,(yamop *,yamop *,yamop *,yamop *));