Refactor `new` usage to `rs_new`

Former-commit-id: cbf7b415ed96fe9ad0a0a9a11cc1ffb18b5c07da
This commit is contained in:
Phillip Stephens 2023-10-12 05:14:12 -07:00
parent 2d4ba7275f
commit cc41943a2a
27 changed files with 58 additions and 60 deletions

View File

@ -29,8 +29,7 @@ void* operator new(size_t sz, const char*, const char*);
void* operator new[](size_t sz, const char*, const char*);
// TODO remove
inline void* operator new(size_t sz) { return operator new(sz, "??(??)", nullptr); }
inline void* operator new[](size_t sz) { return operator new[](sz, "??(??)", nullptr); }
//inline void* operator new(size_t sz) { return operator new(sz, "??(??)", nullptr); }
#else
/*__attribute__((weak)) void* operator new(size_t sz) { return operator new(sz, "??(??)", nullptr); }
__attribute__((weak)) void* operator new[](size_t sz) {
@ -44,7 +43,7 @@ inline void* operator new(size_t n, void* ptr) { return ptr; };
#ifdef __MWERKS__
inline void operator delete(void* ptr) { CMemory::Free(ptr); }
inline void operator delete[](void* ptr) { CMemory::Free(ptr); }
#define NEW new ("??(??)", nullptr)
#define rs_new new ("??(??)", nullptr)
#else
__attribute__((weak)) void operator delete(void* ptr) { CMemory::Free(ptr); }
__attribute__((weak)) void operator delete[](void* ptr) { CMemory::Free(ptr); }

View File

@ -38,11 +38,11 @@ public:
T* Owned() { return static_cast< T* >(m_objPtr); }
static rstl::auto_ptr< TObjOwnerDerivedFromIObj< T > > GetNewDerivedObject(T* obj) {
return new TObjOwnerDerivedFromIObj< T >(obj);
return rs_new TObjOwnerDerivedFromIObj< T >(obj);
}
static rstl::auto_ptr< TObjOwnerDerivedFromIObj< T > >
GetNewDerivedObject(const rstl::auto_ptr< T >& obj) {
return new TObjOwnerDerivedFromIObj< T >(obj);
return rs_new TObjOwnerDerivedFromIObj< T >(obj);
}
private:

View File

@ -2,6 +2,7 @@
#define _RSTL_RC_PTR
#include "types.h"
#include "rstl/rmemory_allocator.hpp"
namespace rstl {
class CRefData {
@ -25,7 +26,7 @@ template < typename T >
class rc_ptr {
public:
rc_ptr() : x0_refData(&CRefData::sNull) { x0_refData->AddRef(); }
rc_ptr(const T* ptr) : x0_refData(new CRefData(ptr)) {}
rc_ptr(const T* ptr) : x0_refData(rs_new CRefData(ptr)) {}
rc_ptr(const rc_ptr& other) : x0_refData(other.x0_refData) { x0_refData->AddRef(); }
~rc_ptr() { ReleaseData(); }
T* GetPtr() const { return static_cast< T* >(x0_refData->GetPtr()); }

View File

@ -15,7 +15,7 @@ struct rmemory_allocator {
if (size == 0) {
out = nullptr;
} else {
out = reinterpret_cast< T* >(NEW uchar[size]);
out = reinterpret_cast< T* >(rs_new uchar[size]);
}
}
// TODO: this fixes a regswap in vector::reserve
@ -25,7 +25,7 @@ struct rmemory_allocator {
if (size == 0) {
return nullptr;
} else {
return reinterpret_cast< T* >(NEW uchar[size]);
return reinterpret_cast< T* >(rs_new uchar[size]);
}
}
template < typename T >

View File

@ -25,20 +25,20 @@ CGuiLight* CGuiLight::Create(CGuiFrame* parent, CInputStream& in, IObjectStore*
lt.SetAngleAttenuation(angC, angL, angQ);
lt.SetLightId(lightId);
ret = new CGuiLight(parms, lt);
ret = rs_new CGuiLight(parms, lt);
break;
}
case kLT_Point: {
CLight lt = CLight::BuildPoint(CVector3f::Zero(), color);
lt.SetAttenuation(distC, distL, distQ);
lt.SetLightId(lightId);
ret = new CGuiLight(parms, lt);
ret = rs_new CGuiLight(parms, lt);
break;
}
case kLT_Directional: {
CLight lt = CLight::BuildDirectional(CVector3f::Zero(), color);
lt.SetLightId(lightId);
ret = new CGuiLight(parms, lt);
ret = rs_new CGuiLight(parms, lt);
break;
}
default:

View File

@ -10,8 +10,8 @@ CGuiSys* CGuiSys::spGuiSys = nullptr;
CGuiSys::CGuiSys(IFactory* factory, CSimplePool* pool, EUsageMode mode)
: x0_resFactory(factory), x4_resStore(pool), x8_mode(mode) {
AddFactories(x8_mode);
xc_textExecuteBuffer = new CTextExecuteBuffer();
x10_textParser = new CTextParser(*pool);
xc_textExecuteBuffer = rs_new CTextExecuteBuffer();
x10_textParser = rs_new CTextParser(*pool);
CGuiTextSupport::Initialize(xc_textExecuteBuffer.get(), x10_textParser.get());
}

View File

@ -36,5 +36,5 @@ CFactoryFnReturn::CFactoryFnReturn(CDependencyGroup* ptr)
CFactoryFnReturn FDependencyGroupFactory(const SObjectTag& tag, CInputStream& in,
const CVParamTransfer& xfer) {
return new CDependencyGroup(in);
return rs_new CDependencyGroup(in);
}

View File

@ -6,7 +6,7 @@ CToken::CToken(CObjectReference* ref) : x0_objRef(ref), x4_lockHeld(false) {
}
CToken::CToken(IObj* obj)
: x0_objRef(NEW CObjectReference(obj)), x4_lockHeld(false) {
: x0_objRef(rs_new CObjectReference(obj)), x4_lockHeld(false) {
x0_objRef->AddReference();
Lock();
}

View File

@ -127,7 +127,7 @@ void CDvdFile::TryARAMFile() {
if (CARAMManager::GetInvalidAlloc() == x4_) {
return;
}
xc_ = NEW CDvdFileARAM();
xc_ = rs_new CDvdFileARAM();
CDvdFileARAM* arfile = xc_.get();
arfile->x5c_file = this;
arfile->x78_ = true;
@ -254,10 +254,10 @@ CDvdRequest* CDvdFile::AsyncSeekRead(void* dest, uint len, ESeekOrigin origin, i
if (x8_) {
int roundedLen = (len + 31) & ~31;
DCFlushRange(dest, roundedLen);
request = NEW CARAMDvdRequest(
request = rs_new CARAMDvdRequest(
CARAMManager::DMAToMRAM(x4_ + x10_offset, dest, roundedLen, CARAMManager::kDMAPrio_One));
} else {
CRealDvdRequest* req = NEW CRealDvdRequest();
CRealDvdRequest* req = rs_new CRealDvdRequest();
DVDFileInfo* info = req->FileInfo();
DVDFastOpen(x0_fileEntry, info);
DVDReadAsync(info, dest, (len + 31) & ~31, x10_offset, internalCallback);

View File

@ -12,7 +12,7 @@ IController::IController() {}
IController::~IController() {}
IController* IController::Create(const COsContext& ctx) {
CDolphinController* cont = new CDolphinController();
CDolphinController* cont = rs_new CDolphinController();
cont->Initialize();
return cont;
}

View File

@ -9,7 +9,7 @@ CInputStream::CInputStream(int len)
: x4_blockOffset(0)
, x8_blockLen(0)
, xc_len(len)
, x10_ptr(new uchar[len])
, x10_ptr(rs_new uchar[len])
, x14_owned(true)
, x18_readPosition(0)
, x1c_bitWord(0)

View File

@ -11,7 +11,7 @@
COutputStream::COutputStream(int len)
: mUnwrittenLen(0)
, mBufLen(len)
, mBufPtr(len > 64 ? new uchar[len] : &mScratch[32 - (uintptr_t)(mScratch) % 31])
, mBufPtr(len > 64 ? rs_new uchar[len] : &mScratch[32 - (uintptr_t)(mScratch) % 31])
, mNumWrites(0)
, mShiftRegister(0)
, mShiftRegisterOffset(32) {}

View File

@ -3,9 +3,9 @@
CZipInputStream::CZipInputStream(rstl::auto_ptr<CInputStream> in)
: CInputStream(4096)
, mCompBuf(new uchar[4096])
, mCompBuf(rs_new uchar[4096])
, mStream(in)
, mZStream(new z_stream_s) {
, mZStream(rs_new z_stream_s) {
z_stream_s* zs = mZStream.get();
zs->next_in = mCompBuf.get();
mZStream->avail_in = 0;

View File

@ -7,7 +7,7 @@ static char* hack() {
}
void* CZipSupport::Alloc(void* ptr1, uint w1, uint w2) {
return new uchar[w1 * w2];
return rs_new uchar[w1 * w2];
}
void CZipSupport::Free(void* ptr1, void* ptr2) {

View File

@ -30,7 +30,7 @@ CStringTable::CStringTable(CInputStream& in) : x0_stringCount(0), x4_data(NULL)
}
uint dataLen = in.Get(TType< uint >());
x4_data = new uchar[dataLen];
x4_data = rs_new uchar[dataLen];
in.ReadBytes(x4_data.get(), dataLen);
}
@ -48,5 +48,5 @@ CFactoryFnReturn::CFactoryFnReturn(CStringTable* ptr)
CFactoryFnReturn FStringTableFactory(const SObjectTag& tag, CInputStream& in,
const CVParamTransfer& xfer) {
return new CStringTable(in);
return rs_new CStringTable(in);
}

View File

@ -118,7 +118,7 @@ uint CLightParameters::GetFramesBetweenRecalculation(ELightRecalculationOptions
rstl::auto_ptr< CActorLights > CLightParameters::MakeActorLights() const {
rstl::auto_ptr< CActorLights > result;
if (x1c_makeLights) {
result = new CActorLights(GetFramesBetweenRecalculation(x24_lightRecalculation),
result = rs_new CActorLights(GetFramesBetweenRecalculation(x24_lightRecalculation),
x2c_lightingPositionOffset, x38_maxDynamicLights, x3c_maxAreaLights,
CActorLights::kDefaultPositionUpdateThreshold, x1d_ambientChannelOverflow, x28_useLightSet == 1,
x20_useWorldLighting == kLO_DisableWorld);

View File

@ -16,7 +16,7 @@ CExplosion::CExplosion(const TLockedToken< CGenDescription >& particle, TUniqueI
const CEntityInfo& info, const rstl::string& name, const CTransform4f& xf,
uint flags, const CVector3f& scale, const CColor& color)
: CEffect(uid, info, active, name, xf)
, xe8_particleGen(new CElementGen(TToken< CGenDescription >(particle), CElementGen::kMOT_Normal,
, xe8_particleGen(rs_new CElementGen(TToken< CGenDescription >(particle), CElementGen::kMOT_Normal,
flags & 0x2 ? CElementGen::kOSF_Two : CElementGen::kOSF_One))
, xec_explosionLight(kInvalidUniqueId)
, xf0_sourceId(CToken(particle).GetTag().id)
@ -36,7 +36,7 @@ CExplosion::CExplosion(const TLockedToken< CElectricDescription >& electric, TUn
const CTransform4f& xf, uint flags, const CVector3f& scale,
const CColor& color)
: CEffect(uid, info, active, name, xf)
, xe8_particleGen(new CParticleElectric(electric))
, xe8_particleGen(rs_new CParticleElectric(electric))
, xec_explosionLight(kInvalidUniqueId)
, xf0_sourceId(CToken(electric).GetTag().id)
, xf4_24_renderThermalHot(flags & 0x4)
@ -102,7 +102,7 @@ void CExplosion::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId sender, CSt
if (xe8_particleGen->SystemHasLight()) {
xec_explosionLight = mgr.AllocateUniqueId();
uint sourceId = xf0_sourceId;
mgr.AddObject(new CGameLight(xec_explosionLight, GetCurrentAreaId(), GetActive(),
mgr.AddObject(rs_new CGameLight(xec_explosionLight, GetCurrentAreaId(), GetActive(),
rstl::string_l("ExplodePLight_") + GetDebugName(),
GetTransform(), GetUniqueId(), xe8_particleGen->GetLight(),
sourceId, 1, 0.f));

View File

@ -27,7 +27,7 @@ TUniqueId _initializeLight(const rstl::ncrc_ptr< CParticleGen >& system, CStateM
TAreaId areaId, int lightId) {
if (system->SystemHasLight()) {
TUniqueId ret = stateMgr.AllocateUniqueId();
stateMgr.AddObject(new CGameLight(
stateMgr.AddObject(rs_new CGameLight(
ret, areaId, false, rstl::string_l("ParticleLight"),
CTransform4f(system->GetOrientation().BuildMatrix3f(), system->GetTranslation()),
kInvalidUniqueId, system->GetLight(), lightId, 0, 0.f));

View File

@ -9,7 +9,7 @@ CArchitectureMessage MakeMsg::CreateCreateIOWin(EArchMsgTarget target, const int
const int& pmax, CIOWin* const& iowin) {
return CArchitectureMessage(
target, kAM_CreateIOWin,
new CArchMsgParmInt32Int32VoidPtr(pmin, pmax, reinterpret_cast< const void* >(iowin)));
rs_new CArchMsgParmInt32Int32VoidPtr(pmin, pmax, reinterpret_cast< const void* >(iowin)));
}
const CArchMsgParmInt32Int32VoidPtr& MakeMsg::GetParmCreateIOWin(const CArchitectureMessage& msg) {
@ -22,7 +22,7 @@ MakeMsg::GetParmChangeIOWinPriority(const CArchitectureMessage& msg) {
}
CArchitectureMessage MakeMsg::CreateTimerTick(EArchMsgTarget target, const float& val) {
return CArchitectureMessage(target, kAM_TimerTick, new CArchMsgParmReal32(val));
return CArchitectureMessage(target, kAM_TimerTick, rs_new CArchMsgParmReal32(val));
}
const CArchMsgParmReal32& MakeMsg::GetParmTimerTick(const CArchitectureMessage& msg) {
@ -30,7 +30,7 @@ const CArchMsgParmReal32& MakeMsg::GetParmTimerTick(const CArchitectureMessage&
}
CArchitectureMessage MakeMsg::CreateUserInput(EArchMsgTarget target, const CFinalInput& input) {
return CArchitectureMessage(target, kAM_UserInput, new CArchMsgParmUserInput(input));
return CArchitectureMessage(target, kAM_UserInput, rs_new CArchMsgParmUserInput(input));
}
const CArchMsgParmUserInput& MakeMsg::GetParmUserInput(const CArchitectureMessage& msg) {
@ -44,15 +44,15 @@ const CArchMsgParmInt32& MakeMsg::GetParmNewGameflowState(const CArchitectureMes
CArchitectureMessage MakeMsg::CreateControllerStatus(EArchMsgTarget target, const short& chan,
const bool& connected) {
return CArchitectureMessage(target, kAM_ControllerStatus,
new CArchMsgParmControllerStatus(chan, connected));
rs_new CArchMsgParmControllerStatus(chan, connected));
}
CArchitectureMessage MakeMsg::CreateQuitGameplay(EArchMsgTarget target) {
return CArchitectureMessage(target, kAM_QuitGameplay, new CArchMsgParmNull());
return CArchitectureMessage(target, kAM_QuitGameplay, new("??(??)", nullptr) CArchMsgParmNull());
}
CArchitectureMessage MakeMsg::CreateFrameBegin(EArchMsgTarget target, const int& a) {
return CArchitectureMessage(target, kAM_FrameBegin, new CArchMsgParmInt32(a));
return CArchitectureMessage(target, kAM_FrameBegin, new("??(??)", nullptr) CArchMsgParmInt32(a));
}
const CArchMsgParmInt32& MakeMsg::GetParmFrameBegin(const CArchitectureMessage& msg) {
@ -60,5 +60,5 @@ const CArchMsgParmInt32& MakeMsg::GetParmFrameBegin(const CArchitectureMessage&
}
CArchitectureMessage MakeMsg::CreateFrameEnd(EArchMsgTarget target, const int& a) {
return CArchitectureMessage(target, kAM_FrameEnd, new CArchMsgParmInt32(a));
return CArchitectureMessage(target, kAM_FrameEnd, new("??(??)", nullptr) CArchMsgParmInt32(a));
}

View File

@ -12,7 +12,7 @@ CFlaahgraPlants::CFlaahgraPlants(const TToken< CGenDescription >& genDesc,
const CVector3f& extents)
: CActor(uid, true, "Flaahgra Plants", CEntityInfo(aId, NullConnectionList), xf,
CModelData::CModelDataNull(), CMaterialList(kMT_Projectile), actParms, kInvalidUniqueId)
, xe8_elementGen(new CElementGen(genDesc))
, xe8_elementGen(rs_new CElementGen(genDesc))
, xf0_ownerId(owner)
, xf4_damageInfo(dInfo)
, x12c_lastDt(0.f)
@ -81,7 +81,7 @@ void CFlaahgraPlants::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, C
if (x16c_colAct == kInvalidUniqueId) {
x16c_colAct = mgr.AllocateUniqueId();
CVector3f extent = x130_obbox.GetSize() + CVector3f(0.f, 5.f, 10.f);
CCollisionActor* colAct = new CCollisionActor(x16c_colAct, GetCurrentAreaId(), GetUniqueId(),
CCollisionActor* colAct = rs_new CCollisionActor(x16c_colAct, GetCurrentAreaId(), GetUniqueId(),
extent, CVector3f::Zero(), true, 0.001f);
if (colAct != nullptr) {
colAct->SetTransform(GetTransform());

View File

@ -32,12 +32,12 @@ bool CMetroidPrimeProjectile::Explode(const CVector3f& pos, const CVector3f& nor
.GetTransformedAABox(GetTransform() *
CTransform4f::Scale(x3d8_auxData.GetDamageInfo().GetRadius())));
CFire* fire =
new CFire(x3d8_auxData.x4_particle, newId, GetCurrentAreaId(), true, GetUniqueId(),
GetTransform(), x3d8_auxData.GetDamageInfo(), box, CVector3f(1.f, 1.f, 1.f),
x3d8_auxData.GetFlag_27(), x3d8_auxData.GetTexture(), x3d8_auxData.GetFlag_24(),
x3d8_auxData.GetFlag_25(), x3d8_auxData.GetFlag_26(), 1.0,
x3d8_auxData.Get_0x28(), x3d8_auxData.Get_0x2c(), x3d8_auxData.Get_0x30());
CFire* fire = rs_new CFire(
x3d8_auxData.x4_particle, newId, GetCurrentAreaId(), true, GetUniqueId(), GetTransform(),
x3d8_auxData.GetDamageInfo(), box, CVector3f(1.f, 1.f, 1.f), x3d8_auxData.GetFlag_27(),
x3d8_auxData.GetTexture(), x3d8_auxData.GetFlag_24(), x3d8_auxData.GetFlag_25(),
x3d8_auxData.GetFlag_26(), 1.0, x3d8_auxData.Get_0x28(), x3d8_auxData.Get_0x2c(),
x3d8_auxData.Get_0x30());
if (fire) {
mgr.AddObject(fire);
}

View File

@ -19,7 +19,7 @@ void CScriptBeam::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId objId, CSt
case kSM_Registered: {
x154_projectileId = mgr.AllocateUniqueId();
mgr.AddObject(new CPlasmaProjectile(
mgr.AddObject(rs_new CPlasmaProjectile(
xe8_weaponDescription, GetDebugName() + rstl::string_l("-Projectile"),
x138_damageInfo.GetWeaponMode().GetType(), xf4_beamInfo, GetTransform(), kMT_Projectile,
x138_damageInfo, x154_projectileId, GetCurrentAreaId(), GetUniqueId(),

View File

@ -318,7 +318,7 @@ void CScriptMazeNode::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, C
case kSM_InitializedInArea: {
if (mgr.CurrentMaze() == nullptr) {
rstl::single_ptr< CMazeState > maze =
new CMazeState(skEnterCol, skEnterRow, skTargetCol, skTargetRow);
rs_new CMazeState(skEnterCol, skEnterRow, skTargetCol, skTargetRow);
maze->Reset(sMazeSeeds[mgr.Random()->Next() % 300]);
maze->Initialize();
maze->GenerateObstacles();

View File

@ -153,12 +153,11 @@ void CScriptPickup::Touch(CActor& act, CStateManager& mgr) {
if (x27c_pickupParticleDesc) {
if (mgr.GetPlayerState()->GetActiveVisor(mgr) != CPlayerState::kPV_Thermal) {
mgr.AddObject(new CExplosion(
mgr.AddObject(rs_new CExplosion(
TLockedToken< CGenDescription >(*x27c_pickupParticleDesc), mgr.AllocateUniqueId(), true,
CEntityInfo(GetCurrentAreaId(), CEntity::NullConnectionList, kInvalidEditorId),
rstl::string_l("Explosion - Pickup Effect"), GetTransform(), 0,
CVector3f(1.f, 1.f, 1.f), CColor::White()));
}
}
@ -198,8 +197,7 @@ rstl::optional_object< CAABox > CScriptPickup::GetTouchBounds() const {
return CPhysicsActor::GetBoundingBox();
}
void CScriptPickup::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid,
CStateManager& mgr) {
void CScriptPickup::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CStateManager& mgr) {
CPhysicsActor::AcceptScriptMsg(msg, uid, mgr);
}

View File

@ -161,7 +161,7 @@ void CPlasmaBeam::EnableSecondaryFx(ESecondaryFxType type) {
}
case kSFT_Charge:
x228_chargeFx = new CElementGen(x21c_plasma2nd1);
x228_chargeFx = rs_new CElementGen(x21c_plasma2nd1);
x228_chargeFx->SetGlobalScale(x4_scale);
default:

View File

@ -96,7 +96,7 @@ void CPowerBeam::Update(float dt, CStateManager& mgr) {
if (CGunWeapon::IsLoaded() && !x244_25_loaded) {
x244_25_loaded = x21c_shotSmoke.IsLoaded() && x228_power2nd1.IsLoaded();
if (x244_25_loaded) {
x234_shotSmokeGen = NEW CElementGen(x21c_shotSmoke);
x234_shotSmokeGen = rs_new CElementGen(x21c_shotSmoke);
x234_shotSmokeGen->SetParticleEmission(false);
}
}
@ -140,7 +140,7 @@ void CPowerBeam::EnableSecondaryFx(ESecondaryFxType type) {
x1cc_enabledSecondaryEffect = kSFT_None;
break;
case kSFT_Charge:
x238_power2ndGen = NEW CElementGen(x228_power2nd1);
x238_power2ndGen = rs_new CElementGen(x228_power2nd1);
x238_power2ndGen->SetGlobalScale(x4_scale);
x1cc_enabledSecondaryEffect = type;
break;

View File

@ -26,7 +26,7 @@ CPowerBomb::CPowerBomb(TToken< CGenDescription > particle, TUniqueId uid, TAreaI
, x15c_curTime(0.f)
, x160_curRadius(0.f)
, x164_radiusIncrement(dInfo.GetRadius() / 2.5f)
, x168_particle(new CElementGen(particle))
, x168_particle(rs_new CElementGen(particle))
, x16c_radius(dInfo.GetRadius()) {
x168_particle->SetGlobalTranslation(xf.GetTranslation());
}