From b331c4bed00739be8c3557cbd40b36e5cbfae849 Mon Sep 17 00:00:00 2001 From: Vitor Santos Costa Date: Wed, 31 Aug 2011 21:13:29 -0700 Subject: [PATCH] ClSize should be the block size in bytes, and not the amount of code. Check that for megaclauses. --- C/cdmgr.c | 6 ++++-- C/index.c | 8 +++++--- C/qlyr.c | 10 ++++++++-- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/C/cdmgr.c b/C/cdmgr.c index c750b9820..7a688d705 100644 --- a/C/cdmgr.c +++ b/C/cdmgr.c @@ -838,7 +838,9 @@ Yap_BuildMegaClause(PredEntry *ap) required = sz*ap->cs.p_code.NOfClauses+sizeof(MegaClause)+(UInt)NEXTOP((yamop *)NULL,l); #ifdef DEBUG total_megaclause += required; - total_released += ap->cs.p_code.NOfClauses*(sz+sizeof(StaticClause)); + cl = + ClauseCodeToStaticClause(ap->cs.p_code.FirstClause); + total_released += ap->cs.p_code.NOfClauses*cl->ClSize; nof_megaclauses++; #endif while (!(mcl = (MegaClause *)Yap_AllocCodeSpace(required))) { @@ -850,7 +852,7 @@ Yap_BuildMegaClause(PredEntry *ap) Yap_ClauseSpace += required; /* cool, it's our turn to do the conversion */ mcl->ClFlags = MegaMask | has_blobs; - mcl->ClSize = sz*ap->cs.p_code.NOfClauses; + mcl->ClSize = required; mcl->ClPred = ap; mcl->ClItemSize = sz; mcl->ClNext = NULL; diff --git a/C/index.c b/C/index.c index 56411192c..148902e5a 100644 --- a/C/index.c +++ b/C/index.c @@ -2671,7 +2671,8 @@ init_clauses(ClauseDef *cl, PredEntry *ap) { if (ap->PredFlags & MegaClausePredFlag) { MegaClause *mcl = ClauseCodeToMegaClause(ap->cs.p_code.FirstClause); - yamop *end = (yamop *)((char *)mcl->ClCode+mcl->ClSize); + UInt nclauses = mcl->ClPred->cs.p_code.NOfClauses; + yamop *end = (yamop *)((char *)mcl->ClCode+nclauses*mcl->ClItemSize); yamop *cd = mcl->ClCode; while (cd < end) { cl->Code = cl->CurrentCode = cd; @@ -2926,7 +2927,8 @@ install_clauses(ClauseDef *cls, PredEntry *ap, istack_entry *stack, yamop *beg, istack_entry *sp = stack; if (ap->PredFlags & MegaClausePredFlag) { MegaClause *mcl = ClauseCodeToMegaClause(beg); - yamop *end = (yamop *)((char *)mcl->ClCode+mcl->ClSize); + UInt nclauses = mcl->ClPred->cs.p_code.NOfClauses; + yamop *end = (yamop *)((char *)mcl->ClCode+nclauses*mcl->ClItemSize); yamop *cd = mcl->ClCode; if (stack[0].pos == 0) { @@ -3211,7 +3213,7 @@ count_clauses_left(yamop *cl, PredEntry *ap) return i; } else if (ap->PredFlags & MegaClausePredFlag) { MegaClause *mcl = ClauseCodeToMegaClause(ap->cs.p_code.FirstClause); - UInt ncls = mcl->ClSize/mcl->ClItemSize; + UInt ncls = mcl->ClPred->cs.p_code.NOfClauses; return (ncls-1)-((char *)cl-(char *)mcl->ClCode)/mcl->ClItemSize; } else { diff --git a/C/qlyr.c b/C/qlyr.c index c576a8ce5..4b9a7a7ab 100644 --- a/C/qlyr.c +++ b/C/qlyr.c @@ -828,10 +828,16 @@ read_clauses(IOSTREAM *stream, PredEntry *pp, UInt nclauses, UInt flags) { } LOCAL_HDiff = (char *)cl-base; read_bytes(stream, cl, size); - RestoreMegaClause(cl PASS_REGS); pp->cs.p_code.FirstClause = pp->cs.p_code.LastClause = cl->ClCode; + pp->PredFlags |= MegaClausePredFlag; + /* enter index mode */ + pp->OpcodeOfPred = INDEX_OPCODE; + pp->CodeOfPred = pp->cs.p_code.TrueCodeOfPred = (yamop *)(&(pp->OpcodeOfPred)); + /* This must be set for restoremegaclause */ + pp->cs.p_code.NOfClauses = nclauses; + RestoreMegaClause(cl PASS_REGS); } else if (pp->PredFlags & DynamicPredFlag) { UInt i; @@ -923,7 +929,7 @@ read_pred(IOSTREAM *stream, Term mod) { ap->src.IndxId = read_uint(stream); } else { ap->src.OwnerFile = (Atom)read_uint(stream); - if (ap->src.OwnerFile && !(flags & MultiFileFlag)) { + if (ap->src.OwnerFile) { ap->src.OwnerFile = AtomAdjust(ap->src.OwnerFile); } }