fork
Fork of cpputest by
include/CppUTest/MemoryLeakDetectorNewMacros.h@1:4769360130ed, 2014-06-17 (annotated)
- Committer:
- Rohit Grover
- Date:
- Tue Jun 17 15:52:54 2014 +0100
- Revision:
- 1:4769360130ed
- Parent:
- 0:0b799af9d58e
updating to the latest version of cppUtest; tested against nordic's m-kit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rgrover1 | 0:0b799af9d58e | 1 | |
rgrover1 | 0:0b799af9d58e | 2 | /* |
rgrover1 | 0:0b799af9d58e | 3 | * This file can be used to get extra debugging information about memory leaks in your production code. |
rgrover1 | 0:0b799af9d58e | 4 | * It defines a preprocessor macro for operator new. This will pass additional information to the |
rgrover1 | 0:0b799af9d58e | 5 | * operator new and this will give the line/file information of the memory leaks in your code. |
rgrover1 | 0:0b799af9d58e | 6 | * |
rgrover1 | 0:0b799af9d58e | 7 | * You can use this by including this file to all your production code. When using gcc, you can use |
rgrover1 | 0:0b799af9d58e | 8 | * the -include file to do this for you. |
rgrover1 | 0:0b799af9d58e | 9 | * |
rgrover1 | 0:0b799af9d58e | 10 | * Warning: Using the new macro can cause a conflict with newly declared operator news. This can be |
rgrover1 | 0:0b799af9d58e | 11 | * resolved by: |
rgrover1 | 0:0b799af9d58e | 12 | * 1. #undef operator new before including this file |
rgrover1 | 0:0b799af9d58e | 13 | * 2. Including the files that override operator new before this file. |
rgrover1 | 0:0b799af9d58e | 14 | * This can be done by creating your own NewMacros.h file that includes your operator new overrides |
rgrover1 | 0:0b799af9d58e | 15 | * and THEN this file. |
rgrover1 | 0:0b799af9d58e | 16 | * |
rgrover1 | 0:0b799af9d58e | 17 | * STL (or StdC++ lib) also does overrides for operator new. Therefore, you'd need to include the STL |
rgrover1 | 0:0b799af9d58e | 18 | * files *before* this file too. |
rgrover1 | 0:0b799af9d58e | 19 | * |
rgrover1 | 0:0b799af9d58e | 20 | */ |
rgrover1 | 0:0b799af9d58e | 21 | |
rgrover1 | 0:0b799af9d58e | 22 | #include "CppUTestConfig.h" |
rgrover1 | 0:0b799af9d58e | 23 | |
Rohit Grover |
1:4769360130ed | 24 | /* Make sure that mem leak detection is on and that this is being included from a C++ file */ |
Rohit Grover |
1:4769360130ed | 25 | #if CPPUTEST_USE_MEM_LEAK_DETECTION && defined(__cplusplus) |
rgrover1 | 0:0b799af9d58e | 26 | |
rgrover1 | 0:0b799af9d58e | 27 | /* This #ifndef prevents <new> from being included twice and enables the file to be included anywhere */ |
rgrover1 | 0:0b799af9d58e | 28 | #ifndef CPPUTEST_USE_NEW_MACROS |
rgrover1 | 0:0b799af9d58e | 29 | |
rgrover1 | 0:0b799af9d58e | 30 | #if CPPUTEST_USE_STD_CPP_LIB |
rgrover1 | 0:0b799af9d58e | 31 | #include <new> |
rgrover1 | 0:0b799af9d58e | 32 | #include <memory> |
rgrover1 | 0:0b799af9d58e | 33 | #include <string> |
rgrover1 | 0:0b799af9d58e | 34 | #endif |
rgrover1 | 0:0b799af9d58e | 35 | |
rgrover1 | 0:0b799af9d58e | 36 | void* operator new(size_t size, const char* file, int line) UT_THROW (std::bad_alloc); |
rgrover1 | 0:0b799af9d58e | 37 | void* operator new[](size_t size, const char* file, int line) UT_THROW (std::bad_alloc); |
rgrover1 | 0:0b799af9d58e | 38 | void* operator new(size_t size) UT_THROW(std::bad_alloc); |
rgrover1 | 0:0b799af9d58e | 39 | void* operator new[](size_t size) UT_THROW(std::bad_alloc); |
rgrover1 | 0:0b799af9d58e | 40 | |
rgrover1 | 0:0b799af9d58e | 41 | void operator delete(void* mem) UT_NOTHROW; |
rgrover1 | 0:0b799af9d58e | 42 | void operator delete[](void* mem) UT_NOTHROW; |
rgrover1 | 0:0b799af9d58e | 43 | void operator delete(void* mem, const char* file, int line) UT_NOTHROW; |
rgrover1 | 0:0b799af9d58e | 44 | void operator delete[](void* mem, const char* file, int line) UT_NOTHROW; |
rgrover1 | 0:0b799af9d58e | 45 | |
rgrover1 | 0:0b799af9d58e | 46 | #endif |
rgrover1 | 0:0b799af9d58e | 47 | |
rgrover1 | 0:0b799af9d58e | 48 | #define new new(__FILE__, __LINE__) |
rgrover1 | 0:0b799af9d58e | 49 | |
rgrover1 | 0:0b799af9d58e | 50 | #define CPPUTEST_USE_NEW_MACROS 1 |
rgrover1 | 0:0b799af9d58e | 51 | |
rgrover1 | 0:0b799af9d58e | 52 | #endif |