diff options
| author | Neil <nyamatongwe@gmail.com> | 2020-06-06 13:41:58 +1000 | 
|---|---|---|
| committer | Neil <nyamatongwe@gmail.com> | 2020-06-06 13:41:58 +1000 | 
| commit | 554d1cc7c885291618ec50b6045e27fc1cf87a28 (patch) | |
| tree | 85b548fe63cc42a1487ad8f8122d341bcdad9138 | |
| parent | f1f8eeddbe3437c3e3f4f4580435996ea3cd0904 (diff) | |
| download | scintilla-mirror-554d1cc7c885291618ec50b6045e27fc1cf87a28.tar.gz | |
Backport: Add ReleaseUnknown to safely release IUnknown* and avoid warnings when done in
noexcept context.
Backport of changeset 8286:bddda9b7df4f.
| -rw-r--r-- | win32/PlatWin.cxx | 11 | ||||
| -rw-r--r-- | win32/PlatWin.h | 17 | ||||
| -rw-r--r-- | win32/ScintillaWin.cxx | 8 | 
3 files changed, 22 insertions, 14 deletions
| diff --git a/win32/PlatWin.cxx b/win32/PlatWin.cxx index 75d420068..9d5d32141 100644 --- a/win32/PlatWin.cxx +++ b/win32/PlatWin.cxx @@ -199,9 +199,7 @@ struct FormatAndMetrics {  		if (hfont)  			::DeleteObject(hfont);  #if defined(USE_D2D) -		if (pTextFormat) -			pTextFormat->Release(); -		pTextFormat = nullptr; +		ReleaseUnknown(pTextFormat);  #endif  		extraFontFlag = 0;  		characterSet = 0; @@ -1143,10 +1141,7 @@ SurfaceD2D::~SurfaceD2D() {  }  void SurfaceD2D::Clear() noexcept { -	if (pBrush) { -		pBrush->Release(); -		pBrush = nullptr; -	} +	ReleaseUnknown(pBrush);  	if (pRenderTarget) {  		while (clipsActive) {  			pRenderTarget->PopAxisAlignedClip(); @@ -1154,7 +1149,7 @@ void SurfaceD2D::Clear() noexcept {  		}  		if (ownRenderTarget) {  			pRenderTarget->EndDraw(); -			pRenderTarget->Release(); +			ReleaseUnknown(pRenderTarget);  			ownRenderTarget = false;  		}  		pRenderTarget = nullptr; diff --git a/win32/PlatWin.h b/win32/PlatWin.h index 2555daac0..23c889d14 100644 --- a/win32/PlatWin.h +++ b/win32/PlatWin.h @@ -52,6 +52,23 @@ T DLLFunction(HMODULE hModule, LPCSTR lpProcName) noexcept {  	return fp;  } +// Release an IUnknown* and set to nullptr. +// While IUnknown::Release must be noexcept, it isn't marked as such so produces +// warnings which are avoided by the catch. +template <class T> +void ReleaseUnknown(T *&ppUnknown) noexcept { +	if (ppUnknown) { +		try { +			ppUnknown->Release(); +		} +		catch (...) { +			// Never occurs +		} +		ppUnknown = nullptr; +	} +} + +  UINT DpiForWindow(WindowID wid) noexcept;  int SystemMetricsForDpi(int nIndex, UINT dpi) noexcept; diff --git a/win32/ScintillaWin.cxx b/win32/ScintillaWin.cxx index c33944db4..651a2629f 100644 --- a/win32/ScintillaWin.cxx +++ b/win32/ScintillaWin.cxx @@ -672,10 +672,7 @@ void ScintillaWin::EnsureRenderTarget(HDC hdc) {  }  void ScintillaWin::DropRenderTarget() { -	if (pRenderTarget) { -		pRenderTarget->Release(); -		pRenderTarget = nullptr; -	} +	ReleaseUnknown(pRenderTarget);  }  #endif @@ -3533,8 +3530,7 @@ LRESULT PASCAL ScintillaWin::CTWndProc(  #endif  				surfaceWindow->Release();  #if defined(USE_D2D) -				if (pCTRenderTarget) -					pCTRenderTarget->Release(); +				ReleaseUnknown(pCTRenderTarget);  #endif  				::EndPaint(hWnd, &ps);  				return 0; | 
