AllocateFromAssimpHeap: add overload for nothrow-new.

git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@666 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
pull/1/head
aramis_acg 2010-04-11 02:14:52 +00:00
parent 33544456cd
commit 875b7f9ca2
2 changed files with 40 additions and 17 deletions

View File

@ -45,19 +45,20 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "AssimpPCH.h"
// .......................................................................................
// ------------------------------------------------------------------------------------------------
/* Uncomment this line to prevent Assimp from catching unknown exceptions.
*
* Note that any Exception except ImportErrorException may lead to
* Note that any Exception except DeadlyImportError may lead to
* undefined behaviour -> loaders could remain in an unusable state and
* further imports with the same Importer instance could fail/crash/burn ...
*/
// .......................................................................................
// ------------------------------------------------------------------------------------------------
#define ASSIMP_CATCH_GLOBAL_EXCEPTIONS
// .......................................................................................
// ------------------------------------------------------------------------------------------------
// Internal headers
// .......................................................................................
// ------------------------------------------------------------------------------------------------
#include "BaseImporter.h"
#include "BaseProcess.h"
#include "DefaultIOStream.h"
@ -67,10 +68,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "ScenePreprocessor.h"
#include "MemoryIOWrapper.h"
// .......................................................................................
// ------------------------------------------------------------------------------------------------
// Importers
// (include_new_importers_here)
// .......................................................................................
// ------------------------------------------------------------------------------------------------
#ifndef AI_BUILD_NO_X_IMPORTER
# include "XFileImporter.h"
#endif
@ -168,9 +169,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# include "COBLoader.h"
#endif
// .......................................................................................
// PostProcess-Steps
// .......................................................................................
// ------------------------------------------------------------------------------------------------
// Post processing-Steps
// ------------------------------------------------------------------------------------------------
#ifndef AI_BUILD_NO_CALCTANGENTS_PROCESS
# include "CalcTangentsProcess.h"
#endif
@ -241,15 +242,25 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
using namespace Assimp;
using namespace Assimp::Intern;
// .......................................................................................
// ------------------------------------------------------------------------------------------------
// Intern::AllocateFromAssimpHeap serves as abstract base class. It overrides
// new and delete (and their array counterparts) of public API classes (e.g. Logger) to
// utilize our DLL heap
// .......................................................................................
// utilize our DLL heap.
// See http://www.gotw.ca/publications/mill15.htm
// ------------------------------------------------------------------------------------------------
void* AllocateFromAssimpHeap::operator new ( size_t num_bytes) {
return ::operator new(num_bytes);
}
void* AllocateFromAssimpHeap::operator new ( size_t num_bytes, const std::nothrow_t& ) {
try {
return AllocateFromAssimpHeap::operator new( num_bytes );
}
catch( ... ) {
return NULL;
}
}
void AllocateFromAssimpHeap::operator delete ( void* data) {
return ::operator delete(data);
}
@ -258,6 +269,15 @@ void* AllocateFromAssimpHeap::operator new[] ( size_t num_bytes) {
return ::operator new[](num_bytes);
}
void* AllocateFromAssimpHeap::operator new[] ( size_t num_bytes, const std::nothrow_t& ) {
try {
return AllocateFromAssimpHeap::operator new[]( num_bytes );
}
catch( ... ) {
return NULL;
}
}
void AllocateFromAssimpHeap::operator delete[] ( void* data) {
return ::operator delete[](data);
}

View File

@ -63,10 +63,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "aiQuaternion.h"
#ifdef __cplusplus
# include <string> // for aiString::Set(const std::string&)
#include <new> // for std::nothrow_t
#include <string> // for aiString::Set(const std::string&)
namespace Assimp {
//! @cond never
namespace Intern {
// --------------------------------------------------------------------
@ -83,13 +83,16 @@ namespace Intern {
*/
// --------------------------------------------------------------------
struct ASSIMP_API AllocateFromAssimpHeap {
// http://www.gotw.ca/publications/mill15.htm
// new/delete overload
void *operator new ( size_t num_bytes);
void *operator new ( size_t num_bytes) /* throw( std::bad_alloc ) */;
void *operator new ( size_t num_bytes, const std::nothrow_t& ) throw();
void operator delete ( void* data);
// array new/delete overload
void *operator new[] ( size_t num_bytes);
void *operator new[] ( size_t num_bytes) /* throw( std::bad_alloc ) */;
void *operator new[] ( size_t num_bytes, const std::nothrow_t& ) throw();
void operator delete[] ( void* data);
}; // struct AllocateFromAssimpHeap