mem_leak.h 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /****************************************************************************
  2. **
  3. ** https://www.qxorm.com/
  4. ** Copyright (C) 2013 Lionel Marty (contact@qxorm.com)
  5. **
  6. ** This file is part of the QxOrm library
  7. **
  8. ** This software is provided 'as-is', without any express or implied
  9. ** warranty. In no event will the authors be held liable for any
  10. ** damages arising from the use of this software
  11. **
  12. ** Commercial Usage
  13. ** Licensees holding valid commercial QxOrm licenses may use this file in
  14. ** accordance with the commercial license agreement provided with the
  15. ** Software or, alternatively, in accordance with the terms contained in
  16. ** a written agreement between you and Lionel Marty
  17. **
  18. ** GNU General Public License Usage
  19. ** Alternatively, this file may be used under the terms of the GNU
  20. ** General Public License version 3.0 as published by the Free Software
  21. ** Foundation and appearing in the file 'license.gpl3.txt' included in the
  22. ** packaging of this file. Please review the following information to
  23. ** ensure the GNU General Public License version 3.0 requirements will be
  24. ** met : http://www.gnu.org/copyleft/gpl.html
  25. **
  26. ** If you are unsure which license is appropriate for your use, or
  27. ** if you have questions regarding the use of this file, please contact :
  28. ** contact@qxorm.com
  29. **
  30. ****************************************************************************/
  31. /*** http://wyw.dcweb.cn/leakage.htm ***/
  32. #ifndef QT_NO_DEBUG
  33. #ifndef _QX_MODE_RELEASE
  34. #if _QX_USE_MEM_LEAK_DETECTION
  35. #define _DEBUG_NEW_REDEFINE_NEW 0
  36. #include "debug_new.h"
  37. #ifdef _MSC_VER
  38. #pragma warning(disable: 4290) // C++ exception specification ignored
  39. #endif // _MSC_VER
  40. #ifndef QX_MEM_LEAK_STATIC_OR_INLINE
  41. #ifdef _MSC_VER
  42. #define QX_MEM_LEAK_STATIC_OR_INLINE static
  43. #else
  44. #define QX_MEM_LEAK_STATIC_OR_INLINE inline
  45. #endif // _MSC_VER
  46. #endif // QX_MEM_LEAK_STATIC_OR_INLINE
  47. QX_MEM_LEAK_STATIC_OR_INLINE void * operator new(size_t size) throw(std::bad_alloc) { return operator new(size, (char *)_DEBUG_NEW_CALLER_ADDRESS, 0); };
  48. QX_MEM_LEAK_STATIC_OR_INLINE void * operator new[](size_t size) throw(std::bad_alloc) { return operator new[](size, (char *)_DEBUG_NEW_CALLER_ADDRESS, 0); };
  49. QX_MEM_LEAK_STATIC_OR_INLINE void operator delete(void * pointer) throw() { qx::memory::__debug_new_recorder::free_pointer(pointer, _DEBUG_NEW_CALLER_ADDRESS, false); };
  50. QX_MEM_LEAK_STATIC_OR_INLINE void operator delete[](void * pointer) throw() { qx::memory::__debug_new_recorder::free_pointer(pointer, _DEBUG_NEW_CALLER_ADDRESS, true); };
  51. #if HAVE_PLACEMENT_DELETE
  52. QX_MEM_LEAK_STATIC_OR_INLINE void operator delete(void * pointer, const std::nothrow_t &) throw() { operator delete(pointer, (char *)_DEBUG_NEW_CALLER_ADDRESS, 0); };
  53. QX_MEM_LEAK_STATIC_OR_INLINE void operator delete[](void * pointer, const std::nothrow_t &) throw() { operator delete[](pointer, (char *)_DEBUG_NEW_CALLER_ADDRESS, 0); };
  54. #endif // HAVE_PLACEMENT_DELETE
  55. #ifdef new
  56. #undef new
  57. #endif // new
  58. #define new DEBUG_NEW
  59. #endif // _QX_USE_MEM_LEAK_DETECTION
  60. #endif // _QX_MODE_RELEASE
  61. #endif // QT_NO_DEBUG
  62. #if (! _QX_USE_MEM_LEAK_DETECTION)
  63. #ifndef DEBUG_NEW
  64. #define DEBUG_NEW new
  65. #endif // DEBUG_NEW
  66. #endif // (! _QX_USE_MEM_LEAK_DETECTION)
  67. #ifdef _QX_MODE_RELEASE
  68. #ifndef DEBUG_NEW
  69. #define DEBUG_NEW new
  70. #endif // DEBUG_NEW
  71. #endif // _QX_MODE_RELEASE