Home | History | Annotate | Download | only in Common
      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 
     25 class CNewException {};
     26 
     27 #ifdef WIN32
     28 // We can compile my_new and my_delete with _fastcall
     29 /*
     30 void * my_new(size_t size);
     31 void my_delete(void *p) throw();
     32 // void * my_Realloc(void *p, size_t newSize, size_t oldSize);
     33 */
     34 #endif
     35 
     36 #ifdef _WIN32
     37 
     38 void *
     39 #ifdef _MSC_VER
     40 __cdecl
     41 #endif
     42 operator new(size_t size);
     43 
     44 void
     45 #ifdef _MSC_VER
     46 __cdecl
     47 #endif
     48 operator delete(void *p) throw();
     49 
     50 #endif
     51 
     52 /*
     53 #ifdef _WIN32
     54 void *
     55 #ifdef _MSC_VER
     56 __cdecl
     57 #endif
     58 operator new[](size_t size);
     59 
     60 void
     61 #ifdef _MSC_VER
     62 __cdecl
     63 #endif
     64 operator delete[](void *p) throw();
     65 #endif
     66 */
     67 
     68 #endif
     69