Skip to content

Commit

Permalink
LogUtils as macro
Browse files Browse the repository at this point in the history
  • Loading branch information
Baoulettes committed Jun 28, 2022
1 parent 0ef8463 commit 4606929
Show file tree
Hide file tree
Showing 18 changed files with 81 additions and 64 deletions.
17 changes: 17 additions & 0 deletions soh/include/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,23 @@
#define LOG_FLOAT(exp, value) ((void)0)
#endif

// LogUtils as macro
#ifndef NDEBUG
#define LOG_POINTER(val, max, ptr, name) LogUtils_LogPointer(val, max, ptr, name, __FILE__, __LINE__)
#define LOG_CHECK_BOUNDARY(name, value, unk) LogUtils_CheckBoundary(name, value, unk, __FILE__, __LINE__)
#define LOG_CHECK_NULL_POINTER(exp, ptr) LogUtils_CheckNullPointer(exp, ptr,__FILE__, __LINE__)
#define LOG_CHECK_VALID_POINTER(exp, ptr) LogUtils_CheckValidPointer(exp, ptr,__FILE__, __LINE__)
#define LOG_THREAD_ID() LogUtils_LogThreadId(__FILE__, __LINE__)
#define LOG_HUNGUP_THREAD() LogUtils_HungupThread(__FILE__, __LINE__)
#else
#define LOG_POINTER(val, max, ptr, name) ((void)0)
#define LOG_CHECKBOUNDARY(name, value, unk) ((void)0)
#define LOG_CHECK_NULL_POINTER(exp, ptr) ((void)0)
#define LOG_CHECK_VALID_POINTER(exp, ptr) ((void)0)
#define LOG_THREAD_ID() ((void)0)
#define LOG_HUNGUP_THREAD() ((void)0)
#endif

#define SET_NEXT_GAMESTATE(curState, newInit, newStruct) \
do { \
(curState)->init = newInit; \
Expand Down
2 changes: 1 addition & 1 deletion soh/src/boot/z_locale.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ void Locale_Init(void) {
default:
osSyncPrintf(VT_COL(RED, WHITE));
osSyncPrintf("z_locale_init: 日本用かアメリカ用か判別できません\n");
LogUtils_HungupThread("../z_locale.c", 118);
LOG_HUNGUP_THREAD();
osSyncPrintf(VT_RST);
break;
}
Expand Down
40 changes: 20 additions & 20 deletions soh/src/code/PreRender.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ void func_800C0F28(PreRender* this, Gfx** gfxp, void* buf, void* bufSave) {
s32 x2;
s32 dx;

LogUtils_CheckNullPointer("this", this, __FILE__, __LINE__);
LogUtils_CheckNullPointer("glistpp", gfxp, __FILE__, __LINE__);
LOG_CHECK_NULL_POINTER("this", this);
LOG_CHECK_NULL_POINTER("glistpp", gfxp);
gfx = *gfxp;
LogUtils_CheckNullPointer("glistp", gfx, __FILE__, __LINE__);
LOG_CHECK_NULL_POINTER("glistp", gfx);

gDPPipeSync(gfx++);
gDPSetOtherMode(gfx++,
Expand Down Expand Up @@ -89,10 +89,10 @@ void func_800C1258(PreRender* this, Gfx** gfxp) {
s32 y2;
s32 dy;

LogUtils_CheckNullPointer("this", this, __FILE__, __LINE__);
LogUtils_CheckNullPointer("glistpp", gfxp, __FILE__, __LINE__);
LOG_CHECK_NULL_POINTER("this", this);
LOG_CHECK_NULL_POINTER("glistpp", gfxp);
gfx = *gfxp;
LogUtils_CheckNullPointer("glistp", gfx, __FILE__, __LINE__);
LOG_CHECK_NULL_POINTER("glistp", gfx);

gDPPipeSync(gfx++);
gDPSetOtherMode(gfx++,
Expand Down Expand Up @@ -139,10 +139,10 @@ void func_800C170C(PreRender* this, Gfx** gfxp, void* fbuf, void* fbufSave, u32
s32 x2;
s32 dx;

LogUtils_CheckNullPointer("this", this, __FILE__, __LINE__);
LogUtils_CheckNullPointer("glistpp", gfxp, __FILE__, __LINE__);
LOG_CHECK_NULL_POINTER("this", this);
LOG_CHECK_NULL_POINTER("glistpp", gfxp);
gfx = *gfxp;
LogUtils_CheckNullPointer("glistp", gfx, __FILE__, __LINE__);
LOG_CHECK_NULL_POINTER("glistp", gfx);

gDPPipeSync(gfx++);
gDPSetOtherMode(gfx++,
Expand Down Expand Up @@ -195,10 +195,10 @@ void func_800C1B24(PreRender* this, Gfx** gfxp, void* fbuf, void* cvgSave) {
s32 x2;
s32 dx;

LogUtils_CheckNullPointer("this", this, __FILE__, __LINE__);
LogUtils_CheckNullPointer("glistpp", gfxp, __FILE__, __LINE__);
LOG_CHECK_NULL_POINTER("this", this);
LOG_CHECK_NULL_POINTER("glistpp", gfxp);
gfx = *gfxp;
LogUtils_CheckNullPointer("glistp", gfx, __FILE__, __LINE__);
LOG_CHECK_NULL_POINTER("glistp", gfx);

gDPPipeSync(gfx++);
gDPSetOtherMode(gfx++,
Expand Down Expand Up @@ -239,17 +239,17 @@ void func_800C1B24(PreRender* this, Gfx** gfxp, void* fbuf, void* cvgSave) {
}

void func_800C1E9C(PreRender* this, Gfx** gfxp) {
LogUtils_CheckNullPointer("this->zbuf_save", this->zbufSave, __FILE__, __LINE__);
LogUtils_CheckNullPointer("this->zbuf", this->zbuf, __FILE__, __LINE__);
LOG_CHECK_NULL_POINTER("this->zbuf_save", this->zbufSave);
LOG_CHECK_NULL_POINTER("this->zbuf", this->zbuf);

if ((this->zbufSave != NULL) && (this->zbuf != NULL)) {
func_800C0F28(this, gfxp, this->zbuf, this->zbufSave);
}
}

void func_800C1F20(PreRender* this, Gfx** gfxp) {
LogUtils_CheckNullPointer("this->fbuf_save", this->fbufSave, __FILE__, __LINE__);
LogUtils_CheckNullPointer("this->fbuf", this->fbuf, __FILE__, __LINE__);
LOG_CHECK_NULL_POINTER("this->fbuf_save", this->fbufSave);
LOG_CHECK_NULL_POINTER("this->fbuf", this->fbuf);

if ((this->fbufSave != NULL) && (this->fbuf != NULL)) {
func_800C1AE8(this, gfxp, this->fbuf, this->fbufSave);
Expand All @@ -275,7 +275,7 @@ void func_800C1FA4(PreRender* this, Gfx** gfxp) {

void func_800C20B4(PreRender* this, Gfx** gfxp) {
func_800C1FA4(this, gfxp);
LogUtils_CheckNullPointer("this->cvg_save", this->cvgSave, __FILE__, __LINE__);
LOG_CHECK_NULL_POINTER("this->cvg_save", this->cvgSave);
if (this->cvgSave != NULL) {
func_800C1B24(this, gfxp, this->fbuf, this->cvgSave);
}
Expand All @@ -293,10 +293,10 @@ void func_800C213C(PreRender* this, Gfx** gfxp) {
s32 rtile = 1;

if (this->cvgSave != NULL) {
LogUtils_CheckNullPointer("this", this, __FILE__, __LINE__);
LogUtils_CheckNullPointer("glistpp", gfxp, __FILE__, __LINE__);
LOG_CHECK_NULL_POINTER("this", this);
LOG_CHECK_NULL_POINTER("glistpp", gfxp);
gfx = *gfxp;
LogUtils_CheckNullPointer("glistp", gfx, __FILE__, __LINE__);
LOG_CHECK_NULL_POINTER("glistp", gfx);

gDPPipeSync(gfx++);
gDPSetEnvColor(gfx++, 255, 255, 255, 32);
Expand Down
4 changes: 2 additions & 2 deletions soh/src/code/game.c
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ void GameState_Init(GameState* gameState, GameStateFunc init, GraphicsContext* g
osSyncPrintf("init 処理時間 %d us\n", OS_CYCLES_TO_USEC(endTime - startTime));

startTime = endTime;
LogUtils_CheckNullPointer("this->cleanup", gameState->destroy, __FILE__, __LINE__);
LOG_CHECK_NULL_POINTER("this->cleanup", gameState->destroy);
func_800ACE70(&D_801664F0);
func_800AD920(&D_80166500);
VisMono_Init(&sMonoColors);
Expand All @@ -537,7 +537,7 @@ void GameState_Destroy(GameState* gameState) {
func_800C3C20();
func_800F3054();
osRecvMesg(&gameState->gfxCtx->queue, NULL, OS_MESG_BLOCK);
LogUtils_CheckNullPointer("this->cleanup", gameState->destroy, __FILE__, __LINE__);
LOG_CHECK_NULL_POINTER("this->cleanup", gameState->destroy);
if (gameState->destroy != NULL) {
gameState->destroy(gameState);
}
Expand Down
4 changes: 2 additions & 2 deletions soh/src/code/gamealloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ void GameAlloc_Free(GameAlloc* this, void* data) {

if (data != NULL) {
ptr = &((GameAllocEntry*)data)[-1];
LogUtils_CheckNullPointer("ptr->prev", ptr->prev, __FILE__, __LINE__);
LogUtils_CheckNullPointer("ptr->next", ptr->next, __FILE__, __LINE__);
LOG_CHECK_NULL_POINTER("ptr->prev", ptr->prev);
LOG_CHECK_NULL_POINTER("ptr->next", ptr->next);
ptr->prev->next = ptr->next;
ptr->next->prev = ptr->prev;
this->head = this->base.prev;
Expand Down
14 changes: 7 additions & 7 deletions soh/src/code/irqmgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ u32 sIrqMgrRetraceCount = 0;
void IrqMgr_AddClient(IrqMgr* this, IrqMgrClient* c, OSMesgQueue* msgQ) {
OSIntMask prevInt;

LogUtils_CheckNullPointer("this", this, __FILE__, __LINE__);
LogUtils_CheckNullPointer("c", c, __FILE__, __LINE__);
LogUtils_CheckNullPointer("msgQ", msgQ, __FILE__, __LINE__);
LOG_CHECK_NULL_POINTER("this", this);
LOG_CHECK_NULL_POINTER("c", c);
LOG_CHECK_NULL_POINTER("msgQ", msgQ);

prevInt = osSetIntMask(1);

Expand All @@ -45,8 +45,8 @@ void IrqMgr_RemoveClient(IrqMgr* this, IrqMgrClient* c) {
IrqMgrClient* lastIter = NULL;
OSIntMask prevInt;

LogUtils_CheckNullPointer("this", this, __FILE__, __LINE__);
LogUtils_CheckNullPointer("c", c, __FILE__, __LINE__);
LOG_CHECK_NULL_POINTER("this", this);
LOG_CHECK_NULL_POINTER("c", c);

prevInt = osSetIntMask(1);

Expand Down Expand Up @@ -214,8 +214,8 @@ void IrqMgr_ThreadEntry(void* arg0) {
}

void IrqMgr_Init(IrqMgr* this, void* stack, OSPri pri, u8 retraceCount) {
LogUtils_CheckNullPointer("this", this, __FILE__, __LINE__);
LogUtils_CheckNullPointer("stack", stack, __FILE__, __LINE__);
LOG_CHECK_NULL_POINTER("this", this);
LOG_CHECK_NULL_POINTER("stack", stack);

this->clients = NULL;
this->retraceMsg.type = OS_SC_RETRACE_MSG;
Expand Down
8 changes: 4 additions & 4 deletions soh/src/code/mtxuty-cvt.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ void MtxConv_F2L(Mtx* m1, MtxF* m2) {
s32 i;
s32 j;

LogUtils_CheckNullPointer("m1", m1, __FILE__, __LINE__);
LogUtils_CheckNullPointer("m2", m2, __FILE__, __LINE__);
LOG_CHECK_NULL_POINTER("m1", m1);
LOG_CHECK_NULL_POINTER("m2", m2);

for (i = 0; i < 4; i++) {
for (j = 0; j < 4; j++) {
Expand All @@ -18,7 +18,7 @@ void MtxConv_F2L(Mtx* m1, MtxF* m2) {
}

void MtxConv_L2F(MtxF* m1, Mtx* m2) {
LogUtils_CheckNullPointer("m1", m1, __FILE__, __LINE__);
LogUtils_CheckNullPointer("m2", m2, __FILE__, __LINE__);
LOG_CHECK_NULL_POINTER("m1", m1);
LOG_CHECK_NULL_POINTER("m2", m2);
guMtxL2F(m1, m2);
}
2 changes: 1 addition & 1 deletion soh/src/code/padmgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ void PadMgr_ThreadEntry(PadMgr* padMgr) {
}

osRecvMesg(&padMgr->interruptMsgQ, (OSMesg*)&mesg, OS_MESG_BLOCK);
//LogUtils_CheckNullPointer("msg", mesg);
//LOG_CHECK_NULL_POINTER("msg", mesg);

PadMgr_HandleRetraceMsg(padMgr);
break;
Expand Down
4 changes: 2 additions & 2 deletions soh/src/code/sched.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ OSTime sRDPStartTime;
void Sched_SwapFrameBuffer(CfbInfo* cfbInfo) {
u16 width;

LogUtils_CheckValidPointer("cfbinfo->swapbuffer", cfbInfo->swapBuffer, __FILE__, __LINE__);
LOG_CHECK_VALID_POINTER("cfbinfo->swapbuffer", cfbInfo->swapBuffer);
if (cfbInfo->swapBuffer != NULL) {
osViSwapBuffer(cfbInfo->swapBuffer);
cfbInfo->updateRate2 = cfbInfo->updateRate;
Expand Down Expand Up @@ -221,7 +221,7 @@ void func_800C8BC4(SchedContext* sc, OSScTask* task) {
if (sc->pendingSwapBuf1 == NULL) {
sc->pendingSwapBuf1 = task->framebuffer;

LogUtils_CheckValidPointer("sc->pending_swapbuffer1", sc->pendingSwapBuf1, __FILE__, __LINE__);
LOG_CHECK_VALID_POINTER("sc->pending_swapbuffer1", sc->pendingSwapBuf1);

if ((sc->curBuf == NULL) || (sc->curBuf->updateRate2 < 1)) {
func_800C84E4(sc, task->framebuffer);
Expand Down
2 changes: 1 addition & 1 deletion soh/src/code/speed_meter.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ SpeedMeterTimeEntry sSpeedMeterTimeEntryArray[] = {
gDPPipeSync(gfx);

void SpeedMeter_InitImpl(SpeedMeter* this, u32 arg1, u32 y) {
LogUtils_CheckNullPointer("this", this, __FILE__, __LINE__);
LOG_CHECK_NULL_POINTER("this", this);
this->unk_18 = arg1;
this->y = y;
}
Expand Down
2 changes: 1 addition & 1 deletion soh/src/code/sys_cfb.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ void SysCfb_Init(s32 n64dd) {
osSyncPrintf("RAM4M mode\n");
sSysCfbEnd = 0x80400000;
} else {
LogUtils_HungupThread("../sys_cfb.c", 354);
LOG_HUNGUP_THREAD();
}
*/

Expand Down
4 changes: 2 additions & 2 deletions soh/src/code/z_bgcheck.c
Original file line number Diff line number Diff line change
Expand Up @@ -1569,7 +1569,7 @@ void BgCheck_Allocate(CollisionContext* colCtx, GlobalContext* globalCtx, Collis
&globalCtx->state.tha,
colCtx->subdivAmount.x * sizeof(StaticLookup) * colCtx->subdivAmount.y * colCtx->subdivAmount.z, ~1);
if (colCtx->lookupTbl == NULL) {
LogUtils_HungupThread(__FILE__, __LINE__);
LOG_HUNGUP_THREAD();
}
colCtx->minBounds.x = colCtx->colHeader->minBounds.x;
colCtx->minBounds.y = colCtx->colHeader->minBounds.y;
Expand Down Expand Up @@ -1598,7 +1598,7 @@ void BgCheck_Allocate(CollisionContext* colCtx, GlobalContext* globalCtx, Collis
tblMax = customNodeListMax;
} else {
if (colCtx->memSize < memSize) {
LogUtils_HungupThread(__FILE__, __LINE__);
LOG_HUNGUP_THREAD();
}
tblMax = (colCtx->memSize - memSize) / sizeof(SSNode);
}
Expand Down
4 changes: 2 additions & 2 deletions soh/src/code/z_kaleido_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ KaleidoMgrOverlay* gKaleidoMgrCurOvl = NULL;
u8 gBossMarkState = 0;

void KaleidoManager_LoadOvl(KaleidoMgrOverlay* ovl) {
//LogUtils_CheckNullPointer("KaleidoArea_allocp", sKaleidoAreaPtr, __FILE__, __LINE__);
//LOG_CHECK_NULL_POINTER("KaleidoArea_allocp", sKaleidoAreaPtr);

ovl->loadedRamAddr = sKaleidoAreaPtr;
Overlay_Load(ovl->vromStart, ovl->vromEnd, ovl->vramStart, ovl->vramEnd, ovl->loadedRamAddr);
Expand Down Expand Up @@ -63,7 +63,7 @@ void KaleidoManager_Init(GlobalContext* globalCtx) {
osSyncPrintf(VT_RST);

sKaleidoAreaPtr = GameState_Alloc(&globalCtx->state, largestSize, __FILE__, __LINE__);
LogUtils_CheckNullPointer("KaleidoArea_allocp", sKaleidoAreaPtr, __FILE__, __LINE__);
LOG_CHECK_NULL_POINTER("KaleidoArea_allocp", sKaleidoAreaPtr);

osSyncPrintf(VT_FGCOL(GREEN));
osSyncPrintf("KaleidoArea %08x - %08x\n", sKaleidoAreaPtr, (uintptr_t)sKaleidoAreaPtr + largestSize);
Expand Down
2 changes: 1 addition & 1 deletion soh/src/code/z_map_mark.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void MapMark_Init(GlobalContext* globalCtx) {
u32 overlaySize = (uintptr_t)overlay->vramEnd - (uintptr_t)overlay->vramStart;

overlay->loadedRamAddr = GameState_Alloc(&globalCtx->state, overlaySize, __FILE__, __LINE__);
LogUtils_CheckNullPointer("dlftbl->allocp", overlay->loadedRamAddr, __FILE__, __LINE__);
LOG_CHECK_NULL_POINTER("dlftbl->allocp", overlay->loadedRamAddr);

Overlay_Load(overlay->vromStart, overlay->vromEnd, overlay->vramStart, overlay->vramEnd, overlay->loadedRamAddr);

Expand Down
4 changes: 2 additions & 2 deletions soh/src/code/z_room.c
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ BgImage* func_80096A74(PolygonType1* polygon1, GlobalContext* globalCtx) {

// "z_room.c: Data consistent with camera id does not exist camid=%d"
osSyncPrintf(VT_COL(RED, WHITE) "z_room.c:カメラIDに一致するデータが存在しません camid=%d\n" VT_RST, camId);
LogUtils_HungupThread(__FILE__, __LINE__);
LOG_HUNGUP_THREAD();

return NULL;
}
Expand Down Expand Up @@ -496,7 +496,7 @@ void func_80096F6C(GlobalContext* globalCtx, Room* room, u32 flags) {
} else if (polygon1->format == 2) {
func_80096B6C(globalCtx, room, flags);
} else {
LogUtils_HungupThread(__FILE__, __LINE__);
LOG_HUNGUP_THREAD();
}
}

Expand Down
Loading

0 comments on commit 4606929

Please sign in to comment.