1
0
forked from 0ad/0ad

sync with work: add and use NOTHROW; export file_system functions; throw Status from File ctor; add WARN_THROW equivalents of WARN_RETURN

This was SVN commit r10384.
This commit is contained in:
janwas 2011-10-10 10:04:36 +00:00
parent 6c6c374a11
commit 8ac994e4e6
10 changed files with 58 additions and 23 deletions

View File

@ -81,24 +81,24 @@ public:
return &value;
}
AlignedAllocator() throw()
AlignedAllocator() NOTHROW
{
}
AlignedAllocator(const AlignedAllocator&) throw()
AlignedAllocator(const AlignedAllocator&) NOTHROW
{
}
template <class U>
AlignedAllocator (const AlignedAllocator<U>&) throw()
AlignedAllocator (const AlignedAllocator<U>&) NOTHROW
{
}
~AlignedAllocator() throw()
~AlignedAllocator() NOTHROW
{
}
size_type max_size() const throw()
size_type max_size() const NOTHROW
{
// maximum number of *elements* that can be allocated
return std::numeric_limits<std::size_t>::max() / sizeof(T);
@ -133,13 +133,13 @@ public:
// indicate that all specializations of this allocator are interchangeable
template <class T1, class T2>
bool operator==(const AlignedAllocator<T1>&, const AlignedAllocator<T2>&) throw()
bool operator==(const AlignedAllocator<T1>&, const AlignedAllocator<T2>&) NOTHROW
{
return true;
}
template <class T1, class T2>
bool operator!=(const AlignedAllocator<T1>&, const AlignedAllocator<T2>&) throw()
bool operator!=(const AlignedAllocator<T1>&, const AlignedAllocator<T2>&) NOTHROW
{
return false;
}

View File

@ -627,7 +627,7 @@ public:
Validate();
}
void* Allocate(size_t size) throw()
void* Allocate(size_t size) NOTHROW
{
ENSURE(IsValidSize(size));
Validate();
@ -754,7 +754,7 @@ void HeaderlessAllocator::Reset()
return impl->Reset();
}
void* HeaderlessAllocator::Allocate(size_t size) throw()
void* HeaderlessAllocator::Allocate(size_t size) NOTHROW
{
return impl->Allocate(size);
}

View File

@ -76,7 +76,7 @@ public:
* (this allocator is designed for requests on the order of several KiB)
* @return allocated memory or 0 if the pool is too fragmented or full.
**/
void* Allocate(size_t size) throw();
void* Allocate(size_t size) NOTHROW;
/**
* deallocate memory.

View File

@ -50,7 +50,7 @@ void RegisterUniqueRangeDeleter(UniqueRangeDeleter deleter, volatile IdxDeleter*
}
void CallUniqueRangeDeleter(void* pointer, size_t size, IdxDeleter idxDeleter) throw()
void CallUniqueRangeDeleter(void* pointer, size_t size, IdxDeleter idxDeleter) NOTHROW
{
ASSERT(idxDeleter < numDeleters);
// (some deleters do not tolerate null pointers)

View File

@ -43,7 +43,7 @@ typedef void (*UniqueRangeDeleter)(void* pointer, size_t size);
**/
LIB_API void RegisterUniqueRangeDeleter(UniqueRangeDeleter deleter, volatile IdxDeleter* idxDeleter);
LIB_API void CallUniqueRangeDeleter(void* pointer, size_t size, IdxDeleter idxDeleter) throw();
LIB_API void CallUniqueRangeDeleter(void* pointer, size_t size, IdxDeleter idxDeleter) NOTHROW;
// unfortunately, unique_ptr allows constructing without a custom deleter. to ensure callers can

View File

@ -57,6 +57,20 @@
#endif
/**
* void function() NOTHROW - indicate the function will not
* throw any synchronous exceptions, thus hopefully generating
* smaller and more efficient code.
**/
#if GCC_VERSION >= 303
# define NOTHROW __attribute__((nothrow))
#elif MSC_VERSION
# define NOTHROW throw() // special meaning, equivalent to __declspec(nothrow)
#else
# define NOTHROW // throw() might result in ADDITIONAL checks
#endif
/**
* "unreachable code" helpers
*

View File

@ -52,7 +52,7 @@ public:
File(const OsPath& pathname, int oflag)
{
(void)Open(pathname, oflag);
THROW_STATUS_IF_ERR(Open(pathname, oflag));
}
~File()

View File

@ -71,17 +71,17 @@ private:
time_t mtime;
};
extern Status GetFileInfo(const OsPath& pathname, FileInfo* fileInfo);
LIB_API Status GetFileInfo(const OsPath& pathname, FileInfo* fileInfo);
typedef std::vector<FileInfo> FileInfos;
typedef std::vector<OsPath> DirectoryNames;
extern Status GetDirectoryEntries(const OsPath& path, FileInfos* files, DirectoryNames* subdirectoryNames);
LIB_API Status GetDirectoryEntries(const OsPath& path, FileInfos* files, DirectoryNames* subdirectoryNames);
// same as boost::filesystem::create_directories, except that mkdir is invoked with
// <mode> instead of 0755.
extern Status CreateDirectories(const OsPath& path, mode_t mode);
LIB_API Status CreateDirectories(const OsPath& path, mode_t mode);
extern Status DeleteDirectory(const OsPath& dirPath);
LIB_API Status DeleteDirectory(const OsPath& dirPath);
#endif // #ifndef INCLUDED_FILE_SYSTEM

View File

@ -297,9 +297,30 @@ extern Status StatusFromErrno();
}\
while(0)
// warn and throw expression if it is negative. use to propagate
// errors from within constructors.
// warn and throw a status. use when an error is first detected to
// begin propagating it to callers.
#define WARN_THROW(status)\
do\
{\
DEBUG_WARN_ERR(status);\
throw status;\
}\
while(0)
// throw expression if it is negative. use to propagate
// expected errors from constructors.
#define THROW_STATUS_IF_ERR(expression)\
do\
{\
const Status status_ = (expression);\
if(status_ < 0)\
throw status_;\
}\
while(0)
// warn and throw expression if it is negative. use to propagate
// errors from constructors.
#define WARN_THROW_STATUS_IF_ERR(expression)\
do\
{\
const Status status_ = (expression);\

View File

@ -39,7 +39,7 @@
#include "lib/sysdep/arch/x86_x64/apic.h"
//-----------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------
// detect *maximum* number of cores/packages/caches.
// note: some of them may be disabled by the OS or BIOS.
// note: Intel Appnote 485 assures us that they are uniform across packages.
@ -116,7 +116,7 @@ static size_t MaxLogicalPerCache()
}
//-----------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------
// CPU topology interface
// APIC IDs consist of variable-length bit fields indicating the logical,
@ -298,7 +298,7 @@ size_t cpu_topology_ApicId(size_t idxLogical, size_t idxCore, size_t idxPackage)
}
//-----------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------
// cache topology
// note: Windows 2003 GetLogicalProcessorInformation provides similar
@ -430,7 +430,7 @@ static void DetermineProcessorsCache(const uintptr_t* cachesProcessorMask, size_
}
//-----------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------
// cache topology interface
struct CacheTopology // POD