From aa2a3ddffc8dfd2038bc058d5675d99c127e4789 Mon Sep 17 00:00:00 2001 From: "N.E.C" Date: Thu, 16 Jun 2022 23:18:22 -0700 Subject: [PATCH] Add workaround for TAG unable to store 8-byte pointer --- INC/TAGMAN.H | 6 +++- SRC/ENGINE/ACTREDIT.CPP | 4 +-- SRC/ENGINE/MOVIE.CPP | 2 +- SRC/ENGINE/SCENE.CPP | 6 ++-- SRC/ENGINE/TAGMAN.CPP | 79 ++++++++++++++++++++++++++++++----------- SRC/STUDIO/BROWSER.CPP | 10 +++--- SRC/STUDIO/ESL.CPP | 4 +-- SRC/STUDIO/STDIOBRW.CPP | 6 ++-- 8 files changed, 80 insertions(+), 37 deletions(-) diff --git a/INC/TAGMAN.H b/INC/TAGMAN.H index 30045c68..b629e93d 100644 --- a/INC/TAGMAN.H +++ b/INC/TAGMAN.H @@ -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 @@ -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 }; diff --git a/SRC/ENGINE/ACTREDIT.CPP b/SRC/ENGINE/ACTREDIT.CPP index 7dfd3b7f..0034b81e 100644 --- a/SRC/ENGINE/ACTREDIT.CPP +++ b/SRC/ENGINE/ACTREDIT.CPP @@ -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 @@ -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); diff --git a/SRC/ENGINE/MOVIE.CPP b/SRC/ENGINE/MOVIE.CPP index f71967f6..6b9cb86f 100644 --- a/SRC/ENGINE/MOVIE.CPP +++ b/SRC/ENGINE/MOVIE.CPP @@ -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 diff --git a/SRC/ENGINE/SCENE.CPP b/SRC/ENGINE/SCENE.CPP index 95dc1407..6adc45e0 100644 --- a/SRC/ENGINE/SCENE.CPP +++ b/SRC/ENGINE/SCENE.CPP @@ -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)); } @@ -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; } } diff --git a/SRC/ENGINE/TAGMAN.CPP b/SRC/ENGINE/TAGMAN.CPP index b997ec77..138d5850 100644 --- a/SRC/ENGINE/TAGMAN.CPP +++ b/SRC/ENGINE/TAGMAN.CPP @@ -38,9 +38,48 @@ short names. ***************************************************************************/ +#include #include "soc.h" ASSERTNAME +// FIXME: Prevent leaks, prevent g_refIndex overflow +ulong g_refIndex = 1; +std::map g_refToPcrfMap; +std::map 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; @@ -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; @@ -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 @@ -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; } @@ -1015,9 +1054,9 @@ 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 } @@ -1025,8 +1064,8 @@ bool TAGM::FSaveTag(PTAG ptag, PCRF pcrf, bool fRedirect) if (fRedirect) { pcrf->AddRef(); - ReleasePpo(&ptag->pcrf); - ptag->pcrf = pcrf; + ReleasePpo_PcrfRef(&ptag->pcrfRef); + ptag->pcrfRef = PcrfToRef(pcrf); ptag->cno = cnoDest; } @@ -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(); } } @@ -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); } } @@ -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; @@ -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 diff --git a/SRC/STUDIO/BROWSER.CPP b/SRC/STUDIO/BROWSER.CPP index 3c9e6ee3..3b6f0de4 100644 --- a/SRC/STUDIO/BROWSER.CPP +++ b/SRC/STUDIO/BROWSER.CPP @@ -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 } @@ -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; @@ -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 @@ -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; @@ -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); diff --git a/SRC/STUDIO/ESL.CPP b/SRC/STUDIO/ESL.CPP index 27fd89d8..506ef07b 100644 --- a/SRC/STUDIO/ESL.CPP +++ b/SRC/STUDIO/ESL.CPP @@ -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]; @@ -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]; diff --git a/SRC/STUDIO/STDIOBRW.CPP b/SRC/STUDIO/STDIOBRW.CPP index ba06357d..37d326c7 100644 --- a/SRC/STUDIO/STDIOBRW.CPP +++ b/SRC/STUDIO/STDIOBRW.CPP @@ -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; @@ -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; @@ -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))