From f8af2601c28464ea50029d60c792cc961b835960 Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Sun, 17 Jan 2021 23:57:37 +0100 Subject: [PATCH] Add wxOSX_VERIFY_NOERR macro and use it in wxOSX code This macro replaces the deprecated __Verify_noErr defined in the SDK. It is different from assert, as the expression given to the macro is always evaluated and then, if the result is not zero, and asserts are on, an assert containing a human readable message with the description of the error code is triggered. Closes https://github.com/wxWidgets/wxWidgets/pull/1973 Co-authored-by: Vadim Zeitlin --- include/wx/osx/core/private.h | 12 ++++++++++++ src/osx/carbon/region.cpp | 10 +++++----- src/osx/core/bitmap.cpp | 4 ++-- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/include/wx/osx/core/private.h b/include/wx/osx/core/private.h index bc4c852bce..cc584f563b 100644 --- a/include/wx/osx/core/private.h +++ b/include/wx/osx/core/private.h @@ -1098,5 +1098,17 @@ protected: T m_ptr; }; +// This macro checks if the evaluation of cond, having a return value of +// OS Error type, is zero, ie no error occurred, and calls the assert handler +// with the provided message if it isn't. +#define wxOSX_VERIFY_NOERR(cond) \ + wxSTATEMENT_MACRO_BEGIN \ + const unsigned long evalOnce = (cond); \ + if ( evalOnce != 0 ) \ + { \ + wxFAIL_COND_MSG(#cond, GetMacOSStatusErrorString(evalOnce)); \ + } \ + wxSTATEMENT_MACRO_END + #endif // _WX_PRIVATE_CORE_H_ diff --git a/src/osx/carbon/region.cpp b/src/osx/carbon/region.cpp index 907b0f33fd..48e6213059 100644 --- a/src/osx/carbon/region.cpp +++ b/src/osx/carbon/region.cpp @@ -1036,7 +1036,7 @@ bool wxRegion::DoOffset(wxCoord x, wxCoord y) AllocExclusive(); - __Verify_noErr(HIShapeOffset( M_REGION , x , y )) ; + wxOSX_VERIFY_NOERR(HIShapeOffset( M_REGION , x , y )) ; return true ; } @@ -1091,11 +1091,11 @@ bool wxRegion::DoCombine(const wxRegion& region, wxRegionOp op) switch (op) { case wxRGN_AND: - __Verify_noErr(HIShapeIntersect( M_REGION , OTHER_M_REGION(region) , M_REGION )); + wxOSX_VERIFY_NOERR(HIShapeIntersect( M_REGION , OTHER_M_REGION(region) , M_REGION )); break ; case wxRGN_OR: - __Verify_noErr(HIShapeUnion( M_REGION , OTHER_M_REGION(region) , M_REGION )); + wxOSX_VERIFY_NOERR(HIShapeUnion( M_REGION , OTHER_M_REGION(region) , M_REGION )); break ; case wxRGN_XOR: @@ -1103,12 +1103,12 @@ bool wxRegion::DoCombine(const wxRegion& region, wxRegionOp op) // XOR is defined as the difference between union and intersection wxCFRef< HIShapeRef > unionshape( HIShapeCreateUnion( M_REGION , OTHER_M_REGION(region) ) ); wxCFRef< HIShapeRef > intersectionshape( HIShapeCreateIntersection( M_REGION , OTHER_M_REGION(region) ) ); - __Verify_noErr(HIShapeDifference( unionshape, intersectionshape, M_REGION )); + wxOSX_VERIFY_NOERR(HIShapeDifference( unionshape, intersectionshape, M_REGION )); } break ; case wxRGN_DIFF: - __Verify_noErr(HIShapeDifference( M_REGION , OTHER_M_REGION(region) , M_REGION )) ; + wxOSX_VERIFY_NOERR(HIShapeDifference( M_REGION , OTHER_M_REGION(region) , M_REGION )) ; break ; case wxRGN_COPY: diff --git a/src/osx/core/bitmap.cpp b/src/osx/core/bitmap.cpp index 8ea663286f..8a10cc4f93 100644 --- a/src/osx/core/bitmap.cpp +++ b/src/osx/core/bitmap.cpp @@ -893,7 +893,7 @@ IconRef wxBitmap::GetIconRef() const IconRef wxBitmap::CreateIconRef() const { IconRef icon = GetIconRef(); - __Verify_noErr(AcquireIconRef(icon)); + wxOSX_VERIFY_NOERR(AcquireIconRef(icon)); return icon; } #endif @@ -1897,7 +1897,7 @@ bool wxICNSResourceHandler::LoadFile(wxBitmap *bitmap, { IconRef iconRef = NULL ; - __Verify_noErr(GetIconRef( kOnSystemDisk, kSystemIconsCreator, theId, &iconRef )) ; + wxOSX_VERIFY_NOERR(GetIconRef( kOnSystemDisk, kSystemIconsCreator, theId, &iconRef )) ; img = wxOSXGetNSImageFromIconRef(iconRef); } else