From bbecfcfd472b0d6118bd2e8f789492371ed8a1ad Mon Sep 17 00:00:00 2001 From: ADAM David Alan Martin Date: Wed, 24 Apr 2024 21:58:14 -0400 Subject: [PATCH] Start the long road to exception readiness. --- sc2/src/uqm/planets/pstarmap-modern.cpp | 14 ++++++++------ sc2/src/uqm/starmap.h | 8 +++++++- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/sc2/src/uqm/planets/pstarmap-modern.cpp b/sc2/src/uqm/planets/pstarmap-modern.cpp index 1e8fff7e8..2429aada2 100644 --- a/sc2/src/uqm/planets/pstarmap-modern.cpp +++ b/sc2/src/uqm/planets/pstarmap-modern.cpp @@ -61,9 +61,15 @@ SortStarsOnName (STAR_SEARCH_STATE *pSS) } +// Since HMalloc just terminates on failure, +// we can use `new` safely from mixed C++ and +// C. Either I'll use `std::new_handler` to +// do the same thing... or just let exceptions +// tear it down by bumping into the `noexcept` +// boundaries I'll stick on the `extern "C"` +// interfaces. extern "C" bool -DoStarSearch (MENU_STATE *pMS) -try +DoStarSearch (MENU_STATE *pMS) noexcept { TEXTENTRY_STATE tes; bool success; @@ -98,7 +104,3 @@ try return success; } -catch( const std::bad_alloc & ) -{ - return FALSE; -} diff --git a/sc2/src/uqm/starmap.h b/sc2/src/uqm/starmap.h index 5409f5bd6..070d9dc6b 100644 --- a/sc2/src/uqm/starmap.h +++ b/sc2/src/uqm/starmap.h @@ -22,8 +22,14 @@ #include "uqm/menustat.h" #include "uqm/controls.h" +#ifndef CXX_NOEXCEPT +#define CXX_NOEXCEPT +#endif + #if defined(__cplusplus) extern "C" { +#undef CXX_NOEXCEPT +#define CXX_NOEXCEPT noexcept #endif extern STAR_DESC *CurStarDescPtr; @@ -65,7 +71,7 @@ typedef struct starsearch_state int *SortedStars; } STAR_SEARCH_STATE; -bool DoStarSearch( MENU_STATE * ); +bool DoStarSearch( MENU_STATE * ) CXX_NOEXCEPT; BOOLEAN OnStarNameChange( TEXTENTRY_STATE * ); BOOLEAN OnStarNameFrame ( TEXTENTRY_STATE *pTES );