Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2012-06-25 14:35:24 +0400
committerCampbell Barton <ideasman42@gmail.com>2012-06-25 14:35:24 +0400
commit3c8a4c458bc66cfe54e83c00f2d4460a52e04535 (patch)
tree151c0fa579ac0fcdc7230e8224bfdaf3c3c2ed87
parentcc0784c1b9c4d813837dedddd5b2b4c52fe291f0 (diff)
more guardedalloc use in C++, also make compositorMutex a static var, was allocated and never freed.
-rw-r--r--CMakeLists.txt1
-rw-r--r--intern/ghost/GHOST_ISystem.h9
-rw-r--r--intern/ghost/GHOST_ISystemPaths.h5
-rw-r--r--intern/ghost/GHOST_ITimerTask.h9
-rw-r--r--intern/ghost/GHOST_Types.h6
-rw-r--r--intern/ghost/intern/GHOST_CallbackEventConsumer.h4
-rw-r--r--intern/ghost/intern/GHOST_DisplayManager.h5
-rw-r--r--intern/ghost/intern/GHOST_EventManager.h5
-rw-r--r--intern/ghost/intern/GHOST_SystemPaths.h3
-rw-r--r--intern/ghost/intern/GHOST_TimerManager.h5
-rw-r--r--intern/guardedalloc/cpp/mallocn.cpp30
-rw-r--r--source/blender/compositor/intern/COM_ChunkOrderHotspot.h9
-rw-r--r--source/blender/compositor/intern/COM_ExecutionSystem.cpp4
-rw-r--r--source/blender/compositor/intern/COM_NodeOperation.h4
-rw-r--r--source/blender/compositor/intern/COM_Socket.h4
-rw-r--r--source/blender/compositor/intern/COM_SocketReader.h4
-rw-r--r--source/blender/compositor/intern/COM_compositor.cpp15
-rw-r--r--source/gameengine/Expressions/PyObjectPlus.h2
18 files changed, 92 insertions, 32 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index f3614007ef9..0fb635d45d5 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1723,6 +1723,7 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${PLATFORM_CFLAGS} ${CXX_WARNINGS}")
# better not set includes here but this debugging option is off by default.
if(WITH_CXX_GUARDEDALLOC)
include_directories(${CMAKE_SOURCE_DIR}/intern/guardedalloc)
+ add_definitions(-DWITH_CXX_GUARDEDALLOC)
endif()
if(WITH_ASSERT_ABORT)
diff --git a/intern/ghost/GHOST_ISystem.h b/intern/ghost/GHOST_ISystem.h
index bd4f3aed5aa..0bc09077f39 100644
--- a/intern/ghost/GHOST_ISystem.h
+++ b/intern/ghost/GHOST_ISystem.h
@@ -415,14 +415,9 @@ protected:
/** The one and only system */
static GHOST_ISystem *m_system;
+
#ifdef WITH_CXX_GUARDEDALLOC
-public:
- void *operator new(size_t num_bytes) {
- return MEM_mallocN(num_bytes, "GHOST:GHOST_ISystem");
- }
- void operator delete(void *mem) {
- MEM_freeN(mem);
- }
+ MEM_CXX_CLASS_ALLOC_FUNCS("GHOST:GHOST_ISystem")
#endif
};
diff --git a/intern/ghost/GHOST_ISystemPaths.h b/intern/ghost/GHOST_ISystemPaths.h
index ee8bd9d1eda..1ba4ceaaaba 100644
--- a/intern/ghost/GHOST_ISystemPaths.h
+++ b/intern/ghost/GHOST_ISystemPaths.h
@@ -98,6 +98,11 @@ public:
private:
/** The one and only system paths*/
static GHOST_ISystemPaths *m_systemPaths;
+
+
+#ifdef WITH_CXX_GUARDEDALLOC
+ MEM_CXX_CLASS_ALLOC_FUNCS("GHOST:GHOST_ISystemPaths")
+#endif
};
#endif
diff --git a/intern/ghost/GHOST_ITimerTask.h b/intern/ghost/GHOST_ITimerTask.h
index bb4a81be5f8..08c4890939f 100644
--- a/intern/ghost/GHOST_ITimerTask.h
+++ b/intern/ghost/GHOST_ITimerTask.h
@@ -84,14 +84,9 @@ public:
*/
virtual void setUserData(const GHOST_TUserDataPtr userData) = 0;
+
#ifdef WITH_CXX_GUARDEDALLOC
-public:
- void *operator new(size_t num_bytes) {
- return MEM_mallocN(num_bytes, "GHOST:GHOST_ITimerTask");
- }
- void operator delete(void *mem) {
- MEM_freeN(mem);
- }
+ MEM_CXX_CLASS_ALLOC_FUNCS("GHOST:GHOST_ITimerTask")
#endif
};
diff --git a/intern/ghost/GHOST_Types.h b/intern/ghost/GHOST_Types.h
index 8454f338645..4921acde670 100644
--- a/intern/ghost/GHOST_Types.h
+++ b/intern/ghost/GHOST_Types.h
@@ -37,7 +37,11 @@
#include "MEM_guardedalloc.h"
#endif
-#define GHOST_DECLARE_HANDLE(name) typedef struct name##__ { int unused; } *name
+#if defined(WITH_CXX_GUARDEDALLOC) && defined(__cplusplus)
+# define GHOST_DECLARE_HANDLE(name) typedef struct name##__ { int unused; MEM_CXX_CLASS_ALLOC_FUNCS(#name) } *name
+#else
+# define GHOST_DECLARE_HANDLE(name) typedef struct name##__ { int unused; } *name
+#endif
typedef char GHOST_TInt8;
typedef unsigned char GHOST_TUns8;
diff --git a/intern/ghost/intern/GHOST_CallbackEventConsumer.h b/intern/ghost/intern/GHOST_CallbackEventConsumer.h
index 61aef742a48..e13a56c38f4 100644
--- a/intern/ghost/intern/GHOST_CallbackEventConsumer.h
+++ b/intern/ghost/intern/GHOST_CallbackEventConsumer.h
@@ -73,6 +73,10 @@ protected:
GHOST_EventCallbackProcPtr m_eventCallback;
/** The data passed back though the call-back routine. */
GHOST_TUserDataPtr m_userData;
+
+#ifdef WITH_CXX_GUARDEDALLOC
+ MEM_CXX_CLASS_ALLOC_FUNCS("GHOST:GHOST_CallbackEventConsumer")
+#endif
};
#endif // __GHOST_CALLBACKEVENTCONSUMER_H__
diff --git a/intern/ghost/intern/GHOST_DisplayManager.h b/intern/ghost/intern/GHOST_DisplayManager.h
index 3e867054d01..7893f0936b3 100644
--- a/intern/ghost/intern/GHOST_DisplayManager.h
+++ b/intern/ghost/intern/GHOST_DisplayManager.h
@@ -133,6 +133,11 @@ protected:
bool m_settingsInitialized;
/** The list with display settings for the main display. */
std::vector<GHOST_DisplaySettings> m_settings;
+
+
+#ifdef WITH_CXX_GUARDEDALLOC
+ MEM_CXX_CLASS_ALLOC_FUNCS("GHOST:GHOST_DisplayManager")
+#endif
};
diff --git a/intern/ghost/intern/GHOST_EventManager.h b/intern/ghost/intern/GHOST_EventManager.h
index f941dac9fb4..eec00789800 100644
--- a/intern/ghost/intern/GHOST_EventManager.h
+++ b/intern/ghost/intern/GHOST_EventManager.h
@@ -168,6 +168,11 @@ protected:
/** The list with event consumers. */
TConsumerVector m_consumers;
+
+
+#ifdef WITH_CXX_GUARDEDALLOC
+ MEM_CXX_CLASS_ALLOC_FUNCS("GHOST:GHOST_EventManager")
+#endif
};
#endif // __GHOST_EVENTMANAGER_H__
diff --git a/intern/ghost/intern/GHOST_SystemPaths.h b/intern/ghost/intern/GHOST_SystemPaths.h
index 75acbf885e3..f53d4f4a7b7 100644
--- a/intern/ghost/intern/GHOST_SystemPaths.h
+++ b/intern/ghost/intern/GHOST_SystemPaths.h
@@ -57,7 +57,7 @@ public:
*/
virtual const GHOST_TUns8 *getSystemDir(int version, const char *versionstr) const = 0;
- /**
+ /**
* Determine the base dir in which user configuration is stored, including versioning.
* If needed, it will create the base directory.
* @return Unsigned char string pointing to user dir (eg ~/.blender/).
@@ -74,7 +74,6 @@ public:
* Add the file to the operating system most recently used files
*/
virtual void addToSystemRecentFiles(const char *filename) const = 0;
-
};
#endif
diff --git a/intern/ghost/intern/GHOST_TimerManager.h b/intern/ghost/intern/GHOST_TimerManager.h
index 0b189cf3aa9..88d27088c1d 100644
--- a/intern/ghost/intern/GHOST_TimerManager.h
+++ b/intern/ghost/intern/GHOST_TimerManager.h
@@ -119,6 +119,11 @@ protected:
typedef std::vector<GHOST_TimerTask *> TTimerVector;
/** The list with event consumers. */
TTimerVector m_timers;
+
+
+#ifdef WITH_CXX_GUARDEDALLOC
+ MEM_CXX_CLASS_ALLOC_FUNCS("GHOST:GHOST_TimerManager")
+#endif
};
#endif // __GHOST_TIMERMANAGER_H__
diff --git a/intern/guardedalloc/cpp/mallocn.cpp b/intern/guardedalloc/cpp/mallocn.cpp
index 130fcb6960b..21f5e323cf2 100644
--- a/intern/guardedalloc/cpp/mallocn.cpp
+++ b/intern/guardedalloc/cpp/mallocn.cpp
@@ -28,20 +28,36 @@
#include <new>
#include "../MEM_guardedalloc.h"
-void* operator new (size_t size)
+/* not default but can be used when needing to set a string */
+void *operator new(size_t size, const char *str)
{
- return MEM_mallocN(size, "C++/anonymous");
+ return MEM_mallocN(size, str);
}
-
-/* not default but can be used when needing to set a string */
-void* operator new (size_t size, const char *str)
+void *operator new[](size_t size, const char *str)
{
return MEM_mallocN(size, str);
}
-void operator delete (void *p)
+
+void *operator new(size_t size)
+{
+ return MEM_mallocN(size, "C++/anonymous");
+}
+void *operator new[](size_t size)
+{
+ return MEM_mallocN(size, "C++/anonymous[]");
+}
+
+
+void operator delete(void *p)
+{
+ /* delete NULL is valid in c++ */
+ if (p)
+ MEM_freeN(p);
+}
+void operator delete[](void *p)
{
/* delete NULL is valid in c++ */
- if(p)
+ if (p)
MEM_freeN(p);
}
diff --git a/source/blender/compositor/intern/COM_ChunkOrderHotspot.h b/source/blender/compositor/intern/COM_ChunkOrderHotspot.h
index ceb5934a7df..68140745f8b 100644
--- a/source/blender/compositor/intern/COM_ChunkOrderHotspot.h
+++ b/source/blender/compositor/intern/COM_ChunkOrderHotspot.h
@@ -23,6 +23,10 @@
#ifndef _COM_ChunkOrderHotSpot_h_
#define _COM_ChunkOrderHotSpot_h_
+#ifdef WITH_CXX_GUARDEDALLOC
+#include "MEM_guardedalloc.h"
+#endif
+
class ChunkOrderHotspot {
private:
int x;
@@ -32,6 +36,11 @@ private:
public:
ChunkOrderHotspot(int x, int y, float addition);
double determineDistance(int x, int y);
+
+
+#ifdef WITH_CXX_GUARDEDALLOC
+ MEM_CXX_CLASS_ALLOC_FUNCS("COM:ChunkOrderHotspot")
+#endif
};
#endif
diff --git a/source/blender/compositor/intern/COM_ExecutionSystem.cpp b/source/blender/compositor/intern/COM_ExecutionSystem.cpp
index 7e09486fd0b..5001cabbd9f 100644
--- a/source/blender/compositor/intern/COM_ExecutionSystem.cpp
+++ b/source/blender/compositor/intern/COM_ExecutionSystem.cpp
@@ -41,6 +41,10 @@
#include "BKE_global.h"
+#ifdef WITH_CXX_GUARDEDALLOC
+#include "MEM_guardedalloc.h"
+#endif
+
ExecutionSystem::ExecutionSystem(RenderData *rd, bNodeTree *editingtree, bool rendering)
{
context.setbNodeTree(editingtree);
diff --git a/source/blender/compositor/intern/COM_NodeOperation.h b/source/blender/compositor/intern/COM_NodeOperation.h
index f96b994685a..bf2dbd8c9c0 100644
--- a/source/blender/compositor/intern/COM_NodeOperation.h
+++ b/source/blender/compositor/intern/COM_NodeOperation.h
@@ -270,6 +270,10 @@ protected:
* @brief set if this NodeOperation can be scheduled on a OpenCLDevice
*/
void setOpenCL(bool openCL) { this->openCL = openCL; }
+
+#ifdef WITH_CXX_GUARDEDALLOC
+ MEM_CXX_CLASS_ALLOC_FUNCS("COM:NodeOperation")
+#endif
};
#endif
diff --git a/source/blender/compositor/intern/COM_Socket.h b/source/blender/compositor/intern/COM_Socket.h
index 4f82a490e14..9feef1bae93 100644
--- a/source/blender/compositor/intern/COM_Socket.h
+++ b/source/blender/compositor/intern/COM_Socket.h
@@ -29,6 +29,10 @@
#include "DNA_node_types.h"
#include "COM_defines.h"
+#ifdef WITH_CXX_GUARDEDALLOC
+#include "MEM_guardedalloc.h"
+#endif
+
using namespace std;
class SocketConnection;
class NodeBase;
diff --git a/source/blender/compositor/intern/COM_SocketReader.h b/source/blender/compositor/intern/COM_SocketReader.h
index f4f58e6e007..df8899e8eea 100644
--- a/source/blender/compositor/intern/COM_SocketReader.h
+++ b/source/blender/compositor/intern/COM_SocketReader.h
@@ -25,6 +25,10 @@
#include "BLI_rect.h"
#include "COM_defines.h"
+#ifdef WITH_CXX_GUARDEDALLOC
+#include "MEM_guardedalloc.h"
+#endif
+
typedef enum PixelSampler {
COM_PS_NEAREST,
COM_PS_BILINEAR,
diff --git a/source/blender/compositor/intern/COM_compositor.cpp b/source/blender/compositor/intern/COM_compositor.cpp
index bec9ff95eed..ccd3b2e6458 100644
--- a/source/blender/compositor/intern/COM_compositor.cpp
+++ b/source/blender/compositor/intern/COM_compositor.cpp
@@ -33,20 +33,21 @@ extern "C" {
#include "COM_WorkScheduler.h"
#include "OCL_opencl.h"
-static ThreadMutex *compositorMutex;
+static ThreadMutex compositorMutex = {{0}};
+static char is_compositorMutex_init = FALSE;
void COM_execute(RenderData *rd, bNodeTree *editingtree, int rendering)
{
- if (compositorMutex == NULL) { /// TODO: move to blender startup phase
- compositorMutex = new ThreadMutex();
- BLI_mutex_init(compositorMutex);
+ if (is_compositorMutex_init == FALSE) { /// TODO: move to blender startup phase
+ BLI_mutex_init(&compositorMutex);
OCL_init();
WorkScheduler::initialize(); ///TODO: call workscheduler.deinitialize somewhere
+ is_compositorMutex_init = TRUE;
}
- BLI_mutex_lock(compositorMutex);
+ BLI_mutex_lock(&compositorMutex);
if (editingtree->test_break(editingtree->tbh)) {
// during editing multiple calls to this method can be triggered.
// make sure one the last one will be doing the work.
- BLI_mutex_unlock(compositorMutex);
+ BLI_mutex_unlock(&compositorMutex);
return;
}
@@ -60,5 +61,5 @@ void COM_execute(RenderData *rd, bNodeTree *editingtree, int rendering)
system->execute();
delete system;
- BLI_mutex_unlock(compositorMutex);
+ BLI_mutex_unlock(&compositorMutex);
}
diff --git a/source/gameengine/Expressions/PyObjectPlus.h b/source/gameengine/Expressions/PyObjectPlus.h
index af8acaa993f..2fee6aaab92 100644
--- a/source/gameengine/Expressions/PyObjectPlus.h
+++ b/source/gameengine/Expressions/PyObjectPlus.h
@@ -166,7 +166,7 @@ public: \
void *operator new(size_t num_bytes) { \
return MEM_mallocN(num_bytes, Type.tp_name); \
} \
- void operator delete( void *mem ) { \
+ void operator delete(void *mem) { \
MEM_freeN(mem); \
} \