don't ever use memory that has been freed (that was done by LU).

generic fixes for WIN32 libraries


git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@1172 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
vsc 2004-11-04 18:22:36 +00:00
parent 20dcf89f9a
commit 6853d8eecd
15 changed files with 99 additions and 49 deletions

View File

@ -10,8 +10,11 @@
* *
* File: absmi.c *
* comments: Portable abstract machine interpreter *
* Last rev: $Date: 2004-10-26 20:15:36 $,$Author: vsc $ *
* Last rev: $Date: 2004-11-04 18:22:28 $,$Author: vsc $ *
* $Log: not supported by cvs2svn $
* Revision 1.150 2004/10/26 20:15:36 vsc
* More bug fixes for overflow handling
*
* Revision 1.149 2004/10/14 22:14:52 vsc
* don't use a cached version of ARG1 in choice-points
*
@ -1344,7 +1347,7 @@ Yap_absmi(int inp)
}
UNLOCK(lcl->ClLock);
}
Yap_ErLogUpdIndex(cl);
PREG = Yap_ErLogUpdIndex(cl, PREG);
} else {
UNLOCK(cl->ClLock);
}
@ -1364,7 +1367,7 @@ Yap_absmi(int inp)
TRAIL_CLREF(lcl);
}
}
Yap_ErLogUpdIndex(cl);
PREG = Yap_ErLogUpdIndex(cl, PREG);
}
}
#endif
@ -1875,7 +1878,7 @@ Yap_absmi(int inp)
/* at this point,
we are the only ones accessing the clause,
hence we don't need to have a lock it */
Yap_ErLogUpdIndex(cl);
Yap_ErLogUpdIndex(cl, NULL);
setregs();
}
} else {
@ -1925,7 +1928,7 @@ Yap_absmi(int inp)
saveregs();
if (flags & LogUpdMask) {
if (flags & IndexMask) {
Yap_ErLogUpdIndex(ClauseFlagsToLogUpdIndex(pt1));
Yap_ErLogUpdIndex(ClauseFlagsToLogUpdIndex(pt1), NULL);
} else {
Yap_ErLogUpdCl(ClauseFlagsToLogUpdClause(pt1));
}
@ -2014,7 +2017,7 @@ Yap_absmi(int inp)
we are the only ones accessing the clause,
hence we don't need to have a lock it */
saveregs();
Yap_ErLogUpdIndex(cl);
Yap_ErLogUpdIndex(cl, NULL);
setregs();
}
} else {

View File

@ -12,7 +12,7 @@
* Last rev: *
* mods: *
* comments: allocating space *
* version:$Id: alloc.c,v 1.63 2004-10-28 20:12:20 vsc Exp $ *
* version:$Id: alloc.c,v 1.64 2004-11-04 18:22:30 vsc Exp $ *
*************************************************************************/
#ifdef SCCS
static char SccsId[] = "%W% %G%";
@ -57,14 +57,14 @@ static char SccsId[] = "%W% %G%";
/************************************************************************/
/* Yap workspace management */
#if USE_SYSTEM_MALLOC||USE_DL_MALLOC
#if USE_DL_MALLOC
#define malloc Yap_dlmalloc
#define free Yap_dlfree
#define realloc Yap_dlrealloc
#endif
#if USE_SYSTEM_MALLOC||USE_DL_MALLOC
char *
Yap_AllocCodeSpace(unsigned int size)
{

View File

@ -11,8 +11,11 @@
* File: cdmgr.c *
* comments: Code manager *
* *
* Last rev: $Date: 2004-10-31 02:18:03 $,$Author: vsc $ *
* Last rev: $Date: 2004-11-04 18:22:31 $,$Author: vsc $ *
* $Log: not supported by cvs2svn $
* Revision 1.140 2004/10/31 02:18:03 vsc
* fix bug in handling Yap heap overflow while adding new clause.
*
* 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
@ -938,10 +941,34 @@ Yap_kill_iblock(ClauseUnion *blk, ClauseUnion *parent_blk, PredEntry *ap)
This predicate is supposed to be called with a
lock on the current predicate
*/
void
Yap_ErLogUpdIndex(LogUpdIndex *clau)
yamop *
Yap_ErLogUpdIndex(LogUpdIndex *clau, yamop *ipc)
{
LogUpdIndex *c = clau;
yamop *codep;
if (ipc) {
op_numbers op = Yap_op_from_opcode(ipc->opc);
codep = TrustLUCode;
if (op == _trust) {
codep->opc = ipc->opc;
codep->u.ld.s = ipc->u.ld.s;
codep->u.ld.p = ipc->u.ld.p;
codep->u.ld.d = ipc->u.ld.d;
#ifdef YAPOR
codep->u.ld.or_arg = ipc->u.ld.or_arg;
#endif /* YAPOR */
#ifdef TABLING
codep->u.ld.te = ipc->u.ld.te;
#endif /* TABLING */
} else {
Yap_Error(SYSTEM_ERROR,TermNil,"Expected To Find trust, found %d", op);
codep = ipc;
}
} else {
codep = NULL;
}
if (clau->ClFlags & ErasedMask) {
if (!c->ClRefCount) {
if (c->ClFlags & SwitchRootMask) {
@ -953,7 +980,7 @@ Yap_ErLogUpdIndex(LogUpdIndex *clau)
}
}
/* otherwise, nothing I can do, I have been erased already */
return;
return codep;
}
if (c->ClFlags & SwitchRootMask) {
kill_first_log_iblock(clau, NULL, c->u.pred);
@ -973,7 +1000,8 @@ Yap_ErLogUpdIndex(LogUpdIndex *clau)
clau->ClRefCount--;
UNLOCK(clau->u.ParentIndex->ClLock);
#endif
}
}
return codep;
}
/* Routine used when wanting to remove the indexation */

View File

@ -6,6 +6,8 @@
#include "alloc.h"
#include "dlmalloc.h"
#if USE_DL_MALLOC
/*
This is a version (aka dlmalloc) of malloc/free/realloc written by
Doug Lea and released to the public domain. Use, modify, and
@ -777,7 +779,7 @@ static Void_t** iALLOc();
in malloc. In which case, please report it!)
*/
#if ! DEBUG
#if ! DEBUG_DLMALLOC
#define check_chunk(P)
#define check_free_chunk(P)
@ -2487,7 +2489,7 @@ Void_t* cALLOc(n_elements, elem_size) size_t n_elements; size_t elem_size;
assert(nclears >= 3);
if (nclears > 9)
bzero(d, clearsize);
memset(d, 0, clearsize);
else {
*(d+0) = 0;
@ -2633,7 +2635,7 @@ static Void_t** iALLOc(n_elements, sizes, opts, chunks) size_t n_elements; size_
remainder_size = chunksize(p);
if (opts & 0x2) { /* optionally clear the elements */
bzero(mem, remainder_size - SIZE_SZ - array_size);
memset(mem, 0, remainder_size - SIZE_SZ - array_size);
}
/* If not provided, allocate the pointer array as final part of chunk */
@ -2662,7 +2664,7 @@ static Void_t** iALLOc(n_elements, sizes, opts, chunks) size_t n_elements; size_
}
}
#if DEBUG
#if DEBUG_DLMALLOC
if (marray != chunks) {
/* final element must have exactly exhausted chunk */
if (element_size != 0)
@ -3170,7 +3172,9 @@ Yap_initdlmalloc(void)
{
HeapTop = (ADDR)ALIGN_SIZE(HeapTop,16);
Yap_av = (struct malloc_state *)HeapTop;
bzero((void *)Yap_av, sizeof(struct malloc_state));
memset((void *)Yap_av, 0, sizeof(struct malloc_state));
HeapTop += sizeof(struct malloc_state);
HeapMax = HeapUsed = HeapTop-Yap_HeapBase;
}
#endif /* USE_DL_MALLOC */

View File

@ -357,23 +357,19 @@ Yap_Error(yap_error_number type, Term where, char *format,...)
exit(1);
}
/* must do this here */
if (type == FATAL_ERROR
#if !USE_SYSTEM_MALLOC
|| Yap_HeapBase == NULL
#endif
) {
va_start (ap, format);
/* now build the error string */
if (type == FATAL_ERROR || Yap_HeapBase == NULL) {
if (format != NULL) {
va_start (ap, format);
/* now build the error string */
#if HAVE_VSNPRINTF
(void) vsnprintf(tmpbuf, YAP_BUF_SIZE, format, ap);
#else
(void) vsprintf(tmpbuf, format, ap);
#endif
va_end (ap);
} else {
tmpbuf[0] = '\0';
}
va_end (ap);
fprintf(stderr,"%% Fatal YAP Error: %s exiting....\n",tmpbuf);
error_exit_yap (1);
}

View File

@ -35,9 +35,11 @@ static char SccsId[] = "%W% %G%";
/* in a single gc */
static unsigned long int total_marked; /* number of heap objects marked */
#if DEBUG
#ifdef COROUTINING
static unsigned long int total_smarked;
#endif
#endif
STATIC_PROTO(Int p_inform_gc, (void));
STATIC_PROTO(Int p_gc, (void));
@ -458,7 +460,7 @@ pop_registers(Int num_regs, yamop *nextop)
}
}
#ifdef DEBUG
#if DEBUG && COUNT_CELLS_MARKED
static int
count_cells_marked(void)
{
@ -2200,7 +2202,7 @@ sweep_trail(choiceptr gc_B, tr_fr_ptr old_TR)
if (erase) {
/* at this point,
no one is accessing the clause */
Yap_ErLogUpdIndex(indx);
Yap_ErLogUpdIndex(indx, NULL);
}
} else {
LogUpdClause *cl = ClauseFlagsToLogUpdClause(pt0);
@ -3421,7 +3423,7 @@ do_gc(Int predarity, CELL *current_env, yamop *nextop)
}
if (!bp)
return 0;
bzero((void *)bp, alloc_sz);
memset((void *)bp, 0, alloc_sz);
}
#endif /* GC_NO_TAGS */
#ifdef HYBRID_SCHEME
@ -3429,7 +3431,7 @@ do_gc(Int predarity, CELL *current_env, yamop *nextop)
#endif
/* get the number of active registers */
YAPEnterCriticalSection();
Yap_old_TR = old_TR = TR;
Yap_old_TR = (struct trail_frame *)(old_TR = TR);
push_registers(predarity, nextop);
marking_phase(old_TR, current_env, nextop, max);
m_time = Yap_cputime();

View File

@ -11,8 +11,11 @@
* File: index.c *
* comments: Indexing a Prolog predicate *
* *
* Last rev: $Date: 2004-10-27 15:56:33 $,$Author: vsc $ *
* Last rev: $Date: 2004-11-04 18:22:32 $,$Author: vsc $ *
* $Log: not supported by cvs2svn $
* Revision 1.104 2004/10/27 15:56:33 vsc
* bug fixes on memory overflows and on clauses :- fail being ignored by clause.
*
* Revision 1.103 2004/10/22 16:53:19 vsc
* bug fixes
*
@ -7574,6 +7577,7 @@ Yap_FollowIndexingCode(PredEntry *ap, yamop *ipc, Term Terms[3], yamop *ap_pc, y
{
LogUpdIndex *cl = (LogUpdIndex *)ipc->u.l.l;
/* check if we are the ones using this code */
ipc = NEXTOP(ipc,l);
#if defined(YAPOR) || defined(THREADS)
LOCK(cl->ClLock);
DEC_CLREF_COUNT(cl);
@ -7585,7 +7589,7 @@ Yap_FollowIndexingCode(PredEntry *ap, yamop *ipc, Term Terms[3], yamop *ap_pc, y
/* I am the last one using this clause, hence I don't need a lock
to dispose of it
*/
Yap_ErLogUpdIndex(cl);
ipc = Yap_ErLogUpdIndex(cl, ipc);
} else {
UNLOCK(cl->ClLock);
}
@ -7597,7 +7601,7 @@ Yap_FollowIndexingCode(PredEntry *ap, yamop *ipc, Term Terms[3], yamop *ap_pc, y
TR = --(B->cp_tr);
/* next, recover space for the indexing code if it was erased */
if (cl->ClFlags & ErasedMask) {
yamop *next = NEXTOP(ipc,l)->u.ld.d;
yamop *next = ipc->u.ld.d;
if (next != FAILCODE) {
LogUpdClause *lcl = ClauseCodeToLogUpdClause(next);
/* make sure we don't erase the clause we are jumping too */
@ -7606,12 +7610,11 @@ Yap_FollowIndexingCode(PredEntry *ap, yamop *ipc, Term Terms[3], yamop *ap_pc, y
TRAIL_CLREF(lcl);
}
}
Yap_ErLogUpdIndex(cl);
ipc = Yap_ErLogUpdIndex(cl, ipc);
}
}
#endif
}
ipc = NEXTOP(ipc,l);
break;
case _stale_lu_index:
#if defined(YAPOR) || defined(THREADS)

View File

@ -2997,8 +2997,9 @@ do_read(int inp_stream)
if (Yap_ErrorMessage || (t = Yap_Parse()) == 0) {
if (Yap_ErrorMessage && (strcmp(Yap_ErrorMessage,"Stack Overflow") == 0)) {
/* ignore term we just built */
H = old_H;
tr_fr_ptr old_TR = TR;
H = old_H;
TR = (tr_fr_ptr)ScannerStack;
if (Yap_growstack_in_parser(&old_TR, &tokstart, &Yap_VarTable)) {
ScannerStack = (char *)TR;
@ -3758,7 +3759,7 @@ format(volatile Term otail, volatile Term oargs, int sno)
int (* f_putc)(int, int);
int has_tabs;
jmp_buf format_botch;
volatile void *old_handler = NULL;
volatile void *old_handler;
volatile int old_pos;
if (Stream[sno].status & InMemory_Stream_f) {
@ -3778,6 +3779,8 @@ format(volatile Term otail, volatile Term oargs, int sno)
Stream[sno].u.mem_string.pos = old_pos;
H -= 2;
}
} else {
old_handler = NULL;
}
args = oargs;
tail = otail;

View File

@ -1388,7 +1388,7 @@ UnmarkTrEntries(void)
} else {
if (flags & LogUpdMask) {
if (flags & IndexMask) {
Yap_ErLogUpdIndex(ClauseFlagsToLogUpdIndex(ent));
Yap_ErLogUpdIndex(ClauseFlagsToLogUpdIndex(ent), NULL);
} else {
Yap_ErLogUpdCl(ClauseFlagsToLogUpdClause(ent));
}

View File

@ -10,7 +10,7 @@
* File: Heap.h *
* mods: *
* comments: Heap Init Structure *
* version: $Id: Heap.h,v 1.70 2004-10-28 20:12:22 vsc Exp $ *
* version: $Id: Heap.h,v 1.71 2004-11-04 18:22:34 vsc Exp $ *
*************************************************************************/
/* information that can be stored in Code Space */
@ -66,6 +66,7 @@ typedef struct worker_local_struct {
Int tot_gc_recovered; /* number of heap objects in all garbage collections */
jmp_buf gc_restore; /* where to jump if garbage collection crashes */
struct trail_frame *old_TR;
yamop trust_lu_code[3];
} worker_local;
#ifdef THREADS
@ -683,6 +684,7 @@ struct various_codes *heap_regs;
#define TotGcRecovered heap_regs->wl[worker_id].tot_gc_recovered
#define Yap_gc_restore heap_regs->wl[worker_id].gc_restore
#define Yap_old_TR heap_regs->wl[worker_id].old_TR
#define TrustLUCode heap_regs->wl[worker_id].trust_lu_code
#else
#define ActiveSignals heap_regs->wl.active_signals
#define DelayedTrace heap_regs->wl.delayed_trace
@ -700,6 +702,7 @@ struct various_codes *heap_regs;
#define TotGcRecovered heap_regs->wl.tot_gc_recovered
#define Yap_gc_restore heap_regs->wl.gc_restore
#define Yap_old_TR heap_regs->wl.old_TR
#define TrustLUCode heap_regs->wl.trust_lu_code
#endif
#define profiling heap_regs->compiler_profiling
#define call_counting heap_regs->compiler_call_counting
@ -760,8 +763,6 @@ struct various_codes *heap_regs;
#define ReadlinePos heap_regs->readline_pos
#endif
#define USE_DL_MALLOC 1
ADDR STD_PROTO(Yap_ExpandPreAllocCodeSpace, (UInt));
#define Yap_ReleasePreAllocCodeSpace(x)
#if USE_SYSTEM_MALLOC||USE_DL_MALLOC

View File

@ -195,7 +195,7 @@ ClauseUnion *STD_PROTO(Yap_find_owner_index,(yamop *, PredEntry *));
/* dbase.c */
void STD_PROTO(Yap_ErCl,(DynamicClause *));
void STD_PROTO(Yap_ErLogUpdCl,(LogUpdClause *));
void STD_PROTO(Yap_ErLogUpdIndex,(LogUpdIndex *));
yamop *STD_PROTO(Yap_ErLogUpdIndex,(LogUpdIndex *, yamop *));
Int STD_PROTO(Yap_Recordz,(Atom, Term));
/* exec.c */

View File

@ -1,3 +1,6 @@
#if USE_DL_MALLOC
/* YAP only stuff */
void STD_PROTO(Yap_initdlmalloc,(void));
@ -1167,3 +1170,4 @@ nextchunk-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
#endif /* USE_DL_MALLOC */

View File

@ -176,7 +176,9 @@ static void PROTO(freeset,(struct parse *p, cset *cs));
static int PROTO(freezeset,(struct parse *p, cset *cs));
static int PROTO(firstch,(struct parse *p, cset *cs));
static int PROTO(nch,(struct parse *p, cset *cs));
#if 0
static void PROTO(mcadd,(struct parse *p, cset *cs, char *cp));
#endif
#if used
static void PROTO(mcsub,(cset *cs, char *cp));
static int PROTO(mcin,(cset *cs, char *cp));
@ -361,8 +363,8 @@ register struct parse *p;
int stop; /* character this ERE should end at */
{
register char c;
register sopno prevback;
register sopno prevfwd;
register sopno prevback = 0;
register sopno prevfwd = 0;
register sopno conc;
register int first = 1; /* is this the first alternative? */
@ -933,7 +935,7 @@ register cset *cs;
break;
case CBLANK:
for (c = CHAR_MIN; c <= CHAR_MAX; c++)
if (isblank((uch)c))
if (((uch)c) == ' ' || ((uch)c) == '\t')
CHadd(cs, c);
break;
case CCNTRL:
@ -1386,6 +1388,7 @@ register cset *cs;
return(n);
}
#if 0
/*
- mcadd - add a collating element to a cset
== static void mcadd(register struct parse *p, register cset *cs, \
@ -1412,6 +1415,7 @@ register char *cp;
(void) strcpy(cs->multis + oldend - 1, cp);
cs->multis[cs->smultis - 1] = '\0';
}
#endif
#if used
/*
@ -1741,8 +1745,8 @@ struct parse *p;
register struct re_guts *g;
{
register sop *scan;
sop *start;
register sop *newstart;
sop *start = NULL;
register sop *newstart = NULL;
register sopno newlen;
register sop s;
register char *cp;

View File

@ -69,7 +69,9 @@ static char sccsid[] = "@(#)regexec.c 8.3 (Berkeley) 3/20/94";
#include "utils.h"
#include "regex2.h"
#if used
static int nope = 0; /* for use in asserts; shuts lint up */
#endif
/* macros for manipulating states, small version */
#define states long

View File

@ -239,7 +239,7 @@ prolog_load_context(term_position, Position) :-
recorded('$module','$module'(F1,_,P),_),
recorded('$loaded','$loaded'(F1,_,Age),R),
'$same_file'(F1,F), !,
'$loaded_file_age'(F, R).
'$loaded_file_age'(F, R, Age).
'$loaded_file'(F,M,F1) :-
recorded('$loaded','$loaded'(F1,M,Age),R),
'$same_file'(F1,F), !,