1 // Common/NewHandler.h 2 3 #ifndef __COMMON_NEW_HANDLER_H 4 #define __COMMON_NEW_HANDLER_H 5 6 /* 7 This file must be included before any code that uses operators "delete" or "new". 8 Also you must compile and link "NewHandler.cpp", if you use MSVC 6.0. 9 The operator "new" in MSVC 6.0 doesn't throw exception "bad_alloc". 10 So we define another version of operator "new" that throws "CNewException" on failure. 11 12 If you use compiler that throws exception in "new" operator (GCC or new version of MSVC), 13 you can compile without "NewHandler.cpp". So standard exception "bad_alloc" will be used. 14 15 It's still allowed to use redefined version of operator "new" from "NewHandler.cpp" 16 with any compiler. 7-Zip's code can work with "bad_alloc" and "CNewException" exceptions. 17 But if you use some additional code (outside of 7-Zip's code), you must check 18 that redefined version of operator "new" (that throws CNewException) is not 19 problem for your code. 20 21 Also we declare delete(void *p) throw() that creates smaller code. 22 */ 23 24 #include <stddef.h> 25 26 class CNewException {}; 27 28 #ifdef WIN32 29 // We can compile my_new and my_delete with _fastcall 30 /* 31 void * my_new(size_t size); 32 void my_delete(void *p) throw(); 33 // void * my_Realloc(void *p, size_t newSize, size_t oldSize); 34 */ 35 #endif 36 37 #ifdef _WIN32 38 39 void * 40 #ifdef _MSC_VER 41 __cdecl 42 #endif 43 operator new(size_t size); 44 45 void 46 #ifdef _MSC_VER 47 __cdecl 48 #endif 49 operator delete(void *p) throw(); 50 51 #endif 52 53 /* 54 #ifdef _WIN32 55 void * 56 #ifdef _MSC_VER 57 __cdecl 58 #endif 59 operator new[](size_t size); 60 61 void 62 #ifdef _MSC_VER 63 __cdecl 64 #endif 65 operator delete[](void *p) throw(); 66 #endif 67 */ 68 69 #endif 70