mirror of https://github.com/mgba-emu/mgba.git
All: Clean up how assertions are done
This commit is contained in:
parent
2ea11feda6
commit
9318e9b2cb
|
@ -314,6 +314,26 @@ typedef intptr_t ssize_t;
|
|||
|
||||
#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
|
||||
|
||||
#endif
|
||||
|
|
|
@ -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) {
|
||||
if (mTileCacheConfigurationIsShouldStore(cache->config)) {
|
||||
unsigned tiles = mTileCacheSystemInfoGetMaxTiles(cache->sysConfig);
|
||||
#ifndef NDEBUG
|
||||
if (tileId >= tiles) {
|
||||
abort();
|
||||
}
|
||||
if (paletteId >= 1U << mTileCacheSystemInfoGetPaletteCount(cache->sysConfig)) {
|
||||
abort();
|
||||
}
|
||||
#endif
|
||||
mASSERT(tileId < tiles);
|
||||
mASSERT_DEBUG(paletteId < 1U << mTileCacheSystemInfoGetPaletteCount(cache->sysConfig));
|
||||
return &cache->cache[(tileId + paletteId * tiles) << 6];
|
||||
} else {
|
||||
return cache->temporaryTile;
|
||||
|
|
|
@ -339,11 +339,7 @@ static void GBAProcessEvents(struct ARMCore* cpu) {
|
|||
#ifdef ENABLE_DEBUGGERS
|
||||
gba->timing.globalCycles += cycles < nextEvent ? nextEvent : cycles;
|
||||
#endif
|
||||
#ifndef NDEBUG
|
||||
if (cycles < 0) {
|
||||
mLOG(GBA, FATAL, "Negative cycles passed: %i", cycles);
|
||||
}
|
||||
#endif
|
||||
mASSERT_DEBUG_LOG(GBA, cycles >= 0, "Negative cycles passed: %i", cycles);
|
||||
nextEvent = mTimingTick(&gba->timing, cycles < nextEvent ? nextEvent : cycles);
|
||||
} 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)]) {
|
||||
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) {
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -157,10 +157,8 @@ static struct mScriptValue* mScriptCanvasLayerCreate(struct mScriptCanvasContext
|
|||
}
|
||||
|
||||
struct mScriptCanvasLayer* layer = &context->overlays[next];
|
||||
if (layer->image) {
|
||||
// This shouldn't exist yet
|
||||
abort();
|
||||
}
|
||||
// This shouldn't exist yet
|
||||
mASSERT(!layer->image);
|
||||
|
||||
layer->image = mImageCreate(w, h, mCOLOR_ABGR8);
|
||||
layer->dirty = true;
|
||||
|
|
|
@ -458,9 +458,7 @@ bool mScriptContextActivate(struct mScriptContext* context) {
|
|||
void mScriptContextDeactivate(struct mScriptContext* context) {
|
||||
#ifndef NDEBUG
|
||||
struct mScriptContext* threadContext = ThreadLocalGetValue(_threadContext);
|
||||
if (threadContext != context) {
|
||||
abort();
|
||||
}
|
||||
mASSERT(threadContext == context);
|
||||
#endif
|
||||
|
||||
--context->threadDepth;
|
||||
|
|
|
@ -895,9 +895,8 @@ struct mScriptValue* mScriptValueAlloc(const struct mScriptType* type) {
|
|||
}
|
||||
|
||||
void mScriptValueRef(struct mScriptValue* val) {
|
||||
if (val->refs == INT_MAX) {
|
||||
abort();
|
||||
} else if (val->refs == mSCRIPT_VALUE_UNREF) {
|
||||
mASSERT(val->refs != INT_MAX);
|
||||
if (val->refs == mSCRIPT_VALUE_UNREF) {
|
||||
return;
|
||||
}
|
||||
++val->refs;
|
||||
|
@ -1238,12 +1237,8 @@ static void _mScriptClassInit(struct mScriptTypeClass* cls, const struct mScript
|
|||
member->docstring = docstring;
|
||||
docstring = NULL;
|
||||
}
|
||||
if (detail->info.member.type->base != mSCRIPT_TYPE_FUNCTION) {
|
||||
abort();
|
||||
}
|
||||
if (detail->info.member.type->details.function.parameters.count != 3) {
|
||||
abort();
|
||||
}
|
||||
mASSERT(detail->info.member.type->base == mSCRIPT_TYPE_FUNCTION);
|
||||
mASSERT(detail->info.member.type->details.function.parameters.count == 3);
|
||||
HashTableInsert(&cls->setters, detail->info.member.type->details.function.parameters.entries[2]->name, member);
|
||||
break;
|
||||
case mSCRIPT_CLASS_INIT_INTERNAL:
|
||||
|
|
|
@ -77,9 +77,7 @@ size_t mAudioResamplerProcess(struct mAudioResampler* resampler) {
|
|||
};
|
||||
|
||||
size_t read = 0;
|
||||
if (resampler->source->channels > MAX_CHANNELS) {
|
||||
abort();
|
||||
}
|
||||
mASSERT(resampler->source->channels <= MAX_CHANNELS);
|
||||
|
||||
while (true) {
|
||||
if (timestamp + resampler->highWaterMark >= mAudioBufferAvailable(resampler->source)) {
|
||||
|
|
|
@ -59,11 +59,7 @@ int mCircleBufferWrite8(struct mCircleBuffer* buffer, int8_t value) {
|
|||
buffer->writePtr = buffer->data;
|
||||
}
|
||||
buffer->size += sizeof(int8_t);
|
||||
#ifndef NDEBUG
|
||||
if (!_checkIntegrity(buffer)) {
|
||||
abort();
|
||||
}
|
||||
#endif
|
||||
mASSERT_DEBUG(_checkIntegrity(buffer));
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -89,11 +85,7 @@ int mCircleBufferWrite32(struct mCircleBuffer* buffer, int32_t value) {
|
|||
buffer->writePtr = buffer->data;
|
||||
}
|
||||
buffer->size += sizeof(int32_t);
|
||||
#ifndef NDEBUG
|
||||
if (!_checkIntegrity(buffer)) {
|
||||
abort();
|
||||
}
|
||||
#endif
|
||||
mASSERT_DEBUG(_checkIntegrity(buffer));
|
||||
return 4;
|
||||
}
|
||||
|
||||
|
@ -117,11 +109,7 @@ int mCircleBufferWrite16(struct mCircleBuffer* buffer, int16_t value) {
|
|||
buffer->writePtr = buffer->data;
|
||||
}
|
||||
buffer->size += sizeof(int16_t);
|
||||
#ifndef NDEBUG
|
||||
if (!_checkIntegrity(buffer)) {
|
||||
abort();
|
||||
}
|
||||
#endif
|
||||
mASSERT_DEBUG(_checkIntegrity(buffer));
|
||||
return 2;
|
||||
}
|
||||
|
||||
|
@ -145,11 +133,7 @@ size_t mCircleBufferWrite(struct mCircleBuffer* buffer, const void* input, size_
|
|||
}
|
||||
|
||||
buffer->size += length;
|
||||
#ifndef NDEBUG
|
||||
if (!_checkIntegrity(buffer)) {
|
||||
abort();
|
||||
}
|
||||
#endif
|
||||
mASSERT_DEBUG(_checkIntegrity(buffer));
|
||||
return length;
|
||||
}
|
||||
|
||||
|
@ -174,11 +158,7 @@ int mCircleBufferRead8(struct mCircleBuffer* buffer, int8_t* value) {
|
|||
buffer->readPtr = buffer->data;
|
||||
}
|
||||
buffer->size -= sizeof(int8_t);
|
||||
#ifndef NDEBUG
|
||||
if (!_checkIntegrity(buffer)) {
|
||||
abort();
|
||||
}
|
||||
#endif
|
||||
mASSERT_DEBUG(_checkIntegrity(buffer));
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -202,11 +182,7 @@ int mCircleBufferRead16(struct mCircleBuffer* buffer, int16_t* value) {
|
|||
buffer->readPtr = buffer->data;
|
||||
}
|
||||
buffer->size -= sizeof(int16_t);
|
||||
#ifndef NDEBUG
|
||||
if (!_checkIntegrity(buffer)) {
|
||||
abort();
|
||||
}
|
||||
#endif
|
||||
mASSERT_DEBUG(_checkIntegrity(buffer));
|
||||
return 2;
|
||||
}
|
||||
|
||||
|
@ -232,11 +208,7 @@ int mCircleBufferRead32(struct mCircleBuffer* buffer, int32_t* value) {
|
|||
buffer->readPtr = buffer->data;
|
||||
}
|
||||
buffer->size -= sizeof(int32_t);
|
||||
#ifndef NDEBUG
|
||||
if (!_checkIntegrity(buffer)) {
|
||||
abort();
|
||||
}
|
||||
#endif
|
||||
mASSERT_DEBUG(_checkIntegrity(buffer));
|
||||
return 4;
|
||||
}
|
||||
|
||||
|
@ -267,11 +239,7 @@ size_t mCircleBufferRead(struct mCircleBuffer* buffer, void* output, size_t leng
|
|||
}
|
||||
|
||||
buffer->size -= length;
|
||||
#ifndef NDEBUG
|
||||
if (!_checkIntegrity(buffer)) {
|
||||
abort();
|
||||
}
|
||||
#endif
|
||||
mASSERT_DEBUG(_checkIntegrity(buffer));
|
||||
return length;
|
||||
}
|
||||
|
||||
|
|
|
@ -209,9 +209,7 @@ bool SfoWrite(struct Table* sfo, struct VFile* vf) {
|
|||
}
|
||||
}
|
||||
|
||||
if (keysSize != ALIGN4(keysOffset) || dataSize != dataOffset) {
|
||||
abort();
|
||||
}
|
||||
mASSERT(keysSize == ALIGN4(keysOffset) && dataSize == dataOffset);
|
||||
|
||||
free(sortedEntries);
|
||||
|
||||
|
|
|
@ -309,9 +309,7 @@ ssize_t _vfzRead(struct VFile* vf, void* buffer, size_t size) {
|
|||
if (!vfz->buffer) {
|
||||
vfz->bufferSize = BLOCK_SIZE;
|
||||
vfz->buffer = malloc(BLOCK_SIZE);
|
||||
if (vfz->readSize) {
|
||||
abort();
|
||||
}
|
||||
mASSERT(!vfz->readSize);
|
||||
}
|
||||
|
||||
while (bytesRead < size) {
|
||||
|
|
Loading…
Reference in New Issue