Add status panic codes for ref-count errors

This commit is contained in:
Michal Moskal 2015-10-25 12:59:45 -07:00
parent 85b4e45863
commit 98ffcc1fd1
2 changed files with 9 additions and 3 deletions

View file

@ -22,6 +22,12 @@ enum Error{
MICROBIT_OOM = 20,
// Corruption detected in the micro:bit heap space
MICROBIT_HEAP_ERROR = 30
MICROBIT_HEAP_ERROR = 30,
// refcounter on an object is invalid (memory corruption)
MICROBIT_REF_COUNT_CORRUPTION = 31,
// refcounter was incremented/decremented after it already reached zero
MICROBIT_USE_AFTER_FREE = 32,
};
#endif

View file

@ -16,10 +16,10 @@ static inline bool isReadOnlyInline(RefCounted *t)
// Do some sanity checking while we're here
if (refCount == 1)
uBit.panic(30); // object should have been deleted
uBit.panic(MICROBIT_USE_AFTER_FREE); // object should have been deleted
if ((refCount & 1) == 0)
uBit.panic(31); // refCount doesn't look right
uBit.panic(MICROBIT_REF_COUNT_CORRUPTION); // refCount doesn't look right
// Not read only
return false;