ClSize should be the block size in bytes, and not the amount of code. Check that for megaclauses.

This commit is contained in:
Vitor Santos Costa 2011-08-31 21:13:29 -07:00
parent 0c940b2dce
commit b331c4bed0
3 changed files with 17 additions and 7 deletions

View File

@ -838,7 +838,9 @@ Yap_BuildMegaClause(PredEntry *ap)
required = sz*ap->cs.p_code.NOfClauses+sizeof(MegaClause)+(UInt)NEXTOP((yamop *)NULL,l); required = sz*ap->cs.p_code.NOfClauses+sizeof(MegaClause)+(UInt)NEXTOP((yamop *)NULL,l);
#ifdef DEBUG #ifdef DEBUG
total_megaclause += required; 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++; nof_megaclauses++;
#endif #endif
while (!(mcl = (MegaClause *)Yap_AllocCodeSpace(required))) { while (!(mcl = (MegaClause *)Yap_AllocCodeSpace(required))) {
@ -850,7 +852,7 @@ Yap_BuildMegaClause(PredEntry *ap)
Yap_ClauseSpace += required; Yap_ClauseSpace += required;
/* cool, it's our turn to do the conversion */ /* cool, it's our turn to do the conversion */
mcl->ClFlags = MegaMask | has_blobs; mcl->ClFlags = MegaMask | has_blobs;
mcl->ClSize = sz*ap->cs.p_code.NOfClauses; mcl->ClSize = required;
mcl->ClPred = ap; mcl->ClPred = ap;
mcl->ClItemSize = sz; mcl->ClItemSize = sz;
mcl->ClNext = NULL; mcl->ClNext = NULL;

View File

@ -2671,7 +2671,8 @@ init_clauses(ClauseDef *cl, PredEntry *ap)
{ {
if (ap->PredFlags & MegaClausePredFlag) { if (ap->PredFlags & MegaClausePredFlag) {
MegaClause *mcl = ClauseCodeToMegaClause(ap->cs.p_code.FirstClause); 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; yamop *cd = mcl->ClCode;
while (cd < end) { while (cd < end) {
cl->Code = cl->CurrentCode = cd; cl->Code = cl->CurrentCode = cd;
@ -2926,7 +2927,8 @@ install_clauses(ClauseDef *cls, PredEntry *ap, istack_entry *stack, yamop *beg,
istack_entry *sp = stack; istack_entry *sp = stack;
if (ap->PredFlags & MegaClausePredFlag) { if (ap->PredFlags & MegaClausePredFlag) {
MegaClause *mcl = ClauseCodeToMegaClause(beg); 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; yamop *cd = mcl->ClCode;
if (stack[0].pos == 0) { if (stack[0].pos == 0) {
@ -3211,7 +3213,7 @@ count_clauses_left(yamop *cl, PredEntry *ap)
return i; return i;
} else if (ap->PredFlags & MegaClausePredFlag) { } else if (ap->PredFlags & MegaClausePredFlag) {
MegaClause *mcl = ClauseCodeToMegaClause(ap->cs.p_code.FirstClause); 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; return (ncls-1)-((char *)cl-(char *)mcl->ClCode)/mcl->ClItemSize;
} else { } else {

View File

@ -828,10 +828,16 @@ read_clauses(IOSTREAM *stream, PredEntry *pp, UInt nclauses, UInt flags) {
} }
LOCAL_HDiff = (char *)cl-base; LOCAL_HDiff = (char *)cl-base;
read_bytes(stream, cl, size); read_bytes(stream, cl, size);
RestoreMegaClause(cl PASS_REGS);
pp->cs.p_code.FirstClause = pp->cs.p_code.FirstClause =
pp->cs.p_code.LastClause = pp->cs.p_code.LastClause =
cl->ClCode; 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) { } else if (pp->PredFlags & DynamicPredFlag) {
UInt i; UInt i;
@ -923,7 +929,7 @@ read_pred(IOSTREAM *stream, Term mod) {
ap->src.IndxId = read_uint(stream); ap->src.IndxId = read_uint(stream);
} else { } else {
ap->src.OwnerFile = (Atom)read_uint(stream); ap->src.OwnerFile = (Atom)read_uint(stream);
if (ap->src.OwnerFile && !(flags & MultiFileFlag)) { if (ap->src.OwnerFile) {
ap->src.OwnerFile = AtomAdjust(ap->src.OwnerFile); ap->src.OwnerFile = AtomAdjust(ap->src.OwnerFile);
} }
} }