Skip to content

Commit

Permalink
Add workaround for TAG unable to store 8-byte pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
beholdnec committed Jun 17, 2022
1 parent 956ddae commit aa2a3dd
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 37 deletions.
6 changes: 5 additions & 1 deletion INC/TAGMAN.H
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
#ifndef TAGM_H
#define TAGM_H

PCRF RefToPcrf(ulong ref);
ulong PcrfToRef(PCRF pcrf);

const long ksidInvalid = -1; // negative SIDs imply an invalid TAG
const long sidNil = 0;
const long ksidUseCrf = 0; // chunk is in ptag->pcrf
Expand All @@ -54,7 +57,8 @@ struct TAG
#endif // DEBUG

long sid; // Source ID (or ksidUseCrf)
PCRF pcrf; // File to look in for this chunk if sid is ksidUseCrf
//PCRF pcrf; // File to look in for this chunk if sid is ksidUseCrf
ulong pcrfRef;
CTG ctg; // CTG of chunk
CNO cno; // CNO of chunk
};
Expand Down
4 changes: 2 additions & 2 deletions SRC/ENGINE/ACTREDIT.CPP
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@ bool ACTR::FPaste(long nfrm, SCEN *pscen)
{
return fFalse;
}
if (pcrf != _tagTmpl.pcrf)
if (pcrf != RefToPcrf(_tagTmpl.pcrfRef))
{
// Need to save this actor's tagTmpl in this movie because it came from another movie

Expand Down Expand Up @@ -839,7 +839,7 @@ bool ACTR::FPaste(long nfrm, SCEN *pscen)
if (aevsnd.tag.sid != ksidUseCrf)
continue;
// Save tag (this may be a new movie)
if (!aevsnd.tag.pcrf->Pcfl()->FFind(aevsnd.tag.ctg, aevsnd.tag.cno))
if (!RefToPcrf(aevsnd.tag.pcrfRef)->Pcfl()->FFind(aevsnd.tag.ctg, aevsnd.tag.cno))
{
PushErc(ercSocNoSndOnPaste);
_RemoveAev(iaev);
Expand Down
2 changes: 1 addition & 1 deletion SRC/ENGINE/MOVIE.CPP
Original file line number Diff line number Diff line change
Expand Up @@ -6135,7 +6135,7 @@ void MVU::SetTagTool(PTAG ptag)
// Make sure the new tag has been opened, if it's a "ksidUseCrf" tag
if (ptag->sid == ksidUseCrf)
{
AssertPo(ptag->pcrf, 0);
AssertPo(RefToPcrf(ptag->pcrfRef), 0);
}
#endif

Expand Down
6 changes: 3 additions & 3 deletions SRC/ENGINE/SCENE.CPP
Original file line number Diff line number Diff line change
Expand Up @@ -7201,7 +7201,7 @@ void ReleasePpsse(PSSE *ppsse)

for (itagc = 0; itagc < psse->ctagc; itagc++)
{
if (psse->Ptag(itagc)->pcrf != pvNil)
if (RefToPcrf(psse->Ptag(itagc)->pcrfRef) != pvNil)
TAGM::CloseTag(psse->Ptag(itagc));
}

Expand Down Expand Up @@ -7234,14 +7234,14 @@ PSSE SSE::PsseDupFromGg(PGG pgg, long iv, bool fDupTags)
{
if (psse->Ptag(itagc)->sid == ksidUseCrf)
{
AssertPo(psse->Ptag(itagc)->pcrf, 0);
AssertPo(RefToPcrf(psse->Ptag(itagc)->pcrfRef), 0);
TAGM::DupTag(psse->Ptag(itagc));
}
}
else
{
// Clear the crf on read, since the caller isn't having us dupe the tag
psse->Ptag(itagc)->pcrf = pvNil;
psse->Ptag(itagc)->pcrfRef = pvNil;
}
}

Expand Down
79 changes: 59 additions & 20 deletions SRC/ENGINE/TAGMAN.CPP
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,48 @@
short names.
***************************************************************************/
#include <map>
#include "soc.h"
ASSERTNAME

// FIXME: Prevent leaks, prevent g_refIndex overflow
ulong g_refIndex = 1;
std::map<ulong, PCRF> g_refToPcrfMap;
std::map<PCRF, ulong> g_pcrfToRefMap;

PCRF RefToPcrf(ulong ref)
{
return g_refToPcrfMap[ref];
}

ulong PcrfToRef(PCRF pcrf)
{
if (g_pcrfToRefMap.find(pcrf) != g_pcrfToRefMap.end())
return g_pcrfToRefMap[pcrf];

ulong ref = g_refIndex;
g_pcrfToRefMap[pcrf] = ref;
g_refToPcrfMap[ref] = pcrf;
++g_refIndex;
return ref;
}

void ReleasePpo_PcrfRef(ulong* pRef)
{
if (*pRef != pvNil)
{
// TODO: release pcrf
*pRef = pvNil;
}
#if 0
if (*(ppo) != pvNil)
{
(*(ppo))->Release();
*(ppo) = pvNil;
}
#endif
}

RTCLASS(TAGM)

const BOM kbomSid = 0xc0000000;
Expand Down Expand Up @@ -779,14 +818,14 @@ bool TAGM::FBuildChildTag(PTAG ptagPar, CHID chid, CTG ctgChild, PTAG ptagChild)

if (ksidUseCrf == ptagPar->sid)
{
AssertPo(ptagPar->pcrf, 0);
if (!ptagPar->pcrf->Pcfl()->FGetKidChidCtg(ptagPar->ctg, ptagPar->cno, chid, ctgChild, &kid))
AssertPo(RefToPcrf(ptagPar->pcrfRef), 0);
if (!RefToPcrf(ptagPar->pcrfRef)->Pcfl()->FGetKidChidCtg(ptagPar->ctg, ptagPar->cno, chid, ctgChild, &kid))
{
return fFalse; // child chunk not found
}
ptagChild->sid = ksidUseCrf;
ptagChild->pcrf = ptagPar->pcrf;
ptagPar->pcrf->AddRef();
ptagChild->pcrfRef = ptagPar->pcrfRef;
RefToPcrf(ptagPar->pcrfRef)->AddRef();
ptagChild->ctg = kid.cki.ctg;
ptagChild->cno = kid.cki.cno;
return fTrue;
Expand Down Expand Up @@ -890,8 +929,8 @@ PBACO TAGM::PbacoFetch(PTAG ptag, PFNRPO pfnrpo, bool fUseCD)
{
// Tag knows pcrf, so just read from there. Nothing we can do if
// it's not there.
AssertPo(ptag->pcrf, 0);
return ptag->pcrf->PbacoFetch(ptag->ctg, ptag->cno, pfnrpo);
AssertPo(RefToPcrf(ptag->pcrfRef), 0);
return RefToPcrf(ptag->pcrfRef)->PbacoFetch(ptag->ctg, ptag->cno, pfnrpo);
}

// fTrue parameter ensures that _PcrmSourceGet won't hit the CD
Expand Down Expand Up @@ -990,12 +1029,12 @@ bool TAGM::FOpenTag(PTAG ptag, PCRF pcrfDest, PCFL pcflSrc)
{
if (!pcflSrc->FCopy(ptag->ctg, ptag->cno, pcrfDest->Pcfl(), &cnoDest))
{
ptag->pcrf = pvNil;
ptag->pcrfRef = pvNil;
return fFalse; // copy failed
}
ptag->cno = cnoDest;
}
ptag->pcrf = pcrfDest;
ptag->pcrfRef = PcrfToRef(pcrfDest);
pcrfDest->AddRef();
return fTrue;
}
Expand All @@ -1015,18 +1054,18 @@ bool TAGM::FSaveTag(PTAG ptag, PCRF pcrf, bool fRedirect)
if (ptag->sid != ksidUseCrf)
return fTrue;

AssertPo(ptag->pcrf, 0);
AssertPo(RefToPcrf(ptag->pcrfRef), 0);

if (!ptag->pcrf->Pcfl()->FCopy(ptag->ctg, ptag->cno, pcrf->Pcfl(), &cnoDest))
if (!RefToPcrf(ptag->pcrfRef)->Pcfl()->FCopy(ptag->ctg, ptag->cno, pcrf->Pcfl(), &cnoDest))
{
return fFalse; // copy failed
}

if (fRedirect)
{
pcrf->AddRef();
ReleasePpo(&ptag->pcrf);
ptag->pcrf = pcrf;
ReleasePpo_PcrfRef(&ptag->pcrfRef);
ptag->pcrfRef = PcrfToRef(pcrf);
ptag->cno = cnoDest;
}

Expand All @@ -1044,8 +1083,8 @@ void TAGM::DupTag(PTAG ptag)

if (ptag->sid == ksidUseCrf)
{
AssertPo(ptag->pcrf, 0);
ptag->pcrf->AddRef();
AssertPo(RefToPcrf(ptag->pcrfRef), 0);
RefToPcrf(ptag->pcrfRef)->AddRef();
}
}

Expand All @@ -1061,8 +1100,8 @@ void TAGM::CloseTag(PTAG ptag)

if (ptag->sid == ksidUseCrf)
{
AssertPo(ptag->pcrf, 0);
ReleasePpo(&ptag->pcrf);
AssertPo(RefToPcrf(ptag->pcrfRef), 0);
ReleasePpo_PcrfRef(&ptag->pcrfRef);
}
}

Expand Down Expand Up @@ -1091,9 +1130,9 @@ ulong TAGM::FcmpCompareTags(PTAG ptag1, PTAG ptag2)
// If both sids are ksidUseCrf, compare CRFs
if (ptag1->sid == ksidUseCrf) // implies ptag2->sid == ksidUseCrf
{
if (ptag1->pcrf < ptag2->pcrf)
if (ptag1->pcrfRef < ptag2->pcrfRef)
return fcmpLt;
if (ptag1->pcrf > ptag2->pcrf)
if (ptag1->pcrfRef > ptag2->pcrfRef)
return fcmpGt;
}
return fcmpEq;
Expand Down Expand Up @@ -1151,8 +1190,8 @@ void TAG::MarkMem(void)
{
if (sid == ksidUseCrf)
{
AssertPo(pcrf, 0);
MarkMemObj(pcrf);
AssertPo(RefToPcrf(pcrfRef), 0);
MarkMemObj(RefToPcrf(pcrfRef));
}
}
#endif // DEBUG
10 changes: 5 additions & 5 deletions SRC/STUDIO/BROWSER.CPP
Original file line number Diff line number Diff line change
Expand Up @@ -1964,7 +1964,7 @@ bool BRWN::FCmdOk(PCMD pcmd)
PMVU pmvu;
pmvu = (PMVU)(_pstdio->Pmvie()->PddgGet(0));
tag.sid = ksidInvalid;
tag.pcrf = pvNil;
tag.pcrfRef = pvNil;
pmvu->SetTagTool(&tag); // No need to close tag with ksidInvalid
}

Expand Down Expand Up @@ -2057,7 +2057,7 @@ bool BRWM::_FUpdateLists(void)
if (!pcfl->FGetCkiCtg(kctgMsnd, icki, &cki))
goto LNext;
tag.sid = ksidUseCrf; // Non-CD-loaded content
tag.pcrf = _pcrf;
tag.pcrfRef = PcrfToRef(_pcrf);
tag.ctg = kctgMsnd;
tag.cno = cki.cno;

Expand Down Expand Up @@ -2141,7 +2141,7 @@ bool BRWM::_FAddThd(STN *pstn, CKI *pcki)
;

thd.tag.sid = ksidUseCrf;
thd.tag.pcrf = _pcrf;
thd.tag.pcrfRef = PcrfToRef(_pcrf);
thd.tag.ctg = pcki->ctg;
thd.tag.cno = pcki->cno;
thd.cno = cnoNil; // unused
Expand Down Expand Up @@ -2175,7 +2175,7 @@ void BRWM::_ProcessSelection(void)
_GetThumFromIthum(_ithumSelect, &thumSelect, &sid);

tag.sid = sid;
tag.pcrf = (ksidUseCrf == sid) ? _pcrf : pvNil;
tag.pcrfRef = (ksidUseCrf == sid) ? PcrfToRef(_pcrf) : pvNil;
tag.ctg = kctgMsnd;
tag.cno = (CNO)thumSelect;

Expand Down Expand Up @@ -2367,7 +2367,7 @@ bool BRWM::FCmdDel(PCMD pcmd)
// Delete the midi or wave child chunk from the msnd
// Invalidate the sound
tag.sid = ksidUseCrf; // Non-CD-loaded content
tag.pcrf = _pcrf;
tag.pcrfRef = PcrfToRef(_pcrf);
tag.ctg = kctgMsnd;
_GetThumFromIthum(_ithumSelect, &tag.cno, &sid);

Expand Down
4 changes: 2 additions & 2 deletions SRC/STUDIO/ESL.CPP
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ bool ESLT::FCmdSetFont(PCMD pcmd)
TAG tagTdfNew;

tagTdfNew.sid = pcmd->rglw[1];
tagTdfNew.pcrf = pvNil;
tagTdfNew.pcrfRef = pvNil;
tagTdfNew.ctg = kctgTdf;
tagTdfNew.cno = pcmd->rglw[0];

Expand Down Expand Up @@ -530,7 +530,7 @@ bool ESLT::FCmdSetColor(PCMD pcmd)
TAG tagTdfNew;

tagTdfNew.sid = pcmd->rglw[1];
tagTdfNew.pcrf = pvNil;
tagTdfNew.pcrfRef = pvNil;
tagTdfNew.ctg = kctgMtrl;
tagTdfNew.cno = pcmd->rglw[0];

Expand Down
6 changes: 3 additions & 3 deletions SRC/STUDIO/STDIOBRW.CPP
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ void BRWB::_ApplySelection(long thumSelect, long sid)
PMVU pmvu;

tag.sid = sid;
tag.pcrf = pvNil;
tag.pcrfRef = pvNil;
tag.ctg = kctgBkgd;
tag.cno = (CNO)thumSelect;

Expand Down Expand Up @@ -472,7 +472,7 @@ void BRWP::_ApplySelection(long thumSelect, long sid)

AssertPo(pmvu, 0);
tag.sid = sid;
tag.pcrf = pvNil;
tag.pcrfRef = pvNil;
tag.ctg = kctgTmpl;
tag.cno = (CNO)thumSelect;

Expand Down Expand Up @@ -550,7 +550,7 @@ void BRWM::_ApplySelection(long thumSelect, long sid)
tag.cno = (CNO)thumSelect;
tag.sid = sid;
if (ksidUseCrf != sid)
tag.pcrf = pvNil;
tag.pcrfRef = pvNil;
else
{
if (!_pstdio->Pmvie()->FEnsureAutosave(&_pcrf))
Expand Down

0 comments on commit aa2a3dd

Please sign in to comment.