mirror of
https://github.com/TwilitRealm/dusklight
synced 2026-07-05 11:33:39 -04:00
Isolate JKRHeap operator overloads
Fixes #25 This isolates the JKRHeap operator new/delete overloads. Every single new/delete site in the code has been replaced with a macro. Sadly for new[] and delete[] we have to keep global operators. The global new[] just allocates into malloc() however, and delete[] goes into free() if it's not in a JKRHeap. So that's fine.
This commit is contained in:
@@ -1,13 +1,14 @@
|
||||
#ifndef J2DANIMATION_H
|
||||
#define J2DANIMATION_H
|
||||
|
||||
#include "JSystem/JMath/JMath.h"
|
||||
#include "JSystem/J3DGraphAnimator/J3DAnimation.h"
|
||||
#include "JSystem/JKernel/JKRHeap.h"
|
||||
#include "JSystem/JMath/JMath.h"
|
||||
#include "JSystem/JUtility/JUTPalette.h"
|
||||
|
||||
typedef struct _GXColor GXColor;
|
||||
typedef struct _GXColorS10 GXColorS10;
|
||||
class J2DScreen;
|
||||
class JUTPalette;
|
||||
struct ResTIMG;
|
||||
|
||||
enum J2DAnmKind {
|
||||
@@ -286,7 +287,7 @@ public:
|
||||
mPalette = NULL;
|
||||
}
|
||||
~J2DAnmTexPatternTIMGPointer() {
|
||||
delete mPalette;
|
||||
JKR_DELETE(mPalette);
|
||||
}
|
||||
|
||||
/* 0x0 */ ResTIMG* mRes;
|
||||
@@ -306,7 +307,7 @@ public:
|
||||
ResTIMG* getResTIMG(u16) const;
|
||||
JUTPalette* getPalette(u16) const;
|
||||
|
||||
virtual ~J2DAnmTexPattern() { delete[] mTIMGPtrArray; }
|
||||
virtual ~J2DAnmTexPattern() { JKR_DELETE_ARRAY(mTIMGPtrArray); }
|
||||
virtual void searchUpdateMaterialID(J2DScreen*);
|
||||
u16 getUpdateMaterialNum() const { return mUpdateMaterialNum; }
|
||||
u16 getUpdateMaterialID(u16 i) const {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#ifndef JAHPUBDEFINE_H
|
||||
#define JAHPUBDEFINE_H
|
||||
|
||||
#include "JSystem/JKernel/JKRHeap.h"
|
||||
#include "JSystem/JUtility/JUTAssert.h"
|
||||
|
||||
template<class T>
|
||||
@@ -12,7 +13,7 @@ public:
|
||||
static T* newInstance() {
|
||||
JUT_ASSERT(82, sInstance==NULL);
|
||||
if (!sInstance) {
|
||||
sInstance = new T();
|
||||
sInstance = JKR_NEW T();
|
||||
}
|
||||
JUT_ASSERT(85, sInstance!=NULL);
|
||||
return sInstance;
|
||||
|
||||
@@ -209,12 +209,12 @@ public:
|
||||
return true;
|
||||
}
|
||||
MemoryChunk* pMVar4 = field_0x18;
|
||||
field_0x18 = new (JASKernel::getSystemHeap(), 0) MemoryChunk(pMVar4);
|
||||
field_0x18 = JKR_NEW_ARGS (JASKernel::getSystemHeap(), 0) MemoryChunk(pMVar4);
|
||||
if (field_0x18 != NULL) {
|
||||
return true;
|
||||
}
|
||||
JUT_WARN(428, "%s", "Not enough JASSystemHeap");
|
||||
field_0x18 = new (JKRHeap::getSystemHeap(), 0) MemoryChunk(pMVar4);
|
||||
field_0x18 = JKR_NEW_ARGS (JKRHeap::getSystemHeap(), 0) MemoryChunk(pMVar4);
|
||||
if (field_0x18 != NULL) {
|
||||
return true;
|
||||
}
|
||||
@@ -246,7 +246,7 @@ public:
|
||||
bool r26 = false;
|
||||
if (chunk != field_0x18 && chunk->isEmpty()) {
|
||||
MemoryChunk* nextChunk = chunk->getNextChunk();
|
||||
delete chunk;
|
||||
JKR_DELETE(chunk);
|
||||
prevChunk->setNextChunk(nextChunk);
|
||||
}
|
||||
return;
|
||||
@@ -283,6 +283,12 @@ namespace JASKernel {
|
||||
template <typename T>
|
||||
class JASPoolAllocObject {
|
||||
public:
|
||||
#if TARGET_PC
|
||||
static void* operator new(size_t n, JKRHeapToken) {
|
||||
return operator new(n);
|
||||
}
|
||||
#endif
|
||||
|
||||
static void* operator new(size_t n) {
|
||||
#if PLATFORM_GCN
|
||||
JASMemPool<T>& memPool_ = getMemPool_();
|
||||
@@ -292,6 +298,13 @@ public:
|
||||
static void* operator new(size_t n, void* ptr) {
|
||||
return ptr;
|
||||
}
|
||||
|
||||
#if TARGET_PC
|
||||
static void operator delete(void* ptr, size_t n, JKRHeapToken) {
|
||||
operator delete(ptr, n);
|
||||
}
|
||||
#endif
|
||||
|
||||
static void operator delete(void* ptr, size_t n) {
|
||||
#if PLATFORM_GCN
|
||||
JASMemPool<T>& memPool_ = getMemPool_();
|
||||
@@ -362,6 +375,12 @@ public:
|
||||
template <typename T>
|
||||
class JASPoolAllocObject_MultiThreaded {
|
||||
public:
|
||||
#if TARGET_PC
|
||||
static void* operator new(size_t n, JKRHeapToken) {
|
||||
return operator new(n);
|
||||
}
|
||||
#endif
|
||||
|
||||
static void* operator new(size_t n) {
|
||||
#if PLATFORM_GCN
|
||||
JASMemPool_MultiThreaded<T>& memPool_ = getMemPool();
|
||||
@@ -371,6 +390,13 @@ public:
|
||||
static void* operator new(size_t n, void* ptr) {
|
||||
return ptr;
|
||||
}
|
||||
|
||||
#if TARGET_PC
|
||||
static void operator delete(void* ptr, size_t n, JKRHeapToken) {
|
||||
return operator delete(ptr, n);
|
||||
}
|
||||
#endif
|
||||
|
||||
static void operator delete(void* ptr, size_t n) {
|
||||
#if PLATFORM_GCN
|
||||
JASMemPool_MultiThreaded<T>& memPool_ = getMemPool();
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#ifndef POINTER_H
|
||||
#define POINTER_H
|
||||
|
||||
#include "JSystem/JKernel/JKRHeap.h"
|
||||
|
||||
namespace JGadget {
|
||||
|
||||
template<class T>
|
||||
@@ -18,12 +20,12 @@ public:
|
||||
#ifdef __MWERKS__
|
||||
TPointer_delete(T* ptr) : TPointer(ptr) {}
|
||||
~TPointer_delete() {
|
||||
delete mPtr;
|
||||
JKR_DELETE(mPtr);
|
||||
}
|
||||
#else
|
||||
TPointer_delete(T* ptr) : TPointer<T>(ptr) {}
|
||||
~TPointer_delete() {
|
||||
delete this->mPtr;
|
||||
JKR_DELETE(this->mPtr);
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define STD_MEMORY_H
|
||||
|
||||
#include "JSystem/JUtility/JUTAssert.h"
|
||||
#include "JSystem/JKernel/JKRHeap.h"
|
||||
|
||||
namespace JGadget {
|
||||
template <typename T>
|
||||
@@ -19,12 +20,12 @@ struct TAllocator {
|
||||
}
|
||||
|
||||
void DeallocateRaw(void* mem) {
|
||||
delete mem;
|
||||
JKR_DELETE(mem);
|
||||
}
|
||||
|
||||
void construct(T* p, const T& other) {
|
||||
JUT_ASSERT(67, p!=NULL);
|
||||
new(p) T(other);
|
||||
JKR_NEW_ARGS(p) T(other);
|
||||
}
|
||||
|
||||
void destroy(T* p) {
|
||||
|
||||
@@ -4,7 +4,9 @@
|
||||
#include "JSystem/JHostIO/JHIComm.h"
|
||||
#include <dolphin/os.h>
|
||||
|
||||
template<typename T, int I>
|
||||
#include "JSystem/JKernel/JKRHeap.h"
|
||||
|
||||
template <typename T, int I>
|
||||
class JHIpvector {
|
||||
public:
|
||||
JHIpvector() { m_size = 0; }
|
||||
@@ -89,7 +91,7 @@ public:
|
||||
|
||||
static JHIComPortManager<T>* create() {
|
||||
if (instance == NULL) {
|
||||
instance = new JHIComPortManager<T>();
|
||||
instance = JKR_NEW JHIComPortManager<T>();
|
||||
}
|
||||
|
||||
return instance;
|
||||
|
||||
@@ -5,9 +5,11 @@
|
||||
#include "JSystem/JKernel/JKRDisposer.h"
|
||||
#include <dolphin/os.h>
|
||||
|
||||
#include "JKRHeap.h"
|
||||
|
||||
/**
|
||||
* @ingroup jsystem-jkernel
|
||||
*
|
||||
*
|
||||
*/
|
||||
class JKRAramHeap : public JKRDisposer {
|
||||
public:
|
||||
@@ -30,7 +32,7 @@ public:
|
||||
u32 getUsedSize(u8);
|
||||
void dump();
|
||||
void free(JKRAramBlock *block) {
|
||||
delete block;
|
||||
JKR_DELETE(block);
|
||||
}
|
||||
|
||||
u8 getCurrentGroupID() const { return mGroupId; }
|
||||
|
||||
@@ -210,15 +210,45 @@ public:
|
||||
static JKRErrorHandler mErrorHandler;
|
||||
};
|
||||
|
||||
void* operator new(size_t size);
|
||||
void* operator new(size_t size, int alignment);
|
||||
void* operator new(size_t size, JKRHeap* heap, int alignment);
|
||||
#if TARGET_PC
|
||||
enum class JKRHeapToken {
|
||||
Dummy
|
||||
};
|
||||
|
||||
void* operator new[](size_t size);
|
||||
void* operator new[](size_t size, int alignment);
|
||||
void* operator new[](size_t size, JKRHeap* heap, int alignment);
|
||||
inline void* operator new(size_t, JKRHeapToken, void* where) {
|
||||
return where;
|
||||
}
|
||||
|
||||
void operator delete(void* ptr);
|
||||
template<typename T>
|
||||
void jkrDelete(T* ptr) {
|
||||
ptr->~T();
|
||||
operator delete(ptr, JKRHeapToken::Dummy);
|
||||
}
|
||||
|
||||
#define JKR_NEW new (JKRHeapToken::Dummy)
|
||||
#define JKR_NEW_ARGS(...) new (JKRHeapToken::Dummy, __VA_ARGS__ )
|
||||
#define JKR_DELETE(expr) jkrDelete(expr)
|
||||
#define JKR_DELETE_ARRAY(expr) delete[] (expr)
|
||||
#define JKR_HEAP_TOKEN , JKRHeapToken::Dummy
|
||||
#define JKR_HEAP_TOKEN_PARAM , JKRHeapToken
|
||||
#else
|
||||
#define JKR_NEW new
|
||||
#define JKR_NEW_ARGS(...) new (__VA_ARGS__ )
|
||||
#define JKR_DELETE(expr) delete (expr)
|
||||
#define JKR_DELETE_ARRAY(expr) delete[] (expr)
|
||||
#define JKR_HEAP_TOKEN
|
||||
#define JKR_HEAP_TOKEN_PARAM
|
||||
#endif
|
||||
|
||||
void* operator new(size_t size JKR_HEAP_TOKEN_PARAM);
|
||||
void* operator new(size_t size JKR_HEAP_TOKEN_PARAM, int alignment);
|
||||
void* operator new(size_t size JKR_HEAP_TOKEN_PARAM, JKRHeap* heap, int alignment);
|
||||
|
||||
void* operator new[](size_t size JKR_HEAP_TOKEN_PARAM);
|
||||
void* operator new[](size_t size JKR_HEAP_TOKEN_PARAM, int alignment);
|
||||
void* operator new[](size_t size JKR_HEAP_TOKEN_PARAM, JKRHeap* heap, int alignment);
|
||||
|
||||
void operator delete(void* ptr JKR_HEAP_TOKEN_PARAM);
|
||||
void operator delete[](void* ptr);
|
||||
|
||||
void JKRDefaultMemoryErrorRoutine(void* heap, u32 size, int alignment);
|
||||
|
||||
@@ -16,7 +16,7 @@ struct TCreateObject {
|
||||
|
||||
template<class AdaptorT>
|
||||
static typename AdaptorT::ObjectType* createFromAdaptor(JStudio::stb::data::TParse_TBlock_object const& param_1, AdaptorT* param_2) {
|
||||
typename AdaptorT::ObjectType* rv = new typename AdaptorT::ObjectType(param_1, param_2);
|
||||
typename AdaptorT::ObjectType* rv = JKR_NEW typename AdaptorT::ObjectType(param_1, param_2);
|
||||
if (rv == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -133,7 +133,7 @@ public:
|
||||
|
||||
template<class T>
|
||||
T* createFromAdaptor(const stb::data::TParse_TBlock_object& param_0, T* param_1) {
|
||||
T* n = new T(param_0, param_1);
|
||||
T* n = JKR_NEW T(param_0, param_1);
|
||||
|
||||
if (n == NULL) {
|
||||
return NULL;
|
||||
|
||||
@@ -321,7 +321,7 @@ template <class AdaptorT, class ObjectT>
|
||||
JStudio::TObject* createObject_JSG_(const JStudio::stb::data::TParse_TBlock_object& param_1,
|
||||
JStage::TObject* param_2, const JStage::TSystem* param_3) {
|
||||
ObjectT* objt = (ObjectT*)param_2;
|
||||
AdaptorT* pAdaptor = new AdaptorT(param_3, objt);
|
||||
AdaptorT* pAdaptor = JKR_NEW AdaptorT(param_3, objt);
|
||||
if (pAdaptor == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -3,10 +3,12 @@
|
||||
|
||||
#include <dolphin/gx.h>
|
||||
|
||||
#include "JSystem/JKernel/JKRHeap.h"
|
||||
|
||||
/**
|
||||
* @ingroup jsystem-jutility
|
||||
*
|
||||
*/
|
||||
* @ingroup jsystem-jutility
|
||||
*
|
||||
*/
|
||||
class JUTGraphFifo {
|
||||
public:
|
||||
JUTGraphFifo(u32);
|
||||
@@ -36,6 +38,6 @@ private:
|
||||
/* 0x10 */ u8 field_0x10[0xC];
|
||||
};
|
||||
|
||||
inline JUTGraphFifo* JUTCreateFifo(u32 bufSize) { return new JUTGraphFifo(bufSize); }
|
||||
inline JUTGraphFifo* JUTCreateFifo(u32 bufSize) { return JKR_NEW JUTGraphFifo(bufSize); }
|
||||
|
||||
#endif /* JUTGRAPHFIFO_H */
|
||||
|
||||
Reference in New Issue
Block a user