All: Clean up how assertions are done

This commit is contained in:
Vicki Pfau 2024-06-20 02:20:36 -07:00
parent 2ea11feda6
commit 9318e9b2cb
10 changed files with 43 additions and 83 deletions

View File

@ -314,6 +314,26 @@ typedef intptr_t ssize_t;
#define ROR(I, ROTATE) ((((uint32_t) (I)) >> ROTATE) | ((uint32_t) (I) << ((-ROTATE) & 31))) #define ROR(I, ROTATE) ((((uint32_t) (I)) >> ROTATE) | ((uint32_t) (I) << ((-ROTATE) & 31)))
#define mASSERT(COND) \
if (!(COND)) { \
abort(); \
}
#define mASSERT_DEBUG(COND) assert((COND))
#define mASSERT_LOG(CAT, COND, ...) \
if (!(COND)) { \
mLOG(CAT, FATAL, __VA_ARGS__); \
}
#ifdef NDEBUG
#define mASSERT_DEBUG_LOG(...)
#else
#define mASSERT_DEBUG_LOG(CAT, COND, ...) \
if (!(COND)) { \
mLOG(CAT, FATAL, __VA_ARGS__); \
}
#endif
CXX_GUARD_END CXX_GUARD_END
#endif #endif

View File

@ -197,14 +197,8 @@ static void _regenerateTile256(struct mTileCache* cache, color_t* tile, unsigned
static inline color_t* _tileLookup(struct mTileCache* cache, unsigned tileId, unsigned paletteId) { static inline color_t* _tileLookup(struct mTileCache* cache, unsigned tileId, unsigned paletteId) {
if (mTileCacheConfigurationIsShouldStore(cache->config)) { if (mTileCacheConfigurationIsShouldStore(cache->config)) {
unsigned tiles = mTileCacheSystemInfoGetMaxTiles(cache->sysConfig); unsigned tiles = mTileCacheSystemInfoGetMaxTiles(cache->sysConfig);
#ifndef NDEBUG mASSERT(tileId < tiles);
if (tileId >= tiles) { mASSERT_DEBUG(paletteId < 1U << mTileCacheSystemInfoGetPaletteCount(cache->sysConfig));
abort();
}
if (paletteId >= 1U << mTileCacheSystemInfoGetPaletteCount(cache->sysConfig)) {
abort();
}
#endif
return &cache->cache[(tileId + paletteId * tiles) << 6]; return &cache->cache[(tileId + paletteId * tiles) << 6];
} else { } else {
return cache->temporaryTile; return cache->temporaryTile;

View File

@ -339,11 +339,7 @@ static void GBAProcessEvents(struct ARMCore* cpu) {
#ifdef ENABLE_DEBUGGERS #ifdef ENABLE_DEBUGGERS
gba->timing.globalCycles += cycles < nextEvent ? nextEvent : cycles; gba->timing.globalCycles += cycles < nextEvent ? nextEvent : cycles;
#endif #endif
#ifndef NDEBUG mASSERT_DEBUG_LOG(GBA, cycles >= 0, "Negative cycles passed: %i", cycles);
if (cycles < 0) {
mLOG(GBA, FATAL, "Negative cycles passed: %i", cycles);
}
#endif
nextEvent = mTimingTick(&gba->timing, cycles < nextEvent ? nextEvent : cycles); nextEvent = mTimingTick(&gba->timing, cycles < nextEvent ? nextEvent : cycles);
} while (gba->cpuBlocked && !gba->earlyExit); } while (gba->cpuBlocked && !gba->earlyExit);
@ -353,12 +349,9 @@ static void GBAProcessEvents(struct ARMCore* cpu) {
if (!gba->memory.io[GBA_REG(IME)] || !gba->memory.io[GBA_REG(IE)]) { if (!gba->memory.io[GBA_REG(IME)] || !gba->memory.io[GBA_REG(IE)]) {
break; break;
} }
} else {
mASSERT_DEBUG_LOG(GBA, nextEvent >= 0, "Negative cycles will pass: %i", nextEvent);
} }
#ifndef NDEBUG
else if (nextEvent < 0) {
mLOG(GBA, FATAL, "Negative cycles will pass: %i", nextEvent);
}
#endif
if (gba->earlyExit) { if (gba->earlyExit) {
break; break;
} }

View File

@ -157,10 +157,8 @@ static struct mScriptValue* mScriptCanvasLayerCreate(struct mScriptCanvasContext
} }
struct mScriptCanvasLayer* layer = &context->overlays[next]; struct mScriptCanvasLayer* layer = &context->overlays[next];
if (layer->image) {
// This shouldn't exist yet // This shouldn't exist yet
abort(); mASSERT(!layer->image);
}
layer->image = mImageCreate(w, h, mCOLOR_ABGR8); layer->image = mImageCreate(w, h, mCOLOR_ABGR8);
layer->dirty = true; layer->dirty = true;

View File

@ -458,9 +458,7 @@ bool mScriptContextActivate(struct mScriptContext* context) {
void mScriptContextDeactivate(struct mScriptContext* context) { void mScriptContextDeactivate(struct mScriptContext* context) {
#ifndef NDEBUG #ifndef NDEBUG
struct mScriptContext* threadContext = ThreadLocalGetValue(_threadContext); struct mScriptContext* threadContext = ThreadLocalGetValue(_threadContext);
if (threadContext != context) { mASSERT(threadContext == context);
abort();
}
#endif #endif
--context->threadDepth; --context->threadDepth;

View File

@ -895,9 +895,8 @@ struct mScriptValue* mScriptValueAlloc(const struct mScriptType* type) {
} }
void mScriptValueRef(struct mScriptValue* val) { void mScriptValueRef(struct mScriptValue* val) {
if (val->refs == INT_MAX) { mASSERT(val->refs != INT_MAX);
abort(); if (val->refs == mSCRIPT_VALUE_UNREF) {
} else if (val->refs == mSCRIPT_VALUE_UNREF) {
return; return;
} }
++val->refs; ++val->refs;
@ -1238,12 +1237,8 @@ static void _mScriptClassInit(struct mScriptTypeClass* cls, const struct mScript
member->docstring = docstring; member->docstring = docstring;
docstring = NULL; docstring = NULL;
} }
if (detail->info.member.type->base != mSCRIPT_TYPE_FUNCTION) { mASSERT(detail->info.member.type->base == mSCRIPT_TYPE_FUNCTION);
abort(); mASSERT(detail->info.member.type->details.function.parameters.count == 3);
}
if (detail->info.member.type->details.function.parameters.count != 3) {
abort();
}
HashTableInsert(&cls->setters, detail->info.member.type->details.function.parameters.entries[2]->name, member); HashTableInsert(&cls->setters, detail->info.member.type->details.function.parameters.entries[2]->name, member);
break; break;
case mSCRIPT_CLASS_INIT_INTERNAL: case mSCRIPT_CLASS_INIT_INTERNAL:

View File

@ -77,9 +77,7 @@ size_t mAudioResamplerProcess(struct mAudioResampler* resampler) {
}; };
size_t read = 0; size_t read = 0;
if (resampler->source->channels > MAX_CHANNELS) { mASSERT(resampler->source->channels <= MAX_CHANNELS);
abort();
}
while (true) { while (true) {
if (timestamp + resampler->highWaterMark >= mAudioBufferAvailable(resampler->source)) { if (timestamp + resampler->highWaterMark >= mAudioBufferAvailable(resampler->source)) {

View File

@ -59,11 +59,7 @@ int mCircleBufferWrite8(struct mCircleBuffer* buffer, int8_t value) {
buffer->writePtr = buffer->data; buffer->writePtr = buffer->data;
} }
buffer->size += sizeof(int8_t); buffer->size += sizeof(int8_t);
#ifndef NDEBUG mASSERT_DEBUG(_checkIntegrity(buffer));
if (!_checkIntegrity(buffer)) {
abort();
}
#endif
return 1; return 1;
} }
@ -89,11 +85,7 @@ int mCircleBufferWrite32(struct mCircleBuffer* buffer, int32_t value) {
buffer->writePtr = buffer->data; buffer->writePtr = buffer->data;
} }
buffer->size += sizeof(int32_t); buffer->size += sizeof(int32_t);
#ifndef NDEBUG mASSERT_DEBUG(_checkIntegrity(buffer));
if (!_checkIntegrity(buffer)) {
abort();
}
#endif
return 4; return 4;
} }
@ -117,11 +109,7 @@ int mCircleBufferWrite16(struct mCircleBuffer* buffer, int16_t value) {
buffer->writePtr = buffer->data; buffer->writePtr = buffer->data;
} }
buffer->size += sizeof(int16_t); buffer->size += sizeof(int16_t);
#ifndef NDEBUG mASSERT_DEBUG(_checkIntegrity(buffer));
if (!_checkIntegrity(buffer)) {
abort();
}
#endif
return 2; return 2;
} }
@ -145,11 +133,7 @@ size_t mCircleBufferWrite(struct mCircleBuffer* buffer, const void* input, size_
} }
buffer->size += length; buffer->size += length;
#ifndef NDEBUG mASSERT_DEBUG(_checkIntegrity(buffer));
if (!_checkIntegrity(buffer)) {
abort();
}
#endif
return length; return length;
} }
@ -174,11 +158,7 @@ int mCircleBufferRead8(struct mCircleBuffer* buffer, int8_t* value) {
buffer->readPtr = buffer->data; buffer->readPtr = buffer->data;
} }
buffer->size -= sizeof(int8_t); buffer->size -= sizeof(int8_t);
#ifndef NDEBUG mASSERT_DEBUG(_checkIntegrity(buffer));
if (!_checkIntegrity(buffer)) {
abort();
}
#endif
return 1; return 1;
} }
@ -202,11 +182,7 @@ int mCircleBufferRead16(struct mCircleBuffer* buffer, int16_t* value) {
buffer->readPtr = buffer->data; buffer->readPtr = buffer->data;
} }
buffer->size -= sizeof(int16_t); buffer->size -= sizeof(int16_t);
#ifndef NDEBUG mASSERT_DEBUG(_checkIntegrity(buffer));
if (!_checkIntegrity(buffer)) {
abort();
}
#endif
return 2; return 2;
} }
@ -232,11 +208,7 @@ int mCircleBufferRead32(struct mCircleBuffer* buffer, int32_t* value) {
buffer->readPtr = buffer->data; buffer->readPtr = buffer->data;
} }
buffer->size -= sizeof(int32_t); buffer->size -= sizeof(int32_t);
#ifndef NDEBUG mASSERT_DEBUG(_checkIntegrity(buffer));
if (!_checkIntegrity(buffer)) {
abort();
}
#endif
return 4; return 4;
} }
@ -267,11 +239,7 @@ size_t mCircleBufferRead(struct mCircleBuffer* buffer, void* output, size_t leng
} }
buffer->size -= length; buffer->size -= length;
#ifndef NDEBUG mASSERT_DEBUG(_checkIntegrity(buffer));
if (!_checkIntegrity(buffer)) {
abort();
}
#endif
return length; return length;
} }

View File

@ -209,9 +209,7 @@ bool SfoWrite(struct Table* sfo, struct VFile* vf) {
} }
} }
if (keysSize != ALIGN4(keysOffset) || dataSize != dataOffset) { mASSERT(keysSize == ALIGN4(keysOffset) && dataSize == dataOffset);
abort();
}
free(sortedEntries); free(sortedEntries);

View File

@ -309,9 +309,7 @@ ssize_t _vfzRead(struct VFile* vf, void* buffer, size_t size) {
if (!vfz->buffer) { if (!vfz->buffer) {
vfz->bufferSize = BLOCK_SIZE; vfz->bufferSize = BLOCK_SIZE;
vfz->buffer = malloc(BLOCK_SIZE); vfz->buffer = malloc(BLOCK_SIZE);
if (vfz->readSize) { mASSERT(!vfz->readSize);
abort();
}
} }
while (bytesRead < size) { while (bytesRead < size) {