#include "defs.h" #include "exceptions.h" #include #include #ifndef __mac__ #include #endif #include #include "perrors.h" #ifdef __mac__ #include "unixmac.h" #include #endif //#define LAL #ifndef EXC_MSG #define EXC_MSG(i) "Exception " << i #endif #define kDynAllocBlock 10 void EAFailHandler(void); #ifndef COMPILER_EXCEPTIONS #ifndef NO_EXCEPTIONS ExcHndl::ExcHndl(ExcHndl* up) : nextHandler(up), theExc(0), hadExc(0), nObj(0), nObjAlloc(kDynAllocBlock), objects((ExcAwareObject**)malloc(kDynAllocBlock*sizeof(void*))), nDyn(0), nDynAlloc(kDynAllocBlock), dynObjs((ExcAwareObject**)malloc(kDynAllocBlock*sizeof(void*))), nDynTab(0), nDynTabAlloc(kDynAllocBlock), dynTabObjs((ExcAwareObject**)malloc(kDynAllocBlock*sizeof(void*))), dynTabSz((size_t*)malloc(kDynAllocBlock*sizeof(size_t))) { // cerr << "TRY : " << hex << this << " <- " << nextHandler << dec << endl; } ExcHndl::~ExcHndl() { free(objects); free(dynObjs); free(dynTabObjs); free(dynTabSz); // cerr << "~TRY: " << hex << this << " <- " << nextHandler << dec << endl; } void ExcHndl::Add(ExcAwareObject* obj) { // on verifie s'il est dans la liste a ignorer int trouve=0; int i; for (i=0; i= (char*)obj)) { return; } // on l'ajoute a la liste des objets nObj++; if (nObj>nObjAlloc) { nObjAlloc += kDynAllocBlock; objects = (ExcAwareObject**) realloc(objects, nObjAlloc*sizeof(void*)); } objects[nObj-1] = obj; } void ExcHndl::Forget(ExcAwareObject* obj) { // on verifie s'il est dans la liste int trouve=0; int i=0; for (i=0; inDynAlloc) { nDynAlloc += kDynAllocBlock; dynObjs = (ExcAwareObject**) realloc(dynObjs, nDynAlloc*sizeof(void*)); } dynObjs[nDyn-1] = obj; } void ExcHndl::IgnoreTab(ExcAwareObject* obj, size_t sz) { // on l'ajoute a la liste des objets nDynTab++; if (nDynTab>nDynTabAlloc) { nDynTabAlloc += kDynAllocBlock; dynTabObjs =(ExcAwareObject**) realloc(dynTabObjs, nDynTabAlloc*sizeof(void*)); dynTabSz = (size_t*) realloc(dynTabSz, nDynTabAlloc*sizeof(size_t)); } dynTabObjs[nDynTab-1] = obj; dynTabSz [nDynTab-1] = sz; } void ExcHndl::DelTab(ExcAwareObject* obj) { // on le supprime int trouve=0; int i=0; for (i=0; i (char*)obj && (char*)objects[i] < (char*)obj + s) { nObj--; for (int j=i; j=0; i--) objects[i]->~ExcAwareObject(); // et maintenant on saute... longjmp(env, 1); } } void ExcHndl::NoHandler(int i, char* file, int line) { cerr << "No handler : "; cerr << EXC_MSG(i); if (file) cerr << " file " << file << " line " << line; cerr << endl; terminate(); } ExcHndl* topExcHndl = 0; int _ExcAbortNeg = 1; int _ExcAbortAll = 0; #endif #endif void EAFailHandler(void) { set_new_handler(NULL); cerr << "Allocation exception -- out of memory" << endl; THROW(allocationErr); } void InitFailNewHandler() { set_new_handler(EAFailHandler); } #ifdef THINK_CPLUS void terminate() { DebugStr("\pTerminate..."); abort(); } #endif #ifdef x__GNUG__ void terminate() { abort(); } #endif