more const in format detection
BaseImporter::SearchFileHeaderForToken() expected a pointer to a non-const token list. This was probably an oversight, as nobody would realistically expect the function to change the list. Furthermore, it prevented token lists from being compiled to read-only memory, in some cases even causing the compiler to generate thread-safe initialization. The list is now const and all callers declare their token lists static const, thus compiling them to read-only memory.pull/4078/head
parent
d34cd103f4
commit
5895c0c22c
|
@ -511,7 +511,7 @@ bool AMFImporter::CanRead(const std::string &pFile, IOSystem *pIOHandler, bool p
|
|||
}
|
||||
|
||||
if (extension.empty() || pCheckSig) {
|
||||
const char *tokens[] = { "<amf" };
|
||||
static const char * const tokens[] = { "<amf" };
|
||||
return SearchFileHeaderForToken(pIOHandler, pFile, tokens, 1);
|
||||
}
|
||||
|
||||
|
|
|
@ -106,7 +106,7 @@ bool ASEImporter::CanRead(const std::string &pFile, IOSystem *pIOHandler, bool c
|
|||
}
|
||||
|
||||
if ((!extension.length() || cs) && pIOHandler) {
|
||||
const char *tokens[] = { "*3dsmax_asciiexport" };
|
||||
static const char * const tokens[] = { "*3dsmax_asciiexport" };
|
||||
return SearchFileHeaderForToken(pIOHandler, pFile, tokens, 1);
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -100,7 +100,7 @@ bool BVHLoader::CanRead(const std::string &pFile, IOSystem *pIOHandler, bool cs)
|
|||
return true;
|
||||
|
||||
if ((!extension.length() || cs) && pIOHandler) {
|
||||
const char *tokens[] = { "HIERARCHY" };
|
||||
static const char * const tokens[] = { "HIERARCHY" };
|
||||
return SearchFileHeaderForToken(pIOHandler, pFile, tokens, 1);
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -113,8 +113,8 @@ BlenderImporter::~BlenderImporter() {
|
|||
delete modifier_cache;
|
||||
}
|
||||
|
||||
static const char *Tokens[] = { "BLENDER" };
|
||||
static const char *TokensForSearch[] = { "blender" };
|
||||
static const char * const Tokens[] = { "BLENDER" };
|
||||
static const char * const TokensForSearch[] = { "blender" };
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Returns whether the class can handle the format of the given file.
|
||||
|
|
|
@ -110,7 +110,7 @@ bool COBImporter::CanRead(const std::string &pFile, IOSystem *pIOHandler, bool c
|
|||
}
|
||||
|
||||
else if ((!extension.length() || checkSig) && pIOHandler) {
|
||||
const char *tokens[] = { "Caligary" };
|
||||
static const char * const tokens[] = { "Caligary" };
|
||||
return SearchFileHeaderForToken(pIOHandler, pFile, tokens, 1);
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -99,7 +99,7 @@ bool CSMImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler, bool
|
|||
return true;
|
||||
|
||||
if ((checkSig || !extension.length()) && pIOHandler) {
|
||||
const char* tokens[] = {"$Filename"};
|
||||
static const char * const tokens[] = {"$Filename"};
|
||||
return SearchFileHeaderForToken(pIOHandler,pFile,tokens,1);
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -141,7 +141,7 @@ bool ColladaLoader::CanRead(const std::string &pFile, IOSystem *pIOHandler, bool
|
|||
if (nullptr == pIOHandler) {
|
||||
return true;
|
||||
}
|
||||
static const char* tokens[] = {
|
||||
static const char * const tokens[] = {
|
||||
"<collada"
|
||||
};
|
||||
return SearchFileHeaderForToken(pIOHandler, pFile, tokens, 1);
|
||||
|
|
|
@ -130,8 +130,8 @@ bool DXFImporter::CanRead( const std::string& filename, IOSystem* pIOHandler, bo
|
|||
}
|
||||
|
||||
if ( extension.empty() || checkSig ) {
|
||||
const char *pTokens[] = { "SECTION", "HEADER", "ENDSEC", "BLOCKS" };
|
||||
return BaseImporter::SearchFileHeaderForToken(pIOHandler, filename, pTokens, 4, 32 );
|
||||
static const char * const pTokens[] = { "SECTION", "HEADER", "ENDSEC", "BLOCKS" };
|
||||
return SearchFileHeaderForToken(pIOHandler, filename, pTokens, 4, 32 );
|
||||
}
|
||||
|
||||
return false;
|
||||
|
|
|
@ -108,7 +108,7 @@ bool FBXImporter::CanRead(const std::string &pFile, IOSystem *pIOHandler, bool c
|
|||
|
||||
else if ((!extension.length() || checkSig) && pIOHandler) {
|
||||
// at least ASCII-FBX files usually have a 'FBX' somewhere in their head
|
||||
const char *tokens[] = { "fbx" };
|
||||
static const char * const tokens[] = { "fbx" };
|
||||
return SearchFileHeaderForToken(pIOHandler, pFile, tokens, 1);
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -137,9 +137,8 @@ bool IFCImporter::CanRead(const std::string &pFile, IOSystem *pIOHandler, bool c
|
|||
// note: this is the common identification for STEP-encoded files, so
|
||||
// it is only unambiguous as long as we don't support any further
|
||||
// file formats with STEP as their encoding.
|
||||
const char *tokens[] = { "ISO-10303-21" };
|
||||
const bool found(SearchFileHeaderForToken(pIOHandler, pFile, tokens, 1));
|
||||
return found;
|
||||
static const char * const tokens[] = { "ISO-10303-21" };
|
||||
return SearchFileHeaderForToken(pIOHandler, pFile, tokens, 1);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -106,7 +106,7 @@ bool IRRImporter::CanRead(const std::string &pFile, IOSystem *pIOHandler, bool c
|
|||
if (nullptr == pIOHandler) {
|
||||
return true;
|
||||
}
|
||||
const char *tokens[] = { "irr_scene" };
|
||||
static const char * const tokens[] = { "irr_scene" };
|
||||
return SearchFileHeaderForToken(pIOHandler, pFile, tokens, 1);
|
||||
}
|
||||
|
||||
|
|
|
@ -101,7 +101,7 @@ bool IRRMeshImporter::CanRead(const std::string &pFile, IOSystem *pIOHandler, bo
|
|||
* must return true here.
|
||||
*/
|
||||
if (!pIOHandler) return true;
|
||||
const char *tokens[] = { "irrmesh" };
|
||||
static const char * const tokens[] = { "irrmesh" };
|
||||
return SearchFileHeaderForToken(pIOHandler, pFile, tokens, 1);
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -109,7 +109,7 @@ bool MD5Importer::CanRead(const std::string &pFile, IOSystem *pIOHandler, bool c
|
|||
if (!pIOHandler) {
|
||||
return true;
|
||||
}
|
||||
const char *tokens[] = { "MD5Version" };
|
||||
static const char * const tokens[] = { "MD5Version" };
|
||||
return SearchFileHeaderForToken(pIOHandler, pFile, tokens, 1);
|
||||
}
|
||||
|
||||
|
|
|
@ -94,8 +94,8 @@ bool MMDImporter::CanRead(const std::string &pFile, IOSystem *pIOHandler,
|
|||
return SimpleExtensionCheck(pFile, "pmx");
|
||||
} else {
|
||||
// Check file Header
|
||||
static const char *pTokens[] = { "PMX " };
|
||||
return BaseImporter::SearchFileHeaderForToken(pIOHandler, pFile, pTokens, 1);
|
||||
static const char * const pTokens[] = { "PMX " };
|
||||
return SearchFileHeaderForToken(pIOHandler, pFile, pTokens, 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -104,7 +104,7 @@ bool MS3DImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler, bool
|
|||
if (!pIOHandler) {
|
||||
return true;
|
||||
}
|
||||
const char* tokens[] = {"MS3D000000"};
|
||||
static const char * const tokens[] = {"MS3D000000"};
|
||||
return SearchFileHeaderForToken(pIOHandler,pFile,tokens,1);
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -91,7 +91,7 @@ bool NDOImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler, bool
|
|||
return true;
|
||||
|
||||
if ((checkSig || !extension.length()) && pIOHandler) {
|
||||
const char* tokens[] = {"nendo"};
|
||||
static const char * const tokens[] = {"nendo"};
|
||||
return SearchFileHeaderForToken(pIOHandler,pFile,tokens,1,5);
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -94,7 +94,7 @@ bool OFFImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler, bool
|
|||
else if (!extension.length() || checkSig)
|
||||
{
|
||||
if (!pIOHandler)return true;
|
||||
const char* tokens[] = {"off"};
|
||||
static const char * const tokens[] = {"off"};
|
||||
return SearchFileHeaderForToken(pIOHandler,pFile,tokens,1,3);
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -79,7 +79,7 @@ bool OgreImporter::CanRead(const std::string &pFile, Assimp::IOSystem *pIOHandle
|
|||
}
|
||||
|
||||
if (EndsWith(pFile, ".mesh.xml", false)) {
|
||||
const char *tokens[] = { "<mesh>" };
|
||||
static const char * const tokens[] = { "<mesh>" };
|
||||
return SearchFileHeaderForToken(pIOHandler, pFile, tokens, 1);
|
||||
} else {
|
||||
/// @todo Read and validate first header chunk?
|
||||
|
|
|
@ -299,8 +299,8 @@ bool OpenGEXImporter::CanRead(const std::string &file, IOSystem *pIOHandler, boo
|
|||
if (!checkSig) {
|
||||
canRead = SimpleExtensionCheck(file, "ogex");
|
||||
} else {
|
||||
static const char *token[] = { "Metric", "GeometryNode", "VertexArray (attrib", "IndexArray" };
|
||||
canRead = BaseImporter::SearchFileHeaderForToken(pIOHandler, file, token, 4);
|
||||
static const char * const token[] = { "Metric", "GeometryNode", "VertexArray (attrib", "IndexArray" };
|
||||
canRead = SearchFileHeaderForToken(pIOHandler, file, token, 4);
|
||||
}
|
||||
|
||||
return canRead;
|
||||
|
|
|
@ -111,7 +111,7 @@ bool PLYImporter::CanRead(const std::string &pFile, IOSystem *pIOHandler, bool c
|
|||
if (!pIOHandler) {
|
||||
return true;
|
||||
}
|
||||
static const char *tokens[] = {
|
||||
static const char * const tokens[] = {
|
||||
"ply"
|
||||
};
|
||||
return SearchFileHeaderForToken(pIOHandler, pFile, tokens, 1);
|
||||
|
|
|
@ -92,7 +92,7 @@ bool Q3DImporter::CanRead(const std::string &pFile, IOSystem *pIOHandler, bool c
|
|||
else if (!extension.length() || checkSig) {
|
||||
if (!pIOHandler)
|
||||
return true;
|
||||
const char *tokens[] = { "quick3Do", "quick3Ds" };
|
||||
static const char * const tokens[] = { "quick3Do", "quick3Ds" };
|
||||
return SearchFileHeaderForToken(pIOHandler, pFile, tokens, 2);
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -150,7 +150,7 @@ bool STLImporter::CanRead(const std::string &pFile, IOSystem *pIOHandler, bool c
|
|||
if (!pIOHandler) {
|
||||
return true;
|
||||
}
|
||||
const char *tokens[] = { "STL", "solid" };
|
||||
static const char * const tokens[] = { "STL", "solid" };
|
||||
return SearchFileHeaderForToken(pIOHandler, pFile, tokens, 2);
|
||||
}
|
||||
|
||||
|
|
|
@ -93,7 +93,7 @@ bool TerragenImporter::CanRead(const std::string &pFile, IOSystem *pIOHandler, b
|
|||
return true;
|
||||
}
|
||||
|
||||
const char *tokens[] = { "terragen" };
|
||||
static const char * const tokens[] = { "terragen" };
|
||||
return SearchFileHeaderForToken(pIOHandler, pFile, tokens, 1);
|
||||
}
|
||||
|
||||
|
|
|
@ -118,7 +118,7 @@ bool XGLImporter::CanRead(const std::string &pFile, IOSystem *pIOHandler, bool c
|
|||
} else if (extension == "xml" || checkSig) {
|
||||
ai_assert(pIOHandler != NULL);
|
||||
|
||||
const char *tokens[] = { "<world>", "<World>", "<WORLD>" };
|
||||
static const char * const tokens[] = { "<world>", "<World>", "<WORLD>" };
|
||||
return SearchFileHeaderForToken(pIOHandler, pFile, tokens, 3);
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -155,7 +155,7 @@ void BaseImporter::GetExtensionList(std::set<std::string> &extensions) {
|
|||
// ------------------------------------------------------------------------------------------------
|
||||
/*static*/ bool BaseImporter::SearchFileHeaderForToken(IOSystem *pIOHandler,
|
||||
const std::string &pFile,
|
||||
const char **tokens,
|
||||
const char * const *tokens,
|
||||
unsigned int numTokens,
|
||||
unsigned int searchBytes /* = 200 */,
|
||||
bool tokensSol /* false */,
|
||||
|
|
|
@ -259,7 +259,7 @@ public: // static utilities
|
|||
static bool SearchFileHeaderForToken(
|
||||
IOSystem *pIOSystem,
|
||||
const std::string &file,
|
||||
const char **tokens,
|
||||
const char * const *tokens,
|
||||
unsigned int numTokens,
|
||||
unsigned int searchBytes = 200,
|
||||
bool tokensSol = false,
|
||||
|
|
Loading…
Reference in New Issue