allow format to continue work if you hacve overflows in memory allocation (should do the same for write).
fix recordifnot if it is not the first time we see the term (already in stack). more windows fixes and updates. git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@1107 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
parent
281d9b0073
commit
70e112a311
53
C/alloc.c
53
C/alloc.c
@ -12,7 +12,7 @@
|
||||
* Last rev: *
|
||||
* mods: *
|
||||
* comments: allocating space *
|
||||
* version:$Id: alloc.c,v 1.54 2004-07-23 21:08:44 vsc Exp $ *
|
||||
* version:$Id: alloc.c,v 1.55 2004-07-28 22:09:01 vsc Exp $ *
|
||||
*************************************************************************/
|
||||
#ifdef SCCS
|
||||
static char SccsId[] = "%W% %G%";
|
||||
@ -563,22 +563,22 @@ Yap_ExpandPreAllocCodeSpace(UInt sz)
|
||||
|
||||
#define BASE_ADDRESS ((LPVOID) MMAP_ADDR)
|
||||
/* #define MAX_WORKSPACE 0x40000000L */
|
||||
#define MAX_WORKSPACE 0x20000000L
|
||||
#define MAX_WORKSPACE 0x80000000L
|
||||
|
||||
static LPVOID brk;
|
||||
|
||||
static int
|
||||
ExtendWorkSpace(Int s)
|
||||
{
|
||||
LPVOID b;
|
||||
LPVOID b = brk;
|
||||
prolog_exec_mode OldPrologMode = Yap_PrologMode;
|
||||
|
||||
Yap_PrologMode = ExtendStackMode;
|
||||
b = VirtualAlloc(brk, s, MEM_COMMIT, PAGE_READWRITE);
|
||||
b = VirtualAlloc(b, s, MEM_COMMIT, PAGE_READWRITE);
|
||||
if (b) {
|
||||
brk = (LPVOID) ((Int) brk + s);
|
||||
Yap_PrologMode = OldPrologMode;
|
||||
return TRUE;
|
||||
brk = (LPVOID) ((Int) brk + s);
|
||||
Yap_PrologMode = OldPrologMode;
|
||||
return TRUE;
|
||||
}
|
||||
Yap_ErrorMessage = Yap_ErrorSay;
|
||||
snprintf4(Yap_ErrorMessage, MAX_ERROR_MSG_SIZE,
|
||||
@ -592,27 +592,32 @@ static MALLOC_T
|
||||
InitWorkSpace(Int s)
|
||||
{
|
||||
SYSTEM_INFO si;
|
||||
LPVOID b;
|
||||
UInt max_mem = MAX_WORKSPACE;
|
||||
LPVOID b = NULL;
|
||||
|
||||
GetSystemInfo(&si);
|
||||
Yap_page_size = si.dwPageSize;
|
||||
b = VirtualAlloc(BASE_ADDRESS, MAX_WORKSPACE, MEM_RESERVE, PAGE_NOACCESS);
|
||||
if (b==NULL) {
|
||||
b = VirtualAlloc(0x0, MAX_WORKSPACE, MEM_RESERVE, PAGE_NOACCESS);
|
||||
if (b == NULL) {
|
||||
Yap_Error(FATAL_ERROR,TermNil,"VirtualAlloc failed");
|
||||
return(0);
|
||||
}
|
||||
fprintf(stderr,"%% Warning: YAP reserving space at variable address %p\n", b);
|
||||
}
|
||||
brk = BASE_ADDRESS;
|
||||
|
||||
if (ExtendWorkSpace(s)) {
|
||||
return BASE_ADDRESS;
|
||||
} else {
|
||||
Yap_Error(FATAL_ERROR,TermNil,"VirtualAlloc Failed");
|
||||
return(0);
|
||||
brk = NULL;
|
||||
for (max_mem = MAX_WORKSPACE; max_mem >= s; max_mem = max_mem - (max_mem >> 2)) {
|
||||
b = VirtualAlloc((LPVOID)MMAP_ADDR, max_mem, MEM_RESERVE, PAGE_NOACCESS);
|
||||
if (b == NULL) {
|
||||
b = VirtualAlloc(NULL, max_mem, MEM_RESERVE, PAGE_NOACCESS);
|
||||
if (b != NULL) {
|
||||
brk = b;
|
||||
fprintf(stderr,"%% Warning: YAP reserving space at variable address %p\n", brk);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
brk = BASE_ADDRESS;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (brk && ExtendWorkSpace(s)) {
|
||||
return (MALLOC_T)b;
|
||||
}
|
||||
Yap_Error(FATAL_ERROR,TermNil,"VirtualAlloc Failed");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int
|
||||
@ -1193,6 +1198,7 @@ InitHeap(void *heap_addr)
|
||||
HeapTop = Yap_HeapBase + AdjustSize(sizeof(all_heap_codes));
|
||||
HeapMax = HeapUsed = HeapTop-Yap_HeapBase;
|
||||
|
||||
|
||||
/* notice that this forces odd addresses */
|
||||
*((YAP_SEG_SIZE *) HeapTop) = InUseFlag;
|
||||
HeapTop = HeapTop + sizeof(YAP_SEG_SIZE);
|
||||
@ -1286,7 +1292,6 @@ Yap_InitMemory(int Trail, int Heap, int Stack)
|
||||
#endif /* SHORT_INTS */
|
||||
}
|
||||
#endif /* DEBUG */
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
|
16
C/dbase.c
16
C/dbase.c
@ -2319,10 +2319,15 @@ p_still_variant(void)
|
||||
}
|
||||
/* ok, we assume there was a choicepoint before we copied the term */
|
||||
|
||||
/* skip binding for argument variable */
|
||||
old_tr++;
|
||||
if (dbr->Flags & LogUpdMask) {
|
||||
LogUpdClause *cl = (LogUpdClause *)dbr;
|
||||
|
||||
if (old_tr != TR-2)
|
||||
if (old_tr == TR-1) {
|
||||
if (TrailTerm(old_tr) != CLREF_TO_TRENTRY(cl))
|
||||
return FALSE;
|
||||
} else if (old_tr != TR)
|
||||
return FALSE;
|
||||
if (Yap_op_from_opcode(cl->ClCode->opc) == _unify_idb_term) {
|
||||
return TRUE;
|
||||
@ -2330,7 +2335,10 @@ p_still_variant(void)
|
||||
dbt = cl->ClSource;
|
||||
}
|
||||
} else {
|
||||
if (old_tr != TR-2)
|
||||
if (old_tr == TR-1) {
|
||||
if (TrailTerm(old_tr) != REF_TO_TRENTRY(dbr))
|
||||
return FALSE;
|
||||
} else if (old_tr != TR)
|
||||
return FALSE;
|
||||
if (dbr->Flags & (DBNoVars|DBAtomic))
|
||||
return TRUE;
|
||||
@ -2339,6 +2347,10 @@ p_still_variant(void)
|
||||
dbt = &(dbr->DBT);
|
||||
}
|
||||
#ifdef IDB_LINK_TABLE
|
||||
/*
|
||||
we checked the trail, so we are sure only variables in the new term
|
||||
were bound
|
||||
*/
|
||||
{
|
||||
link_entry *lp = (link_entry *)(dbt->Contents+dbt->NOfCells);
|
||||
link_entry link;
|
||||
|
51
C/iopreds.c
51
C/iopreds.c
@ -650,7 +650,12 @@ MemPutc(int sno, int ch)
|
||||
char *newbuf;
|
||||
|
||||
if ((newbuf = Yap_AllocAtomSpace(new_max_size*sizeof(char))) == NULL) {
|
||||
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, "YAP could not grow heap for writing to string");
|
||||
if (Stream[sno].u.mem_string.error_handler) {
|
||||
Yap_Error_Size = new_max_size*sizeof(char);
|
||||
longjmp(*(jmp_buf *)Stream[sno].u.mem_string.error_handler,1);
|
||||
} else {
|
||||
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, "YAP could not grow heap for writing to string");
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
#if HAVE_MEMMOVE
|
||||
@ -2022,6 +2027,7 @@ open_buf_read_stream(char *nbuf, Int nchars)
|
||||
st->u.mem_string.pos = 0;
|
||||
st->u.mem_string.buf = nbuf;
|
||||
st->u.mem_string.max_size = nchars;
|
||||
st->u.mem_string.error_handler = NULL;
|
||||
return sno;
|
||||
}
|
||||
|
||||
@ -3741,18 +3747,44 @@ format_has_tabs(const char *seq)
|
||||
}
|
||||
|
||||
static Int
|
||||
format(Term tail, Term args, int sno)
|
||||
format(volatile Term otail, volatile Term oargs, int sno)
|
||||
{
|
||||
char tmp1[256], tmp2[256];
|
||||
int ch;
|
||||
int column_boundary = 0;
|
||||
int column_boundary;
|
||||
Term mytargs[8], *targs;
|
||||
Int tnum, targ = 0;
|
||||
Int tnum, targ;
|
||||
char *fstr = NULL, *fptr;
|
||||
Term oargs = args;
|
||||
Term args;
|
||||
Term tail;
|
||||
int (* f_putc)(int, int);
|
||||
int has_tabs;
|
||||
jmp_buf format_botch;
|
||||
void *old_handler;
|
||||
volatile int old_pos;
|
||||
|
||||
if (Stream[sno].status & InMemory_Stream_f) {
|
||||
old_handler = Stream[sno].u.mem_string.error_handler;
|
||||
Stream[sno].u.mem_string.error_handler = (void *)&format_botch;
|
||||
old_pos = Stream[sno].u.mem_string.pos;
|
||||
/* set up an error handler */
|
||||
if (setjmp(format_botch)) {
|
||||
*H++ = oargs;
|
||||
*H++ = otail;
|
||||
if (!Yap_growheap(FALSE, Yap_Error_Size, NULL)) {
|
||||
Yap_Error(OUT_OF_HEAP_ERROR,otail,"format/2");
|
||||
return FALSE;
|
||||
}
|
||||
oargs = H[-2];
|
||||
otail = H[-1];
|
||||
Stream[sno].u.mem_string.pos = old_pos;
|
||||
H -= 2;
|
||||
}
|
||||
}
|
||||
args = oargs;
|
||||
tail = otail;
|
||||
targ = 0;
|
||||
column_boundary = 0;
|
||||
if (IsVarTerm(tail)) {
|
||||
Yap_Error(INSTANTIATION_ERROR,tail,"format/2");
|
||||
return(FALSE);
|
||||
@ -4052,6 +4084,9 @@ format(Term tail, Term args, int sno)
|
||||
if (IsAtomTerm(tail)) {
|
||||
fstr = NULL;
|
||||
}
|
||||
if (Stream[sno].status & InMemory_Stream_f) {
|
||||
old_handler = Stream[sno].u.mem_string.error_handler;
|
||||
}
|
||||
format_clean_up(format_base, fstr, targs);
|
||||
Yap_JumpToEnv(ball);
|
||||
}
|
||||
@ -4157,6 +4192,9 @@ format(Term tail, Term args, int sno)
|
||||
if (IsAtomTerm(tail)) {
|
||||
fstr = NULL;
|
||||
}
|
||||
if (Stream[sno].status & InMemory_Stream_f) {
|
||||
old_handler = Stream[sno].u.mem_string.error_handler;
|
||||
}
|
||||
format_clean_up(format_base, fstr, targs);
|
||||
return FALSE;
|
||||
}
|
||||
@ -4177,6 +4215,9 @@ format(Term tail, Term args, int sno)
|
||||
}
|
||||
if (tnum <= 8)
|
||||
targs = NULL;
|
||||
if (Stream[sno].status & InMemory_Stream_f) {
|
||||
old_handler = Stream[sno].u.mem_string.error_handler;
|
||||
}
|
||||
format_clean_up(format_base, fstr, targs);
|
||||
return (TRUE);
|
||||
}
|
||||
|
@ -37,12 +37,18 @@ typedef struct stream_desc
|
||||
struct {
|
||||
Atom name;
|
||||
Term user_name;
|
||||
#if defined(__MINGW32__) || _MSC_VER
|
||||
#define PLGETC_BUF_SIZE 4096
|
||||
char *buf, *ptr;
|
||||
int left;
|
||||
#endif
|
||||
YP_File file;
|
||||
} file;
|
||||
struct {
|
||||
char *buf; /* where the file is being read from/written to */
|
||||
Int max_size; /* maximum buffer size (may be changed dynamically) */
|
||||
Int pos;
|
||||
void *error_handler;
|
||||
} mem_string;
|
||||
struct {
|
||||
#if defined(__MINGW32__) || _MSC_VER
|
||||
|
@ -10,7 +10,7 @@
|
||||
* File: Yap.h.m4 *
|
||||
* mods: *
|
||||
* comments: main header file for YAP *
|
||||
* version: $Id: Yap.h.m4,v 1.61 2004-07-26 16:03:35 vsc Exp $ *
|
||||
* version: $Id: Yap.h.m4,v 1.62 2004-07-28 22:09:02 vsc Exp $ *
|
||||
*************************************************************************/
|
||||
|
||||
#include "config.h"
|
||||
@ -251,6 +251,7 @@ extern char Yap_Option[20];
|
||||
#if !IN_SECOND_QUADRANT
|
||||
#if __linux__ || __FreeBSD__ || __NetBSD__ || mips || __APPLE__
|
||||
#if defined(YAPOR) && defined(__alpha)
|
||||
|
||||
#define MMAP_ADDR 0x40000000
|
||||
#elif mips
|
||||
#define MMAP_ADDR 0x02000000
|
||||
@ -262,7 +263,7 @@ extern char Yap_Option[20];
|
||||
#elif __svr4__ || defined(__SVR4)
|
||||
#define MMAP_ADDR 0x02000000
|
||||
#elif defined(_WIN32)
|
||||
#define MMAP_ADDR 0x18000000L
|
||||
#define MMAP_ADDR 0x10040000L
|
||||
#elif defined(__CYGWIN__)
|
||||
#define MMAP_ADDR 0x30000000L
|
||||
#endif
|
||||
@ -272,7 +273,7 @@ extern char Yap_Option[20];
|
||||
#define HEAP_INIT_BASE 0L
|
||||
#define AtomBase NULL
|
||||
#else
|
||||
#if defined(MMAP_ADDR) && (USE_MMAP || USE_SHMAT || _WIN32) && !__simplescalar__
|
||||
#if defined(MMAP_ADDR) && (USE_MMAP || USE_SHMAT) && !__simplescalar__
|
||||
#define HEAP_INIT_BASE (MMAP_ADDR)
|
||||
#define AtomBase ((char *)MMAP_ADDR)
|
||||
#else
|
||||
|
Reference in New Issue
Block a user