[Bf-blender-cvs] [b617832] compositor-2016: GHOST cleanup (null check before delete, and 0 -> NULL for pointers).

Bastien Montagne noreply at git.blender.org
Wed Jun 8 21:49:50 CEST 2016


Commit: b6178322dd813f0a9bdcb35ff1c78d20935f5b7b
Author: Bastien Montagne
Date:   Tue May 24 11:47:48 2016 +0200
Branches: compositor-2016
https://developer.blender.org/rBb6178322dd813f0a9bdcb35ff1c78d20935f5b7b

GHOST cleanup (null check before delete, and 0 -> NULL for pointers).

Based on patch from Lawrence D'Oliveiro (ldo) in T48499.

===================================================================

M	intern/ghost/intern/GHOST_ContextSDL.cpp
M	intern/ghost/intern/GHOST_DropTargetWin32.cpp
M	intern/ghost/intern/GHOST_ISystem.cpp
M	intern/ghost/intern/GHOST_ISystemPaths.cpp
M	intern/ghost/intern/GHOST_System.cpp
M	intern/ghost/intern/GHOST_SystemCocoa.mm
M	intern/ghost/intern/GHOST_SystemWin32.cpp
M	intern/ghost/intern/GHOST_SystemX11.cpp
M	intern/ghost/intern/GHOST_Window.h
M	intern/ghost/intern/GHOST_WindowCocoa.mm
M	intern/ghost/intern/GHOST_WindowManager.cpp
M	intern/ghost/intern/GHOST_WindowWin32.cpp

===================================================================

diff --git a/intern/ghost/intern/GHOST_ContextSDL.cpp b/intern/ghost/intern/GHOST_ContextSDL.cpp
index d80a638..39627fa 100644
--- a/intern/ghost/intern/GHOST_ContextSDL.cpp
+++ b/intern/ghost/intern/GHOST_ContextSDL.cpp
@@ -69,7 +69,7 @@ GHOST_ContextSDL::GHOST_ContextSDL(
 GHOST_ContextSDL::~GHOST_ContextSDL()
 {
 	if (m_context != NULL) {
-		if (m_window != 0 && m_context == SDL_GL_GetCurrentContext())
+		if (m_window != NULL && m_context == SDL_GL_GetCurrentContext())
 			SDL_GL_MakeCurrent(m_window, m_context);
 
 		if (m_context != s_sharedContext || s_sharedCount == 1) {
diff --git a/intern/ghost/intern/GHOST_DropTargetWin32.cpp b/intern/ghost/intern/GHOST_DropTargetWin32.cpp
index fd9abce..96ff79a 100644
--- a/intern/ghost/intern/GHOST_DropTargetWin32.cpp
+++ b/intern/ghost/intern/GHOST_DropTargetWin32.cpp
@@ -75,7 +75,7 @@ HRESULT __stdcall GHOST_DropTargetWin32::QueryInterface(REFIID riid, void **ppvO
 		return S_OK;
 	}
 	else {
-		*ppvObj = 0;
+		*ppvObj = NULL;
 		return E_NOINTERFACE;
 	}
 }
@@ -97,8 +97,7 @@ ULONG __stdcall GHOST_DropTargetWin32::Release(void)
 {
 	ULONG refs = ::InterlockedDecrement(&m_cRef);
 		
-	if (refs == 0)
-	{
+	if (refs == 0) {
 		delete this;
 		return 0;
 	}
diff --git a/intern/ghost/intern/GHOST_ISystem.cpp b/intern/ghost/intern/GHOST_ISystem.cpp
index d7dd2b1..37d5926 100644
--- a/intern/ghost/intern/GHOST_ISystem.cpp
+++ b/intern/ghost/intern/GHOST_ISystem.cpp
@@ -54,7 +54,7 @@
 #  endif
 #endif
 
-GHOST_ISystem *GHOST_ISystem::m_system = 0;
+GHOST_ISystem *GHOST_ISystem::m_system = NULL;
 
 
 GHOST_TSuccess GHOST_ISystem::createSystem()
@@ -76,7 +76,7 @@ GHOST_TSuccess GHOST_ISystem::createSystem()
 #    endif
 #  endif
 #endif
-		success = m_system != 0 ? GHOST_kSuccess : GHOST_kFailure;
+		success = m_system != NULL ? GHOST_kSuccess : GHOST_kFailure;
 	}
 	else {
 		success = GHOST_kFailure;
@@ -92,7 +92,7 @@ GHOST_TSuccess GHOST_ISystem::disposeSystem()
 	GHOST_TSuccess success = GHOST_kSuccess;
 	if (m_system) {
 		delete m_system;
-		m_system = 0;
+		m_system = NULL;
 	}
 	else {
 		success = GHOST_kFailure;
diff --git a/intern/ghost/intern/GHOST_ISystemPaths.cpp b/intern/ghost/intern/GHOST_ISystemPaths.cpp
index 6ebcb37..93ca0bc 100644
--- a/intern/ghost/intern/GHOST_ISystemPaths.cpp
+++ b/intern/ghost/intern/GHOST_ISystemPaths.cpp
@@ -36,6 +36,9 @@
  * \date	May 7, 2001
  */
 
+
+#include <stdio.h> /* just for NULL */
+
 #include "GHOST_ISystemPaths.h"
 
 #ifdef WIN32
@@ -49,7 +52,7 @@
 #endif
 
 
-GHOST_ISystemPaths *GHOST_ISystemPaths::m_systemPaths = 0;
+GHOST_ISystemPaths *GHOST_ISystemPaths::m_systemPaths = NULL;
 
 
 GHOST_TSuccess GHOST_ISystemPaths::create()
@@ -65,7 +68,7 @@ GHOST_TSuccess GHOST_ISystemPaths::create()
 		m_systemPaths = new GHOST_SystemPathsUnix();
 #  endif
 #endif 
-		success = m_systemPaths != 0 ? GHOST_kSuccess : GHOST_kFailure;
+		success = m_systemPaths != NULL ? GHOST_kSuccess : GHOST_kFailure;
 	}
 	else {
 		success = GHOST_kFailure;
@@ -78,7 +81,7 @@ GHOST_TSuccess GHOST_ISystemPaths::dispose()
 	GHOST_TSuccess success = GHOST_kSuccess;
 	if (m_systemPaths) {
 		delete m_systemPaths;
-		m_systemPaths = 0;
+		m_systemPaths = NULL;
 	}
 	else {
 		success = GHOST_kFailure;
diff --git a/intern/ghost/intern/GHOST_System.cpp b/intern/ghost/intern/GHOST_System.cpp
index 0f5c822..639ce45 100644
--- a/intern/ghost/intern/GHOST_System.cpp
+++ b/intern/ghost/intern/GHOST_System.cpp
@@ -88,7 +88,7 @@ GHOST_ITimerTask *GHOST_System::installTimer(GHOST_TUns64 delay,
 		}
 		else {
 			delete timer;
-			timer = 0;
+			timer = NULL;
 		}
 	}
 	return timer;
@@ -328,27 +328,22 @@ GHOST_TSuccess GHOST_System::exit()
 	if (getFullScreen()) {
 		endFullScreen();
 	}
-	if (m_displayManager) {
-		delete m_displayManager;
-		m_displayManager = NULL;
-	}
-	if (m_windowManager) {
-		delete m_windowManager;
-		m_windowManager = NULL;
-	}
-	if (m_timerManager) {
-		delete m_timerManager;
-		m_timerManager = NULL;
-	}
-	if (m_eventManager) {
-		delete m_eventManager;
-		m_eventManager = NULL;
-	}
+
+	delete m_displayManager;
+	m_displayManager = NULL;
+
+	delete m_windowManager;
+	m_windowManager = NULL;
+
+	delete m_timerManager;
+	m_timerManager = NULL;
+
+	delete m_eventManager;
+	m_eventManager = NULL;
+
 #ifdef WITH_INPUT_NDOF
-	if (m_ndofManager) {
-		delete m_ndofManager;
-		m_ndofManager = 0;
-	}
+	delete m_ndofManager;
+	m_ndofManager = NULL;
 #endif
 	return GHOST_kSuccess;
 }
diff --git a/intern/ghost/intern/GHOST_SystemCocoa.mm b/intern/ghost/intern/GHOST_SystemCocoa.mm
index bf44d93..c9855cf 100644
--- a/intern/ghost/intern/GHOST_SystemCocoa.mm
+++ b/intern/ghost/intern/GHOST_SystemCocoa.mm
@@ -539,7 +539,7 @@ GHOST_IWindow* GHOST_SystemCocoa::createWindow(
 )
 {
 	NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
-	GHOST_IWindow* window = 0;
+	GHOST_IWindow* window = NULL;
 	
 	//Get the available rect for including window contents
 	NSRect frame = [[NSScreen mainScreen] visibleFrame];
@@ -567,7 +567,7 @@ GHOST_IWindow* GHOST_SystemCocoa::createWindow(
 	else {
 		GHOST_PRINT("GHOST_SystemCocoa::createWindow(): window invalid\n");
 		delete window;
-		window = 0;
+		window = NULL;
 	}
 	
 	[pool drain];
diff --git a/intern/ghost/intern/GHOST_SystemWin32.cpp b/intern/ghost/intern/GHOST_SystemWin32.cpp
index d8ec827..43fb5dc 100644
--- a/intern/ghost/intern/GHOST_SystemWin32.cpp
+++ b/intern/ghost/intern/GHOST_SystemWin32.cpp
@@ -253,7 +253,7 @@ GHOST_IWindow *GHOST_SystemWin32::createWindow(
 	else {
 		GHOST_PRINT("GHOST_SystemWin32::createWindow(): window invalid\n");
 		delete window;
-		window = 0;
+		window = NULL;
 	}
 
 	return window;
@@ -766,7 +766,7 @@ GHOST_EventKey *GHOST_SystemWin32::processKeyEvent(GHOST_WindowWin32 *window, RA
 		// GHOST_PRINTF("%c\n", ascii); // we already get this info via EventPrinter
 	}
 	else {
-		event = 0;
+		event = NULL;
 	}
 	return event;
 }
@@ -900,7 +900,7 @@ bool GHOST_SystemWin32::processNDOF(RAWINPUT const &raw)
 
 LRESULT WINAPI GHOST_SystemWin32::s_wndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
 {
-	GHOST_Event *event = 0;
+	GHOST_Event *event = NULL;
 	bool eventHandled = false;
 
 	LRESULT lResult = 0;
diff --git a/intern/ghost/intern/GHOST_SystemX11.cpp b/intern/ghost/intern/GHOST_SystemX11.cpp
index 95dea38..c9946c1 100644
--- a/intern/ghost/intern/GHOST_SystemX11.cpp
+++ b/intern/ghost/intern/GHOST_SystemX11.cpp
@@ -302,7 +302,7 @@ createWindow(const STR_String& title,
 		const bool exclusive,
 		const GHOST_TEmbedderWindowID parentWindow)
 {
-	GHOST_WindowX11 *window = 0;
+	GHOST_WindowX11 *window = NULL;
 	
 	if (!m_display) return 0;
 	
@@ -324,7 +324,7 @@ createWindow(const STR_String& title,
 		}
 		else {
 			delete window;
-			window = 0;
+			window = NULL;
 		}
 	}
 	return window;
diff --git a/intern/ghost/intern/GHOST_Window.h b/intern/ghost/intern/GHOST_Window.h
index 52cb9cb..d778628 100644
--- a/intern/ghost/intern/GHOST_Window.h
+++ b/intern/ghost/intern/GHOST_Window.h
@@ -106,7 +106,7 @@ public:
 	 * \return The validity of the window.
 	 */
 	virtual bool getValid() const { 
-		return m_context != 0;
+		return m_context != NULL;
 	}
 
 	/**
diff --git a/intern/ghost/intern/GHOST_WindowCocoa.mm b/intern/ghost/intern/GHOST_WindowCocoa.mm
index b3fc8ef..00e00b6 100644
--- a/intern/ghost/intern/GHOST_WindowCocoa.mm
+++ b/intern/ghost/intern/GHOST_WindowCocoa.mm
@@ -663,7 +663,7 @@ GHOST_WindowCocoa::~GHOST_WindowCocoa()
 
 bool GHOST_WindowCocoa::getValid() const
 {
-	return GHOST_Window::getValid() && m_window != 0 && m_openGLView != 0;
+	return GHOST_Window::getValid() && m_window != NULL && m_openGLView != NULL;
 }
 
 void* GHOST_WindowCocoa::getOSWindow() const
diff --git a/intern/ghost/intern/GHOST_WindowManager.cpp b/intern/ghost/intern/GHOST_WindowManager.cpp
index 83490ce..790c73d 100644
--- a/intern/ghost/intern/GHOST_WindowManager.cpp
+++ b/intern/ghost/intern/GHOST_WindowManager.cpp
@@ -110,7 +110,7 @@ bool GHOST_WindowManager::getWindowFound(const GHOST_IWindow *window) const
 
 bool GHOST_WindowManager::getFullScreen(void) const
 {
-	return m_fullScreenWindow != 0;
+	return m_fullScreenWindow != NULL;
 }
 
 
@@ -140,13 +140,13 @@ GHOST_TSuccess GHOST_WindowManager::endFullScreen(void)
 {
 	GHOST_TSuccess success = GHOST_kFailure;
 	if (getFullScreen()) {
-		if (m_fullScreenWindow != 0) {
+		if (m_fullScreenWindow != NULL) {
 			//GHOST_PRINT("GHOST_WindowManager::endFullScreen(): deleting full-screen window\n");
 			setWindowInactive(m_fullScreenWindow);
 			m_fullScreenWindow->endFullScreen();
 			delete m_fullScreenWindow;
 			//GHOST_PRINT("GHOST_WindowManager::endFullScreen(): done\n");
-			m_fullScreenWindow = 0;
+			m_fullScreenWindow = NULL;
 			if (m_activeWindowBeforeFullScreen) {
 				setActiveWindow(m_activeWindowBeforeFullScreen);
 			}
@@ -181,7 +181,7 @@ GHOST_IWindow *GHOST_WindowManager::getActiveWindow(void) const
 void GHOST_WindowManager::setWindowInactive(const GHOST_IWindow *window)
 {
 	if (window == m_activeWindow) {
-		m_activeWindow = 0;
+		m_activeWindow = NULL;
 	}
 }
 
diff --git a/intern/ghost/intern/GHOST_WindowWin32.cpp b/intern/ghost/intern/GHOST_WindowWin32.cpp
index 7247753..81c08f4 100644
--- a/intern/ghost/intern/GHOST_WindowWin32.cpp
+++ b/intern/ghost/intern/GHOST_WindowWin32.cpp
@@ -339,8 +339,7 @@ GHOST_WindowWin32::~GHOST_WindowWin32()
 		if (fpWTClose) {
 			if (m_tablet)
 				fpWTClose(m_tablet);
-			if (m_tabletData)
-				delete m_tabletData;
+			delete m_tabletData;
 			m_tabletData = NULL;
 		}
 	}




More information about the Bf-blender-cvs mailing list