forked from 0ad/0ad
refactor status code definitions: allow modules to define an array of them (more convenient+efficient).
merge ERR::NO_SYS, NOT_IMPLEMENTED into NOT_SUPPORTED renderer: remove unnecessary ogl_shader include This was SVN commit r9447.
This commit is contained in:
parent
fd561cb88b
commit
5c76bc12fa
@ -42,17 +42,19 @@
|
||||
# include "lib/sysdep/os/win/wdbg_heap.h"
|
||||
#endif
|
||||
|
||||
|
||||
STATUS_DEFINE(ERR, SYM_NO_STACK_FRAMES_FOUND, L"No stack frames found", -1);
|
||||
STATUS_DEFINE(ERR, SYM_UNRETRIEVABLE_STATIC, L"Value unretrievable (stored in external module)", -1);
|
||||
STATUS_DEFINE(ERR, SYM_UNRETRIEVABLE, L"Value unretrievable", -1);
|
||||
STATUS_DEFINE(ERR, SYM_TYPE_INFO_UNAVAILABLE, L"Error getting type_info", -1);
|
||||
STATUS_DEFINE(ERR, SYM_INTERNAL_ERROR, L"Exception raised while processing a symbol", -1);
|
||||
STATUS_DEFINE(ERR, SYM_UNSUPPORTED, L"Symbol type not (fully) supported", -1);
|
||||
STATUS_DEFINE(ERR, SYM_CHILD_NOT_FOUND, L"Symbol does not have the given child", -1);
|
||||
STATUS_DEFINE(ERR, SYM_NESTING_LIMIT, L"Symbol nesting too deep or infinite recursion", -1);
|
||||
STATUS_DEFINE(ERR, SYM_SINGLE_SYMBOL_LIMIT, L"Symbol has produced too much output", -1);
|
||||
STATUS_DEFINE(INFO, SYM_SUPPRESS_OUTPUT, L"Symbol was suppressed", -1);
|
||||
static const StatusDefinition debugStatusDefinitions[] = {
|
||||
{ ERR::SYM_NO_STACK_FRAMES_FOUND, L"No stack frames found" },
|
||||
{ ERR::SYM_UNRETRIEVABLE_STATIC, L"Value unretrievable (stored in external module)" },
|
||||
{ ERR::SYM_UNRETRIEVABLE, L"Value unretrievable" },
|
||||
{ ERR::SYM_TYPE_INFO_UNAVAILABLE, L"Error getting type_info" },
|
||||
{ ERR::SYM_INTERNAL_ERROR, L"Exception raised while processing a symbol" },
|
||||
{ ERR::SYM_UNSUPPORTED, L"Symbol type not (fully) supported" },
|
||||
{ ERR::SYM_CHILD_NOT_FOUND, L"Symbol does not have the given child" },
|
||||
{ ERR::SYM_NESTING_LIMIT, L"Symbol nesting too deep or infinite recursion" },
|
||||
{ ERR::SYM_SINGLE_SYMBOL_LIMIT, L"Symbol has produced too much output" },
|
||||
{ INFO::SYM_SUPPRESS_OUTPUT, L"Symbol was suppressed" }
|
||||
};
|
||||
STATUS_ADD_DEFINITIONS(debugStatusDefinitions);
|
||||
|
||||
|
||||
// need to shoehorn printf-style variable params into
|
||||
|
@ -35,9 +35,11 @@
|
||||
|
||||
#include "lib/regex.h"
|
||||
|
||||
|
||||
STATUS_DEFINE(ERR, STL_CNT_UNKNOWN, L"Unknown STL container type_name", -1);
|
||||
STATUS_DEFINE(ERR, STL_CNT_INVALID, L"Container type is known but contents are invalid", -1);
|
||||
static const StatusDefinition debugStlStatusDefinitions[] = {
|
||||
{ ERR::STL_CNT_UNKNOWN, L"Unknown STL container type_name" },
|
||||
{ ERR::STL_CNT_INVALID, L"Container type is known but contents are invalid" }
|
||||
};
|
||||
STATUS_ADD_DEFINITIONS(debugStlStatusDefinitions);
|
||||
|
||||
|
||||
// used in debug_stl_simplify_name.
|
||||
|
@ -27,8 +27,11 @@
|
||||
#include "precompiled.h"
|
||||
#include "lib/file/archive/archive.h"
|
||||
|
||||
STATUS_DEFINE(ERR, ARCHIVE_UNKNOWN_FORMAT, L"Unknown archive format", -1);
|
||||
STATUS_DEFINE(ERR, ARCHIVE_UNKNOWN_METHOD, L"Unknown compression method", -1);
|
||||
static const StatusDefinition archiveStatusDefinitions[] = {
|
||||
{ ERR::ARCHIVE_UNKNOWN_FORMAT, L"Unknown archive format" },
|
||||
{ ERR::ARCHIVE_UNKNOWN_METHOD, L"Unknown compression method" }
|
||||
};
|
||||
STATUS_ADD_DEFINITIONS(archiveStatusDefinitions);
|
||||
|
||||
IArchiveReader::~IArchiveReader()
|
||||
{
|
||||
|
@ -680,7 +680,7 @@ static Status build_mini_archive(const char* mini_archive_fn_fmt)
|
||||
delete[] V_fns;
|
||||
return INFO::OK;
|
||||
#else
|
||||
return ERR::NOT_IMPLEMENTED;
|
||||
return ERR::NOT_SUPPORTED;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -30,9 +30,11 @@
|
||||
#include "lib/sysdep/filesystem.h" // O_*, S_*
|
||||
#include "lib/file/common/file_stats.h"
|
||||
|
||||
|
||||
STATUS_DEFINE(ERR, FILE_ACCESS, L"Insufficient access rights to open file", EACCES);
|
||||
STATUS_DEFINE(ERR, FILE_NOT_FOUND, L"No such file or directory", ENOENT);
|
||||
static const StatusDefinition fileStatusDefinitions[] = {
|
||||
{ ERR::FILE_ACCESS, L"Insufficient access rights to open file", EACCES },
|
||||
{ ERR::FILE_NOT_FOUND, L"No such file or directory", ENOENT }
|
||||
};
|
||||
STATUS_ADD_DEFINITIONS(fileStatusDefinitions);
|
||||
|
||||
|
||||
Status FileOpen(const OsPath& pathname, int opcode, int& fd)
|
||||
|
@ -25,7 +25,10 @@
|
||||
|
||||
#include "lib/sysdep/rtl.h"
|
||||
|
||||
STATUS_DEFINE(ERR, IO, L"Error during IO", EIO);
|
||||
static const StatusDefinition ioStatusDefinitions[] = {
|
||||
{ ERR::IO, L"Error during IO", EIO }
|
||||
};
|
||||
STATUS_ADD_DEFINITIONS(ioStatusDefinitions);
|
||||
|
||||
namespace io {
|
||||
|
||||
|
@ -35,9 +35,12 @@
|
||||
#include "lib/file/vfs/vfs_populate.h"
|
||||
#include "lib/file/vfs/file_cache.h"
|
||||
|
||||
STATUS_DEFINE(ERR, VFS_DIR_NOT_FOUND, L"VFS directory not found", -1);
|
||||
STATUS_DEFINE(ERR, VFS_FILE_NOT_FOUND, L"VFS file not found", -1);
|
||||
STATUS_DEFINE(ERR, VFS_ALREADY_MOUNTED, L"VFS path already mounted", -1);
|
||||
static const StatusDefinition vfsStatusDefinitions[] = {
|
||||
{ ERR::VFS_DIR_NOT_FOUND, L"VFS directory not found" },
|
||||
{ ERR::VFS_FILE_NOT_FOUND, L"VFS file not found" },
|
||||
{ ERR::VFS_ALREADY_MOUNTED, L"VFS path already mounted" }
|
||||
};
|
||||
STATUS_ADD_DEFINITIONS(vfsStatusDefinitions);
|
||||
|
||||
static pthread_mutex_t vfs_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
struct ScopedLock
|
||||
|
@ -30,10 +30,13 @@
|
||||
#include <cstring>
|
||||
#include <cerrno>
|
||||
|
||||
STATUS_DEFINE(ERR, PATH_CHARACTER_ILLEGAL, L"illegal path character", -1);
|
||||
STATUS_DEFINE(ERR, PATH_CHARACTER_UNSAFE, L"unsafe path character", -1);
|
||||
STATUS_DEFINE(ERR, PATH_NOT_FOUND, L"path not found", -1);
|
||||
STATUS_DEFINE(ERR, PATH_MIXED_SEPARATORS, L"path contains both slash and backslash separators", -1);
|
||||
static const StatusDefinition pathStatusDefinitions[] = {
|
||||
{ ERR::PATH_CHARACTER_ILLEGAL, L"illegal path character" },
|
||||
{ ERR::PATH_CHARACTER_UNSAFE, L"unsafe path character" },
|
||||
{ ERR::PATH_NOT_FOUND, L"path not found" },
|
||||
{ ERR::PATH_MIXED_SEPARATORS, L"path contains both slash and backslash separators" }
|
||||
};
|
||||
STATUS_ADD_DEFINITIONS(pathStatusDefinitions);
|
||||
|
||||
|
||||
static bool path_is_dir_sep(wchar_t c)
|
||||
|
@ -39,12 +39,14 @@
|
||||
#include "lib/file/vfs/vfs.h"
|
||||
extern PIVFS vfs;
|
||||
|
||||
|
||||
STATUS_DEFINE(ERR, SHDR_CREATE, L"Shader creation failed", -1);
|
||||
STATUS_DEFINE(ERR, SHDR_COMPILE, L"Shader compile failed", -1);
|
||||
STATUS_DEFINE(ERR, SHDR_NO_SHADER, L"Invalid shader reference", -1);
|
||||
STATUS_DEFINE(ERR, SHDR_LINK, L"Shader linking failed", -1);
|
||||
STATUS_DEFINE(ERR, SHDR_NO_PROGRAM, L"Invalid shader program reference", -1);
|
||||
static const StatusDefinition oglShaderStatusDefs[] = {
|
||||
{ ERR::SHDR_CREATE, L"Shader creation failed" },
|
||||
{ ERR::SHDR_COMPILE, L"Shader compile failed" },
|
||||
{ ERR::SHDR_NO_SHADER, L"Invalid shader reference" },
|
||||
{ ERR::SHDR_LINK, L"Shader linking failed" },
|
||||
{ ERR::SHDR_NO_PROGRAM, L"Invalid shader program reference" }
|
||||
};
|
||||
STATUS_ADD_DEFINITIONS(oglShaderStatusDefs);
|
||||
|
||||
|
||||
// Convert a shader object type into a descriptive string.
|
||||
|
@ -22,7 +22,7 @@ static Status LibErrorFromVorbis(int err)
|
||||
case OV_EFAULT:
|
||||
return ERR::LOGIC;
|
||||
case OV_EIMPL:
|
||||
return ERR::NOT_IMPLEMENTED;
|
||||
return ERR::NOT_SUPPORTED;
|
||||
case OV_EINVAL:
|
||||
return ERR::INVALID_PARAM;
|
||||
case OV_ENOTVORBIS:
|
||||
|
@ -741,7 +741,7 @@ static const char* devs;
|
||||
Status snd_dev_prepare_enum()
|
||||
{
|
||||
if(alcIsExtensionPresent(0, (alcString)"ALC_ENUMERATION_EXT") != AL_TRUE)
|
||||
WARN_RETURN(ERR::NO_SYS);
|
||||
WARN_RETURN(ERR::NOT_SUPPORTED);
|
||||
|
||||
devs = (const char*)alcGetString(0, ALC_DEVICE_SPECIFIER);
|
||||
return INFO::OK;
|
||||
|
@ -35,7 +35,10 @@
|
||||
// we were included from wsecure_crt.cpp; skip all stuff that
|
||||
// must only be done once.
|
||||
#ifndef WSECURE_CRT
|
||||
STATUS_DEFINE(ERR, STRING_NOT_TERMINATED, L"Invalid string (no 0 terminator found in buffer)", -1);
|
||||
static const StatusDefinition secureCrtStatusDefinitions[] = {
|
||||
{ ERR::STRING_NOT_TERMINATED, L"Invalid string (no 0 terminator found in buffer)" }
|
||||
};
|
||||
STATUS_ADD_DEFINITIONS(secureCrtStatusDefinitions);
|
||||
#endif
|
||||
|
||||
|
||||
|
@ -35,32 +35,26 @@
|
||||
#include "lib/posix/posix_errno.h"
|
||||
|
||||
|
||||
// linked list (most recent first)
|
||||
// note: no memory is allocated, all nodes are static instances.
|
||||
//
|
||||
// rationale: don't use a std::map. we don't care about lookup speed,
|
||||
// dynamic allocation would be ugly, and returning a local static object
|
||||
// from a function doesn't work, either (the compiler generates calls to
|
||||
// atexit, which leads to disaster since we're sometimes called before
|
||||
// the CRT has initialized)
|
||||
static StatusDefinition* definitions;
|
||||
static StatusDefinitionBucket* buckets;
|
||||
|
||||
int StatusAddDefinition(StatusDefinition* def)
|
||||
StatusDefinitionBucket* StatusAddDefinitions(StatusDefinitionBucket* bucket)
|
||||
{
|
||||
// insert at front of list
|
||||
def->next = definitions;
|
||||
definitions = def;
|
||||
|
||||
return 0; // stored in dummy variable
|
||||
StatusDefinitionBucket* next = buckets;
|
||||
buckets = bucket;
|
||||
return next;
|
||||
}
|
||||
|
||||
|
||||
static const StatusDefinition* DefinitionFromStatus(Status status)
|
||||
{
|
||||
for(const StatusDefinition* def = definitions; def; def = def->next)
|
||||
for(const StatusDefinitionBucket* bucket = buckets; bucket; bucket = bucket->next)
|
||||
{
|
||||
if(def->status == status)
|
||||
return def;
|
||||
for(size_t i = 0; i < bucket->numDefinitions; i++)
|
||||
{
|
||||
if(bucket->definitions[i].status == status)
|
||||
return &bucket->definitions[i];
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
@ -69,10 +63,13 @@ static const StatusDefinition* DefinitionFromStatus(Status status)
|
||||
|
||||
static const StatusDefinition* DefinitionFromErrno(int errno_equivalent)
|
||||
{
|
||||
for(const StatusDefinition* def = definitions; def; def = def->next)
|
||||
for(const StatusDefinitionBucket* bucket = buckets; bucket; bucket = bucket->next)
|
||||
{
|
||||
if(def->errno_equivalent == errno_equivalent)
|
||||
return def;
|
||||
for(size_t i = 0; i < bucket->numDefinitions; i++)
|
||||
{
|
||||
if(bucket->definitions[i].errno_equivalent == errno_equivalent)
|
||||
return &bucket->definitions[i];
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
@ -88,7 +85,7 @@ wchar_t* StatusDescription(Status status, wchar_t* buf, size_t max_chars)
|
||||
return buf;
|
||||
}
|
||||
|
||||
swprintf_s(buf, max_chars, L"Unknown error (%d, 0x%X)", (int)status, (unsigned int)status);
|
||||
swprintf_s(buf, max_chars, L"Unknown error (%lld, 0x%llX)", status, (unsigned int)status);
|
||||
return buf;
|
||||
}
|
||||
|
||||
@ -96,7 +93,7 @@ wchar_t* StatusDescription(Status status, wchar_t* buf, size_t max_chars)
|
||||
int ErrnoFromStatus(Status status)
|
||||
{
|
||||
const StatusDefinition* def = DefinitionFromStatus(status);
|
||||
if(def && def->errno_equivalent != -1)
|
||||
if(def && def->errno_equivalent != 0)
|
||||
return def->errno_equivalent;
|
||||
|
||||
// the set of errnos in wposix.h doesn't have an "unknown error".
|
||||
@ -114,58 +111,62 @@ Status StatusFromErrno()
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
static const StatusDefinition statusDefs[] = {
|
||||
|
||||
// INFO::OK doesn't really need a string because calling StatusDescription(0)
|
||||
// should never happen, but we'll play it safe.
|
||||
STATUS_DEFINE(INFO, OK, L"(but return value was 0 which indicates success)", -1);
|
||||
STATUS_DEFINE(ERR, FAIL, L"Function failed (no details available)", -1);
|
||||
{ INFO::OK, L"(but return value was 0 which indicates success)" },
|
||||
{ ERR::FAIL, L"Function failed (no details available)" },
|
||||
|
||||
STATUS_DEFINE(INFO, CB_CONTINUE, L"Continue (not an error)", -1);
|
||||
STATUS_DEFINE(INFO, SKIPPED, L"Skipped (not an error)", -1);
|
||||
STATUS_DEFINE(INFO, CANNOT_HANDLE, L"Cannot handle (not an error)", -1);
|
||||
STATUS_DEFINE(INFO, ALL_COMPLETE, L"All complete (not an error)", -1);
|
||||
STATUS_DEFINE(INFO, ALREADY_EXISTS, L"Already exists (not an error)", -1);
|
||||
{ INFO::CB_CONTINUE, L"Continue (not an error)" },
|
||||
{ INFO::SKIPPED, L"Skipped (not an error)" },
|
||||
{ INFO::CANNOT_HANDLE, L"Cannot handle (not an error)" },
|
||||
{ INFO::ALL_COMPLETE, L"All complete (not an error)" },
|
||||
{ INFO::ALREADY_EXISTS, L"Already exists (not an error)" },
|
||||
|
||||
STATUS_DEFINE(ERR, LOGIC, L"Logic error in code", -1);
|
||||
STATUS_DEFINE(ERR, TIMED_OUT, L"Timed out", -1);
|
||||
STATUS_DEFINE(ERR, REENTERED, L"Single-call function was reentered", -1);
|
||||
STATUS_DEFINE(ERR, CORRUPTED, L"File/memory data is corrupted", -1);
|
||||
STATUS_DEFINE(ERR, VERSION, L"Version mismatch", -1);
|
||||
STATUS_DEFINE(ERR, ABORTED, L"Operation aborted", -1);
|
||||
{ ERR::LOGIC, L"Logic error in code" },
|
||||
{ ERR::TIMED_OUT, L"Timed out" },
|
||||
{ ERR::REENTERED, L"Single-call function was reentered" },
|
||||
{ ERR::CORRUPTED, L"File/memory data is corrupted" },
|
||||
{ ERR::VERSION, L"Version mismatch" },
|
||||
{ ERR::ABORTED, L"Operation aborted" },
|
||||
|
||||
STATUS_DEFINE(ERR, INVALID_PARAM, L"Invalid function argument", EINVAL);
|
||||
STATUS_DEFINE(ERR, INVALID_HANDLE, L"Invalid Handle (argument)", -1);
|
||||
STATUS_DEFINE(ERR, BUF_SIZE, L"Buffer argument too small", -1);
|
||||
STATUS_DEFINE(ERR, AGAIN, L"Try again later", -1);
|
||||
STATUS_DEFINE(ERR, LIMIT, L"Fixed limit exceeded", -1);
|
||||
STATUS_DEFINE(ERR, NO_SYS, L"OS doesn't provide a required API", -1);
|
||||
STATUS_DEFINE(ERR, NOT_IMPLEMENTED, L"Feature currently not implemented", ENOSYS);
|
||||
STATUS_DEFINE(ERR, NOT_SUPPORTED, L"Feature isn't and won't be supported", -1);
|
||||
STATUS_DEFINE(ERR, NO_MEM, L"Not enough memory", ENOMEM);
|
||||
{ ERR::INVALID_PARAM, L"Invalid function argument", EINVAL},
|
||||
{ ERR::INVALID_HANDLE, L"Invalid Handle (argument)" },
|
||||
{ ERR::BUF_SIZE, L"Buffer argument too small" },
|
||||
|
||||
STATUS_DEFINE(ERR, _1, L"Case 1", -1);
|
||||
STATUS_DEFINE(ERR, _2, L"Case 2", -1);
|
||||
STATUS_DEFINE(ERR, _3, L"Case 3", -1);
|
||||
STATUS_DEFINE(ERR, _4, L"Case 4", -1);
|
||||
STATUS_DEFINE(ERR, _5, L"Case 5", -1);
|
||||
STATUS_DEFINE(ERR, _6, L"Case 6", -1);
|
||||
STATUS_DEFINE(ERR, _7, L"Case 7", -1);
|
||||
STATUS_DEFINE(ERR, _8, L"Case 8", -1);
|
||||
STATUS_DEFINE(ERR, _9, L"Case 9", -1);
|
||||
STATUS_DEFINE(ERR, _11, L"Case 11", -1);
|
||||
STATUS_DEFINE(ERR, _12, L"Case 12", -1);
|
||||
STATUS_DEFINE(ERR, _13, L"Case 13", -1);
|
||||
STATUS_DEFINE(ERR, _14, L"Case 14", -1);
|
||||
STATUS_DEFINE(ERR, _15, L"Case 15", -1);
|
||||
STATUS_DEFINE(ERR, _16, L"Case 16", -1);
|
||||
STATUS_DEFINE(ERR, _17, L"Case 17", -1);
|
||||
STATUS_DEFINE(ERR, _18, L"Case 18", -1);
|
||||
STATUS_DEFINE(ERR, _19, L"Case 19", -1);
|
||||
STATUS_DEFINE(ERR, _21, L"Case 21", -1);
|
||||
STATUS_DEFINE(ERR, _22, L"Case 22", -1);
|
||||
STATUS_DEFINE(ERR, _23, L"Case 23", -1);
|
||||
STATUS_DEFINE(ERR, _24, L"Case 24", -1);
|
||||
STATUS_DEFINE(ERR, _25, L"Case 25", -1);
|
||||
STATUS_DEFINE(ERR, _26, L"Case 26", -1);
|
||||
STATUS_DEFINE(ERR, _27, L"Case 27", -1);
|
||||
STATUS_DEFINE(ERR, _28, L"Case 28", -1);
|
||||
STATUS_DEFINE(ERR, _29, L"Case 29", -1);
|
||||
{ ERR::AGAIN, L"Try again later" },
|
||||
{ ERR::LIMIT, L"Fixed limit exceeded" },
|
||||
{ ERR::NOT_SUPPORTED, L"Function not supported", ENOSYS },
|
||||
{ ERR::NO_MEM, L"Not enough memory", ENOMEM},
|
||||
|
||||
{ ERR::_1, L"Case 1" },
|
||||
{ ERR::_2, L"Case 2" },
|
||||
{ ERR::_3, L"Case 3" },
|
||||
{ ERR::_4, L"Case 4" },
|
||||
{ ERR::_5, L"Case 5" },
|
||||
{ ERR::_6, L"Case 6" },
|
||||
{ ERR::_7, L"Case 7" },
|
||||
{ ERR::_8, L"Case 8" },
|
||||
{ ERR::_9, L"Case 9" },
|
||||
{ ERR::_11, L"Case 11" },
|
||||
{ ERR::_12, L"Case 12" },
|
||||
{ ERR::_13, L"Case 13" },
|
||||
{ ERR::_14, L"Case 14" },
|
||||
{ ERR::_15, L"Case 15" },
|
||||
{ ERR::_16, L"Case 16" },
|
||||
{ ERR::_17, L"Case 17" },
|
||||
{ ERR::_18, L"Case 18" },
|
||||
{ ERR::_19, L"Case 19" },
|
||||
{ ERR::_21, L"Case 21" },
|
||||
{ ERR::_22, L"Case 22" },
|
||||
{ ERR::_23, L"Case 23" },
|
||||
{ ERR::_24, L"Case 24" },
|
||||
{ ERR::_25, L"Case 25" },
|
||||
{ ERR::_26, L"Case 26" },
|
||||
{ ERR::_27, L"Case 27" },
|
||||
{ ERR::_28, L"Case 28" },
|
||||
{ ERR::_29, L"Case 29" }
|
||||
|
||||
};
|
||||
STATUS_ADD_DEFINITIONS(statusDefs)
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (c) 2010 Wildfire Games
|
||||
/* Copyright (c) 2011 Wildfire Games
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
@ -163,39 +163,57 @@ To summarize: +/-1SHHCC (S=subsystem, HH=header, CC=code number)
|
||||
|
||||
#include "lib/lib_api.h"
|
||||
|
||||
// an integral type allows defining error codes in individual headers,
|
||||
// an integral type allows defining error codes in separate headers,
|
||||
// but is not as type-safe as an enum. use Lint's 'strong type' checking
|
||||
// to catch errors such as Status Func() { return 1; }.
|
||||
// this must be signed and 64-bit because some functions may multiplex
|
||||
// file offsets/sizes and Status in their return value.
|
||||
// this must be i64 because some functions may multiplex Status with
|
||||
// file offsets/sizes in their return value.
|
||||
typedef i64 Status;
|
||||
|
||||
// opaque - do not access its fields!
|
||||
// note: must be defined here because clients instantiate them;
|
||||
// fields cannot be made private due to POD requirements.
|
||||
// associates a status code with a description [and errno_equivalent].
|
||||
struct StatusDefinition // POD
|
||||
{
|
||||
Status status;
|
||||
|
||||
// must remain valid until end of program.
|
||||
// typically a string literal; must remain valid until end of program.
|
||||
const wchar_t* description;
|
||||
|
||||
StatusDefinition* next;
|
||||
// omit initializer (or initialize to 0) if there is no errno equivalent.
|
||||
int errno_equivalent;
|
||||
};
|
||||
|
||||
int errno_equivalent; // (-1 if there is none)
|
||||
// retrieving description and errno_equivalent requires going through all
|
||||
// StatusDefinition instances. we avoid dynamic memory allocation (which
|
||||
// is problematic because status codes may be needed before _cinit) by
|
||||
// organizing them into a linked list, with nodes residing in static storage.
|
||||
// since modules may introduce many status codes, they are stored in an
|
||||
// array, aka "bucket", which includes a link to the next bucket.
|
||||
// initialized via STATUS_ADD_DEFINITIONS; opaque.
|
||||
struct StatusDefinitionBucket // POD
|
||||
{
|
||||
const StatusDefinition* definitions;
|
||||
size_t numDefinitions;
|
||||
StatusDefinitionBucket* next;
|
||||
};
|
||||
|
||||
/**
|
||||
* associating a Status with a description and errno equivalent.
|
||||
* @return dummy integer to allow calling via static initializer.
|
||||
* (called via STATUS_ADD_DEFINITIONS)
|
||||
*
|
||||
* @param bucket is being added; its definitions and numDefinitions must
|
||||
* already be initialized.
|
||||
* @return previous bucket in list, suitable for initializing bucket->next.
|
||||
*
|
||||
* (this function must be callable as a static initializer; initializing
|
||||
* next avoids the need for a separate dummy variable)
|
||||
**/
|
||||
LIB_API int StatusAddDefinition(StatusDefinition*);
|
||||
LIB_API StatusDefinitionBucket* StatusAddDefinitions(StatusDefinitionBucket* bucket);
|
||||
|
||||
// associate a Status with a description and errno equivalent.
|
||||
// Invoke this at file or function scope.
|
||||
#define STATUS_DEFINE(namespaceName, identifier, description, errno_equivalent)\
|
||||
static StatusDefinition identifier##_def = { namespaceName::identifier, description, NULL, errno_equivalent };\
|
||||
static int identifier##_dummy = StatusAddDefinition(&identifier##_def)
|
||||
/**
|
||||
* add a module's array of StatusDefinition to the list.
|
||||
* typically invoked at file scope.
|
||||
* @param definitions name (identifier) of the array
|
||||
**/
|
||||
#define STATUS_ADD_DEFINITIONS(definitions) static StatusDefinitionBucket definitions##_bucket = { definitions, ARRAY_SIZE(definitions), StatusAddDefinitions(&definitions##_bucket) };
|
||||
|
||||
|
||||
/**
|
||||
@ -208,13 +226,6 @@ LIB_API int StatusAddDefinition(StatusDefinition*);
|
||||
**/
|
||||
LIB_API wchar_t* StatusDescription(Status status, wchar_t* buf, size_t max_chars);
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// conversion to/from other error code definitions.
|
||||
// note: other conversion routines (e.g. to/from Win32) are implemented in
|
||||
// the corresponding modules to keep this header portable.
|
||||
|
||||
/**
|
||||
* @return the errno equivalent of a Status.
|
||||
*
|
||||
@ -226,13 +237,18 @@ extern int ErrnoFromStatus(Status status);
|
||||
|
||||
/**
|
||||
* @return Status equivalent of errno, or ERR::FAIL if there's no equivalent.
|
||||
* should only be called directly after a POSIX function indicates failure;
|
||||
* errno may otherwise still be set from another error cause.
|
||||
*
|
||||
* NB: reset errno to 0 before calling POSIX functions to avoid confusion
|
||||
* with previous errors.
|
||||
**/
|
||||
extern Status StatusFromErrno();
|
||||
|
||||
// note: other conversion routines (e.g. to/from Win32) are implemented in
|
||||
// the corresponding modules to keep this header portable.
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// propagation macros
|
||||
|
||||
// warn and return a status. use when an error is first detected to
|
||||
// begin propagating it to callers.
|
||||
@ -338,6 +354,7 @@ extern Status StatusFromErrno();
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// shared status code definitions
|
||||
|
||||
namespace INFO
|
||||
{
|
||||
@ -385,10 +402,8 @@ namespace ERR
|
||||
// system limitations
|
||||
const Status AGAIN = -100030;
|
||||
const Status LIMIT = -100031;
|
||||
const Status NO_SYS = -100032;
|
||||
const Status NOT_IMPLEMENTED = -100033;
|
||||
const Status NOT_SUPPORTED = -100034;
|
||||
const Status NO_MEM = -100035;
|
||||
const Status NOT_SUPPORTED = -100032;
|
||||
const Status NO_MEM = -100033;
|
||||
|
||||
// these are for cases where we just want a distinct value to display and
|
||||
// a symbolic name + string would be overkill (e.g. the various
|
||||
|
@ -27,9 +27,12 @@
|
||||
#include "precompiled.h"
|
||||
#include "lib/sysdep/cpu.h"
|
||||
|
||||
STATUS_DEFINE(ERR, CPU_FEATURE_MISSING, L"This CPU doesn't support a required feature", -1);
|
||||
STATUS_DEFINE(ERR, CPU_UNKNOWN_OPCODE, L"Disassembly failed", -1);
|
||||
STATUS_DEFINE(ERR, CPU_UNKNOWN_VENDOR, L"CPU vendor unknown", -1);
|
||||
static const StatusDefinition cpuStatusDefinitions[] = {
|
||||
{ ERR::CPU_FEATURE_MISSING, L"This CPU doesn't support a required feature" },
|
||||
{ ERR::CPU_UNKNOWN_OPCODE, L"Disassembly failed" },
|
||||
{ ERR::CPU_UNKNOWN_VENDOR, L"CPU vendor unknown" }
|
||||
};
|
||||
STATUS_ADD_DEFINITIONS(cpuStatusDefinitions);
|
||||
|
||||
|
||||
// ensure the actual pointer size matches expectations on the most common
|
||||
|
@ -78,7 +78,7 @@ Status wcpu_ReadFrequencyFromRegistry(u32& freqMhz)
|
||||
{
|
||||
HKEY hKey;
|
||||
if(RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0", 0, KEY_QUERY_VALUE, &hKey) != ERROR_SUCCESS)
|
||||
return ERR::NO_SYS;
|
||||
return ERR::NOT_SUPPORTED;
|
||||
|
||||
DWORD size = sizeof(&freqMhz);
|
||||
LONG ret = RegQueryValueExW(hKey, L"~MHz", 0, 0, (LPBYTE)&freqMhz, &size);
|
||||
|
@ -130,7 +130,7 @@ static Status AppendDriverVersionsFromRegistry(VersionList& versionList)
|
||||
if(i == 0)
|
||||
{
|
||||
RegCloseKey(hkDrivers);
|
||||
return ERR::NO_SYS; // NOWARN (ATI and NVidia don't create sub-keys on Windows 7)
|
||||
return ERR::NOT_SUPPORTED; // NOWARN (ATI and NVidia don't create sub-keys on Windows 7)
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -153,7 +153,7 @@ private:
|
||||
|
||||
const HpetDescriptionTable* hpet = (const HpetDescriptionTable*)acpi_GetTable("HPET");
|
||||
if(!hpet)
|
||||
return ERR::NO_SYS; // NOWARN (HPET not reported by BIOS)
|
||||
return ERR::NOT_SUPPORTED; // NOWARN (HPET not reported by BIOS)
|
||||
|
||||
if(hpet->baseAddress.addressSpaceId != ACPI_AS_MEMORY)
|
||||
return ERR::NOT_SUPPORTED; // NOWARN (happens on some BIOSes)
|
||||
|
@ -59,7 +59,7 @@ public:
|
||||
// (note: it's called FADT, but the signature is "FACP")
|
||||
const FADT* fadt = (const FADT*)acpi_GetTable("FACP");
|
||||
if(!fadt)
|
||||
return ERR::NO_SYS; // NOWARN (ACPI tables might not be available)
|
||||
return ERR::NOT_SUPPORTED; // NOWARN (ACPI tables might not be available)
|
||||
m_portAddress = u16_from_larger(fadt->pmTimerPortAddress);
|
||||
|
||||
return INFO::OK;
|
||||
|
@ -123,7 +123,7 @@ public:
|
||||
{
|
||||
#if ARCH_X86_X64
|
||||
if(!x86_x64_cap(X86_X64_CAP_TSC))
|
||||
return ERR::NO_SYS; // NOWARN (CPU doesn't support RDTSC)
|
||||
return ERR::NOT_SUPPORTED; // NOWARN (CPU doesn't support RDTSC)
|
||||
#endif
|
||||
|
||||
return INFO::OK;
|
||||
|
@ -639,7 +639,7 @@ int aio_cancel(int UNUSED(fd), struct aiocb* cb)
|
||||
|
||||
int aio_fsync(int, struct aiocb*)
|
||||
{
|
||||
WARN_IF_ERR(ERR::NOT_IMPLEMENTED);
|
||||
WARN_IF_ERR(ERR::NOT_SUPPORTED);
|
||||
errno = ENOSYS;
|
||||
return -1;
|
||||
}
|
||||
|
@ -31,7 +31,6 @@
|
||||
#include <stdlib.h> // __argc
|
||||
|
||||
#include "lib/file/file.h"
|
||||
#include "lib/file/vfs/vfs.h"
|
||||
#include "lib/posix/posix.h"
|
||||
#include "lib/sysdep/sysdep.h"
|
||||
#include "lib/sysdep/os/win/win.h"
|
||||
@ -139,20 +138,17 @@ Status StatusFromWin()
|
||||
case ERROR_ACCESS_DENIED:
|
||||
return ERR::FILE_ACCESS;
|
||||
case ERROR_NOT_SUPPORTED:
|
||||
return ERR::NOT_SUPPORTED;
|
||||
case ERROR_CALL_NOT_IMPLEMENTED:
|
||||
return ERR::NOT_IMPLEMENTED;
|
||||
case ERROR_PROC_NOT_FOUND:
|
||||
return ERR::NO_SYS;
|
||||
return ERR::NOT_SUPPORTED;
|
||||
case ERROR_BUSY:
|
||||
case WAIT_TIMEOUT:
|
||||
return ERR::AGAIN;
|
||||
case ERROR_OPERATION_ABORTED:
|
||||
return ERR::ABORTED;
|
||||
case ERROR_FILE_NOT_FOUND:
|
||||
return ERR::VFS_FILE_NOT_FOUND;
|
||||
case ERROR_PATH_NOT_FOUND:
|
||||
return ERR::VFS_DIR_NOT_FOUND;
|
||||
return ERR::FILE_NOT_FOUND;
|
||||
default:
|
||||
return ERR::FAIL;
|
||||
}
|
||||
|
@ -34,8 +34,10 @@
|
||||
# include "lib/sysdep/os/win/wcpu.h"
|
||||
#endif
|
||||
|
||||
|
||||
STATUS_DEFINE(ERR, OS_CPU_RESTRICTED_AFFINITY, L"Cannot set desired CPU affinity", -1);
|
||||
static const StatusDefinition osCpuStatusDefinitions[] = {
|
||||
{ ERR::OS_CPU_RESTRICTED_AFFINITY, L"Cannot set desired CPU affinity" }
|
||||
};
|
||||
STATUS_ADD_DEFINITIONS(osCpuStatusDefinitions);
|
||||
|
||||
|
||||
double os_cpu_ClockFrequency()
|
||||
|
@ -419,7 +419,7 @@ static Status InitStructures()
|
||||
RETURN_STATUS_IF_ERR(GetTable(table));
|
||||
#else
|
||||
std::vector<u8> table;
|
||||
return ERR::NOT_IMPLEMENTED;
|
||||
return ERR::NOT_SUPPORTED;
|
||||
#endif
|
||||
|
||||
// (instead of counting the total string size, just use the
|
||||
|
@ -39,14 +39,17 @@
|
||||
#include "tex_codec.h"
|
||||
|
||||
|
||||
STATUS_DEFINE(ERR, TEX_FMT_INVALID, L"Invalid/unsupported texture format", -1);
|
||||
STATUS_DEFINE(ERR, TEX_INVALID_COLOR_TYPE, L"Invalid color type", -1);
|
||||
STATUS_DEFINE(ERR, TEX_NOT_8BIT_PRECISION, L"Not 8-bit channel precision", -1);
|
||||
STATUS_DEFINE(ERR, TEX_INVALID_LAYOUT, L"Unsupported texel layout, e.g. right-to-left", -1);
|
||||
STATUS_DEFINE(ERR, TEX_COMPRESSED, L"Unsupported texture compression", -1);
|
||||
STATUS_DEFINE(WARN, TEX_INVALID_DATA, L"Warning: invalid texel data encountered", -1);
|
||||
STATUS_DEFINE(ERR, TEX_INVALID_SIZE, L"Texture size is incorrect", -1);
|
||||
STATUS_DEFINE(INFO, TEX_CODEC_CANNOT_HANDLE, L"Texture codec cannot handle the given format", -1);
|
||||
static const StatusDefinition texStatusDefinitions[] = {
|
||||
{ ERR::TEX_FMT_INVALID, L"Invalid/unsupported texture format" },
|
||||
{ ERR::TEX_INVALID_COLOR_TYPE, L"Invalid color type" },
|
||||
{ ERR::TEX_NOT_8BIT_PRECISION, L"Not 8-bit channel precision" },
|
||||
{ ERR::TEX_INVALID_LAYOUT, L"Unsupported texel layout, e.g. right-to-left" },
|
||||
{ ERR::TEX_COMPRESSED, L"Unsupported texture compression" },
|
||||
{ WARN::TEX_INVALID_DATA, L"Warning: invalid texel data encountered" },
|
||||
{ ERR::TEX_INVALID_SIZE, L"Texture size is incorrect" },
|
||||
{ INFO::TEX_CODEC_CANNOT_HANDLE, L"Texture codec cannot handle the given format" }
|
||||
};
|
||||
STATUS_ADD_DEFINITIONS(texStatusDefinitions);
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -550,7 +550,7 @@ static Status decode_sd(const DDS_HEADER* sd, size_t& w, size_t& h, size_t& bpp,
|
||||
{
|
||||
const size_t depth = (size_t)read_le32(&sd->dwDepth);
|
||||
if(depth)
|
||||
WARN_RETURN(ERR::NOT_IMPLEMENTED);
|
||||
WARN_RETURN(ERR::NOT_SUPPORTED);
|
||||
}
|
||||
|
||||
// check caps
|
||||
@ -599,7 +599,7 @@ static Status dds_decode(DynArray* RESTRICT da, Tex* RESTRICT t)
|
||||
|
||||
static Status dds_encode(Tex* RESTRICT UNUSED(t), DynArray* RESTRICT UNUSED(da))
|
||||
{
|
||||
// note: do not return ERR::NOT_IMPLEMENTED et al. because that would
|
||||
// note: do not return ERR::NOT_SUPPORTED et al. because that would
|
||||
// break tex_write (which assumes either this, 0 or errors are returned).
|
||||
return INFO::TEX_CODEC_CANNOT_HANDLE;
|
||||
}
|
||||
|
@ -23,10 +23,13 @@
|
||||
#include "precompiled.h"
|
||||
#include "lib/utf8.h"
|
||||
|
||||
STATUS_DEFINE(ERR, UTF8_SURROGATE, L"UTF-16 surrogate pairs aren't supported", -1);
|
||||
STATUS_DEFINE(ERR, UTF8_OUTSIDE_BMP, L"Code point outside BMP (> 0x10000)", -1);
|
||||
STATUS_DEFINE(ERR, UTF8_NONCHARACTER, L"Noncharacter (e.g. WEOF)", -1);
|
||||
STATUS_DEFINE(ERR, UTF8_INVALID_UTF8, L"Invalid UTF-8 sequence", -1);
|
||||
static const StatusDefinition utf8StatusDefinitions[] = {
|
||||
{ ERR::UTF8_SURROGATE, L"UTF-16 surrogate pairs aren't supported" },
|
||||
{ ERR::UTF8_OUTSIDE_BMP, L"Code point outside BMP (> 0x10000)" },
|
||||
{ ERR::UTF8_NONCHARACTER, L"Noncharacter (e.g. WEOF)" },
|
||||
{ ERR::UTF8_INVALID_UTF8, L"Invalid UTF-8 sequence" }
|
||||
};
|
||||
STATUS_ADD_DEFINITIONS(utf8StatusDefinitions);
|
||||
|
||||
|
||||
// adapted from http://unicode.org/Public/PROGRAMS/CVTUTF/ConvertUTF.c
|
||||
|
@ -18,7 +18,6 @@
|
||||
#include "precompiled.h"
|
||||
|
||||
#include "lib/ogl.h"
|
||||
#include "lib/res/graphics/ogl_shader.h"
|
||||
#include "maths/Vector3D.h"
|
||||
#include "maths/Vector4D.h"
|
||||
|
||||
|
@ -22,7 +22,6 @@
|
||||
#include "precompiled.h"
|
||||
|
||||
#include "lib/ogl.h"
|
||||
#include "lib/res/graphics/ogl_shader.h"
|
||||
#include "maths/Vector3D.h"
|
||||
#include "maths/Vector4D.h"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user