From 9af43ce7356c09e65d7fadf6c1975c22c3a7986d Mon Sep 17 00:00:00 2001 From: cxl Date: Sun, 29 Nov 2015 11:30:26 +0000 Subject: [PATCH] Core: GCC Leak detection altered git-svn-id: svn://ultimatepp.org/upp/trunk@9243 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/Core/Core.h | 12 ++++-------- uppsrc/Core/heapdbg.cpp | 21 +++++++++++++++++++++ uppsrc/CtrlCore/GtkApp.cpp | 16 +++++++++++++--- 3 files changed, 38 insertions(+), 11 deletions(-) diff --git a/uppsrc/Core/Core.h b/uppsrc/Core/Core.h index 84725e15f..fea1f0f51 100644 --- a/uppsrc/Core/Core.h +++ b/uppsrc/Core/Core.h @@ -317,10 +317,6 @@ class JsonIO; #include "InVector.hpp" #include "InMap.hpp" -#if (defined(HEAPDBG) || defined(TESTLEAKS)) && defined(PLATFORM_POSIX) -extern int sMemDiagInitCount; -#endif - #ifdef PLATFORM_WIN32 NTL_MOVEABLE(POINT) NTL_MOVEABLE(SIZE) @@ -329,14 +325,14 @@ NTL_MOVEABLE(RECT) END_UPP_NAMESPACE -#if (defined(TESTLEAKS) || defined(HEAPDBG)) && defined(PLATFORM_POSIX) && !defined(PLATFORM_OSX11) && defined(UPP_HEAP) +#if (defined(TESTLEAKS) || defined(HEAPDBG)) && defined(COMPILER_GCC) && defined(UPP_HEAP) //Place it to the begining of each file to be the first function called in whole executable... - +//This is now backup to init_priority attribute in heapdbg.cpp //$- struct MemDiagCls { - MemDiagCls() { if(!UPP::sMemDiagInitCount++) UPP::MemoryInitDiagnostics(); } - ~MemDiagCls() { if(!--UPP::sMemDiagInitCount) UPP::MemoryDumpLeaks(); } + MemDiagCls(); + ~MemDiagCls(); }; static const MemDiagCls sMemDiagHelper__upp__; //$+ diff --git a/uppsrc/Core/heapdbg.cpp b/uppsrc/Core/heapdbg.cpp index 88e361e26..05d6696e8 100644 --- a/uppsrc/Core/heapdbg.cpp +++ b/uppsrc/Core/heapdbg.cpp @@ -223,4 +223,25 @@ void MemoryInitDiagnostics() #endif #endif + END_UPP_NAMESPACE + +#if (defined(TESTLEAKS) || defined(HEAPDBG)) && defined(COMPILER_GCC) && defined(UPP_HEAP) + +int sMemDiagInitCount; + +MemDiagCls::MemDiagCls() +{ + if(sMemDiagInitCount++ == 0) + UPP::MemoryInitDiagnostics(); +} + +MemDiagCls::~MemDiagCls() +{ + if(--sMemDiagInitCount == 0) + UPP::MemoryDumpLeaks(); +} + +static const MemDiagCls sMemDiagHelper __attribute__ ((init_priority (101))); + +#endif diff --git a/uppsrc/CtrlCore/GtkApp.cpp b/uppsrc/CtrlCore/GtkApp.cpp index aaac6bf76..4cf55697c 100644 --- a/uppsrc/CtrlCore/GtkApp.cpp +++ b/uppsrc/CtrlCore/GtkApp.cpp @@ -28,14 +28,24 @@ void Ctrl::PanicMsgBox(const char *title, const char *text) LLOG("PanicMsgBox " << title << ": " << text); if(gdk_pointer_is_grabbed()) gdk_pointer_ungrab(CurrentTime); + char m[2000]; + *m = 0; if(system("which gxmessage") == 0) - IGNORE_RESULT(system(String().Cat() << "gxmessage -center \"" << title << "\n" << text << "\"")); + strcpy(m, "gxmessage -center \""); else if(system("which kdialog") == 0) - IGNORE_RESULT(system(String().Cat() << "kdialog --error \"" << title << "\n" << text << "\"")); + strcpy(m, "kdialog --error \""); else if(system("which xmessage") == 0) - IGNORE_RESULT(system(String().Cat() << "xmessage -center \"" << title << "\n" << text << "\"")); + strcpy(m, "xmessage -center \""); + + if(*m) { + strcat(m, title); + strcat(m, "\n"); + strcat(m, text); + strcat(m, "\""); + IGNORE_RESULT(system(m)); + } else { _DBG_Ungrab(); GtkWidget *dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR,