split debug_assert into ENSURE and ASSERT as discussed in a previous meeting.
the old debug_assert always ran and tested the expression, which slows down release builds. wrapping them in #ifndef NDEBUG is clumsy. the new ASSERT behaves like assert and ENSURE like the old debug_assert. Let's change any time-critical but not-super-important ENSURE to ASSERT to speed up release builds. (already done in bits.h and unique_range.h) This was SVN commit r9362.
This commit is contained in:
parent
6c915291cc
commit
4663ac0fe7
@ -260,7 +260,7 @@ CCinemaManager::CCinemaManager() : m_DrawCurrentSpline(false), m_Active(true), m
|
|||||||
|
|
||||||
void CCinemaManager::AddPath(CCinemaPath path, const CStrW& name)
|
void CCinemaManager::AddPath(CCinemaPath path, const CStrW& name)
|
||||||
{
|
{
|
||||||
debug_assert( m_Paths.find( name ) == m_Paths.end() );
|
ENSURE( m_Paths.find( name ) == m_Paths.end() );
|
||||||
m_Paths[name] = path;
|
m_Paths[name] = path;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -272,7 +272,7 @@ void CCinemaManager::QueuePath(const CStrW& name, bool queue )
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
debug_assert(HasTrack(name));
|
ENSURE(HasTrack(name));
|
||||||
m_PathQueue.push_back(m_Paths[name]);
|
m_PathQueue.push_back(m_Paths[name]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -280,7 +280,7 @@ void CCinemaManager::QueuePath(const CStrW& name, bool queue )
|
|||||||
void CCinemaManager::OverridePath(const CStrW& name)
|
void CCinemaManager::OverridePath(const CStrW& name)
|
||||||
{
|
{
|
||||||
m_PathQueue.clear();
|
m_PathQueue.clear();
|
||||||
debug_assert(HasTrack(name));
|
ENSURE(HasTrack(name));
|
||||||
m_PathQueue.push_back( m_Paths[name] );
|
m_PathQueue.push_back( m_Paths[name] );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -318,7 +318,7 @@ void CCinemaManager::DrawSpline() const
|
|||||||
|
|
||||||
void CCinemaManager::MoveToPointAt(float time)
|
void CCinemaManager::MoveToPointAt(float time)
|
||||||
{
|
{
|
||||||
debug_assert(m_CurrentPath != m_Paths.end());
|
ENSURE(m_CurrentPath != m_Paths.end());
|
||||||
StopPlaying();
|
StopPlaying();
|
||||||
|
|
||||||
m_CurrentPath->second.m_TimeElapsed = time;
|
m_CurrentPath->second.m_TimeElapsed = time;
|
||||||
|
@ -148,7 +148,7 @@ public:
|
|||||||
if(writeBuffer.Size())
|
if(writeBuffer.Size())
|
||||||
{
|
{
|
||||||
LibError ret = g_VFS->CreateFile(pmdFilename, writeBuffer.Data(), writeBuffer.Size());
|
LibError ret = g_VFS->CreateFile(pmdFilename, writeBuffer.Data(), writeBuffer.Size());
|
||||||
debug_assert(ret == INFO::OK);
|
ENSURE(ret == INFO::OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -242,7 +242,7 @@ VfsPath CColladaManager::GetLoadableFilename(const VfsPath& pathnameNoExtension,
|
|||||||
// realDaePath_ is "[..]/mods/whatever/art/meshes/whatever.dae"
|
// realDaePath_ is "[..]/mods/whatever/art/meshes/whatever.dae"
|
||||||
OsPath realDaePath_;
|
OsPath realDaePath_;
|
||||||
LibError ret = g_VFS->GetRealPath(dae, realDaePath_);
|
LibError ret = g_VFS->GetRealPath(dae, realDaePath_);
|
||||||
debug_assert(ret == INFO::OK);
|
ENSURE(ret == INFO::OK);
|
||||||
wchar_t realDaeBuf[PATH_MAX];
|
wchar_t realDaeBuf[PATH_MAX];
|
||||||
wcscpy_s(realDaeBuf, ARRAY_SIZE(realDaeBuf), realDaePath_.string().c_str());
|
wcscpy_s(realDaeBuf, ARRAY_SIZE(realDaeBuf), realDaePath_.string().c_str());
|
||||||
const wchar_t* realDaePath = wcsstr(realDaeBuf, L"mods/");
|
const wchar_t* realDaePath = wcsstr(realDaeBuf, L"mods/");
|
||||||
|
@ -78,7 +78,7 @@ void CModelDecal::ValidatePosition()
|
|||||||
{
|
{
|
||||||
if (m_PositionValid)
|
if (m_PositionValid)
|
||||||
{
|
{
|
||||||
debug_assert(!m_Parent || m_Parent->m_PositionValid);
|
ENSURE(!m_Parent || m_Parent->m_PositionValid);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,7 +89,7 @@ void CModelDecal::ValidatePosition()
|
|||||||
m_Parent->ValidatePosition();
|
m_Parent->ValidatePosition();
|
||||||
|
|
||||||
// Parent will recursively call our validation.
|
// Parent will recursively call our validation.
|
||||||
debug_assert(m_PositionValid);
|
ENSURE(m_PositionValid);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,13 +91,13 @@ GLuint CLOSTexture::GetTexture()
|
|||||||
|
|
||||||
const float* CLOSTexture::GetTextureMatrix()
|
const float* CLOSTexture::GetTextureMatrix()
|
||||||
{
|
{
|
||||||
debug_assert(!m_Dirty);
|
ENSURE(!m_Dirty);
|
||||||
return &m_TextureMatrix._11;
|
return &m_TextureMatrix._11;
|
||||||
}
|
}
|
||||||
|
|
||||||
const float* CLOSTexture::GetMinimapTextureMatrix()
|
const float* CLOSTexture::GetMinimapTextureMatrix()
|
||||||
{
|
{
|
||||||
debug_assert(!m_Dirty);
|
ENSURE(!m_Dirty);
|
||||||
return &m_MinimapTextureMatrix._11;
|
return &m_MinimapTextureMatrix._11;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@ void CMapGeneratorWorker::Initialize(const VfsPath& scriptFile, const std::strin
|
|||||||
|
|
||||||
// Launch the worker thread
|
// Launch the worker thread
|
||||||
int ret = pthread_create(&m_WorkerThread, NULL, &RunThread, this);
|
int ret = pthread_create(&m_WorkerThread, NULL, &RunThread, this);
|
||||||
debug_assert(ret == 0);
|
ENSURE(ret == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void* CMapGeneratorWorker::RunThread(void *data)
|
void* CMapGeneratorWorker::RunThread(void *data)
|
||||||
|
@ -228,7 +228,7 @@ int CMapReader::UnpackTerrain()
|
|||||||
CStr texturename;
|
CStr texturename;
|
||||||
unpacker.UnpackString(texturename);
|
unpacker.UnpackString(texturename);
|
||||||
|
|
||||||
debug_assert(CTerrainTextureManager::IsInitialised()); // we need this for the terrain properties (even when graphics are disabled)
|
ENSURE(CTerrainTextureManager::IsInitialised()); // we need this for the terrain properties (even when graphics are disabled)
|
||||||
CTerrainTextureEntry* texentry = g_TexMan.FindTexture(texturename);
|
CTerrainTextureEntry* texentry = g_TexMan.FindTexture(texturename);
|
||||||
m_TerrainTextures.push_back(texentry);
|
m_TerrainTextures.push_back(texentry);
|
||||||
|
|
||||||
@ -327,7 +327,7 @@ PSRETURN CMapSummaryReader::LoadMap(const VfsPath& pathname)
|
|||||||
#undef EL
|
#undef EL
|
||||||
|
|
||||||
XMBElement root = xmb_file.GetRoot();
|
XMBElement root = xmb_file.GetRoot();
|
||||||
debug_assert(root.GetNodeName() == el_scenario);
|
ENSURE(root.GetNodeName() == el_scenario);
|
||||||
|
|
||||||
XERO_ITER_EL(root, child)
|
XERO_ITER_EL(root, child)
|
||||||
{
|
{
|
||||||
@ -440,7 +440,7 @@ void CXMLReader::Init(const VfsPath& xml_filename)
|
|||||||
#undef EL
|
#undef EL
|
||||||
|
|
||||||
XMBElement root = xmb_file.GetRoot();
|
XMBElement root = xmb_file.GetRoot();
|
||||||
debug_assert(xmb_file.GetElementString(root.GetNodeName()) == "Scenario");
|
ENSURE(xmb_file.GetElementString(root.GetNodeName()) == "Scenario");
|
||||||
nodes = root.GetChildNodes();
|
nodes = root.GetChildNodes();
|
||||||
|
|
||||||
// find out total number of entities+nonentities
|
// find out total number of entities+nonentities
|
||||||
@ -466,7 +466,7 @@ void CXMLReader::Init(const VfsPath& xml_filename)
|
|||||||
CStr CXMLReader::ReadScriptSettings()
|
CStr CXMLReader::ReadScriptSettings()
|
||||||
{
|
{
|
||||||
XMBElement root = xmb_file.GetRoot();
|
XMBElement root = xmb_file.GetRoot();
|
||||||
debug_assert(xmb_file.GetElementString(root.GetNodeName()) == "Scenario");
|
ENSURE(xmb_file.GetElementString(root.GetNodeName()) == "Scenario");
|
||||||
nodes = root.GetChildNodes();
|
nodes = root.GetChildNodes();
|
||||||
|
|
||||||
XMBElement settings = nodes.GetFirstNamedItem(xmb_file.GetElementID("ScriptSettings"));
|
XMBElement settings = nodes.GetFirstNamedItem(xmb_file.GetElementID("ScriptSettings"));
|
||||||
@ -504,7 +504,7 @@ void CXMLReader::ReadTerrain(XMBElement parent)
|
|||||||
m_MapReader.m_PatchesPerSide = patches;
|
m_MapReader.m_PatchesPerSide = patches;
|
||||||
|
|
||||||
// Load the texture
|
// Load the texture
|
||||||
debug_assert(CTerrainTextureManager::IsInitialised()); // we need this for the terrain properties (even when graphics are disabled)
|
ENSURE(CTerrainTextureManager::IsInitialised()); // we need this for the terrain properties (even when graphics are disabled)
|
||||||
CTerrainTextureEntry* texentry = g_TexMan.FindTexture(texture);
|
CTerrainTextureEntry* texentry = g_TexMan.FindTexture(texture);
|
||||||
|
|
||||||
m_MapReader.pTerrain->Initialize(patches, NULL);
|
m_MapReader.pTerrain->Initialize(patches, NULL);
|
||||||
@ -613,14 +613,14 @@ void CXMLReader::ReadEnvironment(XMBElement parent)
|
|||||||
{
|
{
|
||||||
XERO_ITER_EL(element, waterbody)
|
XERO_ITER_EL(element, waterbody)
|
||||||
{
|
{
|
||||||
debug_assert(waterbody.GetNodeName() == el_waterbody);
|
ENSURE(waterbody.GetNodeName() == el_waterbody);
|
||||||
XERO_ITER_EL(waterbody, waterelement)
|
XERO_ITER_EL(waterbody, waterelement)
|
||||||
{
|
{
|
||||||
int element_name = waterelement.GetNodeName();
|
int element_name = waterelement.GetNodeName();
|
||||||
if (element_name == el_height)
|
if (element_name == el_height)
|
||||||
{
|
{
|
||||||
CmpPtr<ICmpWaterManager> cmpWaterMan(*m_MapReader.pSimulation2, SYSTEM_ENTITY);
|
CmpPtr<ICmpWaterManager> cmpWaterMan(*m_MapReader.pSimulation2, SYSTEM_ENTITY);
|
||||||
debug_assert(!cmpWaterMan.null());
|
ENSURE(!cmpWaterMan.null());
|
||||||
cmpWaterMan->SetWaterLevel(entity_pos_t::FromString(waterelement.GetText()));
|
cmpWaterMan->SetWaterLevel(entity_pos_t::FromString(waterelement.GetText()));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -832,7 +832,7 @@ void CXMLReader::ReadCinema(XMBElement parent)
|
|||||||
pathList[name] = path;
|
pathList[name] = path;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
debug_assert("Invalid cinema child");
|
ENSURE("Invalid cinema child");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_MapReader.pCinema)
|
if (m_MapReader.pCinema)
|
||||||
@ -853,11 +853,11 @@ int CXMLReader::ReadEntities(XMBElement parent, double end_time)
|
|||||||
// wrapped, since we only yield after a complete iteration.
|
// wrapped, since we only yield after a complete iteration.
|
||||||
|
|
||||||
XMBElement entity = entities.Item(entity_idx++);
|
XMBElement entity = entities.Item(entity_idx++);
|
||||||
debug_assert(entity.GetNodeName() == el_entity);
|
ENSURE(entity.GetNodeName() == el_entity);
|
||||||
|
|
||||||
XMBAttributeList attrs = entity.GetAttributes();
|
XMBAttributeList attrs = entity.GetAttributes();
|
||||||
CStr uid = attrs.GetNamedItem(at_uid);
|
CStr uid = attrs.GetNamedItem(at_uid);
|
||||||
debug_assert(!uid.empty());
|
ENSURE(!uid.empty());
|
||||||
int EntityUid = uid.ToInt();
|
int EntityUid = uid.ToInt();
|
||||||
|
|
||||||
CStrW TemplateName;
|
CStrW TemplateName;
|
||||||
@ -1142,7 +1142,7 @@ int CMapReader::ParseTerrain()
|
|||||||
|
|
||||||
while (cur_terrain_tex < num_terrain_tex)
|
while (cur_terrain_tex < num_terrain_tex)
|
||||||
{
|
{
|
||||||
debug_assert(CTerrainTextureManager::IsInitialised()); // we need this for the terrain properties (even when graphics are disabled)
|
ENSURE(CTerrainTextureManager::IsInitialised()); // we need this for the terrain properties (even when graphics are disabled)
|
||||||
CTerrainTextureEntry* texentry = g_TexMan.FindTexture(textureNames[cur_terrain_tex]);
|
CTerrainTextureEntry* texentry = g_TexMan.FindTexture(textureNames[cur_terrain_tex]);
|
||||||
m_TerrainTextures.push_back(texentry);
|
m_TerrainTextures.push_back(texentry);
|
||||||
|
|
||||||
@ -1156,7 +1156,7 @@ int CMapReader::ParseTerrain()
|
|||||||
std::vector<CMapIO::STileDesc> tileData;
|
std::vector<CMapIO::STileDesc> tileData;
|
||||||
GET_TERRAIN_PROPERTY(tileData, tileData)
|
GET_TERRAIN_PROPERTY(tileData, tileData)
|
||||||
|
|
||||||
debug_assert(SQR(size) == tileData.size());
|
ENSURE(SQR(size) == tileData.size());
|
||||||
|
|
||||||
// reorder by patches and store
|
// reorder by patches and store
|
||||||
for (size_t x = 0; x < size; ++x)
|
for (size_t x = 0; x < size; ++x)
|
||||||
@ -1287,7 +1287,7 @@ int CMapReader::ParseEnvironment()
|
|||||||
GET_ENVIRONMENT_PROPERTY(waterBodyObj.get(), Height, waterHeight)
|
GET_ENVIRONMENT_PROPERTY(waterBodyObj.get(), Height, waterHeight)
|
||||||
|
|
||||||
CmpPtr<ICmpWaterManager> cmpWaterMan(*pSimulation2, SYSTEM_ENTITY);
|
CmpPtr<ICmpWaterManager> cmpWaterMan(*pSimulation2, SYSTEM_ENTITY);
|
||||||
debug_assert(!cmpWaterMan.null());
|
ENSURE(!cmpWaterMan.null());
|
||||||
cmpWaterMan->SetWaterLevel(entity_pos_t::FromFloat(waterHeight));
|
cmpWaterMan->SetWaterLevel(entity_pos_t::FromFloat(waterHeight));
|
||||||
|
|
||||||
// If we have graphics, get rest of settings
|
// If we have graphics, get rest of settings
|
||||||
|
@ -230,7 +230,7 @@ void CMapWriter::WriteXML(const VfsPath& filename,
|
|||||||
XML_Attribute("b", pWaterMan->m_WaterColor.b);
|
XML_Attribute("b", pWaterMan->m_WaterColor.b);
|
||||||
}
|
}
|
||||||
CmpPtr<ICmpWaterManager> cmpWaterMan(*pSimulation2, SYSTEM_ENTITY);
|
CmpPtr<ICmpWaterManager> cmpWaterMan(*pSimulation2, SYSTEM_ENTITY);
|
||||||
debug_assert(!cmpWaterMan.null());
|
ENSURE(!cmpWaterMan.null());
|
||||||
XML_Setting("Height", cmpWaterMan->GetExactWaterLevel(0, 0));
|
XML_Setting("Height", cmpWaterMan->GetExactWaterLevel(0, 0));
|
||||||
XML_Setting("Shininess", pWaterMan->m_Shininess);
|
XML_Setting("Shininess", pWaterMan->m_Shininess);
|
||||||
XML_Setting("Waviness", pWaterMan->m_Waviness);
|
XML_Setting("Waviness", pWaterMan->m_Waviness);
|
||||||
@ -294,7 +294,7 @@ void CMapWriter::WriteXML(const VfsPath& filename,
|
|||||||
CSimulation2& sim = *pSimulation2;
|
CSimulation2& sim = *pSimulation2;
|
||||||
|
|
||||||
CmpPtr<ICmpTemplateManager> cmpTemplateManager(sim, SYSTEM_ENTITY);
|
CmpPtr<ICmpTemplateManager> cmpTemplateManager(sim, SYSTEM_ENTITY);
|
||||||
debug_assert(!cmpTemplateManager.null());
|
ENSURE(!cmpTemplateManager.null());
|
||||||
|
|
||||||
// This will probably need to be changed in the future, but for now we'll
|
// This will probably need to be changed in the future, but for now we'll
|
||||||
// just save all entities that have a position
|
// just save all entities that have a position
|
||||||
@ -386,7 +386,7 @@ void CMapWriter::WriteXML(const VfsPath& filename,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (! XML_StoreVFS(g_VFS, filename))
|
if (! XML_StoreVFS(g_VFS, filename))
|
||||||
debug_assert(0); // failed to write map XML file
|
ENSURE(0); // failed to write map XML file
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -116,7 +116,7 @@ void CModel::CalcBounds()
|
|||||||
{
|
{
|
||||||
if (m_Anim->m_ObjectBounds.IsEmpty())
|
if (m_Anim->m_ObjectBounds.IsEmpty())
|
||||||
CalcAnimatedObjectBound(m_Anim->m_AnimDef, m_Anim->m_ObjectBounds);
|
CalcAnimatedObjectBound(m_Anim->m_AnimDef, m_Anim->m_ObjectBounds);
|
||||||
debug_assert(! m_Anim->m_ObjectBounds.IsEmpty()); // (if this happens, it'll be recalculating the bounds every time)
|
ENSURE(! m_Anim->m_ObjectBounds.IsEmpty()); // (if this happens, it'll be recalculating the bounds every time)
|
||||||
m_ObjectBounds = m_Anim->m_ObjectBounds;
|
m_ObjectBounds = m_Anim->m_ObjectBounds;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -261,7 +261,7 @@ void CModel::ValidatePosition()
|
|||||||
{
|
{
|
||||||
if (m_PositionValid)
|
if (m_PositionValid)
|
||||||
{
|
{
|
||||||
debug_assert(!m_Parent || m_Parent->m_PositionValid);
|
ENSURE(!m_Parent || m_Parent->m_PositionValid);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -272,7 +272,7 @@ void CModel::ValidatePosition()
|
|||||||
m_Parent->ValidatePosition();
|
m_Parent->ValidatePosition();
|
||||||
|
|
||||||
// Parent will recursively call our validation.
|
// Parent will recursively call our validation.
|
||||||
debug_assert(m_PositionValid);
|
ENSURE(m_PositionValid);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -280,7 +280,7 @@ void CModel::ValidatePosition()
|
|||||||
{
|
{
|
||||||
// PROFILE( "generating bone matrices" );
|
// PROFILE( "generating bone matrices" );
|
||||||
|
|
||||||
debug_assert(m_pModelDef->GetNumBones() == m_Anim->m_AnimDef->GetNumKeys());
|
ENSURE(m_pModelDef->GetNumBones() == m_Anim->m_AnimDef->GetNumKeys());
|
||||||
|
|
||||||
m_Anim->m_AnimDef->BuildBoneMatrices(m_AnimTime, m_BoneMatrices, !(m_Flags & MODELFLAG_NOLOOPANIMATION));
|
m_Anim->m_AnimDef->BuildBoneMatrices(m_AnimTime, m_BoneMatrices, !(m_Flags & MODELFLAG_NOLOOPANIMATION));
|
||||||
|
|
||||||
|
@ -156,7 +156,7 @@ public:
|
|||||||
|
|
||||||
// return the models bone matrices
|
// return the models bone matrices
|
||||||
const CMatrix3D* GetAnimatedBoneMatrices() {
|
const CMatrix3D* GetAnimatedBoneMatrices() {
|
||||||
debug_assert(m_PositionValid);
|
ENSURE(m_PositionValid);
|
||||||
return m_BoneMatrices;
|
return m_BoneMatrices;
|
||||||
}
|
}
|
||||||
const CMatrix3D* GetInverseBindBoneMatrices() {
|
const CMatrix3D* GetInverseBindBoneMatrices() {
|
||||||
|
@ -130,7 +130,7 @@ bool CObjectBase::Load(const VfsPath& pathname)
|
|||||||
std::vector<Variant>::iterator currentVariant = currentGroup->begin();
|
std::vector<Variant>::iterator currentVariant = currentGroup->begin();
|
||||||
XERO_ITER_EL(child, variant)
|
XERO_ITER_EL(child, variant)
|
||||||
{
|
{
|
||||||
debug_assert(variant.GetNodeName() == el_variant);
|
ENSURE(variant.GetNodeName() == el_variant);
|
||||||
XERO_ITER_ATTR(variant, attr)
|
XERO_ITER_ATTR(variant, attr)
|
||||||
{
|
{
|
||||||
if (attr.Name == at_name)
|
if (attr.Name == at_name)
|
||||||
@ -181,7 +181,7 @@ bool CObjectBase::Load(const VfsPath& pathname)
|
|||||||
{
|
{
|
||||||
XERO_ITER_EL(option, anim_element)
|
XERO_ITER_EL(option, anim_element)
|
||||||
{
|
{
|
||||||
debug_assert(anim_element.GetNodeName() == el_animation);
|
ENSURE(anim_element.GetNodeName() == el_animation);
|
||||||
|
|
||||||
Anim anim;
|
Anim anim;
|
||||||
XERO_ITER_ATTR(anim_element, ae)
|
XERO_ITER_ATTR(anim_element, ae)
|
||||||
@ -218,7 +218,7 @@ bool CObjectBase::Load(const VfsPath& pathname)
|
|||||||
{
|
{
|
||||||
XERO_ITER_EL(option, prop_element)
|
XERO_ITER_EL(option, prop_element)
|
||||||
{
|
{
|
||||||
debug_assert(prop_element.GetNodeName() == el_prop);
|
ENSURE(prop_element.GetNodeName() == el_prop);
|
||||||
|
|
||||||
Prop prop;
|
Prop prop;
|
||||||
XERO_ITER_ATTR(prop_element, pe)
|
XERO_ITER_ATTR(prop_element, pe)
|
||||||
@ -310,7 +310,7 @@ std::vector<u8> CObjectBase::CalculateVariationKey(const std::vector<std::set<CS
|
|||||||
|
|
||||||
for (std::vector<std::set<CStr> >::const_iterator selset = selections.begin(); selset < selections.end(); ++selset)
|
for (std::vector<std::set<CStr> >::const_iterator selset = selections.begin(); selset < selections.end(); ++selset)
|
||||||
{
|
{
|
||||||
debug_assert(grp->size() < 256); // else they won't fit in 'choices'
|
ENSURE(grp->size() < 256); // else they won't fit in 'choices'
|
||||||
|
|
||||||
for (size_t i = 0; i < grp->size(); ++i)
|
for (size_t i = 0; i < grp->size(); ++i)
|
||||||
{
|
{
|
||||||
@ -518,7 +518,7 @@ std::set<CStr> CObjectBase::CalculateRandomVariation(rng_t& rng, const std::set<
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
debug_assert(randNum < 0);
|
ENSURE(randNum < 0);
|
||||||
// This should always succeed; otherwise it
|
// This should always succeed; otherwise it
|
||||||
// wouldn't have chosen any of the variants.
|
// wouldn't have chosen any of the variants.
|
||||||
}
|
}
|
||||||
|
@ -74,7 +74,7 @@ CObjectManager::~CObjectManager()
|
|||||||
|
|
||||||
CObjectBase* CObjectManager::FindObjectBase(const CStrW& objectname)
|
CObjectBase* CObjectManager::FindObjectBase(const CStrW& objectname)
|
||||||
{
|
{
|
||||||
debug_assert(!objectname.empty());
|
ENSURE(!objectname.empty());
|
||||||
|
|
||||||
// See if the base type has been loaded yet:
|
// See if the base type has been loaded yet:
|
||||||
|
|
||||||
|
@ -75,7 +75,7 @@ void CParticleEmitter::UpdateArrayData()
|
|||||||
VertexArrayIterator<float[2]> attrUV = m_AttributeUV.GetIterator<float[2]>();
|
VertexArrayIterator<float[2]> attrUV = m_AttributeUV.GetIterator<float[2]>();
|
||||||
VertexArrayIterator<SColor4ub> attrColor = m_AttributeColor.GetIterator<SColor4ub>();
|
VertexArrayIterator<SColor4ub> attrColor = m_AttributeColor.GetIterator<SColor4ub>();
|
||||||
|
|
||||||
debug_assert(m_Particles.size() <= m_Type->m_MaxParticles);
|
ENSURE(m_Particles.size() <= m_Type->m_MaxParticles);
|
||||||
|
|
||||||
CBound bounds;
|
CBound bounds;
|
||||||
|
|
||||||
|
@ -501,7 +501,7 @@ void CParticleEmitterType::UpdateEmitter(CParticleEmitter& emitter, float dt)
|
|||||||
|
|
||||||
void CParticleEmitterType::UpdateEmitterStep(CParticleEmitter& emitter, float dt)
|
void CParticleEmitterType::UpdateEmitterStep(CParticleEmitter& emitter, float dt)
|
||||||
{
|
{
|
||||||
debug_assert(emitter.m_Type.get() == this);
|
ENSURE(emitter.m_Type.get() == this);
|
||||||
|
|
||||||
if (emitter.m_Active)
|
if (emitter.m_Active)
|
||||||
{
|
{
|
||||||
|
@ -175,7 +175,7 @@ bool CShaderManager::NewProgram(const char* name, const std::map<CStr, CStr>& ba
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: add GLSL support
|
// TODO: add GLSL support
|
||||||
debug_assert(!isGLSL);
|
ENSURE(!isGLSL);
|
||||||
|
|
||||||
program = CShaderProgramPtr(CShaderProgram::ConstructARB(vertexFile, fragmentFile, defines, vertexUniforms, fragmentUniforms, streamFlags));
|
program = CShaderProgramPtr(CShaderProgram::ConstructARB(vertexFile, fragmentFile, defines, vertexUniforms, fragmentUniforms, streamFlags));
|
||||||
program->Reload();
|
program->Reload();
|
||||||
|
@ -116,19 +116,19 @@ int CShaderTechnique::GetNumPasses()
|
|||||||
|
|
||||||
void CShaderTechnique::BeginPass(int pass)
|
void CShaderTechnique::BeginPass(int pass)
|
||||||
{
|
{
|
||||||
debug_assert(0 <= pass && pass < (int)m_Passes.size());
|
ENSURE(0 <= pass && pass < (int)m_Passes.size());
|
||||||
m_Passes[pass].Bind();
|
m_Passes[pass].Bind();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CShaderTechnique::EndPass(int pass)
|
void CShaderTechnique::EndPass(int pass)
|
||||||
{
|
{
|
||||||
debug_assert(0 <= pass && pass < (int)m_Passes.size());
|
ENSURE(0 <= pass && pass < (int)m_Passes.size());
|
||||||
m_Passes[pass].Unbind();
|
m_Passes[pass].Unbind();
|
||||||
}
|
}
|
||||||
|
|
||||||
CShaderProgramPtr CShaderTechnique::GetShader(int pass)
|
CShaderProgramPtr CShaderTechnique::GetShader(int pass)
|
||||||
{
|
{
|
||||||
debug_assert(0 <= pass && pass < (int)m_Passes.size());
|
ENSURE(0 <= pass && pass < (int)m_Passes.size());
|
||||||
return m_Passes[pass].GetShader();
|
return m_Passes[pass].GetShader();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ CTerrainTextureEntry::CTerrainTextureEntry(CTerrainPropertiesPtr props, const Vf
|
|||||||
m_BaseColor(0),
|
m_BaseColor(0),
|
||||||
m_BaseColorValid(false)
|
m_BaseColorValid(false)
|
||||||
{
|
{
|
||||||
debug_assert(props);
|
ENSURE(props);
|
||||||
|
|
||||||
CTextureProperties texture(path);
|
CTextureProperties texture(path);
|
||||||
texture.SetWrap(GL_REPEAT);
|
texture.SetWrap(GL_REPEAT);
|
||||||
|
@ -273,7 +273,7 @@ CTextureConverter::CTextureConverter(PIVFS vfs, bool highQuality) :
|
|||||||
{
|
{
|
||||||
// Verify that we are running with at least the version we were compiled with,
|
// Verify that we are running with at least the version we were compiled with,
|
||||||
// to avoid bugs caused by ABI changes
|
// to avoid bugs caused by ABI changes
|
||||||
debug_assert(nvtt::version() >= NVTT_VERSION);
|
ENSURE(nvtt::version() >= NVTT_VERSION);
|
||||||
|
|
||||||
// Set up the worker thread:
|
// Set up the worker thread:
|
||||||
|
|
||||||
@ -281,13 +281,13 @@ CTextureConverter::CTextureConverter(PIVFS vfs, bool highQuality) :
|
|||||||
|
|
||||||
// Use SDL semaphores since OS X doesn't implement sem_init
|
// Use SDL semaphores since OS X doesn't implement sem_init
|
||||||
m_WorkerSem = SDL_CreateSemaphore(0);
|
m_WorkerSem = SDL_CreateSemaphore(0);
|
||||||
debug_assert(m_WorkerSem);
|
ENSURE(m_WorkerSem);
|
||||||
|
|
||||||
ret = pthread_mutex_init(&m_WorkerMutex, NULL);
|
ret = pthread_mutex_init(&m_WorkerMutex, NULL);
|
||||||
debug_assert(ret == 0);
|
ENSURE(ret == 0);
|
||||||
|
|
||||||
ret = pthread_create(&m_WorkerThread, NULL, &RunThread, this);
|
ret = pthread_create(&m_WorkerThread, NULL, &RunThread, this);
|
||||||
debug_assert(ret == 0);
|
ENSURE(ret == 0);
|
||||||
|
|
||||||
// Maybe we should share some centralised pool of worker threads?
|
// Maybe we should share some centralised pool of worker threads?
|
||||||
// For now we'll just stick with a single thread for this specific use.
|
// For now we'll just stick with a single thread for this specific use.
|
||||||
|
@ -266,7 +266,7 @@ public:
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
debug_assert(ret < 0);
|
ENSURE(ret < 0);
|
||||||
|
|
||||||
// No source file or archive cache was found, so we can't load the
|
// No source file or archive cache was found, so we can't load the
|
||||||
// real texture at all - return the error texture instead
|
// real texture at all - return the error texture instead
|
||||||
|
@ -60,7 +60,7 @@ void CUnitAnimation::AddModel(CModel* model, const CObjectEntry* object)
|
|||||||
|
|
||||||
if (state.anims.empty())
|
if (state.anims.empty())
|
||||||
state.anims = object->GetAnimations("idle");
|
state.anims = object->GetAnimations("idle");
|
||||||
debug_assert(!state.anims.empty()); // there must always be an idle animation
|
ENSURE(!state.anims.empty()); // there must always be an idle animation
|
||||||
|
|
||||||
state.model = model;
|
state.model = model;
|
||||||
state.animIdx = rand(0, state.anims.size());
|
state.animIdx = rand(0, state.anims.size());
|
||||||
|
@ -61,7 +61,7 @@ void CButton::SetupText()
|
|||||||
if (!GetGUI())
|
if (!GetGUI())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
debug_assert(m_GeneratedTexts.size()==1);
|
ENSURE(m_GeneratedTexts.size()==1);
|
||||||
|
|
||||||
CStrW font;
|
CStrW font;
|
||||||
if (GUI<CStrW>::GetSetting(this, "font", font) != PSRETURN_OK || font.empty())
|
if (GUI<CStrW>::GetSetting(this, "font", font) != PSRETURN_OK || font.empty())
|
||||||
|
@ -66,7 +66,7 @@ void CCheckBox::SetupText()
|
|||||||
if (!GetGUI())
|
if (!GetGUI())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
debug_assert(m_GeneratedTexts.size()==1);
|
ENSURE(m_GeneratedTexts.size()==1);
|
||||||
|
|
||||||
CStrW font;
|
CStrW font;
|
||||||
if (GUI<CStrW>::GetSetting(this, "font", font) != PSRETURN_OK || font.empty())
|
if (GUI<CStrW>::GetSetting(this, "font", font) != PSRETURN_OK || font.empty())
|
||||||
|
@ -1161,7 +1161,7 @@ void CGUI::Xeromyces_ReadRootSetup(XMBElement Element, CXeromyces* pFile)
|
|||||||
|
|
||||||
void CGUI::Xeromyces_ReadObject(XMBElement Element, CXeromyces* pFile, IGUIObject *pParent, const std::vector<std::pair<CStr, CStr> >& NameSubst, boost::unordered_set<VfsPath>& Paths)
|
void CGUI::Xeromyces_ReadObject(XMBElement Element, CXeromyces* pFile, IGUIObject *pParent, const std::vector<std::pair<CStr, CStr> >& NameSubst, boost::unordered_set<VfsPath>& Paths)
|
||||||
{
|
{
|
||||||
debug_assert(pParent);
|
ENSURE(pParent);
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
// Our object we are going to create
|
// Our object we are going to create
|
||||||
|
@ -68,7 +68,7 @@ CInput::~CInput()
|
|||||||
|
|
||||||
InReaction CInput::ManuallyHandleEvent(const SDL_Event_* ev)
|
InReaction CInput::ManuallyHandleEvent(const SDL_Event_* ev)
|
||||||
{
|
{
|
||||||
debug_assert(m_iBufferPos != -1);
|
ENSURE(m_iBufferPos != -1);
|
||||||
|
|
||||||
// Since the GUI framework doesn't handle to set settings
|
// Since the GUI framework doesn't handle to set settings
|
||||||
// in Unicode (CStrW), we'll simply retrieve the actual
|
// in Unicode (CStrW), we'll simply retrieve the actual
|
||||||
@ -1093,7 +1093,7 @@ void CInput::UpdateText(int from, int to_before, int to_after)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
debug_assert(to_before != -1);
|
ENSURE(to_before != -1);
|
||||||
|
|
||||||
std::list<SRow>::iterator destroy_row_from, destroy_row_to;
|
std::list<SRow>::iterator destroy_row_from, destroy_row_to;
|
||||||
// Used to check if the above has been set to anything,
|
// Used to check if the above has been set to anything,
|
||||||
|
@ -77,7 +77,7 @@ void CList::SetupText()
|
|||||||
CGUIList *pList;
|
CGUIList *pList;
|
||||||
GUI<CGUIList>::GetSettingPointer(this, "list", pList);
|
GUI<CGUIList>::GetSettingPointer(this, "list", pList);
|
||||||
|
|
||||||
//debug_assert(m_GeneratedTexts.size()>=1);
|
//ENSURE(m_GeneratedTexts.size()>=1);
|
||||||
|
|
||||||
m_ItemsYPositions.resize( pList->m_Items.size()+1 );
|
m_ItemsYPositions.resize( pList->m_Items.size()+1 );
|
||||||
|
|
||||||
@ -348,7 +348,7 @@ void CList::DrawList(const int &selected,
|
|||||||
|
|
||||||
if (selected != -1)
|
if (selected != -1)
|
||||||
{
|
{
|
||||||
debug_assert(selected >= 0 && selected+1 < (int)m_ItemsYPositions.size());
|
ENSURE(selected >= 0 && selected+1 < (int)m_ItemsYPositions.size());
|
||||||
|
|
||||||
// Get rectangle of selection:
|
// Get rectangle of selection:
|
||||||
CRect rect_sel(rect.left, rect.top + m_ItemsYPositions[selected] - scroll,
|
CRect rect_sel(rect.left, rect.top + m_ItemsYPositions[selected] - scroll,
|
||||||
|
@ -74,7 +74,7 @@ void CText::SetupText()
|
|||||||
if (!GetGUI())
|
if (!GetGUI())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
debug_assert(m_GeneratedTexts.size()>=1);
|
ENSURE(m_GeneratedTexts.size()>=1);
|
||||||
|
|
||||||
CStrW font;
|
CStrW font;
|
||||||
if (GUI<CStrW>::GetSetting(this, "font", font) != PSRETURN_OK || font.empty())
|
if (GUI<CStrW>::GetSetting(this, "font", font) != PSRETURN_OK || font.empty())
|
||||||
|
@ -62,7 +62,7 @@ void CTooltip::SetupText()
|
|||||||
if (!GetGUI())
|
if (!GetGUI())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
debug_assert(m_GeneratedTexts.size()==1);
|
ENSURE(m_GeneratedTexts.size()==1);
|
||||||
|
|
||||||
CStrW font;
|
CStrW font;
|
||||||
if (GUI<CStrW>::GetSetting(this, "font", font) != PSRETURN_OK || font.empty())
|
if (GUI<CStrW>::GetSetting(this, "font", font) != PSRETURN_OK || font.empty())
|
||||||
|
@ -51,7 +51,7 @@ InReaction gui_handler(const SDL_Event_* ev)
|
|||||||
CGUIManager::CGUIManager(ScriptInterface& scriptInterface) :
|
CGUIManager::CGUIManager(ScriptInterface& scriptInterface) :
|
||||||
m_ScriptInterface(scriptInterface)
|
m_ScriptInterface(scriptInterface)
|
||||||
{
|
{
|
||||||
debug_assert(ScriptInterface::GetCallbackData(scriptInterface.GetContext()) == NULL);
|
ENSURE(ScriptInterface::GetCallbackData(scriptInterface.GetContext()) == NULL);
|
||||||
scriptInterface.SetCallbackData(this);
|
scriptInterface.SetCallbackData(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -280,6 +280,6 @@ JSObject* CGUIManager::GetScriptObject()
|
|||||||
// calls SwitchPage)
|
// calls SwitchPage)
|
||||||
shared_ptr<CGUI> CGUIManager::top() const
|
shared_ptr<CGUI> CGUIManager::top() const
|
||||||
{
|
{
|
||||||
debug_assert(m_PageStack.size());
|
ENSURE(m_PageStack.size());
|
||||||
return m_PageStack.back().gui;
|
return m_PageStack.back().gui;
|
||||||
}
|
}
|
||||||
|
@ -396,7 +396,7 @@ void GUIRenderer::UpdateDrawCallCache(DrawCalls &Calls, const CStr& SpriteName,
|
|||||||
Sprites[SpriteName] = Sprite;
|
Sprites[SpriteName] = Sprite;
|
||||||
|
|
||||||
it = Sprites.find(SpriteName);
|
it = Sprites.find(SpriteName);
|
||||||
debug_assert(it != Sprites.end()); // The insertion above shouldn't fail
|
ENSURE(it != Sprites.end()); // The insertion above shouldn't fail
|
||||||
}
|
}
|
||||||
else if (SpriteName.substr(0, 7) == "colour:")
|
else if (SpriteName.substr(0, 7) == "colour:")
|
||||||
{
|
{
|
||||||
@ -424,7 +424,7 @@ void GUIRenderer::UpdateDrawCallCache(DrawCalls &Calls, const CStr& SpriteName,
|
|||||||
Sprites[SpriteName] = Sprite;
|
Sprites[SpriteName] = Sprite;
|
||||||
|
|
||||||
it = Sprites.find(SpriteName);
|
it = Sprites.find(SpriteName);
|
||||||
debug_assert(it != Sprites.end()); // The insertion above shouldn't fail
|
ENSURE(it != Sprites.end()); // The insertion above shouldn't fail
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -139,7 +139,7 @@ bool GUITooltip::GetTooltip(IGUIObject* obj, CStr& style)
|
|||||||
|
|
||||||
void GUITooltip::ShowTooltip(IGUIObject* obj, CPos pos, const CStr& style, CGUI* gui)
|
void GUITooltip::ShowTooltip(IGUIObject* obj, CPos pos, const CStr& style, CGUI* gui)
|
||||||
{
|
{
|
||||||
debug_assert(obj);
|
ENSURE(obj);
|
||||||
|
|
||||||
// Ignore attempts to use tooltip ""
|
// Ignore attempts to use tooltip ""
|
||||||
if (style.empty())
|
if (style.empty())
|
||||||
|
@ -116,7 +116,7 @@ bool CClientArea::SetClientArea(const CStr& Value)
|
|||||||
{
|
{
|
||||||
if (valuenr!=3)
|
if (valuenr!=3)
|
||||||
{
|
{
|
||||||
debug_assert(valuenr <= 2);
|
ENSURE(valuenr <= 2);
|
||||||
arg_start[valuenr+1] = i+1;
|
arg_start[valuenr+1] = i+1;
|
||||||
arg_count[valuenr] = arg_start[valuenr+1] - arg_start[valuenr] - 1;
|
arg_count[valuenr] = arg_start[valuenr+1] - arg_start[valuenr] - 1;
|
||||||
}
|
}
|
||||||
|
@ -72,7 +72,7 @@ void CGUIString::GenerateTextCall(SFeedback &Feedback,
|
|||||||
if (_to == _from && itTextChunk->m_From == itTextChunk->m_To)
|
if (_to == _from && itTextChunk->m_From == itTextChunk->m_To)
|
||||||
{
|
{
|
||||||
// These should never be able to have more than one tag.
|
// These should never be able to have more than one tag.
|
||||||
debug_assert(itTextChunk->m_Tags.size()==1);
|
ENSURE(itTextChunk->m_Tags.size()==1);
|
||||||
|
|
||||||
// Now do second check
|
// Now do second check
|
||||||
// because icons and images are placed on exactly one position
|
// because icons and images are placed on exactly one position
|
||||||
|
@ -308,7 +308,7 @@ void CInternalCGUIAccessorBase::HandleMessage(IGUIObject *pObject, SGUIMessage &
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
PSRETURN GUI<T>::GetSettingPointer(const IGUIObject *pObject, const CStr& Setting, T* &Value)
|
PSRETURN GUI<T>::GetSettingPointer(const IGUIObject *pObject, const CStr& Setting, T* &Value)
|
||||||
{
|
{
|
||||||
debug_assert(pObject != NULL);
|
ENSURE(pObject != NULL);
|
||||||
|
|
||||||
std::map<CStr, SGUISetting>::const_iterator it = pObject->m_Settings.find(Setting);
|
std::map<CStr, SGUISetting>::const_iterator it = pObject->m_Settings.find(Setting);
|
||||||
if (it == pObject->m_Settings.end())
|
if (it == pObject->m_Settings.end())
|
||||||
@ -358,7 +358,7 @@ template <typename T>
|
|||||||
PSRETURN GUI<T>::SetSetting(IGUIObject *pObject, const CStr& Setting,
|
PSRETURN GUI<T>::SetSetting(IGUIObject *pObject, const CStr& Setting,
|
||||||
const T &Value, const bool& SkipMessage)
|
const T &Value, const bool& SkipMessage)
|
||||||
{
|
{
|
||||||
debug_assert(pObject != NULL);
|
ENSURE(pObject != NULL);
|
||||||
|
|
||||||
if (!pObject->SettingExists(Setting))
|
if (!pObject->SettingExists(Setting))
|
||||||
{
|
{
|
||||||
|
@ -104,7 +104,7 @@ IGUIObject::~IGUIObject()
|
|||||||
void IGUIObject::AddChild(IGUIObject *pChild)
|
void IGUIObject::AddChild(IGUIObject *pChild)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
// debug_assert(pChild);
|
// ENSURE(pChild);
|
||||||
|
|
||||||
pChild->SetParent(this);
|
pChild->SetParent(this);
|
||||||
|
|
||||||
|
@ -417,7 +417,7 @@ void CMiniMap::Draw()
|
|||||||
vertexArray.reserve(ents.size());
|
vertexArray.reserve(ents.size());
|
||||||
|
|
||||||
CmpPtr<ICmpRangeManager> cmpRangeManager(*sim, SYSTEM_ENTITY);
|
CmpPtr<ICmpRangeManager> cmpRangeManager(*sim, SYSTEM_ENTITY);
|
||||||
debug_assert(!cmpRangeManager.null());
|
ENSURE(!cmpRangeManager.null());
|
||||||
|
|
||||||
for (CSimulation2::InterfaceList::const_iterator it = ents.begin(); it != ents.end(); ++it)
|
for (CSimulation2::InterfaceList::const_iterator it = ents.begin(); it != ents.end(); ++it)
|
||||||
{
|
{
|
||||||
|
@ -282,7 +282,7 @@ JSBool JSI_IGUIObject::getProperty(JSContext* cx, JSObject* obj, jsid id, jsval*
|
|||||||
|
|
||||||
default:
|
default:
|
||||||
JS_ReportError(cx, "Setting '%s' uses an unimplemented type", propName.c_str());
|
JS_ReportError(cx, "Setting '%s' uses an unimplemented type", propName.c_str());
|
||||||
debug_assert(0);
|
ENSURE(0);
|
||||||
return JS_FALSE;
|
return JS_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,7 +90,7 @@ CScriptVal GuiInterfaceCall(void* cbdata, std::wstring name, CScriptVal data)
|
|||||||
if (!g_Game)
|
if (!g_Game)
|
||||||
return JSVAL_VOID;
|
return JSVAL_VOID;
|
||||||
CSimulation2* sim = g_Game->GetSimulation2();
|
CSimulation2* sim = g_Game->GetSimulation2();
|
||||||
debug_assert(sim);
|
ENSURE(sim);
|
||||||
|
|
||||||
CmpPtr<ICmpGuiInterface> gui(*sim, SYSTEM_ENTITY);
|
CmpPtr<ICmpGuiInterface> gui(*sim, SYSTEM_ENTITY);
|
||||||
if (gui.null())
|
if (gui.null())
|
||||||
@ -112,7 +112,7 @@ void PostNetworkCommand(void* cbdata, CScriptVal cmd)
|
|||||||
if (!g_Game)
|
if (!g_Game)
|
||||||
return;
|
return;
|
||||||
CSimulation2* sim = g_Game->GetSimulation2();
|
CSimulation2* sim = g_Game->GetSimulation2();
|
||||||
debug_assert(sim);
|
ENSURE(sim);
|
||||||
|
|
||||||
CmpPtr<ICmpCommandQueue> queue(*sim, SYSTEM_ENTITY);
|
CmpPtr<ICmpCommandQueue> queue(*sim, SYSTEM_ENTITY);
|
||||||
if (queue.null())
|
if (queue.null())
|
||||||
@ -169,7 +169,7 @@ std::wstring GetDefaultPlayerName(void* UNUSED(cbdata))
|
|||||||
|
|
||||||
void StartNetworkGame(void* UNUSED(cbdata))
|
void StartNetworkGame(void* UNUSED(cbdata))
|
||||||
{
|
{
|
||||||
debug_assert(g_NetServer);
|
ENSURE(g_NetServer);
|
||||||
g_NetServer->StartGame();
|
g_NetServer->StartGame();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -177,10 +177,10 @@ void StartGame(void* cbdata, CScriptVal attribs, int playerID)
|
|||||||
{
|
{
|
||||||
CGUIManager* guiManager = static_cast<CGUIManager*> (cbdata);
|
CGUIManager* guiManager = static_cast<CGUIManager*> (cbdata);
|
||||||
|
|
||||||
debug_assert(!g_NetServer);
|
ENSURE(!g_NetServer);
|
||||||
debug_assert(!g_NetClient);
|
ENSURE(!g_NetClient);
|
||||||
|
|
||||||
debug_assert(!g_Game);
|
ENSURE(!g_Game);
|
||||||
g_Game = new CGame();
|
g_Game = new CGame();
|
||||||
|
|
||||||
// Convert from GUI script context to sim script context
|
// Convert from GUI script context to sim script context
|
||||||
@ -196,7 +196,7 @@ void SetNetworkGameAttributes(void* cbdata, CScriptVal attribs)
|
|||||||
{
|
{
|
||||||
CGUIManager* guiManager = static_cast<CGUIManager*> (cbdata);
|
CGUIManager* guiManager = static_cast<CGUIManager*> (cbdata);
|
||||||
|
|
||||||
debug_assert(g_NetServer);
|
ENSURE(g_NetServer);
|
||||||
|
|
||||||
g_NetServer->UpdateGameAttributes(attribs, guiManager->GetScriptInterface());
|
g_NetServer->UpdateGameAttributes(attribs, guiManager->GetScriptInterface());
|
||||||
}
|
}
|
||||||
@ -205,9 +205,9 @@ void StartNetworkHost(void* cbdata, std::wstring playerName)
|
|||||||
{
|
{
|
||||||
CGUIManager* guiManager = static_cast<CGUIManager*> (cbdata);
|
CGUIManager* guiManager = static_cast<CGUIManager*> (cbdata);
|
||||||
|
|
||||||
debug_assert(!g_NetClient);
|
ENSURE(!g_NetClient);
|
||||||
debug_assert(!g_NetServer);
|
ENSURE(!g_NetServer);
|
||||||
debug_assert(!g_Game);
|
ENSURE(!g_Game);
|
||||||
|
|
||||||
g_NetServer = new CNetServer();
|
g_NetServer = new CNetServer();
|
||||||
if (!g_NetServer->SetupConnection())
|
if (!g_NetServer->SetupConnection())
|
||||||
@ -233,9 +233,9 @@ void StartNetworkJoin(void* cbdata, std::wstring playerName, std::string serverA
|
|||||||
{
|
{
|
||||||
CGUIManager* guiManager = static_cast<CGUIManager*> (cbdata);
|
CGUIManager* guiManager = static_cast<CGUIManager*> (cbdata);
|
||||||
|
|
||||||
debug_assert(!g_NetClient);
|
ENSURE(!g_NetClient);
|
||||||
debug_assert(!g_NetServer);
|
ENSURE(!g_NetServer);
|
||||||
debug_assert(!g_Game);
|
ENSURE(!g_Game);
|
||||||
|
|
||||||
g_Game = new CGame();
|
g_Game = new CGame();
|
||||||
g_NetClient = new CNetClient(g_Game);
|
g_NetClient = new CNetClient(g_Game);
|
||||||
@ -272,14 +272,14 @@ CScriptVal PollNetworkClient(void* cbdata)
|
|||||||
|
|
||||||
void AssignNetworkPlayer(void* UNUSED(cbdata), int playerID, std::string guid)
|
void AssignNetworkPlayer(void* UNUSED(cbdata), int playerID, std::string guid)
|
||||||
{
|
{
|
||||||
debug_assert(g_NetServer);
|
ENSURE(g_NetServer);
|
||||||
|
|
||||||
g_NetServer->AssignPlayer(playerID, guid);
|
g_NetServer->AssignPlayer(playerID, guid);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SendNetworkChat(void* UNUSED(cbdata), std::wstring message)
|
void SendNetworkChat(void* UNUSED(cbdata), std::wstring message)
|
||||||
{
|
{
|
||||||
debug_assert(g_NetClient);
|
ENSURE(g_NetClient);
|
||||||
|
|
||||||
g_NetClient->SendChatMessage(message);
|
g_NetClient->SendChatMessage(message);
|
||||||
}
|
}
|
||||||
|
@ -76,7 +76,7 @@ class DynHashTbl
|
|||||||
T& get_slot(Key key) const
|
T& get_slot(Key key) const
|
||||||
{
|
{
|
||||||
size_t hash = tr.hash(key);
|
size_t hash = tr.hash(key);
|
||||||
debug_assert(max_entries != 0); // otherwise, mask will be incorrect
|
ENSURE(max_entries != 0); // otherwise, mask will be incorrect
|
||||||
const size_t mask = max_entries-1;
|
const size_t mask = max_entries-1;
|
||||||
for(;;)
|
for(;;)
|
||||||
{
|
{
|
||||||
@ -155,7 +155,7 @@ public:
|
|||||||
expand_tbl();
|
expand_tbl();
|
||||||
|
|
||||||
T& slot = get_slot(key);
|
T& slot = get_slot(key);
|
||||||
debug_assert(slot == 0); // not already present
|
ENSURE(slot == 0); // not already present
|
||||||
slot = t;
|
slot = t;
|
||||||
num_entries++;
|
num_entries++;
|
||||||
}
|
}
|
||||||
@ -297,35 +297,35 @@ public:
|
|||||||
|
|
||||||
const T& operator[](int ofs) const
|
const T& operator[](int ofs) const
|
||||||
{
|
{
|
||||||
debug_assert(!empty());
|
ENSURE(!empty());
|
||||||
size_t idx = (size_t)(head + ofs);
|
size_t idx = (size_t)(head + ofs);
|
||||||
return data[idx % n];
|
return data[idx % n];
|
||||||
}
|
}
|
||||||
T& operator[](int ofs)
|
T& operator[](int ofs)
|
||||||
{
|
{
|
||||||
debug_assert(!empty());
|
ENSURE(!empty());
|
||||||
size_t idx = (size_t)(head + ofs);
|
size_t idx = (size_t)(head + ofs);
|
||||||
return data[idx % n];
|
return data[idx % n];
|
||||||
}
|
}
|
||||||
|
|
||||||
T& front()
|
T& front()
|
||||||
{
|
{
|
||||||
debug_assert(!empty());
|
ENSURE(!empty());
|
||||||
return data[head];
|
return data[head];
|
||||||
}
|
}
|
||||||
const T& front() const
|
const T& front() const
|
||||||
{
|
{
|
||||||
debug_assert(!empty());
|
ENSURE(!empty());
|
||||||
return data[head];
|
return data[head];
|
||||||
}
|
}
|
||||||
T& back()
|
T& back()
|
||||||
{
|
{
|
||||||
debug_assert(!empty());
|
ENSURE(!empty());
|
||||||
return data[tail];
|
return data[tail];
|
||||||
}
|
}
|
||||||
const T& back() const
|
const T& back() const
|
||||||
{
|
{
|
||||||
debug_assert(!empty());
|
ENSURE(!empty());
|
||||||
return data[tail];
|
return data[tail];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -350,7 +350,7 @@ public:
|
|||||||
head = (head + 1) % n;
|
head = (head + 1) % n;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
debug_assert(0); // underflow
|
ENSURE(0); // underflow
|
||||||
}
|
}
|
||||||
|
|
||||||
class iterator
|
class iterator
|
||||||
@ -492,7 +492,7 @@ class MateiHashTbl
|
|||||||
Entry& get_slot(K key) const
|
Entry& get_slot(K key) const
|
||||||
{
|
{
|
||||||
size_t hash = hashFunc(key);
|
size_t hash = hashFunc(key);
|
||||||
//debug_assert(max_entries != 0); // otherwise, mask will be incorrect
|
//ENSURE(max_entries != 0); // otherwise, mask will be incorrect
|
||||||
const size_t mask = max_entries-1;
|
const size_t mask = max_entries-1;
|
||||||
int stride = 1; // for quadratic probing
|
int stride = 1; // for quadratic probing
|
||||||
for(;;)
|
for(;;)
|
||||||
@ -554,7 +554,7 @@ public:
|
|||||||
tbl = 0;
|
tbl = 0;
|
||||||
num_entries = 0;
|
num_entries = 0;
|
||||||
max_entries = initial_entries/2; // will be doubled in expand_tbl
|
max_entries = initial_entries/2; // will be doubled in expand_tbl
|
||||||
//debug_assert(is_pow2(max_entries));
|
//ENSURE(is_pow2(max_entries));
|
||||||
expand_tbl();
|
expand_tbl();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,19 +37,19 @@ public:
|
|||||||
{
|
{
|
||||||
const Allocs::value_type item = std::make_pair(p, size);
|
const Allocs::value_type item = std::make_pair(p, size);
|
||||||
std::pair<Allocs::iterator, bool> ret = allocs.insert(item);
|
std::pair<Allocs::iterator, bool> ret = allocs.insert(item);
|
||||||
debug_assert(ret.second == true); // wasn't already in map
|
ENSURE(ret.second == true); // wasn't already in map
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnDeallocate(void* p, size_t size)
|
void OnDeallocate(void* p, size_t size)
|
||||||
{
|
{
|
||||||
Allocs::iterator it = allocs.find(p);
|
Allocs::iterator it = allocs.find(p);
|
||||||
if(it == allocs.end())
|
if(it == allocs.end())
|
||||||
debug_assert(0); // freeing invalid pointer
|
ENSURE(0); // freeing invalid pointer
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// size must match what was passed to OnAllocate
|
// size must match what was passed to OnAllocate
|
||||||
const size_t allocated_size = it->second;
|
const size_t allocated_size = it->second;
|
||||||
debug_assert(size == allocated_size);
|
ENSURE(size == allocated_size);
|
||||||
|
|
||||||
allocs.erase(it);
|
allocs.erase(it);
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,7 @@ void bucket_destroy(Bucket* b)
|
|||||||
b->num_buckets--;
|
b->num_buckets--;
|
||||||
}
|
}
|
||||||
|
|
||||||
debug_assert(b->num_buckets == 0);
|
ENSURE(b->num_buckets == 0);
|
||||||
|
|
||||||
// poison pill: cause subsequent alloc and free to fail
|
// poison pill: cause subsequent alloc and free to fail
|
||||||
b->freelist = 0;
|
b->freelist = 0;
|
||||||
@ -80,7 +80,7 @@ void* bucket_alloc(Bucket* b, size_t size)
|
|||||||
{
|
{
|
||||||
size_t el_size = b->el_size? b->el_size : Align<allocationAlignment>(size);
|
size_t el_size = b->el_size? b->el_size : Align<allocationAlignment>(size);
|
||||||
// must fit in a bucket
|
// must fit in a bucket
|
||||||
debug_assert(el_size <= bucketSize-sizeof(u8*));
|
ENSURE(el_size <= bucketSize-sizeof(u8*));
|
||||||
|
|
||||||
// try to satisfy alloc from freelist
|
// try to satisfy alloc from freelist
|
||||||
void* el = mem_freelist_Detach(b->freelist);
|
void* el = mem_freelist_Detach(b->freelist);
|
||||||
|
@ -41,10 +41,8 @@ LIB_API void* mem_freelist_Sentinel();
|
|||||||
|
|
||||||
static inline void mem_freelist_AddToFront(void*& freelist, void* el)
|
static inline void mem_freelist_AddToFront(void*& freelist, void* el)
|
||||||
{
|
{
|
||||||
#ifndef NDEBUG
|
ASSERT(freelist != 0);
|
||||||
debug_assert(freelist != 0);
|
ASSERT(el != 0);
|
||||||
debug_assert(el != 0);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
memcpy(el, &freelist, sizeof(void*));
|
memcpy(el, &freelist, sizeof(void*));
|
||||||
freelist = el;
|
freelist = el;
|
||||||
@ -54,9 +52,7 @@ static inline void mem_freelist_AddToFront(void*& freelist, void* el)
|
|||||||
// previously been passed to mem_freelist_AddToFront.
|
// previously been passed to mem_freelist_AddToFront.
|
||||||
static inline void* mem_freelist_Detach(void*& freelist)
|
static inline void* mem_freelist_Detach(void*& freelist)
|
||||||
{
|
{
|
||||||
#ifndef NDEBUG
|
ASSERT(freelist != 0);
|
||||||
debug_assert(freelist != 0);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void* prev_el;
|
void* prev_el;
|
||||||
memcpy(&prev_el, freelist, sizeof(void*));
|
memcpy(&prev_el, freelist, sizeof(void*));
|
||||||
|
@ -99,8 +99,8 @@ public:
|
|||||||
// note: we can't check for prev != next because we're called for
|
// note: we can't check for prev != next because we're called for
|
||||||
// footers as well, and they don't have valid pointers.
|
// footers as well, and they don't have valid pointers.
|
||||||
|
|
||||||
debug_assert(IsValidSize(m_size));
|
ENSURE(IsValidSize(m_size));
|
||||||
debug_assert(IsFreedBlock(id));
|
ENSURE(IsFreedBlock(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -198,7 +198,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// none found, so average block size is less than the desired size
|
// none found, so average block size is less than the desired size
|
||||||
debug_assert(m_freeBytes/m_freeBlocks < minSize);
|
ENSURE(m_freeBytes/m_freeBlocks < minSize);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -207,8 +207,8 @@ public:
|
|||||||
freedBlock->next->prev = freedBlock->prev;
|
freedBlock->next->prev = freedBlock->prev;
|
||||||
freedBlock->prev->next = freedBlock->next;
|
freedBlock->prev->next = freedBlock->next;
|
||||||
|
|
||||||
debug_assert(m_freeBlocks != 0);
|
ENSURE(m_freeBlocks != 0);
|
||||||
debug_assert(m_freeBytes >= freedBlock->Size());
|
ENSURE(m_freeBytes >= freedBlock->Size());
|
||||||
m_freeBlocks--;
|
m_freeBlocks--;
|
||||||
m_freeBytes -= freedBlock->Size();
|
m_freeBytes -= freedBlock->Size();
|
||||||
}
|
}
|
||||||
@ -234,9 +234,9 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// our idea of the number and size of free blocks is correct
|
// our idea of the number and size of free blocks is correct
|
||||||
debug_assert(freeBlocks == m_freeBlocks*2 && freeBytes == m_freeBytes*2);
|
ENSURE(freeBlocks == m_freeBlocks*2 && freeBytes == m_freeBytes*2);
|
||||||
// if empty, state must be as established by Reset
|
// if empty, state must be as established by Reset
|
||||||
debug_assert(!IsEmpty() || (m_sentinel.next == &m_sentinel && m_sentinel.prev == &m_sentinel));
|
ENSURE(!IsEmpty() || (m_sentinel.next == &m_sentinel && m_sentinel.prev == &m_sentinel));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsEmpty() const
|
bool IsEmpty() const
|
||||||
@ -311,7 +311,7 @@ public:
|
|||||||
|
|
||||||
// apparently all classes above minSizeClass are empty,
|
// apparently all classes above minSizeClass are empty,
|
||||||
// or the above would have succeeded.
|
// or the above would have succeeded.
|
||||||
debug_assert(m_bitmap < Bit<uintptr_t>(minSizeClass+1));
|
ENSURE(m_bitmap < Bit<uintptr_t>(minSizeClass+1));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -332,7 +332,7 @@ public:
|
|||||||
m_rangeLists[i].Validate(id);
|
m_rangeLists[i].Validate(id);
|
||||||
|
|
||||||
// both bitmap and list must agree on whether they are empty
|
// both bitmap and list must agree on whether they are empty
|
||||||
debug_assert(((m_bitmap & Bit<uintptr_t>(i)) == 0) == m_rangeLists[i].IsEmpty());
|
ENSURE(((m_bitmap & Bit<uintptr_t>(i)) == 0) == m_rangeLists[i].IsEmpty());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -424,8 +424,8 @@ public:
|
|||||||
{
|
{
|
||||||
Validate(freedBlock);
|
Validate(freedBlock);
|
||||||
|
|
||||||
debug_assert(m_freeBlocks != 0);
|
ENSURE(m_freeBlocks != 0);
|
||||||
debug_assert(m_freeBytes >= freedBlock->Size());
|
ENSURE(m_freeBytes >= freedBlock->Size());
|
||||||
m_freeBlocks--;
|
m_freeBlocks--;
|
||||||
m_freeBytes -= freedBlock->Size();
|
m_freeBytes -= freedBlock->Size();
|
||||||
|
|
||||||
@ -486,8 +486,8 @@ private:
|
|||||||
|
|
||||||
// the existence of freedBlock means our bookkeeping better have
|
// the existence of freedBlock means our bookkeeping better have
|
||||||
// records of at least that much memory.
|
// records of at least that much memory.
|
||||||
debug_assert(m_freeBlocks != 0);
|
ENSURE(m_freeBlocks != 0);
|
||||||
debug_assert(m_freeBytes >= freedBlock->Size());
|
ENSURE(m_freeBytes >= freedBlock->Size());
|
||||||
|
|
||||||
freedBlock->Validate(s_headerId);
|
freedBlock->Validate(s_headerId);
|
||||||
Footer(freedBlock)->Validate(s_footerId);
|
Footer(freedBlock)->Validate(s_footerId);
|
||||||
@ -538,11 +538,11 @@ public:
|
|||||||
|
|
||||||
m_totalDeallocatedBlocks++;
|
m_totalDeallocatedBlocks++;
|
||||||
m_totalDeallocatedBytes += size;
|
m_totalDeallocatedBytes += size;
|
||||||
debug_assert(m_totalDeallocatedBlocks <= m_totalAllocatedBlocks);
|
ENSURE(m_totalDeallocatedBlocks <= m_totalAllocatedBlocks);
|
||||||
debug_assert(m_totalDeallocatedBytes <= m_totalDeallocatedBytes);
|
ENSURE(m_totalDeallocatedBytes <= m_totalDeallocatedBytes);
|
||||||
|
|
||||||
debug_assert(m_currentExtantBlocks != 0);
|
ENSURE(m_currentExtantBlocks != 0);
|
||||||
debug_assert(m_currentExtantBytes >= size);
|
ENSURE(m_currentExtantBytes >= size);
|
||||||
m_currentExtantBlocks--;
|
m_currentExtantBlocks--;
|
||||||
m_currentExtantBytes -= size;
|
m_currentExtantBytes -= size;
|
||||||
}
|
}
|
||||||
@ -557,8 +557,8 @@ public:
|
|||||||
{
|
{
|
||||||
if(!performSanityChecks) return;
|
if(!performSanityChecks) return;
|
||||||
|
|
||||||
debug_assert(m_currentFreeBlocks != 0);
|
ENSURE(m_currentFreeBlocks != 0);
|
||||||
debug_assert(m_currentFreeBytes >= size);
|
ENSURE(m_currentFreeBytes >= size);
|
||||||
m_currentFreeBlocks--;
|
m_currentFreeBlocks--;
|
||||||
m_currentFreeBytes -= size;
|
m_currentFreeBytes -= size;
|
||||||
}
|
}
|
||||||
@ -567,11 +567,11 @@ public:
|
|||||||
{
|
{
|
||||||
if(!performSanityChecks) return;
|
if(!performSanityChecks) return;
|
||||||
|
|
||||||
debug_assert(m_totalDeallocatedBlocks <= m_totalAllocatedBlocks);
|
ENSURE(m_totalDeallocatedBlocks <= m_totalAllocatedBlocks);
|
||||||
debug_assert(m_totalDeallocatedBytes <= m_totalAllocatedBytes);
|
ENSURE(m_totalDeallocatedBytes <= m_totalAllocatedBytes);
|
||||||
|
|
||||||
debug_assert(m_currentExtantBlocks == m_totalAllocatedBlocks-m_totalDeallocatedBlocks);
|
ENSURE(m_currentExtantBlocks == m_totalAllocatedBlocks-m_totalDeallocatedBlocks);
|
||||||
debug_assert(m_currentExtantBytes == m_totalAllocatedBytes-m_totalDeallocatedBytes);
|
ENSURE(m_currentExtantBytes == m_totalAllocatedBytes-m_totalDeallocatedBytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t FreeBlocks() const
|
size_t FreeBlocks() const
|
||||||
@ -598,7 +598,7 @@ private:
|
|||||||
|
|
||||||
static void AssertEqual(size_t x1, size_t x2, size_t x3)
|
static void AssertEqual(size_t x1, size_t x2, size_t x3)
|
||||||
{
|
{
|
||||||
debug_assert(x1 == x2 && x2 == x3);
|
ENSURE(x1 == x2 && x2 == x3);
|
||||||
}
|
}
|
||||||
|
|
||||||
class HeaderlessAllocator::Impl
|
class HeaderlessAllocator::Impl
|
||||||
@ -629,7 +629,7 @@ public:
|
|||||||
|
|
||||||
void* Allocate(size_t size) throw()
|
void* Allocate(size_t size) throw()
|
||||||
{
|
{
|
||||||
debug_assert(IsValidSize(size));
|
ENSURE(IsValidSize(size));
|
||||||
Validate();
|
Validate();
|
||||||
|
|
||||||
void* p = TakeAndSplitFreeBlock(size);
|
void* p = TakeAndSplitFreeBlock(size);
|
||||||
@ -644,16 +644,16 @@ public:
|
|||||||
m_stats.OnAllocate(size);
|
m_stats.OnAllocate(size);
|
||||||
|
|
||||||
Validate();
|
Validate();
|
||||||
debug_assert((uintptr_t)p % allocationAlignment == 0);
|
ENSURE((uintptr_t)p % allocationAlignment == 0);
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Deallocate(u8* p, size_t size)
|
void Deallocate(u8* p, size_t size)
|
||||||
{
|
{
|
||||||
debug_assert((uintptr_t)p % allocationAlignment == 0);
|
ENSURE((uintptr_t)p % allocationAlignment == 0);
|
||||||
debug_assert(IsValidSize(size));
|
ENSURE(IsValidSize(size));
|
||||||
debug_assert(pool_contains(&m_pool, p));
|
ENSURE(pool_contains(&m_pool, p));
|
||||||
debug_assert(pool_contains(&m_pool, p+size-1));
|
ENSURE(pool_contains(&m_pool, p+size-1));
|
||||||
|
|
||||||
Validate();
|
Validate();
|
||||||
|
|
||||||
|
@ -103,7 +103,7 @@ void page_aligned_free(void* p, size_t size)
|
|||||||
{
|
{
|
||||||
if(!p)
|
if(!p)
|
||||||
return;
|
return;
|
||||||
debug_assert(IsAligned(p, pageSize));
|
ENSURE(IsAligned(p, pageSize));
|
||||||
const size_t alignedSize = Align<pageSize>(size);
|
const size_t alignedSize = Align<pageSize>(size);
|
||||||
(void)mem_Release((u8*)p, alignedSize);
|
(void)mem_Release((u8*)p, alignedSize);
|
||||||
}
|
}
|
||||||
|
@ -64,7 +64,7 @@ bool pool_contains(const Pool* p, void* el)
|
|||||||
return false;
|
return false;
|
||||||
// sanity check: it should be aligned (if pool has fixed-size elements)
|
// sanity check: it should be aligned (if pool has fixed-size elements)
|
||||||
if(p->el_size)
|
if(p->el_size)
|
||||||
debug_assert((uintptr_t)((u8*)el - p->da.base) % p->el_size == 0);
|
ENSURE((uintptr_t)((u8*)el - p->da.base) % p->el_size == 0);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,7 +93,7 @@ void* pool_alloc(Pool* p, size_t size)
|
|||||||
}
|
}
|
||||||
|
|
||||||
have_el:
|
have_el:
|
||||||
debug_assert(pool_contains(p, el)); // paranoia
|
ENSURE(pool_contains(p, el)); // paranoia
|
||||||
return el;
|
return el;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,14 +105,14 @@ void pool_free(Pool* p, void* el)
|
|||||||
// check if requested_size matches that when allocating)
|
// check if requested_size matches that when allocating)
|
||||||
if(p->el_size == 0)
|
if(p->el_size == 0)
|
||||||
{
|
{
|
||||||
debug_assert(0); // cannot free variable-size items
|
ENSURE(0); // cannot free variable-size items
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(pool_contains(p, el))
|
if(pool_contains(p, el))
|
||||||
mem_freelist_AddToFront(p->freelist, el);
|
mem_freelist_AddToFront(p->freelist, el);
|
||||||
else
|
else
|
||||||
debug_assert(0); // invalid pointer (not in pool)
|
ENSURE(0); // invalid pointer (not in pool)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ public:
|
|||||||
|
|
||||||
void operator()(u8* p)
|
void operator()(u8* p)
|
||||||
{
|
{
|
||||||
debug_assert(m_size != 0);
|
ENSURE(m_size != 0);
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
s_allocatorChecker.OnDeallocate(p, m_size);
|
s_allocatorChecker.OnDeallocate(p, m_size);
|
||||||
#endif
|
#endif
|
||||||
@ -54,7 +54,7 @@ private:
|
|||||||
|
|
||||||
shared_ptr<u8> Allocate(size_t size)
|
shared_ptr<u8> Allocate(size_t size)
|
||||||
{
|
{
|
||||||
debug_assert(size != 0);
|
ENSURE(size != 0);
|
||||||
|
|
||||||
u8* p = new u8[size];
|
u8* p = new u8[size];
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
|
@ -23,9 +23,9 @@ static IdxDeleter numDeleters = 2;
|
|||||||
|
|
||||||
IdxDeleter AddUniqueRangeDeleter(UniqueRangeDeleter deleter)
|
IdxDeleter AddUniqueRangeDeleter(UniqueRangeDeleter deleter)
|
||||||
{
|
{
|
||||||
debug_assert(deleter);
|
ENSURE(deleter);
|
||||||
IdxDeleter idxDeleter = cpu_AtomicAdd(&numDeleters, 1);
|
IdxDeleter idxDeleter = cpu_AtomicAdd(&numDeleters, 1);
|
||||||
debug_assert(idxDeleter < (IdxDeleter)ARRAY_SIZE(deleters));
|
ENSURE(idxDeleter < (IdxDeleter)ARRAY_SIZE(deleters));
|
||||||
deleters[idxDeleter] = deleter;
|
deleters[idxDeleter] = deleter;
|
||||||
return idxDeleter;
|
return idxDeleter;
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,6 @@
|
|||||||
#ifndef INCLUDED_ALLOCATORS_UNIQUE_RANGE
|
#ifndef INCLUDED_ALLOCATORS_UNIQUE_RANGE
|
||||||
#define INCLUDED_ALLOCATORS_UNIQUE_RANGE
|
#define INCLUDED_ALLOCATORS_UNIQUE_RANGE
|
||||||
|
|
||||||
#define ASSERT debug_assert
|
|
||||||
|
|
||||||
|
|
||||||
#include "lib/lib_api.h"
|
#include "lib/lib_api.h"
|
||||||
|
|
||||||
// we usually don't hold multiple references to allocations, so unique_ptr
|
// we usually don't hold multiple references to allocations, so unique_ptr
|
||||||
|
@ -114,7 +114,7 @@ static AppHooks default_ah = ah;
|
|||||||
// (these default to the stub hooks which are functional but basic).
|
// (these default to the stub hooks which are functional but basic).
|
||||||
void app_hooks_update(AppHooks* new_ah)
|
void app_hooks_update(AppHooks* new_ah)
|
||||||
{
|
{
|
||||||
debug_assert(new_ah);
|
ENSURE(new_ah);
|
||||||
|
|
||||||
#define OVERRIDE_IF_NONZERO(HOOKNAME) if(new_ah->HOOKNAME) ah.HOOKNAME = new_ah->HOOKNAME;
|
#define OVERRIDE_IF_NONZERO(HOOKNAME) if(new_ah->HOOKNAME) ah.HOOKNAME = new_ah->HOOKNAME;
|
||||||
OVERRIDE_IF_NONZERO(override_gl_upload_caps)
|
OVERRIDE_IF_NONZERO(override_gl_upload_caps)
|
||||||
|
@ -113,7 +113,7 @@ template<typename T>
|
|||||||
inline T SetBitsTo(T num, size_t lo_idx, size_t hi_idx, size_t value)
|
inline T SetBitsTo(T num, size_t lo_idx, size_t hi_idx, size_t value)
|
||||||
{
|
{
|
||||||
const size_t numBits = (hi_idx - lo_idx)+1;
|
const size_t numBits = (hi_idx - lo_idx)+1;
|
||||||
debug_assert(value < (T(1) << numBits));
|
ASSERT(value < (T(1) << numBits));
|
||||||
const T mask = bit_mask<T>(numBits) << lo_idx;
|
const T mask = bit_mask<T>(numBits) << lo_idx;
|
||||||
T result = num & ~mask;
|
T result = num & ~mask;
|
||||||
result = T(result | (value << lo_idx));
|
result = T(result | (value << lo_idx));
|
||||||
@ -214,18 +214,18 @@ inline T round_up_to_pow2(T x)
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
inline T round_up(T n, T multiple)
|
inline T round_up(T n, T multiple)
|
||||||
{
|
{
|
||||||
debug_assert(is_pow2(multiple));
|
ASSERT(is_pow2(multiple));
|
||||||
const T result = (n + multiple-1) & ~(multiple-1);
|
const T result = (n + multiple-1) & ~(multiple-1);
|
||||||
debug_assert(n <= result && result < n+multiple);
|
ASSERT(n <= result && result < n+multiple);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
inline T round_down(T n, T multiple)
|
inline T round_down(T n, T multiple)
|
||||||
{
|
{
|
||||||
debug_assert(is_pow2(multiple));
|
ASSERT(is_pow2(multiple));
|
||||||
const T result = n & ~(multiple-1);
|
const T result = n & ~(multiple-1);
|
||||||
debug_assert(result <= n && n < result+multiple);
|
ASSERT(result <= n && n < result+multiple);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -233,7 +233,7 @@ inline T round_down(T n, T multiple)
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
inline T MaxPowerOfTwoDivisor(T value)
|
inline T MaxPowerOfTwoDivisor(T value)
|
||||||
{
|
{
|
||||||
debug_assert(value != T(0));
|
ASSERT(value != T(0));
|
||||||
|
|
||||||
for(size_t log2 = 0; log2 < sizeof(T)*CHAR_BIT; log2++)
|
for(size_t log2 = 0; log2 < sizeof(T)*CHAR_BIT; log2++)
|
||||||
{
|
{
|
||||||
@ -241,7 +241,7 @@ inline T MaxPowerOfTwoDivisor(T value)
|
|||||||
return T(1) << log2;
|
return T(1) << log2;
|
||||||
}
|
}
|
||||||
|
|
||||||
debug_assert(0); // unreachable (!= 0 => there is a set bit)
|
ENSURE(0); // unreachable (!= 0 => there is a set bit)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -286,7 +286,7 @@ again:
|
|||||||
// different evictions than Landlord_Lazy, which is unacceptable.
|
// different evictions than Landlord_Lazy, which is unacceptable.
|
||||||
// nor is doing so necessary: if mcd is tiny, so is credit.
|
// nor is doing so necessary: if mcd is tiny, so is credit.
|
||||||
const float min_credit_density = mcd_calc(map);
|
const float min_credit_density = mcd_calc(map);
|
||||||
debug_assert(min_credit_density > 0.0f);
|
ENSURE(min_credit_density > 0.0f);
|
||||||
|
|
||||||
for(MapIt it = map.begin(); it != map.end();) // no ++it
|
for(MapIt it = map.begin(); it != map.end();) // no ++it
|
||||||
{
|
{
|
||||||
@ -329,7 +329,7 @@ protected:
|
|||||||
typedef std::pair<MapIt, bool> PairIB;
|
typedef std::pair<MapIt, bool> PairIB;
|
||||||
typename Map::value_type val = std::make_pair(key, entry);
|
typename Map::value_type val = std::make_pair(key, entry);
|
||||||
PairIB ret = map.insert(val);
|
PairIB ret = map.insert(val);
|
||||||
debug_assert(ret.second); // must not already be in map
|
ENSURE(ret.second); // must not already be in map
|
||||||
|
|
||||||
mcd_calc.notify_added(entry);
|
mcd_calc.notify_added(entry);
|
||||||
|
|
||||||
@ -444,7 +444,7 @@ public:
|
|||||||
// this entry); then add the resulting density to pending_delta.
|
// this entry); then add the resulting density to pending_delta.
|
||||||
entry.credit -= pending_delta*entry.size;
|
entry.credit -= pending_delta*entry.size;
|
||||||
const float credit_density = entry.credit_density();
|
const float credit_density = entry.credit_density();
|
||||||
debug_assert(credit_density > 0.0f);
|
ENSURE(credit_density > 0.0f);
|
||||||
pending_delta += credit_density;
|
pending_delta += credit_density;
|
||||||
|
|
||||||
Parent::remove_(least_valuable_it);
|
Parent::remove_(least_valuable_it);
|
||||||
@ -581,7 +581,7 @@ public:
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
debug_assert(0); // entry not found in list
|
ENSURE(0); // entry not found in list
|
||||||
}
|
}
|
||||||
|
|
||||||
void remove_least_valuable(std::list<Entry>& entry_list)
|
void remove_least_valuable(std::list<Entry>& entry_list)
|
||||||
@ -641,7 +641,7 @@ template<class Item, class Divider> struct CacheEntry
|
|||||||
credit = (float)cost;
|
credit = (float)cost;
|
||||||
|
|
||||||
// else divider will fail
|
// else divider will fail
|
||||||
debug_assert(size != 0);
|
ENSURE(size != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
float credit_density() const
|
float credit_density() const
|
||||||
@ -723,7 +723,7 @@ public:
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
mgr.remove_least_valuable(entries_awaiting_eviction);
|
mgr.remove_least_valuable(entries_awaiting_eviction);
|
||||||
debug_assert(!entries_awaiting_eviction.empty());
|
ENSURE(!entries_awaiting_eviction.empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
const Entry& entry = entries_awaiting_eviction.front();
|
const Entry& entry = entries_awaiting_eviction.front();
|
||||||
|
@ -105,7 +105,7 @@
|
|||||||
#else
|
#else
|
||||||
# define UNREACHABLE\
|
# define UNREACHABLE\
|
||||||
STMT(\
|
STMT(\
|
||||||
debug_assert(0); /* hit supposedly unreachable code */\
|
ENSURE(0); /* hit supposedly unreachable code */\
|
||||||
for(;;){};\
|
for(;;){};\
|
||||||
)
|
)
|
||||||
#endif
|
#endif
|
||||||
@ -135,7 +135,7 @@ switch(x % 2)
|
|||||||
#define UID2__ PASTE3__(LINE_, __LINE__, _2)
|
#define UID2__ PASTE3__(LINE_, __LINE__, _2)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compile-time debug_assert. Causes a compile error if the expression
|
* Compile-time ENSURE. Causes a compile error if the expression
|
||||||
* evaluates to zero/false.
|
* evaluates to zero/false.
|
||||||
*
|
*
|
||||||
* No runtime overhead; may be used anywhere, including file scope.
|
* No runtime overhead; may be used anywhere, including file scope.
|
||||||
@ -328,6 +328,12 @@ private:\
|
|||||||
#define STRINGIZE2(id) # id
|
#define STRINGIZE2(id) # id
|
||||||
#define STRINGIZE(id) STRINGIZE2(id)
|
#define STRINGIZE(id) STRINGIZE2(id)
|
||||||
|
|
||||||
|
// for widening non-literals (e.g. __FILE__)
|
||||||
|
// note: C99 says __func__ is a magic *variable*, and GCC doesn't allow
|
||||||
|
// widening it via preprocessor.
|
||||||
|
#define WIDEN2(x) L ## x
|
||||||
|
#define WIDEN(x) WIDEN2(x)
|
||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// C++0x rvalue references (required for UniqueRange)
|
// C++0x rvalue references (required for UniqueRange)
|
||||||
|
@ -83,7 +83,7 @@ void debug_filter_add(const wchar_t* tag)
|
|||||||
// too many already?
|
// too many already?
|
||||||
if(num_tags == MAX_TAGS)
|
if(num_tags == MAX_TAGS)
|
||||||
{
|
{
|
||||||
debug_assert(0); // increase MAX_TAGS
|
ENSURE(0); // increase MAX_TAGS
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,7 +143,7 @@ void debug_printf(const wchar_t* fmt, ...)
|
|||||||
va_list ap;
|
va_list ap;
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
const int numChars = vswprintf_s(buf, ARRAY_SIZE(buf), fmt, ap);
|
const int numChars = vswprintf_s(buf, ARRAY_SIZE(buf), fmt, ap);
|
||||||
debug_assert(numChars >= 0);
|
ENSURE(numChars >= 0);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
if(debug_filter_allows(buf))
|
if(debug_filter_allows(buf))
|
||||||
|
@ -37,6 +37,7 @@
|
|||||||
// crashlogs with "last-known activity" reporting.
|
// crashlogs with "last-known activity" reporting.
|
||||||
|
|
||||||
#include "lib/lib_errors.h"
|
#include "lib/lib_errors.h"
|
||||||
|
#include "lib/code_annotation.h"
|
||||||
#include "lib/code_generation.h"
|
#include "lib/code_generation.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -51,12 +52,6 @@
|
|||||||
extern void debug_break();
|
extern void debug_break();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// for widening non-literals (e.g. __FILE__)
|
|
||||||
// note: C99 says __func__ is a magic *variable*, and GCC doesn't allow
|
|
||||||
// widening it via preprocessor.
|
|
||||||
#define WIDEN2(x) L ## x
|
|
||||||
#define WIDEN(x) WIDEN2(x)
|
|
||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// output
|
// output
|
||||||
@ -265,33 +260,72 @@ LIB_API LibError debug_WriteCrashlog(const wchar_t* text);
|
|||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// debug_assert
|
// assertions
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* make sure the expression \<expr\> evaluates to non-zero. used to validate
|
* ensure the expression \<expr\> evaluates to non-zero. used to validate
|
||||||
* invariants in the program during development and thus gives a
|
* invariants in the program during development and thus gives a
|
||||||
* very helpful warning if something isn't going as expected.
|
* very helpful warning if something isn't going as expected.
|
||||||
* sprinkle these liberally throughout your code!
|
* sprinkle these liberally throughout your code!
|
||||||
*
|
*
|
||||||
* recommended use is debug_assert(expression && "descriptive string") -
|
* to pass more information to users at runtime, you can write
|
||||||
* the string can pass more information about the problem on to whomever
|
* ENSURE(expression && "descriptive string").
|
||||||
* is seeing the error.
|
|
||||||
*
|
|
||||||
* rationale: we call this "debug_assert" instead of "assert" for the
|
|
||||||
* following reasons:
|
|
||||||
* - consistency (everything here is prefixed with debug_) and
|
|
||||||
* - to avoid inadvertent use of the much less helpful built-in CRT assert.
|
|
||||||
* if we were to override assert, it would be difficult to tell whether
|
|
||||||
* user source has included \<assert.h\> (possibly indirectly via other
|
|
||||||
* headers) and thereby stomped on our definition.
|
|
||||||
**/
|
**/
|
||||||
#define debug_assert(expr) \
|
#define ENSURE(expr)\
|
||||||
STMT(\
|
do\
|
||||||
static atomic_bool suppress__;\
|
|
||||||
if(!(expr))\
|
|
||||||
{\
|
{\
|
||||||
switch(debug_OnAssertionFailure(WIDEN(#expr), &suppress__, WIDEN(__FILE__), __LINE__, __func__))\
|
static atomic_bool suppress__;\
|
||||||
|
if(!(expr))\
|
||||||
|
{\
|
||||||
|
switch(debug_OnAssertionFailure(WIDEN(#expr), &suppress__, WIDEN(__FILE__), __LINE__, __func__))\
|
||||||
|
{\
|
||||||
|
case ER_CONTINUE:\
|
||||||
|
break;\
|
||||||
|
case ER_BREAK:\
|
||||||
|
default:\
|
||||||
|
debug_break();\
|
||||||
|
break;\
|
||||||
|
}\
|
||||||
|
}\
|
||||||
|
}\
|
||||||
|
while(0)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* same as ENSURE in debug mode, does nothing in release mode.
|
||||||
|
* (we don't override the `assert' macro because users may
|
||||||
|
* inadvertently include \<assert.h\> afterwards)
|
||||||
|
* (we do not provide an MFC-style VERIFY macro because the distinction
|
||||||
|
* between ENSURE and VERIFY is unclear. to always run code but only
|
||||||
|
* check for success in debug builds without raising unused-variable warnings,
|
||||||
|
* use ASSERT + UNUSED2.)
|
||||||
|
**/
|
||||||
|
#define ASSERT(expr) ENSURE(expr)
|
||||||
|
#ifdef NDEBUG
|
||||||
|
# undef ASSERT
|
||||||
|
# define ASSERT(expr) (void)expr
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* display the error dialog with the given text. this is less error-prone than
|
||||||
|
* ENSURE(0 && "text"). note that "conditional expression is constant" warnings
|
||||||
|
* are disabled anyway.
|
||||||
|
*
|
||||||
|
* if being able to suppress the warning is desirable (e.g. for self-tests),
|
||||||
|
* then use DEBUG_WARN_ERR instead.
|
||||||
|
**/
|
||||||
|
#define debug_warn(expr) ENSURE(0 && (expr))
|
||||||
|
|
||||||
|
/**
|
||||||
|
* display the error dialog with text corresponding to the given error code.
|
||||||
|
* used by CHECK_ERR et al., which wrap function calls and automatically
|
||||||
|
* raise warnings and return to the caller.
|
||||||
|
**/
|
||||||
|
#define DEBUG_WARN_ERR(err)\
|
||||||
|
do\
|
||||||
|
{\
|
||||||
|
static atomic_bool suppress__;\
|
||||||
|
switch(debug_OnError(err, &suppress__, WIDEN(__FILE__), __LINE__, __func__))\
|
||||||
{\
|
{\
|
||||||
case ER_CONTINUE:\
|
case ER_CONTINUE:\
|
||||||
break;\
|
break;\
|
||||||
@ -301,58 +335,10 @@ STMT(\
|
|||||||
break;\
|
break;\
|
||||||
}\
|
}\
|
||||||
}\
|
}\
|
||||||
)
|
while(0)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* show a dialog to make sure unexpected states in the program are noticed.
|
* called when a ENSURE/ASSERT fails;
|
||||||
* this is less error-prone than "debug_assert(0 && "text");" and avoids
|
|
||||||
* "conditional expression is constant" warnings. we'd really like to
|
|
||||||
* completely eliminate the problem; replacing 0 literals with LIB_API
|
|
||||||
* volatile variables fools VC7 but isn't guaranteed to be free of overhead.
|
|
||||||
* we therefore just squelch the warning (unfortunately non-portable).
|
|
||||||
* this duplicates the code from debug_assert to avoid compiler warnings about
|
|
||||||
* constant conditions.
|
|
||||||
*
|
|
||||||
* if being able to suppress the warning is desirable (e.g. for self-tests),
|
|
||||||
* then use DEBUG_WARN_ERR instead.
|
|
||||||
**/
|
|
||||||
#define debug_warn(expr) \
|
|
||||||
STMT(\
|
|
||||||
static atomic_bool suppress__;\
|
|
||||||
switch(debug_OnAssertionFailure(expr, &suppress__, WIDEN(__FILE__), __LINE__, __func__))\
|
|
||||||
{\
|
|
||||||
case ER_CONTINUE:\
|
|
||||||
break;\
|
|
||||||
case ER_BREAK:\
|
|
||||||
default:\
|
|
||||||
debug_break();\
|
|
||||||
break;\
|
|
||||||
}\
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* if (LibError)err indicates an function failed, display the error dialog.
|
|
||||||
* used by CHECK_ERR et al., which wrap function calls and automatically
|
|
||||||
* warn user and return to caller.
|
|
||||||
**/
|
|
||||||
#define DEBUG_WARN_ERR(err)\
|
|
||||||
STMT(\
|
|
||||||
static atomic_bool suppress__;\
|
|
||||||
switch(debug_OnError(err, &suppress__, WIDEN(__FILE__), __LINE__, __func__))\
|
|
||||||
{\
|
|
||||||
case ER_CONTINUE:\
|
|
||||||
break;\
|
|
||||||
case ER_BREAK:\
|
|
||||||
default:\
|
|
||||||
debug_break();\
|
|
||||||
break;\
|
|
||||||
}\
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* called when a debug_assert fails;
|
|
||||||
* notifies the user via debug_DisplayError.
|
* notifies the user via debug_DisplayError.
|
||||||
*
|
*
|
||||||
* @param assert_expr the expression that failed; typically passed as
|
* @param assert_expr the expression that failed; typically passed as
|
||||||
@ -393,6 +379,9 @@ LIB_API ErrorReaction debug_OnError(LibError err, atomic_bool* suppress, const w
|
|||||||
*/
|
*/
|
||||||
LIB_API void debug_SkipErrors(LibError err);
|
LIB_API void debug_SkipErrors(LibError err);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return how many errors were skipped since the call to debug_SkipErrors()
|
||||||
|
**/
|
||||||
LIB_API size_t debug_StopSkippingErrors();
|
LIB_API size_t debug_StopSkippingErrors();
|
||||||
|
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ ERROR_ASSOCIATE(ERR::STL_CNT_INVALID, L"Container type is known but contents are
|
|||||||
dst--;\
|
dst--;\
|
||||||
src += ARRAY_SIZE(what)-1;\
|
src += ARRAY_SIZE(what)-1;\
|
||||||
/* strip everything until trailing > is matched */\
|
/* strip everything until trailing > is matched */\
|
||||||
debug_assert(nesting == 0);\
|
ENSURE(nesting == 0);\
|
||||||
nesting = 1;\
|
nesting = 1;\
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,7 +110,7 @@ wchar_t* debug_stl_simplify_name(wchar_t* name)
|
|||||||
else if(c == '>')
|
else if(c == '>')
|
||||||
{
|
{
|
||||||
nesting--;
|
nesting--;
|
||||||
debug_assert(nesting >= 0);
|
ENSURE(nesting >= 0);
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -276,9 +276,9 @@ private:
|
|||||||
{
|
{
|
||||||
const size_t el_per_bucket = ElementsPerBucket(el_size);
|
const size_t el_per_bucket = ElementsPerBucket(el_size);
|
||||||
const size_t bucket_idx = i / el_per_bucket;
|
const size_t bucket_idx = i / el_per_bucket;
|
||||||
debug_assert(bucket_idx < _Mapsize);
|
ENSURE(bucket_idx < _Mapsize);
|
||||||
const size_t idx_in_bucket = i - bucket_idx * el_per_bucket;
|
const size_t idx_in_bucket = i - bucket_idx * el_per_bucket;
|
||||||
debug_assert(idx_in_bucket < el_per_bucket);
|
ENSURE(idx_in_bucket < el_per_bucket);
|
||||||
const u8** map = (const u8**)_Map;
|
const u8** map = (const u8**)_Map;
|
||||||
const u8* bucket = map[bucket_idx];
|
const u8* bucket = map[bucket_idx];
|
||||||
const u8* p = bucket + idx_in_bucket*el_size;
|
const u8* p = bucket + idx_in_bucket*el_size;
|
||||||
@ -517,8 +517,8 @@ template<class T> bool get_container_info(const T& t, size_t size, size_t el_siz
|
|||||||
typedef typename T::iterator iterator;
|
typedef typename T::iterator iterator;
|
||||||
typedef typename T::const_iterator const_iterator;
|
typedef typename T::const_iterator const_iterator;
|
||||||
|
|
||||||
debug_assert(sizeof(T) == size);
|
ENSURE(sizeof(T) == size);
|
||||||
debug_assert(sizeof(iterator) < DEBUG_STL_MAX_ITERATOR_SIZE);
|
ENSURE(sizeof(iterator) < DEBUG_STL_MAX_ITERATOR_SIZE);
|
||||||
|
|
||||||
el_count = t.NumElements(el_size);
|
el_count = t.NumElements(el_size);
|
||||||
|
|
||||||
|
@ -45,13 +45,13 @@ void dbghelp_ImportFunctions()
|
|||||||
// to our executable directory, which contains a newer dbghelp.dll.
|
// to our executable directory, which contains a newer dbghelp.dll.
|
||||||
const OsPath pathname = sys_ExecutablePathname().Parent()/"dbghelp.dll";
|
const OsPath pathname = sys_ExecutablePathname().Parent()/"dbghelp.dll";
|
||||||
HMODULE hDbghelp = LoadLibraryW(OsString(pathname).c_str());
|
HMODULE hDbghelp = LoadLibraryW(OsString(pathname).c_str());
|
||||||
debug_assert(hDbghelp);
|
ENSURE(hDbghelp);
|
||||||
#define FUNC(ret, name, params) p##name = (ret (__stdcall*) params)GetProcAddress(hDbghelp, #name);
|
#define FUNC(ret, name, params) p##name = (ret (__stdcall*) params)GetProcAddress(hDbghelp, #name);
|
||||||
#include "lib/external_libraries/dbghelp_funcs.h"
|
#include "lib/external_libraries/dbghelp_funcs.h"
|
||||||
#undef FUNC
|
#undef FUNC
|
||||||
|
|
||||||
// if this function is missing, the DLL is too old.
|
// if this function is missing, the DLL is too old.
|
||||||
debug_assert(pSymInitializeW);
|
ENSURE(pSymInitializeW);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // OS_WIN
|
#endif // OS_WIN
|
||||||
|
@ -95,13 +95,13 @@ public:
|
|||||||
{
|
{
|
||||||
// +1 to skip NULL_ID value
|
// +1 to skip NULL_ID value
|
||||||
FileId id = node - &((*nodes)[0]) +1;
|
FileId id = node - &((*nodes)[0]) +1;
|
||||||
debug_assert(id <= nodes->size());
|
ENSURE(id <= nodes->size());
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
FileNode* node_from_id(FileId id) const
|
FileNode* node_from_id(FileId id) const
|
||||||
{
|
{
|
||||||
debug_assert(id != NULL_ID);
|
ENSURE(id != NULL_ID);
|
||||||
return &(*nodes)[id-1];
|
return &(*nodes)[id-1];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -387,7 +387,7 @@ class TourBuilder
|
|||||||
|
|
||||||
const bool introduced_cycle = is_cycle_at(file_nodes, second_id);
|
const bool introduced_cycle = is_cycle_at(file_nodes, second_id);
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
debug_assert(introduced_cycle == is_cycle_at(file_nodes, first_id));
|
ENSURE(introduced_cycle == is_cycle_at(file_nodes, first_id));
|
||||||
#endif
|
#endif
|
||||||
if(introduced_cycle)
|
if(introduced_cycle)
|
||||||
{
|
{
|
||||||
@ -753,7 +753,7 @@ int archive_build_continue(ArchiveBuildState* ab)
|
|||||||
// 0 means "finished", so don't return that!
|
// 0 means "finished", so don't return that!
|
||||||
if(progress_percent == 0)
|
if(progress_percent == 0)
|
||||||
progress_percent = 1;
|
progress_percent = 1;
|
||||||
debug_assert(0 < progress_percent && progress_percent <= 100);
|
ENSURE(0 < progress_percent && progress_percent <= 100);
|
||||||
return progress_percent;
|
return progress_percent;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1020,7 +1020,7 @@ void trace_get(Trace* t)
|
|||||||
if(last_start_idx == start_idx)
|
if(last_start_idx == start_idx)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
debug_assert(start_idx < t->total_ents);
|
ENSURE(start_idx < t->total_ents);
|
||||||
|
|
||||||
TraceRun& run = runs[t->num_runs++];
|
TraceRun& run = runs[t->num_runs++];
|
||||||
run.num_ents = last_start_idx - start_idx;
|
run.num_ents = last_start_idx - start_idx;
|
||||||
@ -1031,7 +1031,7 @@ void trace_get(Trace* t)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
debug_assert(t->num_runs != 0);
|
ENSURE(t->num_runs != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -60,10 +60,10 @@ static time_t time_t_from_FAT(u32 fat_timedate)
|
|||||||
t.tm_isdst = -1; // unknown - let libc determine
|
t.tm_isdst = -1; // unknown - let libc determine
|
||||||
|
|
||||||
// otherwise: totally bogus, and at the limit of 32-bit time_t
|
// otherwise: totally bogus, and at the limit of 32-bit time_t
|
||||||
debug_assert(t.tm_year < 138);
|
ENSURE(t.tm_year < 138);
|
||||||
|
|
||||||
time_t ret = mktime(&t);
|
time_t ret = mktime(&t);
|
||||||
debug_assert(ret != (time_t)-1); // mktime shouldn't fail
|
ENSURE(ret != (time_t)-1); // mktime shouldn't fail
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,7 +130,7 @@ public:
|
|||||||
|
|
||||||
size_t Size() const
|
size_t Size() const
|
||||||
{
|
{
|
||||||
debug_assert(m_magic == lfh_magic);
|
ENSURE(m_magic == lfh_magic);
|
||||||
size_t size = sizeof(LFH);
|
size_t size = sizeof(LFH);
|
||||||
size += read_le16(&m_fn_len);
|
size += read_le16(&m_fn_len);
|
||||||
size += read_le16(&m_e_len);
|
size += read_le16(&m_e_len);
|
||||||
@ -338,7 +338,7 @@ public:
|
|||||||
RETURN_ERR(io::Run(op, io::Parameters(), streamFeeder));
|
RETURN_ERR(io::Run(op, io::Parameters(), streamFeeder));
|
||||||
RETURN_ERR(stream.Finish());
|
RETURN_ERR(stream.Finish());
|
||||||
#if CODEC_COMPUTE_CHECKSUM
|
#if CODEC_COMPUTE_CHECKSUM
|
||||||
debug_assert(m_checksum == stream.Checksum());
|
ENSURE(m_checksum == stream.Checksum());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return INFO::OK;
|
return INFO::OK;
|
||||||
@ -376,7 +376,7 @@ private:
|
|||||||
// avoids cluttering the trace and cache contents.
|
// avoids cluttering the trace and cache contents.
|
||||||
LibError operator()(const u8* block, size_t size) const
|
LibError operator()(const u8* block, size_t size) const
|
||||||
{
|
{
|
||||||
debug_assert(size <= lfh_bytes_remaining);
|
ENSURE(size <= lfh_bytes_remaining);
|
||||||
memcpy(lfh_dst, block, size);
|
memcpy(lfh_dst, block, size);
|
||||||
lfh_dst += size;
|
lfh_dst += size;
|
||||||
lfh_bytes_remaining -= size;
|
lfh_bytes_remaining -= size;
|
||||||
@ -438,7 +438,7 @@ public:
|
|||||||
GetFileInfo(pathname, &fileInfo);
|
GetFileInfo(pathname, &fileInfo);
|
||||||
m_fileSize = fileInfo.Size();
|
m_fileSize = fileInfo.Size();
|
||||||
const size_t minFileSize = sizeof(LFH)+sizeof(CDFH)+sizeof(ECDR);
|
const size_t minFileSize = sizeof(LFH)+sizeof(CDFH)+sizeof(ECDR);
|
||||||
debug_assert(m_fileSize >= off_t(minFileSize));
|
ENSURE(m_fileSize >= off_t(minFileSize));
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual LibError ReadEntries(ArchiveEntryCallback cb, uintptr_t cbData)
|
virtual LibError ReadEntries(ArchiveEntryCallback cb, uintptr_t cbData)
|
||||||
@ -497,7 +497,7 @@ private:
|
|||||||
// found it
|
// found it
|
||||||
if(*(u32*)p == magic)
|
if(*(u32*)p == magic)
|
||||||
{
|
{
|
||||||
debug_assert(p == start); // otherwise, the archive is a bit broken
|
ENSURE(p == start); // otherwise, the archive is a bit broken
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -151,11 +151,11 @@ protected:
|
|||||||
// must have been consumed.
|
// must have been consumed.
|
||||||
if(ret == Z_STREAM_END)
|
if(ret == Z_STREAM_END)
|
||||||
{
|
{
|
||||||
debug_assert(m_zs.avail_in == 0);
|
ENSURE(m_zs.avail_in == 0);
|
||||||
ret = Z_OK;
|
ret = Z_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
debug_assert(inSize >= m_zs.avail_in && outSize >= m_zs.avail_out);
|
ENSURE(inSize >= m_zs.avail_in && outSize >= m_zs.avail_out);
|
||||||
inConsumed = inSize - m_zs.avail_in;
|
inConsumed = inSize - m_zs.avail_in;
|
||||||
outProduced = outSize - m_zs.avail_out;
|
outProduced = outSize - m_zs.avail_out;
|
||||||
|
|
||||||
@ -195,7 +195,7 @@ public:
|
|||||||
const int memLevel = 9; // max speed; total mem ~= 384KiB
|
const int memLevel = 9; // max speed; total mem ~= 384KiB
|
||||||
const int strategy = Z_DEFAULT_STRATEGY; // normal data - not RLE
|
const int strategy = Z_DEFAULT_STRATEGY; // normal data - not RLE
|
||||||
const int ret = deflateInit2(&m_zs, level, Z_DEFLATED, windowBits, memLevel, strategy);
|
const int ret = deflateInit2(&m_zs, level, Z_DEFLATED, windowBits, memLevel, strategy);
|
||||||
debug_assert(ret == Z_OK);
|
ENSURE(ret == Z_OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~Compressor_ZLib()
|
virtual ~Compressor_ZLib()
|
||||||
@ -230,7 +230,7 @@ public:
|
|||||||
// our output buffer has enough space due to use of deflateBound;
|
// our output buffer has enough space due to use of deflateBound;
|
||||||
// therefore, deflate must return Z_STREAM_END.
|
// therefore, deflate must return Z_STREAM_END.
|
||||||
const int ret = deflate(&m_zs, Z_FINISH);
|
const int ret = deflate(&m_zs, Z_FINISH);
|
||||||
debug_assert(ret == Z_STREAM_END);
|
ENSURE(ret == Z_STREAM_END);
|
||||||
|
|
||||||
outProduced = size_t(availOut - m_zs.avail_out);
|
outProduced = size_t(availOut - m_zs.avail_out);
|
||||||
|
|
||||||
@ -249,7 +249,7 @@ public:
|
|||||||
{
|
{
|
||||||
const int windowBits = -MAX_WBITS; // max window size; omit ZLib header
|
const int windowBits = -MAX_WBITS; // max window size; omit ZLib header
|
||||||
const int ret = inflateInit2(&m_zs, windowBits);
|
const int ret = inflateInit2(&m_zs, windowBits);
|
||||||
debug_assert(ret == Z_OK);
|
ENSURE(ret == Z_OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~Decompressor_ZLib()
|
virtual ~Decompressor_ZLib()
|
||||||
@ -263,7 +263,7 @@ public:
|
|||||||
// relying on an upper bound for the output is a really bad idea for
|
// relying on an upper bound for the output is a really bad idea for
|
||||||
// large files. archive formats store the uncompressed file sizes,
|
// large files. archive formats store the uncompressed file sizes,
|
||||||
// so callers should use that when allocating the output buffer.
|
// so callers should use that when allocating the output buffer.
|
||||||
debug_assert(inSize < 1*MiB);
|
ENSURE(inSize < 1*MiB);
|
||||||
|
|
||||||
return inSize*1032; // see http://www.zlib.org/zlib_tech.html
|
return inSize*1032; // see http://www.zlib.org/zlib_tech.html
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ void OutputBufferManager::Reset()
|
|||||||
|
|
||||||
void OutputBufferManager::SetBuffer(u8* buffer, size_t size)
|
void OutputBufferManager::SetBuffer(u8* buffer, size_t size)
|
||||||
{
|
{
|
||||||
debug_assert(IsAllowableBuffer(buffer, size));
|
ENSURE(IsAllowableBuffer(buffer, size));
|
||||||
|
|
||||||
m_buffer = buffer;
|
m_buffer = buffer;
|
||||||
m_size = size;
|
m_size = size;
|
||||||
|
@ -75,7 +75,7 @@ static void timer_start(double* start_time_storage = &start_time)
|
|||||||
{
|
{
|
||||||
// make sure no measurement is currently active
|
// make sure no measurement is currently active
|
||||||
// (since start_time is shared static storage)
|
// (since start_time is shared static storage)
|
||||||
debug_assert(*start_time_storage == 0.0);
|
ENSURE(*start_time_storage == 0.0);
|
||||||
*start_time_storage = timer_Time();
|
*start_time_storage = timer_Time();
|
||||||
}
|
}
|
||||||
static double timer_reset(double* start_time_storage = &start_time)
|
static double timer_reset(double* start_time_storage = &start_time)
|
||||||
@ -136,7 +136,7 @@ void stats_open()
|
|||||||
|
|
||||||
void stats_close()
|
void stats_close()
|
||||||
{
|
{
|
||||||
debug_assert(open_files_cur > 0);
|
ENSURE(open_files_cur > 0);
|
||||||
open_files_cur--;
|
open_files_cur--;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -157,7 +157,7 @@ void stats_buf_alloc(size_t size, size_t alignedSize)
|
|||||||
|
|
||||||
void stats_buf_free()
|
void stats_buf_free()
|
||||||
{
|
{
|
||||||
debug_assert(extant_bufs_cur > 0);
|
ENSURE(extant_bufs_cur > 0);
|
||||||
extant_bufs_cur--;
|
extant_bufs_cur--;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -191,8 +191,8 @@ ScopedIoMonitor::~ScopedIoMonitor()
|
|||||||
|
|
||||||
void ScopedIoMonitor::NotifyOfSuccess(FileIOImplentation fi, int opcode, off_t size)
|
void ScopedIoMonitor::NotifyOfSuccess(FileIOImplentation fi, int opcode, off_t size)
|
||||||
{
|
{
|
||||||
debug_assert(fi < FI_MAX_IDX);
|
ENSURE(fi < FI_MAX_IDX);
|
||||||
debug_assert(opcode == LIO_READ || opcode == LIO_WRITE);
|
ENSURE(opcode == LIO_READ || opcode == LIO_WRITE);
|
||||||
|
|
||||||
io_actual_size_total[fi][opcode == LIO_WRITE] += size;
|
io_actual_size_total[fi][opcode == LIO_WRITE] += size;
|
||||||
io_elapsed_time[fi][opcode == LIO_WRITE] += timer_reset(&m_startTime);
|
io_elapsed_time[fi][opcode == LIO_WRITE] += timer_reset(&m_startTime);
|
||||||
@ -216,7 +216,7 @@ void stats_cb_finish()
|
|||||||
|
|
||||||
void stats_cache(CacheRet cr, size_t size)
|
void stats_cache(CacheRet cr, size_t size)
|
||||||
{
|
{
|
||||||
debug_assert(cr == CR_HIT || cr == CR_MISS);
|
ENSURE(cr == CR_HIT || cr == CR_MISS);
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
if(cr == CR_MISS)
|
if(cr == CR_MISS)
|
||||||
@ -236,7 +236,7 @@ void stats_cache(CacheRet cr, size_t size)
|
|||||||
|
|
||||||
void stats_block_cache(CacheRet cr)
|
void stats_block_cache(CacheRet cr)
|
||||||
{
|
{
|
||||||
debug_assert(cr == CR_HIT || cr == CR_MISS);
|
ENSURE(cr == CR_HIT || cr == CR_MISS);
|
||||||
block_cache_count[cr]++;
|
block_cache_count[cr]++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,14 +64,14 @@ TraceEntry::TraceEntry(const std::wstring& text)
|
|||||||
stream >> m_timestamp;
|
stream >> m_timestamp;
|
||||||
|
|
||||||
stream >> dummy;
|
stream >> dummy;
|
||||||
debug_assert(dummy == ':');
|
ENSURE(dummy == ':');
|
||||||
|
|
||||||
stream >> action;
|
stream >> action;
|
||||||
debug_assert(action == 'L' || action == 'S');
|
ENSURE(action == 'L' || action == 'S');
|
||||||
m_action = (EAction)action;
|
m_action = (EAction)action;
|
||||||
|
|
||||||
stream >> dummy;
|
stream >> dummy;
|
||||||
debug_assert(dummy == '"');
|
ENSURE(dummy == '"');
|
||||||
|
|
||||||
Path::String pathname;
|
Path::String pathname;
|
||||||
std::getline(stream, pathname, L'"');
|
std::getline(stream, pathname, L'"');
|
||||||
@ -79,9 +79,9 @@ TraceEntry::TraceEntry(const std::wstring& text)
|
|||||||
|
|
||||||
stream >> m_size;
|
stream >> m_size;
|
||||||
|
|
||||||
debug_assert(stream.get() == '\n');
|
ENSURE(stream.get() == '\n');
|
||||||
debug_assert(stream.good());
|
ENSURE(stream.good());
|
||||||
debug_assert(stream.get() == WEOF);
|
ENSURE(stream.get() == WEOF);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -215,7 +215,7 @@ private:
|
|||||||
void* Allocate()
|
void* Allocate()
|
||||||
{
|
{
|
||||||
void* p = pool_alloc(&m_pool, 0);
|
void* p = pool_alloc(&m_pool, 0);
|
||||||
debug_assert(p);
|
ENSURE(p);
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ LibError FileOpen(const OsPath& pathname, int opcode, int& fd)
|
|||||||
oflag = O_WRONLY|O_CREAT|O_TRUNC;
|
oflag = O_WRONLY|O_CREAT|O_TRUNC;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
debug_assert(0);
|
ENSURE(0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#if OS_WIN
|
#if OS_WIN
|
||||||
|
@ -34,7 +34,7 @@ struct DirDeleter
|
|||||||
void operator()(WDIR* osDir) const
|
void operator()(WDIR* osDir) const
|
||||||
{
|
{
|
||||||
const int ret = wclosedir(osDir);
|
const int ret = wclosedir(osDir);
|
||||||
debug_assert(ret == 0);
|
ENSURE(ret == 0);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ bool FileExists(const OsPath& pathname)
|
|||||||
u64 FileSize(const OsPath& pathname)
|
u64 FileSize(const OsPath& pathname)
|
||||||
{
|
{
|
||||||
struct stat s;
|
struct stat s;
|
||||||
debug_assert(wstat(pathname, &s) == 0);
|
ENSURE(wstat(pathname, &s) == 0);
|
||||||
return s.st_size;
|
return s.st_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,7 +68,7 @@ namespace io {
|
|||||||
|
|
||||||
UniqueRange Allocate(size_t size, size_t alignment)
|
UniqueRange Allocate(size_t size, size_t alignment)
|
||||||
{
|
{
|
||||||
debug_assert(is_pow2(alignment));
|
ENSURE(is_pow2(alignment));
|
||||||
if(alignment <= (size_t)idxDeleterBits)
|
if(alignment <= (size_t)idxDeleterBits)
|
||||||
alignment = idxDeleterBits+1;
|
alignment = idxDeleterBits+1;
|
||||||
|
|
||||||
@ -91,7 +91,7 @@ LibError Issue(aiocb& cb, size_t queueDepth)
|
|||||||
UNUSED2(queueDepth);
|
UNUSED2(queueDepth);
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
debug_assert(lseek(cb.aio_fildes, cb.aio_offset, SEEK_SET) == cb.aio_offset);
|
ENSURE(lseek(cb.aio_fildes, cb.aio_offset, SEEK_SET) == cb.aio_offset);
|
||||||
|
|
||||||
void* buf = (void*)cb.aio_buf; // cast from volatile void*
|
void* buf = (void*)cb.aio_buf; // cast from volatile void*
|
||||||
const ssize_t bytesTransferred = (cb.aio_lio_opcode == LIO_WRITE)? write(cb.aio_fildes, buf, cb.aio_nbytes) : read(cb.aio_fildes, buf, cb.aio_nbytes);
|
const ssize_t bytesTransferred = (cb.aio_lio_opcode == LIO_WRITE)? write(cb.aio_fildes, buf, cb.aio_nbytes) : read(cb.aio_fildes, buf, cb.aio_nbytes);
|
||||||
@ -123,7 +123,7 @@ SUSPEND_AGAIN:
|
|||||||
}
|
}
|
||||||
|
|
||||||
const int err = aio_error(&cb);
|
const int err = aio_error(&cb);
|
||||||
debug_assert(err != EINPROGRESS); // else aio_return is undefined
|
ENSURE(err != EINPROGRESS); // else aio_return is undefined
|
||||||
ssize_t bytesTransferred = aio_return(&cb);
|
ssize_t bytesTransferred = aio_return(&cb);
|
||||||
if(bytesTransferred == -1) // transfer failed
|
if(bytesTransferred == -1) // transfer failed
|
||||||
{
|
{
|
||||||
|
@ -70,11 +70,11 @@ struct Operation
|
|||||||
|
|
||||||
void Validate() const
|
void Validate() const
|
||||||
{
|
{
|
||||||
debug_assert(fd >= 0);
|
ENSURE(fd >= 0);
|
||||||
debug_assert(opcode == LIO_READ || opcode == LIO_WRITE);
|
ENSURE(opcode == LIO_READ || opcode == LIO_WRITE);
|
||||||
|
|
||||||
debug_assert(offset >= 0);
|
ENSURE(offset >= 0);
|
||||||
debug_assert(size >= 0);
|
ENSURE(size >= 0);
|
||||||
// buf can legitimately be 0 (see above)
|
// buf can legitimately be 0 (see above)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,20 +112,20 @@ struct Parameters
|
|||||||
|
|
||||||
void Validate(const Operation& op) const
|
void Validate(const Operation& op) const
|
||||||
{
|
{
|
||||||
debug_assert(is_pow2(alignment));
|
ENSURE(is_pow2(alignment));
|
||||||
debug_assert(alignment > 0);
|
ENSURE(alignment > 0);
|
||||||
|
|
||||||
if(blockSize != 0)
|
if(blockSize != 0)
|
||||||
{
|
{
|
||||||
debug_assert(is_pow2(blockSize));
|
ENSURE(is_pow2(blockSize));
|
||||||
debug_assert(pageSize <= blockSize); // (don't bother checking an upper bound)
|
ENSURE(pageSize <= blockSize); // (don't bother checking an upper bound)
|
||||||
}
|
}
|
||||||
|
|
||||||
debug_assert(1 <= queueDepth && queueDepth <= maxQueueDepth);
|
ENSURE(1 <= queueDepth && queueDepth <= maxQueueDepth);
|
||||||
|
|
||||||
debug_assert(IsAligned(op.offset, alignment));
|
ENSURE(IsAligned(op.offset, alignment));
|
||||||
// op.size doesn't need to be aligned
|
// op.size doesn't need to be aligned
|
||||||
debug_assert(IsAligned(op.buf, alignment));
|
ENSURE(IsAligned(op.buf, alignment));
|
||||||
}
|
}
|
||||||
|
|
||||||
// (ATTO only allows 10, which improves upon 8)
|
// (ATTO only allows 10, which improves upon 8)
|
||||||
|
@ -56,7 +56,7 @@ void WriteBuffer::Append(const void* data, size_t size)
|
|||||||
|
|
||||||
void WriteBuffer::Overwrite(const void* data, size_t size, size_t offset)
|
void WriteBuffer::Overwrite(const void* data, size_t size, size_t offset)
|
||||||
{
|
{
|
||||||
debug_assert(offset+size < m_size);
|
ENSURE(offset+size < m_size);
|
||||||
memcpy(m_data.get()+offset, data, size);
|
memcpy(m_data.get()+offset, data, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,7 +165,7 @@ public:
|
|||||||
shared_ptr<u8> Reserve(size_t size)
|
shared_ptr<u8> Reserve(size_t size)
|
||||||
{
|
{
|
||||||
// (should never happen because the VFS ensures size != 0.)
|
// (should never happen because the VFS ensures size != 0.)
|
||||||
debug_assert(size != 0);
|
ENSURE(size != 0);
|
||||||
|
|
||||||
// (300 iterations have been observed when reserving several MB
|
// (300 iterations have been observed when reserving several MB
|
||||||
// of space in a full cache)
|
// of space in a full cache)
|
||||||
@ -184,7 +184,7 @@ public:
|
|||||||
bool removed = m_cache.remove_least_valuable(&discardedData, &discardedSize);
|
bool removed = m_cache.remove_least_valuable(&discardedData, &discardedSize);
|
||||||
// only false if cache is empty, which can't be the case because
|
// only false if cache is empty, which can't be the case because
|
||||||
// allocation failed.
|
// allocation failed.
|
||||||
debug_assert(removed);
|
ENSURE(removed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -56,14 +56,14 @@ static LibError CreateDirectory(const OsPath& path)
|
|||||||
// file is "in the way" and needs to be deleted)
|
// file is "in the way" and needs to be deleted)
|
||||||
struct stat s;
|
struct stat s;
|
||||||
const int ret = wstat(path, &s);
|
const int ret = wstat(path, &s);
|
||||||
debug_assert(ret == 0); // (wmkdir said it existed)
|
ENSURE(ret == 0); // (wmkdir said it existed)
|
||||||
debug_assert(S_ISDIR(s.st_mode));
|
ENSURE(S_ISDIR(s.st_mode));
|
||||||
return INFO::OK;
|
return INFO::OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
// unexpected failure
|
// unexpected failure
|
||||||
debug_printf(L"wmkdir failed with errno=%d\n", errno);
|
debug_printf(L"wmkdir failed with errno=%d\n", errno);
|
||||||
debug_assert(0);
|
ENSURE(0);
|
||||||
return LibError_from_errno();
|
return LibError_from_errno();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,7 +74,7 @@ LibError vfs_Lookup(const VfsPath& pathname, VfsDirectory* startDirectory, VfsDi
|
|||||||
const bool addMissingDirectories = (flags & VFS_LOOKUP_ADD) != 0;
|
const bool addMissingDirectories = (flags & VFS_LOOKUP_ADD) != 0;
|
||||||
const bool createMissingDirectories = (flags & VFS_LOOKUP_CREATE) != 0;
|
const bool createMissingDirectories = (flags & VFS_LOOKUP_CREATE) != 0;
|
||||||
const bool skipPopulate = (flags & VFS_LOOKUP_SKIP_POPULATE) != 0;
|
const bool skipPopulate = (flags & VFS_LOOKUP_SKIP_POPULATE) != 0;
|
||||||
debug_assert((flags & ~(VFS_LOOKUP_ADD|VFS_LOOKUP_CREATE|VFS_LOOKUP_SKIP_POPULATE)) == 0);
|
ENSURE((flags & ~(VFS_LOOKUP_ADD|VFS_LOOKUP_CREATE|VFS_LOOKUP_SKIP_POPULATE)) == 0);
|
||||||
|
|
||||||
directory = startDirectory;
|
directory = startDirectory;
|
||||||
if(pfile)
|
if(pfile)
|
||||||
@ -132,7 +132,7 @@ LibError vfs_Lookup(const VfsPath& pathname, VfsDirectory* startDirectory, VfsDi
|
|||||||
|
|
||||||
if(pfile)
|
if(pfile)
|
||||||
{
|
{
|
||||||
debug_assert(!pathname.IsDirectory());
|
ENSURE(!pathname.IsDirectory());
|
||||||
const VfsPath filename = pathname.string().substr(pos);
|
const VfsPath filename = pathname.string().substr(pos);
|
||||||
*pfile = directory->GetFile(filename);
|
*pfile = directory->GetFile(filename);
|
||||||
if(!*pfile)
|
if(!*pfile)
|
||||||
|
@ -127,7 +127,7 @@ VfsDirectory* VfsDirectory::GetSubdirectory(const VfsPath& name)
|
|||||||
void VfsDirectory::SetAssociatedDirectory(const PRealDirectory& realDirectory)
|
void VfsDirectory::SetAssociatedDirectory(const PRealDirectory& realDirectory)
|
||||||
{
|
{
|
||||||
if(!cpu_CAS(&m_shouldPopulate, 0, 1))
|
if(!cpu_CAS(&m_shouldPopulate, 0, 1))
|
||||||
debug_assert(0); // caller didn't check ShouldPopulate
|
ENSURE(0); // caller didn't check ShouldPopulate
|
||||||
m_realDirectory = realDirectory;
|
m_realDirectory = realDirectory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ public:
|
|||||||
, m_lastTime(0) // will be set on first call
|
, m_lastTime(0) // will be set on first call
|
||||||
, m_numEvents(0)
|
, m_numEvents(0)
|
||||||
{
|
{
|
||||||
debug_assert(resolution > 0.0);
|
ENSURE(resolution > 0.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator()(double time, double& frequency)
|
bool operator()(double time, double& frequency)
|
||||||
|
@ -38,7 +38,7 @@ static size_t handler_stack_top = 0;
|
|||||||
|
|
||||||
void in_add_handler(InHandler handler)
|
void in_add_handler(InHandler handler)
|
||||||
{
|
{
|
||||||
debug_assert(handler);
|
ENSURE(handler);
|
||||||
|
|
||||||
if(handler_stack_top >= MAX_HANDLERS)
|
if(handler_stack_top >= MAX_HANDLERS)
|
||||||
WARN_ERR_RETURN(ERR::LIMIT);
|
WARN_ERR_RETURN(ERR::LIMIT);
|
||||||
@ -56,7 +56,7 @@ void in_dispatch_event(const SDL_Event_* ev)
|
|||||||
{
|
{
|
||||||
for(int i = (int)handler_stack_top-1; i >= 0; i--)
|
for(int i = (int)handler_stack_top-1; i >= 0; i--)
|
||||||
{
|
{
|
||||||
debug_assert(handler_stack[i] && ev);
|
ENSURE(handler_stack[i] && ev);
|
||||||
InReaction ret = handler_stack[i](ev);
|
InReaction ret = handler_stack[i](ev);
|
||||||
// .. done, return
|
// .. done, return
|
||||||
if(ret == IN_HANDLED)
|
if(ret == IN_HANDLED)
|
||||||
@ -66,6 +66,6 @@ void in_dispatch_event(const SDL_Event_* ev)
|
|||||||
continue;
|
continue;
|
||||||
// .. invalid return value
|
// .. invalid return value
|
||||||
else
|
else
|
||||||
debug_assert(0); // invalid handler return value
|
ENSURE(0); // invalid handler return value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -97,12 +97,12 @@ u8 u8_from_double(double in)
|
|||||||
{
|
{
|
||||||
if(!(0.0 <= in && in < 1.0))
|
if(!(0.0 <= in && in < 1.0))
|
||||||
{
|
{
|
||||||
debug_assert(0); // clampf not in [0,1)
|
ENSURE(0); // clampf not in [0,1)
|
||||||
return 255;
|
return 255;
|
||||||
}
|
}
|
||||||
|
|
||||||
int l = (int)(in * 255.0);
|
int l = (int)(in * 255.0);
|
||||||
debug_assert((unsigned)l <= 255u);
|
ENSURE((unsigned)l <= 255u);
|
||||||
return (u8)l;
|
return (u8)l;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,11 +111,11 @@ u16 u16_from_double(double in)
|
|||||||
{
|
{
|
||||||
if(!(0.0 <= in && in < 1.0))
|
if(!(0.0 <= in && in < 1.0))
|
||||||
{
|
{
|
||||||
debug_assert(0); // clampf not in [0,1)
|
ENSURE(0); // clampf not in [0,1)
|
||||||
return 65535;
|
return 65535;
|
||||||
}
|
}
|
||||||
|
|
||||||
long l = (long)(in * 65535.0);
|
long l = (long)(in * 65535.0);
|
||||||
debug_assert((unsigned long)l <= 65535u);
|
ENSURE((unsigned long)l <= 65535u);
|
||||||
return (u16)l;
|
return (u16)l;
|
||||||
}
|
}
|
||||||
|
@ -106,18 +106,14 @@ template<typename T, size_t n> u8 (*ArraySizeDeducer(T (&)[n]))[n];
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
T Clamp(T val, T min, T max)
|
T Clamp(T val, T min, T max)
|
||||||
{
|
{
|
||||||
#ifndef NDEBUG
|
ASSERT(min <= max);
|
||||||
debug_assert(min <= max);
|
|
||||||
#endif
|
|
||||||
return std::max(min, std::min(val, max));
|
return std::max(min, std::min(val, max));
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
T DivideRoundUp(T dividend, T divisor)
|
T DivideRoundUp(T dividend, T divisor)
|
||||||
{
|
{
|
||||||
#ifndef NDEBUG
|
ASSERT(divisor != 0);
|
||||||
debug_assert(divisor != 0);
|
|
||||||
#endif
|
|
||||||
return (dividend + divisor-1) / divisor;
|
return (dividend + divisor-1) / divisor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -179,7 +175,7 @@ extern u32 u32_from_u16(u16 hi, u16 lo); /// assemble u32 from u16
|
|||||||
// these are generally useful but included here (instead of e.g. lib.h) for
|
// these are generally useful but included here (instead of e.g. lib.h) for
|
||||||
// several reasons:
|
// several reasons:
|
||||||
// - including implementation in lib.h doesn't work because the definition
|
// - including implementation in lib.h doesn't work because the definition
|
||||||
// of debug_assert in turn requires lib.h's STMT.
|
// of ENSURE in turn requires lib.h's STMT.
|
||||||
// - separate compilation of templates via export isn't supported by
|
// - separate compilation of templates via export isn't supported by
|
||||||
// most compilers.
|
// most compilers.
|
||||||
|
|
||||||
|
@ -114,7 +114,7 @@ LibError LibError_from_errno(bool warn_if_failed)
|
|||||||
|
|
||||||
LibError LibError_from_posix(int ret, bool warn_if_failed)
|
LibError LibError_from_posix(int ret, bool warn_if_failed)
|
||||||
{
|
{
|
||||||
debug_assert(ret == 0 || ret == -1);
|
ENSURE(ret == 0 || ret == -1);
|
||||||
if(ret == 0)
|
if(ret == 0)
|
||||||
return INFO::OK;
|
return INFO::OK;
|
||||||
return LibError_from_errno(warn_if_failed);
|
return LibError_from_errno(warn_if_failed);
|
||||||
|
@ -359,7 +359,7 @@ STMT(\
|
|||||||
)
|
)
|
||||||
|
|
||||||
// if expression evaluates to a negative error code, warn user
|
// if expression evaluates to a negative error code, warn user
|
||||||
// (this is similar to debug_assert but also works in release mode)
|
// (this is similar to ENSURE but also works in release mode)
|
||||||
#define WARN_ERR(expression)\
|
#define WARN_ERR(expression)\
|
||||||
STMT(\
|
STMT(\
|
||||||
i64 err64__ = (i64)(expression);\
|
i64 err64__ = (i64)(expression);\
|
||||||
|
@ -56,7 +56,7 @@ LibError ModuleInit(volatile ModuleInitState* initState, LibError (*init)())
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
debug_assert(latchedInitState == INITIALIZED || latchedInitState < 0);
|
ENSURE(latchedInitState == INITIALIZED || latchedInitState < 0);
|
||||||
return (LibError)latchedInitState;
|
return (LibError)latchedInitState;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -84,7 +84,7 @@ LibError ModuleShutdown(volatile ModuleInitState* initState, void (*shutdown)())
|
|||||||
if(latchedInitState == UNINITIALIZED)
|
if(latchedInitState == UNINITIALIZED)
|
||||||
return INFO::SKIPPED;
|
return INFO::SKIPPED;
|
||||||
|
|
||||||
debug_assert(latchedInitState < 0);
|
ENSURE(latchedInitState < 0);
|
||||||
return (LibError)latchedInitState;
|
return (LibError)latchedInitState;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -67,7 +67,7 @@ static bool have_30, have_21, have_20, have_15, have_14, have_13, have_12;
|
|||||||
// (useful for crash logs).
|
// (useful for crash logs).
|
||||||
const char* ogl_ExtensionString()
|
const char* ogl_ExtensionString()
|
||||||
{
|
{
|
||||||
debug_assert(exts && "call ogl_Init before using this function");
|
ENSURE(exts && "call ogl_Init before using this function");
|
||||||
return exts;
|
return exts;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -186,7 +186,7 @@ static bool isImplementedInCore(const char* ext)
|
|||||||
// takes subsequently added core support for some extensions into account.
|
// takes subsequently added core support for some extensions into account.
|
||||||
bool ogl_HaveExtension(const char* ext)
|
bool ogl_HaveExtension(const char* ext)
|
||||||
{
|
{
|
||||||
debug_assert(exts && "call ogl_Init before using this function");
|
ENSURE(exts && "call ogl_Init before using this function");
|
||||||
|
|
||||||
if(isImplementedInCore(ext))
|
if(isImplementedInCore(ext))
|
||||||
return true;
|
return true;
|
||||||
@ -221,7 +221,7 @@ bool ogl_HaveVersion(const char* desired_version)
|
|||||||
int desired_major, desired_minor;
|
int desired_major, desired_minor;
|
||||||
if(sscanf_s(desired_version, "%d.%d", &desired_major, &desired_minor) != 2)
|
if(sscanf_s(desired_version, "%d.%d", &desired_major, &desired_minor) != 2)
|
||||||
{
|
{
|
||||||
debug_assert(0); // invalid version string
|
ENSURE(0); // invalid version string
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -230,7 +230,7 @@ bool ogl_HaveVersion(const char* desired_version)
|
|||||||
int major, minor;
|
int major, minor;
|
||||||
if(!version || sscanf_s(version, "%d.%d", &major, &minor) != 2)
|
if(!version || sscanf_s(version, "%d.%d", &major, &minor) != 2)
|
||||||
{
|
{
|
||||||
debug_assert(0); // GL_VERSION invalid
|
ENSURE(0); // GL_VERSION invalid
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -475,7 +475,7 @@ void ogl_Init()
|
|||||||
// note: this is less about performance (since the above are not
|
// note: this is less about performance (since the above are not
|
||||||
// time-critical) than centralizing the 'OpenGL is ready' check.
|
// time-critical) than centralizing the 'OpenGL is ready' check.
|
||||||
exts = (const char*)glGetString(GL_EXTENSIONS);
|
exts = (const char*)glGetString(GL_EXTENSIONS);
|
||||||
debug_assert(exts); // else: called before OpenGL is ready for use
|
ENSURE(exts); // else: called before OpenGL is ready for use
|
||||||
have_12 = ogl_HaveVersion("1.2");
|
have_12 = ogl_HaveVersion("1.2");
|
||||||
have_13 = ogl_HaveVersion("1.3");
|
have_13 = ogl_HaveVersion("1.3");
|
||||||
have_14 = ogl_HaveVersion("1.4");
|
have_14 = ogl_HaveVersion("1.4");
|
||||||
|
@ -45,7 +45,7 @@ static inline std::string OsString(const OsPath& path)
|
|||||||
std::string string(wstring.length(), '\0');
|
std::string string(wstring.length(), '\0');
|
||||||
for(size_t i = 0; i < wstring.length(); i++)
|
for(size_t i = 0; i < wstring.length(); i++)
|
||||||
{
|
{
|
||||||
debug_assert(wstring[i] <= UCHAR_MAX);
|
ENSURE(wstring[i] <= UCHAR_MAX);
|
||||||
string[i] = wstring[i];
|
string[i] = wstring[i];
|
||||||
}
|
}
|
||||||
return string;
|
return string;
|
||||||
|
@ -75,6 +75,6 @@ size_t rand(size_t min_inclusive, size_t max_exclusive)
|
|||||||
x /= inv_range;
|
x /= inv_range;
|
||||||
|
|
||||||
x += min_inclusive;
|
x += min_inclusive;
|
||||||
debug_assert(x < max_exclusive);
|
ENSURE(x < max_exclusive);
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
@ -180,7 +180,7 @@ static void Cursor_dtor(Cursor* c)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
debug_assert(0);
|
ENSURE(0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -261,7 +261,7 @@ static LibError Cursor_to_string(const Cursor* c, wchar_t* buf)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
debug_assert(0);
|
ENSURE(0);
|
||||||
type = L"?";
|
type = L"?";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -323,7 +323,7 @@ LibError cursor_draw(const PIVFS& vfs, const wchar_t* name, int x, int y)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
debug_assert(0);
|
ENSURE(0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -328,7 +328,7 @@ static LibError Ogl_Program_reload(Ogl_Program* p, const PIVFS& vfs, const VfsPa
|
|||||||
ogl_WarnIfError();
|
ogl_WarnIfError();
|
||||||
|
|
||||||
// Check that we're not accidentally using shaders when they're not supported
|
// Check that we're not accidentally using shaders when they're not supported
|
||||||
debug_assert(pglCreateProgramObjectARB != NULL);
|
ENSURE(pglCreateProgramObjectARB != NULL);
|
||||||
|
|
||||||
p->id = pglCreateProgramObjectARB();
|
p->id = pglCreateProgramObjectARB();
|
||||||
if (!p->id)
|
if (!p->id)
|
||||||
|
@ -129,7 +129,7 @@ static GLint choose_fmt(size_t bpp, size_t flags)
|
|||||||
case 5:
|
case 5:
|
||||||
return GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
|
return GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
|
||||||
default:
|
default:
|
||||||
debug_assert(0); // invalid DXT value
|
ENSURE(0); // invalid DXT value
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -138,18 +138,18 @@ static GLint choose_fmt(size_t bpp, size_t flags)
|
|||||||
switch(bpp)
|
switch(bpp)
|
||||||
{
|
{
|
||||||
case 8:
|
case 8:
|
||||||
debug_assert(grey);
|
ENSURE(grey);
|
||||||
return GL_LUMINANCE;
|
return GL_LUMINANCE;
|
||||||
case 16:
|
case 16:
|
||||||
return GL_LUMINANCE_ALPHA;
|
return GL_LUMINANCE_ALPHA;
|
||||||
case 24:
|
case 24:
|
||||||
debug_assert(!alpha);
|
ENSURE(!alpha);
|
||||||
return bgr? GL_BGR : GL_RGB;
|
return bgr? GL_BGR : GL_RGB;
|
||||||
case 32:
|
case 32:
|
||||||
debug_assert(alpha);
|
ENSURE(alpha);
|
||||||
return bgr? GL_BGRA : GL_RGBA;
|
return bgr? GL_BGRA : GL_RGBA;
|
||||||
default:
|
default:
|
||||||
debug_assert(0); // invalid bpp
|
ENSURE(0); // invalid bpp
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -188,13 +188,13 @@ void ogl_tex_set_defaults(int q_flags, GLint filter)
|
|||||||
{
|
{
|
||||||
if(q_flags)
|
if(q_flags)
|
||||||
{
|
{
|
||||||
debug_assert(q_flags_valid(q_flags));
|
ENSURE(q_flags_valid(q_flags));
|
||||||
default_q_flags = q_flags;
|
default_q_flags = q_flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(filter)
|
if(filter)
|
||||||
{
|
{
|
||||||
debug_assert(filter_valid(filter));
|
ENSURE(filter_valid(filter));
|
||||||
default_filter = filter;
|
default_filter = filter;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -242,7 +242,7 @@ static GLint choose_int_fmt(GLenum fmt, int q_flags)
|
|||||||
wchar_t buf[100];
|
wchar_t buf[100];
|
||||||
swprintf_s(buf, ARRAY_SIZE(buf), L"choose_int_fmt: fmt 0x%x isn't covered! please add it", fmt);
|
swprintf_s(buf, ARRAY_SIZE(buf), L"choose_int_fmt: fmt 0x%x isn't covered! please add it", fmt);
|
||||||
DEBUG_DISPLAY_ERROR(buf);
|
DEBUG_DISPLAY_ERROR(buf);
|
||||||
debug_assert(0); // given fmt isn't covered! please add it.
|
ENSURE(0); // given fmt isn't covered! please add it.
|
||||||
// fall back to a reasonable default
|
// fall back to a reasonable default
|
||||||
return half_bpp? GL_RGB4 : GL_RGB8;
|
return half_bpp? GL_RGB4 : GL_RGB8;
|
||||||
}
|
}
|
||||||
@ -588,7 +588,7 @@ static void warn_if_uploaded(Handle ht, const OglTex* ot)
|
|||||||
return; // don't complain
|
return; // don't complain
|
||||||
|
|
||||||
if(ot->flags & OT_IS_UPLOADED)
|
if(ot->flags & OT_IS_UPLOADED)
|
||||||
debug_assert(0); // ogl_tex_set_*: texture already uploaded and shouldn't be changed
|
ENSURE(0); // ogl_tex_set_*: texture already uploaded and shouldn't be changed
|
||||||
#else
|
#else
|
||||||
// (prevent warnings; the alternative of wrapping all call sites in
|
// (prevent warnings; the alternative of wrapping all call sites in
|
||||||
// #ifndef is worse)
|
// #ifndef is worse)
|
||||||
@ -674,7 +674,7 @@ static int have_anistropy = -1;
|
|||||||
// given feature. should be called from ah_override_gl_upload_caps.
|
// given feature. should be called from ah_override_gl_upload_caps.
|
||||||
void ogl_tex_override(OglTexOverrides what, OglTexAllow allow)
|
void ogl_tex_override(OglTexOverrides what, OglTexAllow allow)
|
||||||
{
|
{
|
||||||
debug_assert(allow == OGL_TEX_ENABLE || allow == OGL_TEX_DISABLE);
|
ENSURE(allow == OGL_TEX_ENABLE || allow == OGL_TEX_DISABLE);
|
||||||
const bool enable = (allow == OGL_TEX_ENABLE);
|
const bool enable = (allow == OGL_TEX_ENABLE);
|
||||||
|
|
||||||
switch(what)
|
switch(what)
|
||||||
@ -689,7 +689,7 @@ void ogl_tex_override(OglTexOverrides what, OglTexAllow allow)
|
|||||||
have_anistropy = enable;
|
have_anistropy = enable;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
debug_assert(0); // invalid <what>
|
ENSURE(0); // invalid <what>
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -863,7 +863,7 @@ LibError ogl_tex_upload(const Handle ht, GLenum fmt_ovr, int q_flags_ovr, GLint
|
|||||||
|
|
||||||
H_DEREF(ht, OglTex, ot);
|
H_DEREF(ht, OglTex, ot);
|
||||||
Tex* t = &ot->t;
|
Tex* t = &ot->t;
|
||||||
debug_assert(q_flags_valid(q_flags_ovr));
|
ENSURE(q_flags_valid(q_flags_ovr));
|
||||||
// we don't bother verifying *fmt_ovr - there are too many values
|
// we don't bother verifying *fmt_ovr - there are too many values
|
||||||
|
|
||||||
// upload already happened; no work to do.
|
// upload already happened; no work to do.
|
||||||
@ -952,7 +952,7 @@ LibError ogl_tex_get_format(Handle ht, size_t* flags, GLenum* fmt)
|
|||||||
*flags = ot->t.flags;
|
*flags = ot->t.flags;
|
||||||
if(fmt)
|
if(fmt)
|
||||||
{
|
{
|
||||||
debug_assert(ot->flags & OT_IS_UPLOADED);
|
ENSURE(ot->flags & OT_IS_UPLOADED);
|
||||||
*fmt = ot->fmt;
|
*fmt = ot->fmt;
|
||||||
}
|
}
|
||||||
return INFO::OK;
|
return INFO::OK;
|
||||||
@ -1021,7 +1021,7 @@ LibError ogl_tex_bind(Handle ht, size_t unit)
|
|||||||
// if 0, there's a problem in the OglTex reload/dtor logic.
|
// if 0, there's a problem in the OglTex reload/dtor logic.
|
||||||
// binding it results in whiteness, which can have many causes;
|
// binding it results in whiteness, which can have many causes;
|
||||||
// we therefore complain so this one can be ruled out.
|
// we therefore complain so this one can be ruled out.
|
||||||
debug_assert(ot->id != 0);
|
ENSURE(ot->id != 0);
|
||||||
|
|
||||||
glEnable(GL_TEXTURE_2D);
|
glEnable(GL_TEXTURE_2D);
|
||||||
glBindTexture(GL_TEXTURE_2D, ot->id);
|
glBindTexture(GL_TEXTURE_2D, ot->id);
|
||||||
@ -1053,7 +1053,7 @@ LibError ogl_tex_transform_to(Handle ht, size_t new_flags)
|
|||||||
bool ogl_tex_has_s3tc()
|
bool ogl_tex_has_s3tc()
|
||||||
{
|
{
|
||||||
// ogl_tex_upload must be called before this
|
// ogl_tex_upload must be called before this
|
||||||
debug_assert(have_s3tc != -1);
|
ENSURE(have_s3tc != -1);
|
||||||
|
|
||||||
return (have_s3tc != 0);
|
return (have_s3tc != 0);
|
||||||
}
|
}
|
||||||
@ -1062,7 +1062,7 @@ bool ogl_tex_has_s3tc()
|
|||||||
bool ogl_tex_has_anisotropy()
|
bool ogl_tex_has_anisotropy()
|
||||||
{
|
{
|
||||||
// ogl_tex_upload must be called before this
|
// ogl_tex_upload must be called before this
|
||||||
debug_assert(have_anistropy != -1);
|
ENSURE(have_anistropy != -1);
|
||||||
|
|
||||||
return (have_anistropy != 0);
|
return (have_anistropy != 0);
|
||||||
}
|
}
|
||||||
|
@ -127,7 +127,7 @@ static LibError UniFont_reload(UniFont* f, const PIVFS& vfs, const VfsPath& base
|
|||||||
|
|
||||||
if (Codepoint < 0 || Codepoint > 0xFFFF)
|
if (Codepoint < 0 || Codepoint > 0xFFFF)
|
||||||
{
|
{
|
||||||
debug_assert(0); // Invalid codepoint
|
ENSURE(0); // Invalid codepoint
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,7 +145,7 @@ static LibError UniFont_reload(UniFont* f, const PIVFS& vfs, const VfsPath& base
|
|||||||
(*f->glyphs)[(u16)Codepoint] = g;
|
(*f->glyphs)[(u16)Codepoint] = g;
|
||||||
}
|
}
|
||||||
|
|
||||||
debug_assert(f->Height); // Ensure the height has been found (which should always happen if the font includes an 'I')
|
ENSURE(f->Height); // Ensure the height has been found (which should always happen if the font includes an 'I')
|
||||||
|
|
||||||
// Load glyph texture
|
// Load glyph texture
|
||||||
// [cumulative for 12: 20ms]
|
// [cumulative for 12: 20ms]
|
||||||
@ -270,7 +270,7 @@ void glvwprintf(const wchar_t* fmt, va_list args)
|
|||||||
// Make sure there's always null termination
|
// Make sure there's always null termination
|
||||||
buf[buf_size-1] = 0;
|
buf[buf_size-1] = 0;
|
||||||
|
|
||||||
debug_assert(BoundGlyphs != NULL); // You always need to bind something first
|
ENSURE(BoundGlyphs != NULL); // You always need to bind something first
|
||||||
|
|
||||||
// Count the number of characters
|
// Count the number of characters
|
||||||
size_t len = wcslen(buf);
|
size_t len = wcslen(buf);
|
||||||
@ -367,7 +367,7 @@ LibError unifont_stringsize(const Handle h, const wchar_t* text, int& width, int
|
|||||||
|
|
||||||
if (it == f->glyphs->end()) // Missing the missing glyph symbol - give up
|
if (it == f->glyphs->end()) // Missing the missing glyph symbol - give up
|
||||||
{
|
{
|
||||||
debug_assert(0); // Missing the missing glyph in a unifont!
|
ENSURE(0); // Missing the missing glyph in a unifont!
|
||||||
return INFO::OK;
|
return INFO::OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,13 +104,13 @@ static inline u32 h_tag(const Handle h)
|
|||||||
static inline Handle handle(const u32 _idx, const u32 tag)
|
static inline Handle handle(const u32 _idx, const u32 tag)
|
||||||
{
|
{
|
||||||
const u32 idx = _idx+1;
|
const u32 idx = _idx+1;
|
||||||
debug_assert(idx <= IDX_MASK && tag <= TAG_MASK && "handle: idx or tag too big");
|
ENSURE(idx <= IDX_MASK && tag <= TAG_MASK && "handle: idx or tag too big");
|
||||||
// somewhat clunky, but be careful with the shift:
|
// somewhat clunky, but be careful with the shift:
|
||||||
// *_SHIFT may be larger than its field's type.
|
// *_SHIFT may be larger than its field's type.
|
||||||
Handle h_idx = idx & IDX_MASK; h_idx <<= IDX_SHIFT;
|
Handle h_idx = idx & IDX_MASK; h_idx <<= IDX_SHIFT;
|
||||||
Handle h_tag = tag & TAG_MASK; h_tag <<= TAG_SHIFT;
|
Handle h_tag = tag & TAG_MASK; h_tag <<= TAG_SHIFT;
|
||||||
Handle h = h_idx | h_tag;
|
Handle h = h_idx | h_tag;
|
||||||
debug_assert(h > 0);
|
ENSURE(h > 0);
|
||||||
return h;
|
return h;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -288,7 +288,7 @@ static LibError alloc_idx(ssize_t& idx, HDATA*& hd)
|
|||||||
for(idx = 0; idx <= last_in_use; idx++)
|
for(idx = 0; idx <= last_in_use; idx++)
|
||||||
{
|
{
|
||||||
hd = h_data_from_idx(idx);
|
hd = h_data_from_idx(idx);
|
||||||
debug_assert(hd); // can't fail - idx is valid
|
ENSURE(hd); // can't fail - idx is valid
|
||||||
|
|
||||||
// found one - done
|
// found one - done
|
||||||
if(!hd->tag)
|
if(!hd->tag)
|
||||||
@ -306,7 +306,7 @@ static LibError alloc_idx(ssize_t& idx, HDATA*& hd)
|
|||||||
// can't fail for any other reason - idx is checked above.
|
// can't fail for any other reason - idx is checked above.
|
||||||
{ // VC6 goto fix
|
{ // VC6 goto fix
|
||||||
bool is_unused = !hd->tag;
|
bool is_unused = !hd->tag;
|
||||||
debug_assert(is_unused && "invalid last_in_use");
|
ENSURE(is_unused && "invalid last_in_use");
|
||||||
}
|
}
|
||||||
|
|
||||||
have_idx:;
|
have_idx:;
|
||||||
@ -406,7 +406,7 @@ static void key_add(uintptr_t key, Handle h)
|
|||||||
static void key_remove(uintptr_t key, H_Type type)
|
static void key_remove(uintptr_t key, H_Type type)
|
||||||
{
|
{
|
||||||
Handle ret = key_find(key, type, KEY_REMOVE);
|
Handle ret = key_find(key, type, KEY_REMOVE);
|
||||||
debug_assert(ret > 0);
|
ENSURE(ret > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -425,14 +425,14 @@ static void warn_if_invalid(HDATA* hd)
|
|||||||
|
|
||||||
// have the resource validate its user_data
|
// have the resource validate its user_data
|
||||||
LibError err = vtbl->validate(hd->user);
|
LibError err = vtbl->validate(hd->user);
|
||||||
debug_assert(err == INFO::OK);
|
ENSURE(err == INFO::OK);
|
||||||
|
|
||||||
// make sure empty space in control block isn't touched
|
// make sure empty space in control block isn't touched
|
||||||
// .. but only if we're not storing a filename there
|
// .. but only if we're not storing a filename there
|
||||||
const u8* start = hd->user + vtbl->user_size;
|
const u8* start = hd->user + vtbl->user_size;
|
||||||
const u8* end = hd->user + HDATA_USER_SIZE;
|
const u8* end = hd->user + HDATA_USER_SIZE;
|
||||||
for(const u8* p = start; p < end; p++)
|
for(const u8* p = start; p < end; p++)
|
||||||
debug_assert(*p == 0); // else: handle user data was overrun!
|
ENSURE(*p == 0); // else: handle user data was overrun!
|
||||||
#else
|
#else
|
||||||
UNUSED2(hd);
|
UNUSED2(hd);
|
||||||
#endif
|
#endif
|
||||||
@ -675,7 +675,7 @@ void* h_user_data(const Handle h, const H_Type type)
|
|||||||
if(!hd->refs)
|
if(!hd->refs)
|
||||||
{
|
{
|
||||||
// note: resetting the tag is not enough (user might pass in its value)
|
// note: resetting the tag is not enough (user might pass in its value)
|
||||||
debug_assert(0); // no references to resource (it's cached, but someone is accessing it directly)
|
ENSURE(0); // no references to resource (it's cached, but someone is accessing it directly)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -691,7 +691,7 @@ VfsPath h_filename(const Handle h)
|
|||||||
HDATA* hd = h_data_tag(h);
|
HDATA* hd = h_data_tag(h);
|
||||||
if(!hd)
|
if(!hd)
|
||||||
{
|
{
|
||||||
debug_assert(0);
|
ENSURE(0);
|
||||||
return VfsPath();
|
return VfsPath();
|
||||||
}
|
}
|
||||||
return hd->pathname;
|
return hd->pathname;
|
||||||
@ -779,11 +779,11 @@ void h_add_ref(Handle h)
|
|||||||
HDATA* hd = h_data_tag(h);
|
HDATA* hd = h_data_tag(h);
|
||||||
if(!hd)
|
if(!hd)
|
||||||
{
|
{
|
||||||
debug_assert(0); // invalid handle
|
ENSURE(0); // invalid handle
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
debug_assert(hd->refs); // if there are no refs, how did the caller manage to keep a Handle?!
|
ENSURE(hd->refs); // if there are no refs, how did the caller manage to keep a Handle?!
|
||||||
hd->refs++;
|
hd->refs++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -800,7 +800,7 @@ int h_get_refcnt(Handle h)
|
|||||||
if(!hd)
|
if(!hd)
|
||||||
WARN_RETURN(ERR::INVALID_PARAM);
|
WARN_RETURN(ERR::INVALID_PARAM);
|
||||||
|
|
||||||
debug_assert(hd->refs); // if there are no refs, how did the caller manage to keep a Handle?!
|
ENSURE(hd->refs); // if there are no refs, how did the caller manage to keep a Handle?!
|
||||||
return hd->refs;
|
return hd->refs;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -824,7 +824,7 @@ static void Shutdown()
|
|||||||
// each HDATA entry has already been allocated.
|
// each HDATA entry has already been allocated.
|
||||||
if(!hd)
|
if(!hd)
|
||||||
{
|
{
|
||||||
debug_assert(0); // h_data_from_idx failed - why?!
|
ENSURE(0); // h_data_from_idx failed - why?!
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -175,7 +175,7 @@ static void Type_dtor(Res1* r);
|
|||||||
}
|
}
|
||||||
|
|
||||||
again no provision for reporting errors - there's no one to act on it
|
again no provision for reporting errors - there's no one to act on it
|
||||||
if called at exit. you can debug_assert or log the error, though.
|
if called at exit. you can ENSURE or log the error, though.
|
||||||
|
|
||||||
be careful to correctly handle the different cases in which this routine
|
be careful to correctly handle the different cases in which this routine
|
||||||
can be called! some flags should persist across reloads (e.g. choices made
|
can be called! some flags should persist across reloads (e.g. choices made
|
||||||
|
@ -107,10 +107,10 @@ static void hsd_list_free_all();
|
|||||||
|
|
||||||
static void al_ReportError(ALenum err, const char* caller, int line)
|
static void al_ReportError(ALenum err, const char* caller, int line)
|
||||||
{
|
{
|
||||||
debug_assert(al_initialized);
|
ENSURE(al_initialized);
|
||||||
|
|
||||||
debug_printf(L"OpenAL error: %hs; called from %hs (line %d)\n", alGetString(err), caller, line);
|
debug_printf(L"OpenAL error: %hs; called from %hs (line %d)\n", alGetString(err), caller, line);
|
||||||
debug_assert(0);
|
ENSURE(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -409,7 +409,7 @@ static ALuint al_buf_alloc(ALvoid* data, ALsizei size, ALenum fmt, ALsizei freq)
|
|||||||
alBufferData(al_buf, fmt, data, size, freq);
|
alBufferData(al_buf, fmt, data, size, freq);
|
||||||
AL_CHECK;
|
AL_CHECK;
|
||||||
|
|
||||||
debug_assert(alIsBuffer(al_buf));
|
ENSURE(alIsBuffer(al_buf));
|
||||||
al_bufs_outstanding++;
|
al_bufs_outstanding++;
|
||||||
|
|
||||||
return al_buf;
|
return al_buf;
|
||||||
@ -428,7 +428,7 @@ static void al_buf_free(ALuint al_buf)
|
|||||||
if(!al_buf)
|
if(!al_buf)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
debug_assert(alIsBuffer(al_buf));
|
ENSURE(alIsBuffer(al_buf));
|
||||||
|
|
||||||
AL_CHECK;
|
AL_CHECK;
|
||||||
alDeleteBuffers(1, &al_buf);
|
alDeleteBuffers(1, &al_buf);
|
||||||
@ -444,7 +444,7 @@ static void al_buf_free(ALuint al_buf)
|
|||||||
*/
|
*/
|
||||||
static void al_buf_shutdown()
|
static void al_buf_shutdown()
|
||||||
{
|
{
|
||||||
debug_assert(al_bufs_outstanding == 0);
|
ENSURE(al_bufs_outstanding == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -490,7 +490,7 @@ static void al_src_init()
|
|||||||
// we've reached the limit, no more are available.
|
// we've reached the limit, no more are available.
|
||||||
if(alGetError() != AL_NO_ERROR)
|
if(alGetError() != AL_NO_ERROR)
|
||||||
break;
|
break;
|
||||||
debug_assert(alIsSource(al_src));
|
ENSURE(alIsSource(al_src));
|
||||||
al_srcs[i] = al_src;
|
al_srcs[i] = al_src;
|
||||||
al_src_numPreallocated++;
|
al_src_numPreallocated++;
|
||||||
}
|
}
|
||||||
@ -501,7 +501,7 @@ static void al_src_init()
|
|||||||
al_src_maxNumToUse = al_src_numPreallocated;
|
al_src_maxNumToUse = al_src_numPreallocated;
|
||||||
|
|
||||||
// make sure we got the minimum guaranteed by OpenAL.
|
// make sure we got the minimum guaranteed by OpenAL.
|
||||||
debug_assert(al_src_numPreallocated >= 16);
|
ENSURE(al_src_numPreallocated >= 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -513,7 +513,7 @@ static void al_src_init()
|
|||||||
static void al_src_shutdown()
|
static void al_src_shutdown()
|
||||||
{
|
{
|
||||||
for(size_t i = 0; i < al_src_numPreallocated; i++)
|
for(size_t i = 0; i < al_src_numPreallocated; i++)
|
||||||
debug_assert(al_srcs_allocationStates[i] == kAvailable);
|
ENSURE(al_srcs_allocationStates[i] == kAvailable);
|
||||||
|
|
||||||
AL_CHECK;
|
AL_CHECK;
|
||||||
alDeleteSources((ALsizei)al_src_numPreallocated, al_srcs);
|
alDeleteSources((ALsizei)al_src_numPreallocated, al_srcs);
|
||||||
@ -551,16 +551,16 @@ static bool al_src_alloc(ALuint& al_src)
|
|||||||
*/
|
*/
|
||||||
static void al_src_free(ALuint al_src)
|
static void al_src_free(ALuint al_src)
|
||||||
{
|
{
|
||||||
debug_assert(alIsSource(al_src));
|
ENSURE(alIsSource(al_src));
|
||||||
|
|
||||||
const ALuint* pos = std::find(al_srcs, al_srcs+al_src_numPreallocated, al_src);
|
const ALuint* pos = std::find(al_srcs, al_srcs+al_src_numPreallocated, al_src);
|
||||||
if(pos != al_srcs+al_src_numPreallocated) // found it
|
if(pos != al_srcs+al_src_numPreallocated) // found it
|
||||||
{
|
{
|
||||||
const size_t i = pos - al_srcs;
|
const size_t i = pos - al_srcs;
|
||||||
debug_assert(cpu_CAS(&al_srcs_allocationStates[i], kInUse, kAvailable));
|
ENSURE(cpu_CAS(&al_srcs_allocationStates[i], kInUse, kAvailable));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
debug_assert(0); // al_src wasn't in al_srcs
|
ENSURE(0); // al_src wasn't in al_srcs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -698,7 +698,7 @@ LibError snd_disable(bool disabled)
|
|||||||
|
|
||||||
if(snd_disabled)
|
if(snd_disabled)
|
||||||
{
|
{
|
||||||
debug_assert(!al_initialized); // already initialized => disable is pointless
|
ENSURE(!al_initialized); // already initialized => disable is pointless
|
||||||
return INFO::OK;
|
return INFO::OK;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -932,8 +932,8 @@ static LibError SndData_reload(SndData* sd, const PIVFS& vfs, const VfsPath& pat
|
|||||||
const LibError ret = sd->ogg->GetNextChunk(&data[0], data.size());
|
const LibError ret = sd->ogg->GetNextChunk(&data[0], data.size());
|
||||||
RETURN_ERR(ret);
|
RETURN_ERR(ret);
|
||||||
const size_t size = (size_t)ret;
|
const size_t size = (size_t)ret;
|
||||||
debug_assert(size != 0); // must have read something
|
ENSURE(size != 0); // must have read something
|
||||||
debug_assert(size != data.size()); // shouldn't be limited by buffer size
|
ENSURE(size != data.size()); // shouldn't be limited by buffer size
|
||||||
sd->al_buf = al_buf_alloc(&data[0], (ALsizei)size, sd->al_fmt, sd->al_freq);
|
sd->al_buf = al_buf_alloc(&data[0], (ALsizei)size, sd->al_fmt, sd->al_freq);
|
||||||
sd->ogg.reset();
|
sd->ogg.reset();
|
||||||
}
|
}
|
||||||
@ -1122,8 +1122,8 @@ static FadeRet fade(FadeInfo& fi, double cur_time, float& out_val)
|
|||||||
if(fi.type == FT_NONE)
|
if(fi.type == FT_NONE)
|
||||||
return FADE_NO_CHANGE;
|
return FADE_NO_CHANGE;
|
||||||
|
|
||||||
debug_assert(0.0f <= fi.initial_val && fi.initial_val <= 1.0f);
|
ENSURE(0.0f <= fi.initial_val && fi.initial_val <= 1.0f);
|
||||||
debug_assert(0.0f <= fi.final_val && fi.final_val <= 1.0f);
|
ENSURE(0.0f <= fi.final_val && fi.final_val <= 1.0f);
|
||||||
|
|
||||||
// end reached - if fi.length is 0, but the fade is "in progress", do the
|
// end reached - if fi.length is 0, but the fade is "in progress", do the
|
||||||
// processing here, and skip the dangerous division
|
// processing here, and skip the dangerous division
|
||||||
@ -1145,7 +1145,7 @@ static FadeRet fade(FadeInfo& fi, double cur_time, float& out_val)
|
|||||||
|
|
||||||
// how far into the fade are we? [0,1]
|
// how far into the fade are we? [0,1]
|
||||||
const float t = (cur_time - fi.start_time) / fi.length;
|
const float t = (cur_time - fi.start_time) / fi.length;
|
||||||
debug_assert(0.0f <= t && t <= 1.0f);
|
ENSURE(0.0f <= t && t <= 1.0f);
|
||||||
|
|
||||||
float factor;
|
float factor;
|
||||||
switch(fi.type)
|
switch(fi.type)
|
||||||
@ -1225,7 +1225,7 @@ struct VSrc
|
|||||||
{
|
{
|
||||||
if((flags & VS_HAS_AL_SRC) == 0)
|
if((flags & VS_HAS_AL_SRC) == 0)
|
||||||
return false;
|
return false;
|
||||||
debug_assert(alIsSource(al_src));
|
ENSURE(alIsSource(al_src));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1470,7 +1470,7 @@ static void list_remove(VSrc* vs)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
debug_assert(0); // VSrc not found
|
ENSURE(0); // VSrc not found
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1578,7 +1578,7 @@ static void vsrc_latch(VSrc* vs)
|
|||||||
*/
|
*/
|
||||||
static int vsrc_deque_finished_bufs(VSrc* vs)
|
static int vsrc_deque_finished_bufs(VSrc* vs)
|
||||||
{
|
{
|
||||||
debug_assert(vs->HasSource()); // (otherwise there's no sense in calling this function)
|
ENSURE(vs->HasSource()); // (otherwise there's no sense in calling this function)
|
||||||
|
|
||||||
AL_CHECK;
|
AL_CHECK;
|
||||||
int num_processed;
|
int num_processed;
|
||||||
@ -1712,7 +1712,7 @@ static LibError vsrc_reclaim(VSrc* vs)
|
|||||||
{
|
{
|
||||||
if(!vs->HasSource())
|
if(!vs->HasSource())
|
||||||
return ERR::FAIL; // NOWARN
|
return ERR::FAIL; // NOWARN
|
||||||
debug_assert(alIsSource(vs->al_src));
|
ENSURE(alIsSource(vs->al_src));
|
||||||
|
|
||||||
// clear the source's buffer queue (necessary because buffers cannot
|
// clear the source's buffer queue (necessary because buffers cannot
|
||||||
// be deleted at shutdown while still attached to a source).
|
// be deleted at shutdown while still attached to a source).
|
||||||
|
@ -95,7 +95,7 @@ ERROR_ASSOCIATE(ERR::STRING_NOT_TERMINATED, L"Invalid string (no 0 terminator fo
|
|||||||
// currently disabled due to high risk of false positives.
|
// currently disabled due to high risk of false positives.
|
||||||
#define WARN_IF_PTR_LEN(len)\
|
#define WARN_IF_PTR_LEN(len)\
|
||||||
/*
|
/*
|
||||||
debug_assert(len != sizeof(char*));
|
ENSURE(len != sizeof(char*));
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
@ -111,7 +111,7 @@ ERROR_ASSOCIATE(ERR::STRING_NOT_TERMINATED, L"Invalid string (no 0 terminator fo
|
|||||||
size_t tnlen(const tchar* str, size_t max_len)
|
size_t tnlen(const tchar* str, size_t max_len)
|
||||||
{
|
{
|
||||||
// note: we can't bail - what would the return value be?
|
// note: we can't bail - what would the return value be?
|
||||||
debug_assert(str != 0);
|
ENSURE(str != 0);
|
||||||
|
|
||||||
WARN_IF_PTR_LEN(max_len);
|
WARN_IF_PTR_LEN(max_len);
|
||||||
|
|
||||||
|
@ -97,7 +97,7 @@ SELF_TEST_RUN; // (4)
|
|||||||
(2) wrapping in a namespace is optional and must be removed for C programs.
|
(2) wrapping in a namespace is optional and must be removed for C programs.
|
||||||
it avoids possible name collisions with the module being tested.
|
it avoids possible name collisions with the module being tested.
|
||||||
|
|
||||||
(3) TEST *must* be used instead of debug_assert et al.! this is
|
(3) TEST *must* be used instead of ENSURE et al.! this is
|
||||||
explained below.
|
explained below.
|
||||||
|
|
||||||
(4) automatically calls your self_test function at non-local static object
|
(4) automatically calls your self_test function at non-local static object
|
||||||
|
@ -45,7 +45,7 @@ typedef const volatile AcpiTable* PCV_AcpiTable;
|
|||||||
|
|
||||||
static AcpiTable* AllocateTable(size_t size)
|
static AcpiTable* AllocateTable(size_t size)
|
||||||
{
|
{
|
||||||
debug_assert(size >= sizeof(AcpiTable));
|
ENSURE(size >= sizeof(AcpiTable));
|
||||||
return (AcpiTable*)malloc(size);
|
return (AcpiTable*)malloc(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -165,7 +165,7 @@ typedef const volatile BiosDataArea* PCV_BiosDataArea;
|
|||||||
|
|
||||||
static void* UnsafeReadEbdaPhysicalAddress(PCV_u8 mem, size_t numBytes, void* UNUSED(arg))
|
static void* UnsafeReadEbdaPhysicalAddress(PCV_u8 mem, size_t numBytes, void* UNUSED(arg))
|
||||||
{
|
{
|
||||||
debug_assert(numBytes >= sizeof(BiosDataArea));
|
ENSURE(numBytes >= sizeof(BiosDataArea));
|
||||||
|
|
||||||
PCV_BiosDataArea bda = (PCV_BiosDataArea)mem;
|
PCV_BiosDataArea bda = (PCV_BiosDataArea)mem;
|
||||||
const uintptr_t ebdaPhysicalAddress = ((uintptr_t)bda->ebdaSegment) * 16;
|
const uintptr_t ebdaPhysicalAddress = ((uintptr_t)bda->ebdaSegment) * 16;
|
||||||
@ -188,7 +188,7 @@ static const size_t RSDP_ALIGNMENT = 16;
|
|||||||
|
|
||||||
static void* UnsafeLocateAndRetrieveRsdp(PCV_u8 buf, size_t numBytes, void* arg)
|
static void* UnsafeLocateAndRetrieveRsdp(PCV_u8 buf, size_t numBytes, void* arg)
|
||||||
{
|
{
|
||||||
debug_assert(numBytes >= sizeof(RSDP));
|
ENSURE(numBytes >= sizeof(RSDP));
|
||||||
|
|
||||||
for(PCV_u8 p = buf; p < buf+numBytes; p += RSDP_ALIGNMENT)
|
for(PCV_u8 p = buf; p < buf+numBytes; p += RSDP_ALIGNMENT)
|
||||||
{
|
{
|
||||||
@ -232,7 +232,7 @@ static bool RetrieveRsdp(RSDP& rsdp)
|
|||||||
|
|
||||||
static void* UnsafeAllocateAndCopyTable(PCV_u8 mem, size_t numBytes, void* arg)
|
static void* UnsafeAllocateAndCopyTable(PCV_u8 mem, size_t numBytes, void* arg)
|
||||||
{
|
{
|
||||||
debug_assert(numBytes >= sizeof(AcpiTable));
|
ENSURE(numBytes >= sizeof(AcpiTable));
|
||||||
|
|
||||||
PCV_AcpiTable table = (PCV_AcpiTable)mem;
|
PCV_AcpiTable table = (PCV_AcpiTable)mem;
|
||||||
const size_t tableSize = table->size;
|
const size_t tableSize = table->size;
|
||||||
@ -300,7 +300,7 @@ static void AllocateAndCopyTables(const AcpiTable**& tables, size_t& numTables)
|
|||||||
}
|
}
|
||||||
|
|
||||||
numTables = (rsdt->header.size - sizeof(AcpiTable)) / sizeof(rsdt->tableAddresses[0]);
|
numTables = (rsdt->header.size - sizeof(AcpiTable)) / sizeof(rsdt->tableAddresses[0]);
|
||||||
debug_assert(numTables != 0);
|
ENSURE(numTables != 0);
|
||||||
|
|
||||||
tables = new const AcpiTable*[numTables];
|
tables = new const AcpiTable*[numTables];
|
||||||
for(size_t i = 0; i < numTables; i++)
|
for(size_t i = 0; i < numTables; i++)
|
||||||
@ -317,7 +317,7 @@ static void AllocateAndCopyTables(const AcpiTable**& tables, size_t& numTables)
|
|||||||
for(size_t i = 0; i < numTables; i++)
|
for(size_t i = 0; i < numTables; i++)
|
||||||
{
|
{
|
||||||
wfirmware::Table table = wfirmware::GetTable(provider, tableIDs[i]);
|
wfirmware::Table table = wfirmware::GetTable(provider, tableIDs[i]);
|
||||||
debug_assert(!table.empty());
|
ENSURE(!table.empty());
|
||||||
tables[i] = AllocateTable(table.size());
|
tables[i] = AllocateTable(table.size());
|
||||||
memcpy((void*)tables[i], &table[0], table.size());
|
memcpy((void*)tables[i], &table[0], table.size());
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@ static x86_x64_Cache caches[numCaches];
|
|||||||
|
|
||||||
static void AddCache(const x86_x64_Cache& cache)
|
static void AddCache(const x86_x64_Cache& cache)
|
||||||
{
|
{
|
||||||
debug_assert(cache.Validate());
|
ENSURE(cache.Validate());
|
||||||
|
|
||||||
if(cache.type == x86_x64_Cache::kData || cache.type == x86_x64_Cache::kUnified)
|
if(cache.type == x86_x64_Cache::kData || cache.type == x86_x64_Cache::kUnified)
|
||||||
caches[L1D + cache.level-1] = cache;
|
caches[L1D + cache.level-1] = cache;
|
||||||
@ -48,10 +48,10 @@ static void AddCache(const x86_x64_Cache& cache)
|
|||||||
|
|
||||||
static void AddTLB(const x86_x64_Cache& tlb)
|
static void AddTLB(const x86_x64_Cache& tlb)
|
||||||
{
|
{
|
||||||
debug_assert(tlb.Validate());
|
ENSURE(tlb.Validate());
|
||||||
debug_assert(tlb.level == 1 || tlb.level == 2); // see maxTLBs
|
ENSURE(tlb.level == 1 || tlb.level == 2); // see maxTLBs
|
||||||
|
|
||||||
debug_assert(numTLBs < maxTLBs);
|
ENSURE(numTLBs < maxTLBs);
|
||||||
caches[TLB+numTLBs++] = tlb;
|
caches[TLB+numTLBs++] = tlb;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -290,7 +290,7 @@ static Descriptors GetDescriptors()
|
|||||||
break;
|
break;
|
||||||
regs.eax = 2;
|
regs.eax = 2;
|
||||||
const bool ok = x86_x64_cpuid(®s);
|
const bool ok = x86_x64_cpuid(®s);
|
||||||
debug_assert(ok);
|
ENSURE(ok);
|
||||||
}
|
}
|
||||||
|
|
||||||
os_cpu_SetThreadAffinityMask(prevAffinityMask);
|
os_cpu_SetThreadAffinityMask(prevAffinityMask);
|
||||||
@ -331,7 +331,7 @@ struct Characteristics // POD
|
|||||||
case U:
|
case U:
|
||||||
return x86_x64_Cache::kUnified;
|
return x86_x64_Cache::kUnified;
|
||||||
default:
|
default:
|
||||||
debug_assert(0);
|
ENSURE(0);
|
||||||
return x86_x64_Cache::kNull;
|
return x86_x64_Cache::kNull;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -339,7 +339,7 @@ struct Characteristics // POD
|
|||||||
size_t Level() const
|
size_t Level() const
|
||||||
{
|
{
|
||||||
const size_t level = flags & 3;
|
const size_t level = flags & 3;
|
||||||
debug_assert(level != 0);
|
ENSURE(level != 0);
|
||||||
return level;
|
return level;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -623,16 +623,16 @@ static LibError DetectCacheAndTLB()
|
|||||||
// sanity checks
|
// sanity checks
|
||||||
for(size_t idxLevel = 0; idxLevel < x86_x64_Cache::maxLevels; idxLevel++)
|
for(size_t idxLevel = 0; idxLevel < x86_x64_Cache::maxLevels; idxLevel++)
|
||||||
{
|
{
|
||||||
debug_assert(caches[L1D+idxLevel].type == x86_x64_Cache::kData || caches[L1D+idxLevel].type == x86_x64_Cache::kUnified);
|
ENSURE(caches[L1D+idxLevel].type == x86_x64_Cache::kData || caches[L1D+idxLevel].type == x86_x64_Cache::kUnified);
|
||||||
debug_assert(caches[L1D+idxLevel].level == idxLevel+1);
|
ENSURE(caches[L1D+idxLevel].level == idxLevel+1);
|
||||||
debug_assert(caches[L1D+idxLevel].Validate() == true);
|
ENSURE(caches[L1D+idxLevel].Validate() == true);
|
||||||
|
|
||||||
debug_assert(caches[L1I+idxLevel].type == x86_x64_Cache::kInstruction || caches[L1I+idxLevel].type == x86_x64_Cache::kUnified);
|
ENSURE(caches[L1I+idxLevel].type == x86_x64_Cache::kInstruction || caches[L1I+idxLevel].type == x86_x64_Cache::kUnified);
|
||||||
debug_assert(caches[L1I+idxLevel].level == idxLevel+1);
|
ENSURE(caches[L1I+idxLevel].level == idxLevel+1);
|
||||||
debug_assert(caches[L1I+idxLevel].Validate() == true);
|
ENSURE(caches[L1I+idxLevel].Validate() == true);
|
||||||
}
|
}
|
||||||
for(size_t i = 0; i < numTLBs; i++)
|
for(size_t i = 0; i < numTLBs; i++)
|
||||||
debug_assert(caches[TLB+i].Validate() == true);
|
ENSURE(caches[TLB+i].Validate() == true);
|
||||||
|
|
||||||
return INFO::OK;
|
return INFO::OK;
|
||||||
}
|
}
|
||||||
|
@ -78,7 +78,7 @@ struct x86_x64_Cache // POD (may be used before static constructors)
|
|||||||
associativity = 0;
|
associativity = 0;
|
||||||
sharedBy = 0;
|
sharedBy = 0;
|
||||||
|
|
||||||
debug_assert(Validate());
|
ENSURE(Validate());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Validate() const
|
bool Validate() const
|
||||||
|
@ -100,7 +100,7 @@ static size_t MaxLogicalPerCore()
|
|||||||
const size_t logicalPerPackage = bits(regs.ebx, 16, 23);
|
const size_t logicalPerPackage = bits(regs.ebx, 16, 23);
|
||||||
const size_t maxCoresPerPackage = MaxCoresPerPackage();
|
const size_t maxCoresPerPackage = MaxCoresPerPackage();
|
||||||
// cores ought to be uniform WRT # logical processors
|
// cores ought to be uniform WRT # logical processors
|
||||||
debug_assert(logicalPerPackage % maxCoresPerPackage == 0);
|
ENSURE(logicalPerPackage % maxCoresPerPackage == 0);
|
||||||
const size_t maxLogicalPerCore = logicalPerPackage / maxCoresPerPackage;
|
const size_t maxLogicalPerCore = logicalPerPackage / maxCoresPerPackage;
|
||||||
return maxLogicalPerCore;
|
return maxLogicalPerCore;
|
||||||
}
|
}
|
||||||
@ -181,7 +181,7 @@ size_t ProcessorFromApicId(size_t apicId)
|
|||||||
const u8* pos = std::find(apicIds, end, apicId);
|
const u8* pos = std::find(apicIds, end, apicId);
|
||||||
if(pos == end)
|
if(pos == end)
|
||||||
{
|
{
|
||||||
debug_assert(0);
|
ENSURE(0);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return pos - apicIds; // index
|
return pos - apicIds; // index
|
||||||
@ -290,7 +290,7 @@ static LibError InitCpuTopology()
|
|||||||
const size_t logicalPerCore = logicalPerPackage / coresPerPackage;
|
const size_t logicalPerCore = logicalPerPackage / coresPerPackage;
|
||||||
if(logicalPerCore <= maxLogicalPerCore)
|
if(logicalPerCore <= maxLogicalPerCore)
|
||||||
{
|
{
|
||||||
debug_assert(numProcessors == numPackages*coresPerPackage*logicalPerCore);
|
ENSURE(numProcessors == numPackages*coresPerPackage*logicalPerCore);
|
||||||
cpuTopology.logicalPerCore = logicalPerCore;
|
cpuTopology.logicalPerCore = logicalPerCore;
|
||||||
cpuTopology.coresPerPackage = coresPerPackage;
|
cpuTopology.coresPerPackage = coresPerPackage;
|
||||||
cpuTopology.numPackages = numPackages;
|
cpuTopology.numPackages = numPackages;
|
||||||
@ -299,7 +299,7 @@ static LibError InitCpuTopology()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
debug_assert(0); // didn't find a feasible topology
|
ENSURE(0); // didn't find a feasible topology
|
||||||
}
|
}
|
||||||
|
|
||||||
return INFO::OK;
|
return INFO::OK;
|
||||||
@ -350,18 +350,18 @@ size_t cpu_topology_ApicId(size_t idxLogical, size_t idxCore, size_t idxPackage)
|
|||||||
// we therefore compute an index into the sorted ApicIds array.
|
// we therefore compute an index into the sorted ApicIds array.
|
||||||
|
|
||||||
size_t idx = 0;
|
size_t idx = 0;
|
||||||
debug_assert(idxPackage < cpuTopology.numPackages);
|
ENSURE(idxPackage < cpuTopology.numPackages);
|
||||||
idx += idxPackage;
|
idx += idxPackage;
|
||||||
|
|
||||||
idx *= cpuTopology.coresPerPackage;
|
idx *= cpuTopology.coresPerPackage;
|
||||||
debug_assert(idxCore < cpuTopology.coresPerPackage);
|
ENSURE(idxCore < cpuTopology.coresPerPackage);
|
||||||
idx += idxCore;
|
idx += idxCore;
|
||||||
|
|
||||||
idx *= cpuTopology.logicalPerCore;
|
idx *= cpuTopology.logicalPerCore;
|
||||||
debug_assert(idxLogical < cpuTopology.logicalPerCore);
|
ENSURE(idxLogical < cpuTopology.logicalPerCore);
|
||||||
idx += idxLogical;
|
idx += idxLogical;
|
||||||
|
|
||||||
debug_assert(idx < os_cpu_NumProcessors());
|
ENSURE(idx < os_cpu_NumProcessors());
|
||||||
const size_t apicId = ApicIds()[idx];
|
const size_t apicId = ApicIds()[idx];
|
||||||
return apicId;
|
return apicId;
|
||||||
}
|
}
|
||||||
@ -491,7 +491,7 @@ static void DetermineProcessorsCache(const uintptr_t* cachesProcessorMask, size_
|
|||||||
{
|
{
|
||||||
if(IsBitSet(processorMask, processor))
|
if(IsBitSet(processorMask, processor))
|
||||||
{
|
{
|
||||||
debug_assert(processorsCache[processor] == 0);
|
ENSURE(processorsCache[processor] == 0);
|
||||||
processorsCache[processor] = cache;
|
processorsCache[processor] = cache;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -528,13 +528,13 @@ size_t cache_topology_NumCaches()
|
|||||||
size_t cache_topology_CacheFromProcessor(size_t processor)
|
size_t cache_topology_CacheFromProcessor(size_t processor)
|
||||||
{
|
{
|
||||||
ModuleInit(&cacheInitState, InitCacheTopology);
|
ModuleInit(&cacheInitState, InitCacheTopology);
|
||||||
debug_assert(processor < os_cpu_NumProcessors());
|
ENSURE(processor < os_cpu_NumProcessors());
|
||||||
return cacheTopology.processorsCache[processor];
|
return cacheTopology.processorsCache[processor];
|
||||||
}
|
}
|
||||||
|
|
||||||
uintptr_t cache_topology_ProcessorMaskFromCache(size_t cache)
|
uintptr_t cache_topology_ProcessorMaskFromCache(size_t cache)
|
||||||
{
|
{
|
||||||
ModuleInit(&cacheInitState, InitCacheTopology);
|
ModuleInit(&cacheInitState, InitCacheTopology);
|
||||||
debug_assert(cache < cacheTopology.numCaches);
|
ENSURE(cache < cacheTopology.numCaches);
|
||||||
return cacheTopology.cachesProcessorMask[cache];
|
return cacheTopology.cachesProcessorMask[cache];
|
||||||
}
|
}
|
||||||
|
@ -49,15 +49,15 @@ static void TestCAS64()
|
|||||||
{
|
{
|
||||||
volatile i64 var = 1;
|
volatile i64 var = 1;
|
||||||
cpu_CAS64(&var, 1ull, 2ull);
|
cpu_CAS64(&var, 1ull, 2ull);
|
||||||
debug_assert(var == 2ull);
|
ENSURE(var == 2ull);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void TestAtomicAdd()
|
static void TestAtomicAdd()
|
||||||
{
|
{
|
||||||
volatile intptr_t i1 = 1;
|
volatile intptr_t i1 = 1;
|
||||||
intptr_t prev = cpu_AtomicAdd(&i1, 1);
|
intptr_t prev = cpu_AtomicAdd(&i1, 1);
|
||||||
debug_assert(prev == 1);
|
ENSURE(prev == 1);
|
||||||
debug_assert(i1 == 2);
|
ENSURE(i1 == 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void cpu_Test()
|
void cpu_Test()
|
||||||
|
@ -57,21 +57,21 @@ static u32 ReadPort(u16 port, u8 numBytes)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
debug_assert(bytesReturned == sizeof(out));
|
ENSURE(bytesReturned == sizeof(out));
|
||||||
return out.value;
|
return out.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
u8 mahaf_ReadPort8(u16 port)
|
u8 mahaf_ReadPort8(u16 port)
|
||||||
{
|
{
|
||||||
const u32 value = ReadPort(port, 1);
|
const u32 value = ReadPort(port, 1);
|
||||||
debug_assert(value <= 0xFF);
|
ENSURE(value <= 0xFF);
|
||||||
return (u8)(value & 0xFF);
|
return (u8)(value & 0xFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
u16 mahaf_ReadPort16(u16 port)
|
u16 mahaf_ReadPort16(u16 port)
|
||||||
{
|
{
|
||||||
const u32 value = ReadPort(port, 2);
|
const u32 value = ReadPort(port, 2);
|
||||||
debug_assert(value <= 0xFFFF);
|
ENSURE(value <= 0xFFFF);
|
||||||
return (u16)(value & 0xFFFF);
|
return (u16)(value & 0xFFFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,7 +124,7 @@ bool mahaf_IsPhysicalMappingDangerous()
|
|||||||
|
|
||||||
volatile void* mahaf_MapPhysicalMemory(uintptr_t physicalAddress, size_t numBytes)
|
volatile void* mahaf_MapPhysicalMemory(uintptr_t physicalAddress, size_t numBytes)
|
||||||
{
|
{
|
||||||
debug_assert(!mahaf_IsPhysicalMappingDangerous());
|
ENSURE(!mahaf_IsPhysicalMappingDangerous());
|
||||||
|
|
||||||
AkenMapIn in;
|
AkenMapIn in;
|
||||||
in.physicalAddress = (DWORD64)physicalAddress;
|
in.physicalAddress = (DWORD64)physicalAddress;
|
||||||
@ -140,7 +140,7 @@ volatile void* mahaf_MapPhysicalMemory(uintptr_t physicalAddress, size_t numByte
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
debug_assert(bytesReturned == sizeof(out));
|
ENSURE(bytesReturned == sizeof(out));
|
||||||
volatile void* virtualAddress = (volatile void*)(uintptr_t)out.virtualAddress;
|
volatile void* virtualAddress = (volatile void*)(uintptr_t)out.virtualAddress;
|
||||||
return virtualAddress;
|
return virtualAddress;
|
||||||
}
|
}
|
||||||
@ -148,7 +148,7 @@ volatile void* mahaf_MapPhysicalMemory(uintptr_t physicalAddress, size_t numByte
|
|||||||
|
|
||||||
void mahaf_UnmapPhysicalMemory(volatile void* virtualAddress)
|
void mahaf_UnmapPhysicalMemory(volatile void* virtualAddress)
|
||||||
{
|
{
|
||||||
debug_assert(!mahaf_IsPhysicalMappingDangerous());
|
ENSURE(!mahaf_IsPhysicalMappingDangerous());
|
||||||
|
|
||||||
AkenUnmapIn in;
|
AkenUnmapIn in;
|
||||||
in.virtualAddress = (DWORD64)virtualAddress;
|
in.virtualAddress = (DWORD64)virtualAddress;
|
||||||
@ -175,7 +175,7 @@ static u64 ReadRegister(DWORD ioctl, u64 reg)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
debug_assert(bytesReturned == sizeof(out));
|
ENSURE(bytesReturned == sizeof(out));
|
||||||
return out.value;
|
return out.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -219,7 +219,7 @@ static SC_HANDLE OpenServiceControlManager()
|
|||||||
// thus out of the question.
|
// thus out of the question.
|
||||||
|
|
||||||
// rule out other problems
|
// rule out other problems
|
||||||
debug_assert(GetLastError() == ERROR_ACCESS_DENIED);
|
ENSURE(GetLastError() == ERROR_ACCESS_DENIED);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -244,7 +244,7 @@ static void UninstallDriver()
|
|||||||
// if the problem wasn't that the service is already stopped,
|
// if the problem wasn't that the service is already stopped,
|
||||||
// something actually went wrong.
|
// something actually went wrong.
|
||||||
const DWORD err = GetLastError();
|
const DWORD err = GetLastError();
|
||||||
debug_assert(err == ERROR_SERVICE_NOT_ACTIVE || err == ERROR_SERVICE_CANNOT_ACCEPT_CTRL);
|
ENSURE(err == ERROR_SERVICE_NOT_ACTIVE || err == ERROR_SERVICE_CANNOT_ACCEPT_CTRL);
|
||||||
}
|
}
|
||||||
|
|
||||||
// delete service
|
// delete service
|
||||||
@ -290,7 +290,7 @@ static void StartDriver(const OsPath& driverPathname)
|
|||||||
hService = CreateServiceW(hSCM, AKEN_NAME, AKEN_NAME,
|
hService = CreateServiceW(hSCM, AKEN_NAME, AKEN_NAME,
|
||||||
SERVICE_ALL_ACCESS, SERVICE_KERNEL_DRIVER, SERVICE_DEMAND_START, SERVICE_ERROR_NORMAL,
|
SERVICE_ALL_ACCESS, SERVICE_KERNEL_DRIVER, SERVICE_DEMAND_START, SERVICE_ERROR_NORMAL,
|
||||||
OsString(driverPathname).c_str(), 0, 0, 0, startName, 0);
|
OsString(driverPathname).c_str(), 0, 0, 0, startName, 0);
|
||||||
debug_assert(hService != 0);
|
ENSURE(hService != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// start service
|
// start service
|
||||||
@ -303,7 +303,7 @@ static void StartDriver(const OsPath& driverPathname)
|
|||||||
{
|
{
|
||||||
// starting failed. don't raise a warning because this
|
// starting failed. don't raise a warning because this
|
||||||
// always happens on least-permission user accounts.
|
// always happens on least-permission user accounts.
|
||||||
//debug_assert(0);
|
//ENSURE(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,8 +43,8 @@ uintptr_t os_cpu_ProcessorMask()
|
|||||||
const HANDLE hProcess = GetCurrentProcess();
|
const HANDLE hProcess = GetCurrentProcess();
|
||||||
DWORD_PTR processAffinity, systemAffinity;
|
DWORD_PTR processAffinity, systemAffinity;
|
||||||
const BOOL ok = GetProcessAffinityMask(hProcess, &processAffinity, &systemAffinity);
|
const BOOL ok = GetProcessAffinityMask(hProcess, &processAffinity, &systemAffinity);
|
||||||
debug_assert(ok);
|
ENSURE(ok);
|
||||||
debug_assert(processAffinity != 0);
|
ENSURE(processAffinity != 0);
|
||||||
processorMask = processAffinity;
|
processorMask = processAffinity;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,8 +63,8 @@ size_t os_cpu_NumProcessors()
|
|||||||
// sanity check
|
// sanity check
|
||||||
SYSTEM_INFO si;
|
SYSTEM_INFO si;
|
||||||
GetSystemInfo(&si); // guaranteed to succeed
|
GetSystemInfo(&si); // guaranteed to succeed
|
||||||
debug_assert(numProcessors <= (size_t)si.dwNumberOfProcessors);
|
ENSURE(numProcessors <= (size_t)si.dwNumberOfProcessors);
|
||||||
debug_assert(numProcessors >= 1);
|
ENSURE(numProcessors >= 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return numProcessors;
|
return numProcessors;
|
||||||
@ -117,8 +117,8 @@ size_t os_cpu_LargePageSize()
|
|||||||
if(pGetLargePageMinimum)
|
if(pGetLargePageMinimum)
|
||||||
{
|
{
|
||||||
largePageSize = pGetLargePageMinimum();
|
largePageSize = pGetLargePageMinimum();
|
||||||
debug_assert(largePageSize != 0); // IA-32 and AMD64 definitely support large pages
|
ENSURE(largePageSize != 0); // IA-32 and AMD64 definitely support large pages
|
||||||
debug_assert(largePageSize > os_cpu_PageSize());
|
ENSURE(largePageSize > os_cpu_PageSize());
|
||||||
}
|
}
|
||||||
// no OS support for large pages
|
// no OS support for large pages
|
||||||
else
|
else
|
||||||
@ -226,7 +226,7 @@ static void VerifyRunningOnCorrectProcessors(DWORD_PTR affinity)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
debug_assert(IsBitSet(affinity, currentProcessor));
|
ENSURE(IsBitSet(affinity, currentProcessor));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -234,7 +234,7 @@ uintptr_t os_cpu_SetThreadAffinityMask(uintptr_t processorMask)
|
|||||||
{
|
{
|
||||||
const size_t numProcessors = os_cpu_NumProcessors();
|
const size_t numProcessors = os_cpu_NumProcessors();
|
||||||
// (avoid undefined result when right shift count >= number of bits)
|
// (avoid undefined result when right shift count >= number of bits)
|
||||||
debug_assert(numProcessors == sizeof(processorMask)*CHAR_BIT || (processorMask >> numProcessors) == 0);
|
ENSURE(numProcessors == sizeof(processorMask)*CHAR_BIT || (processorMask >> numProcessors) == 0);
|
||||||
|
|
||||||
DWORD_PTR processAffinity, systemAffinity;
|
DWORD_PTR processAffinity, systemAffinity;
|
||||||
const BOOL ok = GetProcessAffinityMask(GetCurrentProcess(), &processAffinity, &systemAffinity);
|
const BOOL ok = GetProcessAffinityMask(GetCurrentProcess(), &processAffinity, &systemAffinity);
|
||||||
@ -242,7 +242,7 @@ uintptr_t os_cpu_SetThreadAffinityMask(uintptr_t processorMask)
|
|||||||
|
|
||||||
const DWORD_PTR affinity = wcpu_AffinityFromProcessorMask(processAffinity, processorMask);
|
const DWORD_PTR affinity = wcpu_AffinityFromProcessorMask(processAffinity, processorMask);
|
||||||
const DWORD_PTR previousAffinity = SetThreadAffinityMask(GetCurrentThread(), affinity);
|
const DWORD_PTR previousAffinity = SetThreadAffinityMask(GetCurrentThread(), affinity);
|
||||||
debug_assert(previousAffinity != 0); // ensure function didn't fail
|
ENSURE(previousAffinity != 0); // ensure function didn't fail
|
||||||
// (MSDN says SetThreadAffinityMask takes care of rescheduling)
|
// (MSDN says SetThreadAffinityMask takes care of rescheduling)
|
||||||
VerifyRunningOnCorrectProcessors(affinity);
|
VerifyRunningOnCorrectProcessors(affinity);
|
||||||
|
|
||||||
|
@ -138,7 +138,7 @@ void debug_SetThreadName(const char* name)
|
|||||||
__except(EXCEPTION_EXECUTE_HANDLER)
|
__except(EXCEPTION_EXECUTE_HANDLER)
|
||||||
{
|
{
|
||||||
// if we get here, the debugger didn't handle the exception.
|
// if we get here, the debugger didn't handle the exception.
|
||||||
// this happens if profiling with Dependency Walker; debug_assert
|
// this happens if profiling with Dependency Walker; ENSURE
|
||||||
// must not be called because we may be in critical init.
|
// must not be called because we may be in critical init.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@
|
|||||||
LIB_API void wdbg_printf(const wchar_t* fmt, ...);
|
LIB_API void wdbg_printf(const wchar_t* fmt, ...);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* similar to debug_assert but safe to use during critical init or
|
* similar to ENSURE but safe to use during critical init or
|
||||||
* while under the heap or dbghelp locks.
|
* while under the heap or dbghelp locks.
|
||||||
**/
|
**/
|
||||||
#define wdbg_assert(expr) STMT(if(!(expr)) debug_break();)
|
#define wdbg_assert(expr) STMT(if(!(expr)) debug_break();)
|
||||||
|
@ -313,7 +313,7 @@ LibError wdbg_sym_WalkStack(StackFrameCallback cb, uintptr_t cbData, const CONTE
|
|||||||
// to function properly, StackWalk64 requires a CONTEXT on
|
// to function properly, StackWalk64 requires a CONTEXT on
|
||||||
// non-x86 systems (documented) or when in release mode (observed).
|
// non-x86 systems (documented) or when in release mode (observed).
|
||||||
// exception handlers can call wdbg_sym_WalkStack with their context record;
|
// exception handlers can call wdbg_sym_WalkStack with their context record;
|
||||||
// otherwise (e.g. dump_stack from debug_assert), we need to query it.
|
// otherwise (e.g. dump_stack from ENSURE), we need to query it.
|
||||||
CONTEXT context;
|
CONTEXT context;
|
||||||
// .. caller knows the context (most likely from an exception);
|
// .. caller knows the context (most likely from an exception);
|
||||||
// since StackWalk64 may modify it, copy to a local variable.
|
// since StackWalk64 may modify it, copy to a local variable.
|
||||||
@ -436,7 +436,7 @@ LibError wdbg_sym_WalkStack(StackFrameCallback cb, uintptr_t cbData, const CONTE
|
|||||||
// (can be either success or failure)
|
// (can be either success or failure)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
debug_assert(ret <= 0); // shouldn't return > 0
|
ENSURE(ret <= 0); // shouldn't return > 0
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -536,7 +536,7 @@ static void out(const wchar_t* fmt, ...)
|
|||||||
// make sure out_chars_left remains nonnegative
|
// make sure out_chars_left remains nonnegative
|
||||||
if((size_t)len > out_chars_left)
|
if((size_t)len > out_chars_left)
|
||||||
{
|
{
|
||||||
debug_assert(0); // apparently wrote more than out_chars_left
|
ENSURE(0); // apparently wrote more than out_chars_left
|
||||||
len = (int)out_chars_left;
|
len = (int)out_chars_left;
|
||||||
}
|
}
|
||||||
out_chars_left -= len;
|
out_chars_left -= len;
|
||||||
@ -969,9 +969,9 @@ static LibError dump_sym_array(DWORD type_id, const u8* p, DumpState state)
|
|||||||
if(!pSymGetTypeInfo(hProcess, mod_base, el_type_id, TI_GET_LENGTH, &el_size_))
|
if(!pSymGetTypeInfo(hProcess, mod_base, el_type_id, TI_GET_LENGTH, &el_size_))
|
||||||
WARN_RETURN(ERR::SYM_TYPE_INFO_UNAVAILABLE);
|
WARN_RETURN(ERR::SYM_TYPE_INFO_UNAVAILABLE);
|
||||||
const size_t el_size = (size_t)el_size_;
|
const size_t el_size = (size_t)el_size_;
|
||||||
debug_assert(el_size != 0);
|
ENSURE(el_size != 0);
|
||||||
const size_t num_elements = size/el_size;
|
const size_t num_elements = size/el_size;
|
||||||
debug_assert(num_elements != 0);
|
ENSURE(num_elements != 0);
|
||||||
|
|
||||||
return dump_array(p, num_elements, el_type_id, el_size, state);
|
return dump_array(p, num_elements, el_type_id, el_size, state);
|
||||||
}
|
}
|
||||||
@ -1036,12 +1036,12 @@ static LibError dump_sym_base_type(DWORD type_id, const u8* p, DumpState state)
|
|||||||
else if(size == sizeof(double))
|
else if(size == sizeof(double))
|
||||||
out(L"%g (0x%016I64X)", data, data);
|
out(L"%g (0x%016I64X)", data, data);
|
||||||
else
|
else
|
||||||
debug_assert(0); // invalid float size
|
ENSURE(0); // invalid float size
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// boolean
|
// boolean
|
||||||
case btBool:
|
case btBool:
|
||||||
debug_assert(size == sizeof(bool));
|
ENSURE(size == sizeof(bool));
|
||||||
if(data == 0 || data == 1)
|
if(data == 0 || data == 1)
|
||||||
out(L"%ls", data? L"true " : L"false");
|
out(L"%ls", data? L"true " : L"false");
|
||||||
else
|
else
|
||||||
@ -1074,14 +1074,14 @@ display_as_hex:
|
|||||||
else if(size == 8)
|
else if(size == 8)
|
||||||
fmt = L"%I64d (0x%016I64X)";
|
fmt = L"%I64d (0x%016I64X)";
|
||||||
else
|
else
|
||||||
debug_assert(0); // invalid size for integers
|
ENSURE(0); // invalid size for integers
|
||||||
out(fmt, data, data);
|
out(fmt, data, data);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// character
|
// character
|
||||||
case btChar:
|
case btChar:
|
||||||
case btWChar:
|
case btWChar:
|
||||||
debug_assert(size == sizeof(char) || size == sizeof(wchar_t));
|
ENSURE(size == sizeof(char) || size == sizeof(wchar_t));
|
||||||
// char*, wchar_t*
|
// char*, wchar_t*
|
||||||
if(state.indirection)
|
if(state.indirection)
|
||||||
{
|
{
|
||||||
@ -1102,11 +1102,11 @@ display_as_hex:
|
|||||||
fmt = L"";
|
fmt = L"";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
debug_assert(0); // non-pointer btVoid or btNoType
|
ENSURE(0); // non-pointer btVoid or btNoType
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
debug_assert(0); // unknown type
|
ENSURE(0); // unknown type
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// unsupported complex types
|
// unsupported complex types
|
||||||
@ -1377,7 +1377,7 @@ static LibError udt_get_child_type(const wchar_t* child_name, ULONG num_children
|
|||||||
if(!pSymFromIndexW(hProcess, mod_base, child_id, sym))
|
if(!pSymFromIndexW(hProcess, mod_base, child_id, sym))
|
||||||
{
|
{
|
||||||
// this happens for several UDTs; cause is unknown.
|
// this happens for several UDTs; cause is unknown.
|
||||||
debug_assert(GetLastError() == ERROR_NOT_FOUND);
|
ENSURE(GetLastError() == ERROR_NOT_FOUND);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if(!wcscmp(sym->Name, child_name))
|
if(!wcscmp(sym->Name, child_name))
|
||||||
@ -1584,7 +1584,7 @@ static LibError udt_dump_normal(const wchar_t* type_name, const u8* p, size_t si
|
|||||||
{
|
{
|
||||||
debug_printf(L"INVALID_UDT %ls %d %d\n", type_name, ofs, size);
|
debug_printf(L"INVALID_UDT %ls %d %d\n", type_name, ofs, size);
|
||||||
}
|
}
|
||||||
//debug_assert(ofs < size);
|
//ENSURE(ofs < size);
|
||||||
|
|
||||||
if(!fits_on_one_line)
|
if(!fits_on_one_line)
|
||||||
INDENT;
|
INDENT;
|
||||||
|
@ -52,8 +52,8 @@ typedef LibError (*StackFrameCallback)(const _tagSTACKFRAME64* frame, uintptr_t
|
|||||||
* an exception record), or 0 to walk the current stack.
|
* an exception record), or 0 to walk the current stack.
|
||||||
* @param lastFuncToSkip
|
* @param lastFuncToSkip
|
||||||
*
|
*
|
||||||
* @note It is safe to use debug_assert/debug_warn/CHECK_ERR even during a
|
* @note It is safe to use ENSURE/debug_warn/CHECK_ERR even during a
|
||||||
* stack trace (which is triggered by debug_assert et al. in app code) because
|
* stack trace (which is triggered by ENSURE et al. in app code) because
|
||||||
* nested stack traces are ignored and only the error is displayed.
|
* nested stack traces are ignored and only the error is displayed.
|
||||||
**/
|
**/
|
||||||
extern LibError wdbg_sym_WalkStack(StackFrameCallback cb, uintptr_t cbData = 0, const _CONTEXT* pcontext = 0, const wchar_t* lastFuncToSkip = 0);
|
extern LibError wdbg_sym_WalkStack(StackFrameCallback cb, uintptr_t cbData = 0, const _CONTEXT* pcontext = 0, const wchar_t* lastFuncToSkip = 0);
|
||||||
|
@ -86,7 +86,7 @@ public:
|
|||||||
: m_path(path), m_dirHandle(path), m_data(new u8[dataSize])
|
: m_path(path), m_dirHandle(path), m_data(new u8[dataSize])
|
||||||
{
|
{
|
||||||
m_ovl = (OVERLAPPED*)calloc(1, sizeof(OVERLAPPED)); // rationale for dynamic alloc: see decl
|
m_ovl = (OVERLAPPED*)calloc(1, sizeof(OVERLAPPED)); // rationale for dynamic alloc: see decl
|
||||||
debug_assert(m_ovl);
|
ENSURE(m_ovl);
|
||||||
|
|
||||||
// (hEvent is needed for the wait after CancelIo below)
|
// (hEvent is needed for the wait after CancelIo below)
|
||||||
const BOOL manualReset = TRUE;
|
const BOOL manualReset = TRUE;
|
||||||
@ -195,7 +195,7 @@ private:
|
|||||||
return DirWatchNotification::Changed;
|
return DirWatchNotification::Changed;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
debug_assert(0);
|
ENSURE(0);
|
||||||
return DirWatchNotification::Changed;
|
return DirWatchNotification::Changed;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -309,7 +309,7 @@ public:
|
|||||||
|
|
||||||
LibError Add(const OsPath& path, PDirWatch& dirWatch)
|
LibError Add(const OsPath& path, PDirWatch& dirWatch)
|
||||||
{
|
{
|
||||||
debug_assert(path.IsDirectory());
|
ENSURE(path.IsDirectory());
|
||||||
|
|
||||||
// check if this is a subdirectory of a tree that's already being
|
// check if this is a subdirectory of a tree that's already being
|
||||||
// watched (this is much faster than issuing a new watch; it also
|
// watched (this is much faster than issuing a new watch; it also
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user